+(86)0752-5103606 E-mail:info@hytech-cn.com

TIA1500 Modbus Client Pitfalls

Last Updated on 2025-04-14 Hits:92

I need to read and write a Modbus slave these days. I thought it would be easy, but I didn't expect that there were many small pitfalls and I wasted a lot of time. To summarize, I hope that those who come later can avoid some pitfalls.


1. Connect parameters, this pitfall is the most harmful. If it is the default PN port of the PLC, it doesn't matter, the address is generally 64, but I added a 1542 communication card with an address of 587. No matter how I set it, it was wrong, which made me confused. I posted a post for consultation, and a hero reminded me to use TSEND_C to configure the connection, and then tried this connection, and it worked. But after looking at the settings carefully, they were exactly the same as my previous settings. I was puzzled, and then I figured it out later. Let's see the following steps...


2. Modbus slave ID number, I didn't find where to set the station number at the beginning, and I thought it should be 1 by default, anyway, the other party is also 1, so I don't care. Later, I found that I couldn't communicate, so I made a software to simulate the slave station, and found that the default station number was 255. After searching for a long time, I found that the address was in the background data block. I changed FF to 1 to solve the problem. Can the people who made this block pay attention?


3. The address pointer of read/write data wasted a lot of time. At first, I set the address and used the struck type, but it reported an error, and I couldn't find the fault code help file. Later, I changed to the Plc data type, but it still had the same fault. Finally, I changed it to a byte array and it worked. After a lot of trouble, I found that the optimized block can only use arrays! ! ! But it doesn't matter for the non-optimized block, it can be used! ! ! Think about it carefully, is the Connect parameter problem in the first step also the same? Because when TSEND_C is configured, a new DB block will be generated, but the content is exactly the same. Why can it work, but the one I put in the DB block can't? Try again, sure enough, configuring TCON_IP_v4 in the non-optimized block will work!


4. Because the other slave only supports one TCP connection, I wondered if I could call MB_Client twice but use the same Connect. It turns out that I can't...


In short, when using MB_Client, try to use non-optimized blocks!

友情链接: 广州到上海物流 集运系统 情趣家具 猎酷网 物流网站 展会运输 淘宝集运