I would like to create a TCP server in my PLC program. The TCP server needs to communicate with an external device. I have been searching the internet and found that the libraries Syssocket or CAA NetBaseSrv are two possible solutions to create a TCP server. From what I have read, CAA NetBaseSrv is more user-friendly to implement than the Syssocket variant.
However, I am still struggling to actually implement this library. Foremost is my little knowledge about creating a TCP server and how to read/understand each function block, especially the outputs of some blocks and the types, e.g. server has an output CAA.Handle, but I cannot find the explanation of CAA.Handle. I tried to find a good document that can help me understand how to implement a TCP server, but I could not find it.
Thank you in advance,
George
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have tried to follow this example but found one problem.When I disconnect with Hercules the system does not acknowledge the lost of its connection this could result in critical errors.
Because of this error I am trying to implement the Syssocket library. With this library I am having a problem which I could not solve.
When I am trying to get this working, the SysSockBind function gives a value of 16#207 which means adress already in use. I find this weird because of the IP-adress of 0.0.0.0. I think I am converting the Ip-adress in the wrong way, but the code does not give a error arround this. So therefore I cannot find the solution to this problem. I hope someone could help me with this problem.
I do not know what the problem is with the syssocket implementation, but when i read the forums it seems the Net Base Services library is the recommended way to go.
Dear people,
I would like to create a TCP server in my PLC program. The TCP server needs to communicate with an external device. I have been searching the internet and found that the libraries Syssocket or CAA NetBaseSrv are two possible solutions to create a TCP server. From what I have read, CAA NetBaseSrv is more user-friendly to implement than the Syssocket variant.
However, I am still struggling to actually implement this library. Foremost is my little knowledge about creating a TCP server and how to read/understand each function block, especially the outputs of some blocks and the types, e.g. server has an output CAA.Handle, but I cannot find the explanation of CAA.Handle. I tried to find a good document that can help me understand how to implement a TCP server, but I could not find it.
Thank you in advance,
George
Hi George,
I am no expert but recently tried and got it working using this example project:
https://forge.codesys.com/prj/codesys-example/nbs/home/Home/#example-for-tcp-server-tcp-client
BR,
Rinie
Thank you for your advice Rinie,
I have tried to follow this example but found one problem.When I disconnect with Hercules the system does not acknowledge the lost of its connection this could result in critical errors.
Because of this error I am trying to implement the Syssocket library. With this library I am having a problem which I could not solve.
I have the following code:
When I am trying to get this working, the SysSockBind function gives a value of 16#207 which means adress already in use. I find this weird because of the IP-adress of 0.0.0.0. I think I am converting the Ip-adress in the wrong way, but the code does not give a error arround this. So therefore I cannot find the solution to this problem. I hope someone could help me with this problem.
Thanks in advance
George
Hi George,
I do not know what the problem is with the syssocket implementation, but when i read the forums it seems the Net Base Services library is the recommended way to go.
There is another more extensive example here:
https://forge.codesys.com/prj/codesys-example/plc-chat-nbs/home/Home/
I have just tested this example and it works very well, also with closing and opening the connection from hercules...
good luck!