This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I want to implement a code for Modbus RTU over TCP/IP usng TM4C1294NCPDT launchpad. Does anyone know a library which can be used to implement it. Also is it possible to obtain data from a PLC using modbus TCP/IP and send it to a Server on cloud using the same ethernet port? Please help.
Thanks.
Hi Tanmay,
I don't know whether a ready library is available for your requirement. But you can write a function to convert your MODBUS data packet to MODBUS over TCP/IP by writing your own function.
Take a sample MODBUS packet (say MODBUS master write packet). Here you have the device ID followed by function code, start address, reg count, data, CRC. To convert this packet to MODBUS RTU over TCP/IP, first remove the device ID from the beginning of the packet & also remove the CRC from the end of the packet. Now, add the following header to the packet:
1. Transaction Identifier, 2. Protocol Identifier, 3. Length, 4. Unit ID.
After Unit ID, the rest of the MODBUS RTU packet (from function code to data) will follow. This way your MODBUS RTU over TCP/IP packet is ready.
Send this data packet over Ethernet to the desired IP address, thats all!!
1. Transaction Identifier - 2 bytes: Starting with 1, keep on increasing this value (on each MODBUS query) to 16 then wrap around to 1 again. This field is used to identify individual MODBUS packets & their corresponding responses in systems where multiple MODBUS query may be issued without receiving one to one replies.
2. Protocol Identifier - 2 bytes: Always set this value to zero
3. Length - 2 bytes: This is the length (in bytes) that follows till the end of the data packet
4. Unit ID - 1 byte: Set this to 0x00 or 0xFF. You need to set it to the desired MODBUS RTU over RS485 address just in case the network is having mixed transport type, like MODBUS over RS485 & MODBUS over TCP/IP
Note that ideally TCP port 502 is used for MODBUS applications
Regarding your second question:
Yes, it is possible to use the same LAN network for MODBUS devices & server/cloud access. But for this, you need a LAN network with working net connection. We have earlier setup a LAN network that is connected to internet using a router. The internal LAN network is running with IP series 192.168.0.X & the router is doing the NAT (network address translation); the router is also configured with port forwarding to forward external requests to internal LAN's terminals.
Hope this helps....
Regards
Soumyajit
Check out the tcpEcho example in the CCS IDE. Using this example, you will be able to open a TCP socket connection & achieve the desired results.
-
In the CCS IDE, open: Menu -> View -> Resource Explorer (Examples) -> TI-RTOS for Tiva C -> Tiva C Series -> Tiva TM4C1294NCPDT -> Driver Examples -> EK-TM4C1294NCPDT -> TI Target Examples -> Ethernet Examples -> TCP Echo
-
Regards
Soumyajit