Home > Forum > IEC 61131 Programming (LogicLab) > Make a simple Ethernet / Serial converter
- This topic has 3 replies, 2 participants and was last updated 8 years, 1 month ago da Massimo.
-
AuthorPost
-
July 24, 2013 at 1: 24 pm #35391Sergio BertanaAdministrator Forum
I receive a request from a customer to create using a CPU module SlimLine an Ethernet / Serial converter, so here is a program that makes the converter. The heart of the program is based on these lines of code.
IF (((SysGetIChars (Fp [0]) = IChars [0]) AND (IChars [0]> 0))) OR (IChars [0]> 192)) THEN
RxChars [0]: = Sysfread (ADR (RxString), 1, IChars [0], Fp [0]); (* Received characters *)
RxChars [0]: = Sysfwrite (ADR (RxString), 1, RxChars [0], Fp [1]); (* Transmitted characters *)
END_IF;IChars [0]: = SysGetIChars (FP [0]); (* Input characters *)
In practice, the characters received from one stream are cyclically checked and when no characters are received for at least one program loop (Alternatively, a timing can be managed) the characters received from the stream are sent out on the other.
If the number of characters received by one stream exceeds 3/4 of the support buffer (192 bytes), the characters received by the stream are sent out on the other.
Of course, at least 3 converters can be created in the CPU module (one for each of the available serial ports), each converter will be assigned a different TCP port. Here she is Press of the program and the source program.
December 10, 2013 at 9: 34 am #37920Sergio BertanaAdministrator ForumGiven other requests related to this topic, I developed the function block DataStreamExch which allows data to be exchanged between two I/O streams (Manual extract). By defining a TCP socket as a stream and a serial port as another stream, an Ethernet/Serial converter can be easily created.
I attach the Press e source program of use of one SlimLine as an Ethernet/Serial converter.
December 13, 2013 at 4: 36 pm #37926Sergio BertanaAdministrator ForumIf you want to use a VirtualCOM software with the program described above, you can use the HW VSP3 - Virtual Serial Port of the HWgroup, this screenshot illustrates the use of one SlimLine with the serial port virtualization software. The Virtual Serial Port software has been installed on a PC with Windows 7 by setting the COM3 port to the IP address of the SlimLine (192.168.0.162) on port 1000 as defined in the program. A USB / Serial converter is also installed in the PC ATC-810 configured as COM8, its RS232 serial port is connected to the COM0 port of the SlimLineUsing Toolly, two terminal sessions have been opened, one connected to COM3 and one to COM8, as you can see, the data sent on COM3 are received by COM8 and vice versa Attention, the serial communication parameters cannot be set on the COM3 virtual port, the value 9600, e, 8 is indicative because in reality it is SlimLine uses the parameters defined in the program with the FB on its serial COM0 SetSMode.
March 18, 2016 at 1: 20 pm #39468MassimoModeratorI made a version of the program for a client EthToSerialConverter with the new version of LogicLab (Screenshot), the whole program is contained in a single ladder file that can easily be imported into your project if you need to manage a Serial / Ethernet converter (Download program).
-
AuthorPost
- You must be logged in to reply to this topic.