Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
I have a few questions about the sysSocket library and about the TCPip example found in the website download area.
First I will tell you guys what I want to reach.
I'm trying to setup a communication between a plc (Wago module) and a computer (windows 7 / application). I searched for some while and i found the sysSocket library. I'm not sure for 150% but with this library my goal should be reached, not?
1) I download and wanted to test the TCPip example (in simulation mode) to get more knowledge about the use of the socket library. But i came with a first disappointment, it didn't work. I couldn't get connection between the Server and Client. If run the program step by step i see the SysSocketOption() gives me a FALSE and the SysSocketBind() also gives me a FALSE, so it doesn't go further. Further debugging doesn't gives me a working example.
What did I do? Load the project, Set simulation mode on, click online, click run, start the client and the server. IP= 127.0.0.1 port 4444 default settings of the example.
2) Is working with sockets the best way to transfer some data (not much) over the network? Like I told before, from the PLC to a Computer and visa versa?
Kind Regards,
Glenn
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I managed to get the socket communication working. Only i run in to a small but important issue.
When i send some chars to my tcp server (PLC), I split up my received chars. The first char followed by nothing and the next run in the repeat loop the other chars.
For example:
I declared a variable "" when I send these chars "+0011-" to my PLC I get the folowing.
abyRecvRaw[1] = +
abyRecvRaw[2] = nothing
..
abyRecvRaw[8] = nothing
the secund repeat gives me this
abyRecvRaw[1] = 0
abyRecvRaw[2] = 0
abyRecvRaw[3] = 1
abyRecvRaw[4] = 1
abyRecvRaw[5] = -
As you can see the send data isn't received well. it should be like this.
abyRecvRaw[1] = +
abyRecvRaw[2] = 0
abyRecvRaw[3] = 0
abyRecvRaw[4] = 1
abyRecvRaw[5] = 1
abyRecvRaw[6] = -
You can find a peice of code below.
Before the core parts you find **, so you can easy track the receiving data part.
If any of you guys have some explaination for it, it should be great.
Kind Regards,
Glenn
Variables
abyRecvRaw:ARRAY[1..8]OFBYTE;
(*Open listening socket*)Â Â IFdiSocket=SOCKET_INVALIDTHENÂ Â Â Â diSocket:=TcpServerOpenSocket(uiPort,1);Â Â ELSEÂ Â Â Â (*Wait for a client connection*)Â Â Â Â IFClient.diSocket=SOCKET_INVALIDTHENÂ Â Â Â Â Â Client:=TcpServerWaitForConnect(diSocket,250);Â Â Â Â ELSEÂ Â Â Â Â Â (*Receive*)Â Â Â Â Â Â REPEAT**Â Â Â Â Â Â Â Â diReceived:=TcpReceiveData(Client.diSocket,ADR(abyRecvRaw),SIZEOF(abyRecvRaw),10);Â Â Â Â Â Â Â Â IFdiReceived<0THEN(*Problem occured*)Â Â Â Â Â Â Â Â Â Â CloseSocket(ADR(Client.diSocket));Â Â Â Â Â Â Â Â Â Â Client.stIPAddress:='';Â Â Â Â Â Â Â Â Â Â LifeSignTimeoutTimer(IN:=FALSE);Â Â Â Â Â Â Â Â ELSIFdiReceived>0THEN(*Something received*)Â Â Â Â Â Â Â Â Â Â LifeSignTimeoutTimer(IN:=FALSE);Â Â Â Â Â Â Â Â Â Â bReceived:=TRUE;Â Â Â Â Â Â Â Â Â Â IFNOT(diReceived=1ANDabyRecvRaw[1]=0)THENÂ Â Â Â Â Â Â Â Â Â Â Â (* Received Protocol data to Protocol_Reader *)Â Â Â Â Â Â Â Â Â Â Â Â abyRecv:=Filter_Protocol_Data(abyRecvRaw);Â Â Â Â Â Â Â Â Â Â Â Â (* Check and Set protocol *)Â Â Â Â Â Â Â Â Â Â Â Â Result:=Protocol_Reader(abyRecv);Â Â Â Â Â Â Â Â Â Â END_IFÂ Â Â Â Â Â Â Â END_IFÂ Â Â Â Â Â UNTILÂ Â Â Â Â Â Â Â diReceived<=0Â Â Â Â Â Â END_REPEAT;
TCPReceiveDAta (FUN)
IFSocketIsReadable(diSocket, diTimeout)THEN**Â Â Â Â TcpReceiveData:=SysSockRecv(diSocket, pbyData, diDataSize, 0); (* Returns 0 if gracefully closed or -1 for an error*)
  IFTcpReceiveData<=0THEN
    TcpReceiveData:=TcpReceiveData-1;
  END_IFEND_IF
Dear all,
I have a few questions about the sysSocket library and about the TCPip example found in the website download area.
First I will tell you guys what I want to reach.
I'm trying to setup a communication between a plc (Wago module) and a computer (windows 7 / application). I searched for some while and i found the sysSocket library. I'm not sure for 150% but with this library my goal should be reached, not?
1) I download and wanted to test the TCPip example (in simulation mode) to get more knowledge about the use of the socket library. But i came with a first disappointment, it didn't work. I couldn't get connection between the Server and Client. If run the program step by step i see the SysSocketOption() gives me a FALSE and the SysSocketBind() also gives me a FALSE, so it doesn't go further. Further debugging doesn't gives me a working example.
What did I do? Load the project, Set simulation mode on, click online, click run, start the client and the server. IP= 127.0.0.1 port 4444 default settings of the example.
2) Is working with sockets the best way to transfer some data (not much) over the network? Like I told before, from the PLC to a Computer and visa versa?
Kind Regards,
Glenn
HI all,
I managed to get the socket communication working. Only i run in to a small but important issue.
When i send some chars to my tcp server (PLC), I split up my received chars. The first char followed by nothing and the next run in the repeat loop the other chars.
For example:
I declared a variable "" when I send these chars "+0011-" to my PLC I get the folowing.
abyRecvRaw[1] = +
abyRecvRaw[2] = nothing
..
abyRecvRaw[8] = nothing
the secund repeat gives me this
abyRecvRaw[1] = 0
abyRecvRaw[2] = 0
abyRecvRaw[3] = 1
abyRecvRaw[4] = 1
abyRecvRaw[5] = -
As you can see the send data isn't received well. it should be like this.
abyRecvRaw[1] = +
abyRecvRaw[2] = 0
abyRecvRaw[3] = 0
abyRecvRaw[4] = 1
abyRecvRaw[5] = 1
abyRecvRaw[6] = -
You can find a peice of code below.
Before the core parts you find **, so you can easy track the receiving data part.
If any of you guys have some explaination for it, it should be great.
Kind Regards,
Glenn
Variables
TCPReceiveDAta (FUN)
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 8