PROGRAMPLC_PRGVARÂ Â Â Â sa:SOCKADDRESS;Â Â saSize:DINT;Â Â port:WORD;Â Â hSocket,hClientSocket:UDINT;Â Â maxConnections:DINT:=10;Â Â result:UDINT;Â Â str:STRING:='Hello, Client!';Â Â str2:STRING(255);Â Â numberOfBytes:DINT;Â Â END_VAR
I got exception.
And it doesnt work.
I even cannot connect (using herkules).
I just put in herkules 'tcp client' IP adress -> PLC IP, and port 999 (is it right?)
And i cannot connect, and it doesnt ping.
What am i doing wrong ?
This is result:
What does the "green C" mean ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1) the IP address and port must be converted to network format with SysSockHton* functions:
sa.sin_addr.ulAddr := SysSockHtonl(SOCKET_INADDR_ANY);
sa.sin_port := SysSockHtons(999);
2) saSize must be initialized before performing the SysSockAccept:
In the sa structure will be copied the information of the connected client, so SysSockAccept() must knows the size of the structure passed.
saSize: = SIZEOF(sa);
hClientSocket := SysSockAccept(hSocket, ADR(sa), ADR(saSize), ADR(result));
3) Disable the task watchdog because SysSockAccept is blocking; by default sockets are blocking when created.
The caller task is 'frozen' until someone connects.
Otherwise to prevent the watchdog I suggest you to use the SysSockSelect to check if someone has requested a connection and only then use the SysSockAccept.
The "green C" I think means Constant variable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Moreno hat geschrieben:
1) the IP address and port must be converted to network format with SysSockHton* functions:
sa.sin_addr.ulAddr := SysSockHtonl(SOCKET_INADDR_ANY);
sa.sin_port := SysSockHtons(999);
2) saSize must be initialized before performing the SysSockAccept:
In the sa structure will be copied the information of the connected client, so SysSockAccept() must knows the size of the structure passed.
saSize: = SIZEOF(sa);
hClientSocket := SysSockAccept(hSocket, ADR(sa), ADR(saSize), ADR(result));
3) Disable the task watchdog because SysSockAccept is blocking; by default sockets are blocking when created.
The caller task is 'frozen' until someone connects.
Otherwise to prevent the watchdog I suggest you to use the SysSockSelect to check if someone has requested a connection and only then use the SysSockAccept.
The "green C" I think means Constant variable.
Dear Moreno
Do you have a complete example of a tcp socket server for reading and writing?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-24
Originally created by: KevinR
As TimvH said, please try out the CAA NetBaseSrv "CAA Net Base Services" Library.
You will see - it's much more easier and it's also well documented. You can get it to work in a short time!
Hello Guys!
I'm trying to communicate my robot controler with PLC using TCP server/client.
First what i want to do, is write correct program on PLC, and test it using Herkules program (http://hercules-setup.soft32.com)
In case PLC as server, my code:
I got exception.
And it doesnt work.
I even cannot connect (using herkules).
I just put in herkules 'tcp client' IP adress -> PLC IP, and port 999 (is it right?)
And i cannot connect, and it doesnt ping.
What am i doing wrong ?
This is result:
What does the "green C" mean ?
1) the IP address and port must be converted to network format with SysSockHton* functions:
sa.sin_addr.ulAddr := SysSockHtonl(SOCKET_INADDR_ANY);
sa.sin_port := SysSockHtons(999);
2) saSize must be initialized before performing the SysSockAccept:
In the sa structure will be copied the information of the connected client, so SysSockAccept() must knows the size of the structure passed.
saSize: = SIZEOF(sa);
hClientSocket := SysSockAccept(hSocket, ADR(sa), ADR(saSize), ADR(result));
3) Disable the task watchdog because SysSockAccept is blocking; by default sockets are blocking when created.
The caller task is 'frozen' until someone connects.
Otherwise to prevent the watchdog I suggest you to use the SysSockSelect to check if someone has requested a connection and only then use the SysSockAccept.
The "green C" I think means Constant variable.
Maybe an option is to use the Use Case library: Network.
It has a much friendlier interace than the syssocket library.
See the store for examples.
Dear Moreno
Do you have a complete example of a tcp socket server for reading and writing?
Originally created by: KevinR
As TimvH said, please try out the CAA NetBaseSrv "CAA Net Base Services" Library.
You will see - it's much more easier and it's also well documented. You can get it to work in a short time!
The HTTP Client example (http://store.codesys.com/http-client-example.html
Best Regards,
Kevin
I'm working on a similar project, does anyone have a complete project where a TCP server is configured using Sockets?
Thank you
If you hardware supports CAA NetBaseServices Library, then this may help :
l viewtopic.php?f=11&t=8641 l
I am walking in the same shoes now, have you got any usable resources in this topic? If so, could you share?
Hi all,
Codesys store have a complete Tcp/Ip server and client solution example.
https://store.codesys.com/communication/plc-chat.html m