Dart Home | PowerTCP Telnet for .NET | Custom Development | Reply | PowerTCP Telnet for .NET Topics | Forums |
Author | Forum: PowerTCP Telnet for .NET Topic: Waiting for 2 different responses |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted February 8, 2010 11:11 AM Hi Everyone, When sending a command thru telnet.Write (non-blocking) is there a way to wait between 2 different text responses? telnet.Write("installpkg /tmp/update-v1.0.2.tgz\r") telnet.Marshal(telnet.Read("wait for text response"), Nothing) "wait for text response" could be either: 1. Installation Successfully, Or 2. If you want to upgrade now, enter 'y': Is there a technique to do this? Thanks, xplorer2k |
Jason Farrar (Admin) From: Oneida, NY USA Posts: 223 Member Since: 07/24/07 Extra Support Options Custom Application Development |
posted February 8, 2010 11:44 AM Hi, Telnet.Read has an overload that takes a string array. So to do what you want you would just construct the string array with the possible responses and pass it in to the read method. You can check out the documentation for more information. ~Jason ------ |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted February 8, 2010 2:52 PM Hi Jason, I have checked the help file but I didn't find any examples. Could you please provide a short sample? Thanks very much, xplorer2k |
Jason Farrar (Admin) From: Oneida, NY USA Posts: 223 Member Since: 07/24/07 Extra Support Options Custom Application Development |
posted February 9, 2010 11:50 AM This should do the trick: Dim MyDelimiters() As String = {"First Delimiter", "Second Delimiter"} telnet1.Read(MyDelimiters) ------ |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted February 9, 2010 8:47 PM Thanks Jason! Is there a way to determine which delimeters was first found so as to send the next command: if "First Delimiter" then do action one if "Second Delimiter" then do action two Thanks again, xplorer2k |
Jason Farrar (Admin) From: Oneida, NY USA Posts: 223 Member Since: 07/24/07 Extra Support Options Custom Application Development |
posted February 10, 2010 4:10 PM The read method returns a Data object which has a Delimiter field. This Field contains the Delimiter found so: Dim MyDelimiters() As String = {"First Delimiter", "Second Delimiter"} Dim ReturnData As Data ReturnData = telnet1.Read(MyDelimiters) If (ReturnData.Delimiter = "First Delimiter") 'Do something ElseIf (ReturnData.Delimiter = "Second Delimiter") Then 'Do something different End If ------ |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted February 10, 2010 7:37 PM Thanks Jason, It works great with one exception. If I used this code: telnet.Write("date\r"); string[] MyDelmiters = { "#", "$" }; telnet.Marshal(telnet.Read(MyDelmiters), null); //Data returnData = telnet.Read(MyDelmiters); //if (returnData.Delimiter == "#") // messageStr = "Date"; //else if (returnData.Delimiter == "$") // messageStr = "Invalid"; //Receive data when it is sent by remote host byte[] buffer = new byte[1024]; while (telnet.State != ConnectionState.Closed) telnet.Marshal(telnet.Read(buffer, 0, 1024), null); it produces this output (which inlcludes date information): [anms@VS183ANMS /mnt/flash/home/anms]352$ su Password: [anms@VS183ANMS /mnt/flash/home/anms]356# date Wed Feb 10 16:22:53 PST 2010 [anms@VS183ANMS /mnt/flash/home/anms]356# If I uncomment above code as follows: telnet.Write("date\r"); string[] MyDelmiters = { "#", "$" }; //telnet.Marshal(telnet.Read(MyDelmiters), null); Data returnData = telnet.Read(MyDelmiters); if (returnData.Delimiter == "#") messageStr = "Date"; else if (returnData.Delimiter == "$") messageStr = "Invalid"; //Receive data when it is sent by remote host byte[] buffer = new byte[1024]; while (telnet.State != ConnectionState.Closed) telnet.Marshal(telnet.Read(buffer, 0, 1024), null); It produces the following output (no date information): [anms@VS183ANMS /mnt/flash/home/anms]343$ su Password: [anms@VS183ANMS /mnt/flash/home/anms]347# The string “messageStr,” stores the right info, but it does not allowed the last 2 lines to be printed. Could you please advice how to fix this issue? Thanks again, xplorer2k |
Jason Farrar (Admin) From: Oneida, NY USA Posts: 223 Member Since: 07/24/07 Extra Support Options Custom Application Development |
posted February 11, 2010 10:53 AM The difference between the two is that when you are not assigning to the Data object you are marshaling back to the UI thread. When you are assigning to the Data object you are not marshaling to the UI thread. You can fix this in one of two ways. Since you are using the Marshal method you can evaluate the delimiters in the event handler using it's data object. Alternatively you can just marshal the Data object when you are done with it. Like so: telnet.Write("date\r"); string[] MyDelimiters = { "#", "$" }; //telnet.Marshal(telnet.Read(MyDelimiters), null); Data returnData = telnet.Read(MyDelimiters); if (returnData.Delimiter == "#") messageStr = "Date"; else if (returnData.Delimiter == "$") messageStr = "Invalid"; //Marshal the data object. telnet.Marshal(Data,null) //Receive data when it is sent by remote host byte[] buffer = new byte[1024]; while (telnet.State != ConnectionState.Closed) telnet.Marshal(telnet.Read(buffer, 0, 1024), null); I don't know where you display code is located but from what I see here it's in the event handler for that gets raised when the marshal method is called. ------ |
xplorer2k From: Oxnard, CA USA Posts: 33 Member Since: 03/27/09 |
posted February 11, 2010 8:05 PM Thanks Jason. . . It works great! xplorer2k |
Reply | PowerTCP Telnet for .NET Topics | Forums |
This site is powered by PowerTCP WebServer for ActiveX |