Jump to content
OMRON Forums

GetResponse method returning wrong data


RickJames
 Share

Recommended Posts

I'm using VB 2008 to communicate with a Power Pmac. I declare an object to the PowerPmacComLib library, and open an asynchronous connection. I created a function for getting variable values, and a sub for setting variable values on the Power Pmac, which use the same connection. When using the SetVariable sub, it should return a null string when the GetResponse method succeeds. But about 1 out of 10 times(and it varies), I will get the results of a GetVariable function call which apparenty is being issued at the same time. So instead of a null string, I get a string of variable values seperated by a delimiter. The SetVariable/GetVariable calls are being made from 2 different Timers.Timer's elapsed events running at different interval times. Should I use 2 different Power Pmac object and connections? Since the connection is asyncronous, are the calls crashing on the Power Pmac side of the process? See code examples below, and thanks for any suggestions you may have. Rick Examples: Private objPowerPmac As New PowerPmacComLib.DTCommunication mResult = objPowerPmac.GPAscii2Connect(.PPmac_Address, 23, .PPmac_Login, .PPmac_Passwd) Public Function GetVariable(ByVal VarName As String) As String Dim fname As String = "GetVariable" Dim mResponse As String = "" 'Dim pos As Integer Try objPowerPmac.GetResponse(VarName, mResponse) If InStr(mResponse.ToUpper, "ERROR") > 0 Then DisplayMsg("The GetResponse method returned an error.") End If Return mResponse Catch ex As Exception DisplayMsg(fname & ":" & ex.Message) Return "" End Try End Function Public Sub SetVariable(ByVal VarName As String, ByVal Value As String) Dim fname As String = "SetVariable" Dim mResponse As String = "" Try objPowerPmac.GetResponse(VarName & "=" & Value, mResponse) 'If InStr("ERROR", mResponse.ToUpper) > 0 Then If mResponse.Length > 0 Then Throw New Exception("The GetResponse method returned an error.") End If Catch ex As Exception Throw New Exception(fname & ":" & ex.Message) End Try End Sub
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The problem is that you are using asyncronous method which means after you send a command you do not block the comms channel and wait for the response to come back. In asynchronous mode the commnds go out and you later check if a response has come back. If thread A sends a command then thread B sends another right after and then checks for an answer it might get the answer to thread A's question. Either use synchrounous methods or use seperate connections.
Link to comment
Share on other sites

That was the conclusion I came up with also. So if I'm issuing GetResponse method calls in a single thread and I issue 2 back to back, I shouldn't have these collisions? Now my questions is about creating a synchronous connection. The PowerPmacComLib has 2 types of connections: DTCommunication AsyncDTCommunication I made the assumption (since there is no com library documentation yet) that the DTCommunication class is the synchronous connection. And that the AsyncDTCommunication class is the asyncronous. Also, the AsyncDTCommunication class has the AsyncGetResponse method. Here is the VB code examples I used to create the class object and retrieve data: Dim objPPMac As New PowerPmacComLib.DTCommunication bIsConnected = objPPMac.GPAscii2Connect("192.168.1.200", 23, "root", "deltatau") objPPMac.GetResponse(TextBox2.Text, mResponse) According to the C# demo application that came with the com lib, this is the code I should be using for a syncronous connection. If I'm wrong, would you send me an example of what my connection code should look like? Thank you for your quick response. I appreciate your help.
Link to comment
Share on other sites

[quote='RickJames' pid='933' dateline='1291993795'] That was the conclusion I came up with also. So if I'm issuing GetResponse method calls in a single thread and I issue 2 back to back, I shouldn't have these collisions? Now my questions is about creating a synchronous connection. The PowerPmacComLib has 2 types of connections: DTCommunication AsyncDTCommunication I made the assumption (since there is no com library documentation yet) that the DTCommunication class is the synchronous connection. And that the AsyncDTCommunication class is the asyncronous. Also, the AsyncDTCommunication class has the AsyncGetResponse method. Here is the VB code examples I used to create the class object and retrieve data: Dim objPPMac As New PowerPmacComLib.DTCommunication bIsConnected = objPPMac.GPAscii2Connect("192.168.1.200", 23, "root", "deltatau") objPPMac.GetResponse(TextBox2.Text, mResponse) According to the C# demo application that came with the com lib, this is the code I should be using for a syncronous connection. If I'm wrong, would you send me an example of what my connection code should look like? Thank you for your quick response. I appreciate your help. [/quote] My understanding is that it still depends on if you are using synchronous or asynchronous comms. Asynchronous means you must wait for the answer. It is meant for situation where you send some question to PPmac and later you check if the answer has been given. So two sequential GetResponse in asynch mode will not always get their respective answer back. The example code should be correct.
Link to comment
Share on other sites

Example: Dim mResponse as String = "" Dim objPPMac As New PowerPmacComLib.DTCommunication bIsConnected = objPPMac.GPAscii2Connect("192.168.1.200", 23, "root", "deltatau") objPPMac.GetResponse(TextBox2.Text, mResponse) OK, sorry but I'm still confused. You said "The example code should be correct". Meaning this should create a syncronous comm? I understand the difference between syncrounous and asyncrous. But when using the comm connection created in this example, I still get the wrong data. And I thought this was a syncronous comm connection. Is the example code a syncronous comm connection? Or do I need to loop after the GetResponse method and wait for the mResponse variable to contain the results of the call?
Link to comment
Share on other sites

I need to know when you got this communication library and from whom. I need to figure out if you have the older version. In the ne version there is a VB example and since you reference the C# example it makes me wonder if you have the older library. Also what is the version and date of the IDE you are using? It looks like you are not really in synch mode.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share


×
×
  • Create New...