NModbus4从PLC读取TXT [英] NModbus4 read TXT from PLC

查看:778
本文介绍了NModbus4从PLC读取TXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NModbus4的C#应用​​程序对Click PLC进行编程. (RS232)

I'm programming a Click PLC with a C# application with NModbus4. (RS232)

现在,我正在尝试读写TXT数据.

Now i'm trying to read and write TXT data.

这是代码和结果:

当我检查Click PLC软件时,我可以看到每个两个字符一个 Modbus地址.

When I check the Click PLC software I can see that for each two chars one Modbus address is used.

如何获取保存在PLC中的文本?有人有主意吗?
PLC中存储的文本为"Dit is tekst"

How can I get the text saved in the PLC? Someone got an idea?
The text stored in the PLC is "Dit is tekst"

推荐答案

Modbus寄存器为16位宽,因此可以存储两个字符.这就是每个两个字符共享相同地址的原因.

A Modbus register is 16-bit wide, so it can store two chars. This is why each two chars share the same address.

也就是说,您需要推断使用的字节顺序:两个字符如何填充到寄存器中?哪一个去往最高有效字节?

That said, you need to infer the byte order used: how are the two chars stuffed into the register? Which one goes to the most significant byte?

以您的示例文本为例,它有12个字符,因此读取6个寄存器就足够了(436865-436870).从调试图片中,地址436865转换为十六进制时,存储值26948、0x6944.查找一个ASCII表并查找代码0x69和0x44.这些是字符"i"和"D"的代码. PLC中的文本以"Di"开头.我们可以推断出,对于存储在寄存器中的每对字符,第二个字符都放置在最高有效字节中.

Take your example text, it has 12 chars, so reading 6 registers is enough (436865-436870). From your debug picture, address 436865 stores value 26948, 0x6944 when converted to hex. Find a ASCII table and look for codes 0x69 and 0x44. These are the codes for chars 'i' and 'D'. The text in the PLC begins with "Di". We can infer that the for each pair of chars stored in a register, the second char is placed in the most significant byte.

然后您可以通过交换每个寄存器中的字节并使用ASCII表转换为char来从PLC中获取文本.

You can then get the text from the PLC by swapping the bytes in each register and converting to a char using a ASCII table.

这篇关于NModbus4从PLC读取TXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆