LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for something similar to RS232 InstallComCallback on TCP communication

Solved!
Go to solution

Hello everyone, I hope that you are safe in this COVID situation!

 

I'm writing an Cleco/Apex/Atlas Copco Open Protocol driver, and I need some suggestion.

My problem is that I don't want to call ConnectToTCPServer with a callback function, but I want to install it later.

This is possible in RS232 with the InstallComCallback() function, but is not present in TCP library.

Do you have any idea?

 

Here an explanation of what I have to do:

 

For every message there are:

- Header [20 byte]

- Data Field [variable byte]

- Message End [1 byte]

 

Most of messages waits for ACK:

PC ask: "Communication Start" (MID = 0001);

Server reply: "Communication Start ACK" (MID = 0002).

 

If everything is fine:

PC ask: "Last result data subscribe" (MID = 0060);

Server reply: "Command accepted" (MID = 0005);

 

If everything is fine, I need the callback, so I want to install here the callback:

Server send: "Last tightening result data upload reply" (MID = 0061)

PC reply: "Last tightening result data acknowledge" (MID = 0062)

 

If no messages for 10 second, I will put a 10s timer that I will ResetTimer() every messages, maybe I will create a panel in a thread.

PC ask: "keepalive" (MID = 9999)

Server reply: "keepalive" (MID = 9999).

 

Davide Vittorio G. - TLGB S.R.L.
Italian SW Developer
0 Kudos
Message 1 of 6
(2,990 Views)

As far as I know there is no mean to install a TCP callback after connecting to a server, at least within CVI libraries. You should try digging in WIN SDK for an alternative solution but I bet it is an unknown and risky way.

What I can suggest you is to try developing your code building a state machine inside of the TCP callback, so as to correctly interpret messages received in TCP_DATAREADY event, that is discriminating answers to a query (MID = 2, 5, 9999 or so) from messages originating from the server (MID = 61)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(2,954 Views)

I think it will become too difficult to mantain using WIN SDK, and, honestly, I don't know where to start!

 

I think i will go that way, when TCP_DATAREADY i will read the header (20 byte) and then a switch(MID) and a case for every MID that i will use.

 

now I have to think how to manage the answer wait for the function that need ACK, I want to be sure to proceed only if I have it.

 

maybe a flag put to 0 when i call the function and put to 1 in the callback, and a while(flag == 0) Sleep(0.1) after the request function.

Davide Vittorio G. - TLGB S.R.L.
Italian SW Developer
0 Kudos
Message 3 of 6
(2,937 Views)
Solution
Accepted by topic author holly7787

i think i've found a solution, it is easyer than i think.

 

if I do a MID that need and ACK, just do a ClientTCPRead() after a ClientTCPWrite().

this will intercept the ACK message data, so there will be no TCP_DATAREADY event.

 

the callback will be executed only when i have a subcription event, like a tightening result

Davide Vittorio G. - TLGB S.R.L.
Italian SW Developer
0 Kudos
Message 4 of 6
(2,915 Views)

Estoy tratando de hacer eso mismo pero lo intente con OPC de NI es mas facil pero mas lento 
a comparación de como usted lo esta haciendo 
de la forma en que usted lo hace tengo el valor de torque y angulo pero me faltan funciones como habilitar herramienta asi como la de cambiar PSet 
yo lo realizo con una PCMX de ingersollrand inalambrica

si puede compartirme su idea le estaria agradecido 

0 Kudos
Message 5 of 6
(2,760 Views)

Actually I have dismissed that idea and i'm always using the callback with this open protocol driver.

 

After some test I have seen that, sometimes, the callback interrupt the execution flow and then I get a TCP Read error when the callback is finished and return in my forced reading.

 

I haven't tryed doing a multithread driver, in that case I'll read the callback only with a ProcessTCPEvents, so the normal execution flow will not be interrupted and I think that will work ok, but it will became more complicated and not necessary for this device that doesn't need high communication speed.

 

I've never used an ingersoll rand but I've used both OPC, classic and UA. for the UA you can find a good thread if you look in my post.

for the classic i suggest to use a UIR and datasocked binding option for the object. I use this method to communicate with Bosch-Rexroth PLC using the Indralogic OPC server, don't know if there is something for Ingersoll.

 

please write in english next time

Davide Vittorio G. - TLGB S.R.L.
Italian SW Developer
0 Kudos
Message 6 of 6
(2,755 Views)