简体   繁体   English

javascript转plc串口modbus rtu问题

[英]javascript to plc serial port modbus rtu problem

I'm trying to establish a communication with a PLC via serial port Modbus RTU using javasccript, I found some libraries online, but I don't know how to manipulate the functions of this libraries in order to write and read data from specific register in the plc, I also guess that I have to do a format changing of data frame from text to hexa.我正在尝试使用 javascript 通过串行端口 Modbus RTU 与 PLC 建立通信,我在网上找到了一些库,但我不知道如何操作这些库的功能以便从特定寄存器写入和读取数据plc,我也猜想我必须将数据帧的格式从文本更改为六进制。 I'm stuck with this for more than a week if you have a lead or explanations plz help me如果您有线索或解释请帮助我,我已经坚持了一个多星期

images: enter image description here图片:在此处输入图片描述

enter image description here在此处输入图像描述

As far as I know, because js cannot directly bypass the browser to obtain the communication permission of the serial port, it cannot directly access the PLC through the browser.据我所知,由于js不能直接绕过浏览器获取串口的通讯权限,所以不能直接通过浏览器访问PLC。

But you can try the LECPServer middleware, which is also developed based on Javascript, and can expose the Modbus address for reading and writing through HTTP POST.不过可以试试LECPServer中间件,也是基于Javascript开发的,可以通过HTTP POST暴露Modbus地址进行读写。

BTW, LECPServer is an open source project.顺便说一句,LECPServer 是一个开源项目。

I would recommend get it working between your code and a Modbus emulator, not the PLC.我建议让它在您的代码和 Modbus 仿真器之间工作,而不是 PLC。 Once you get YOUR code working, then you can work on the PLC.一旦你的代码工作起来,你就可以在 PLC 上工作。

What's cool about using an emulator initially, you could also use IT to be the Master to talk to the PLC (similar to how you got your code working as the Master to the emulator as the Slave).最初使用模拟器有什么好处,您还可以使用 IT 作为主设备与 PLC 对话(类似于您如何让您的代码作为主设备工作,而模拟器作为从设备)。 The emulator can provide good understanding of both sides before getting the 2 ends to talk to themselves (ie the actual Master and the actual Slave(s)).模拟器可以在让两端与自己对话之前提供对双方的良好理解(即实际的 Master 和实际的 Slave(s))。 Emulators can also provide good diagnostic details.模拟器还可以提供良好的诊断细节。 That's one issue when diagnosing comm - which side is causing the problem (or is it a physical layer issue, eg wired wrong).这是诊断通信时的一个问题 - 哪一方导致问题(或者它是物理层问题,例如接线错误)。 A good emulator can help diagnose issues before doing "real" comm.一个好的模拟器可以在进行“真正的”通信之前帮助诊断问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM