openplc Linux 使用modbus RTU 从机通讯

1.Linux 环境下,openplc 默认使用的是modbus tcp协议通信。

想要使用串口 modbus rtu 通讯可以通过在runtime中添加SlaveDevices从机设备

2.添加设备,分配地址。

左边添加串口配置,右边是需要通讯的地址,从机地址都是从100开始,100以内是主机使用。地址最好连续分配使用。

Discrete Inputs (%IX100.0):bit操作,离线输入,主机读从机。

Coils (%QX100.0):bit操作,线圈状态,主机写从机。

Input Registers (%IW100):16位数据,输入寄存器,主机只读从机。

Holding Registers - Read (%IW100):16位数据,保持寄存器,主机读从机。

Holding Registers - Write (%QW100):16位数据,保持寄存器,主机写从机。

3.COM port串口扫描不出来问题。

串口比如 /dev/ttySTM2 有驱动但是在添加设备时扫描不出来。可以修改网页代码手动添加设备名就行了。

网页html源码在webserver.py中,

3.1 先修改add-modbus-device 页面, 1133行,把 设备扫描屏蔽,手动添加串口名。

3.2 修改modbus-edit-device编辑页面,1271行,也是一样,直接屏蔽,手动添加。

  1. 添加地址。

如下:添加 QX100.0 主机bit写从机,IX100.0 主机bit读从机。

IW100 主机16bit只读从机,QW100 主机16bit写从机,QW101主机16bit写从机。

  1. 添加代码测试程序。
bash 复制代码
if tcpGet = 1 then
  tcpGet := 0;
  
  ledSet := 1;
  gpioSet :=1;
  
  dacSet := 1024;
  
  qx100 := 1;
  qx100_1 := 1;
  qw100 := 45;
  qw101 := 45;
  
  gpioRead0 := gpioRead;
  adcRead0 := adcRead;
  ix100st := ix100;
  iw100st := iw100;
  {
    printf("/***/\n");
    printf("/**/\n");
    printf("/*/\n");
    printf("/*********gpio10=%d, adc=%f, ix100.0=%d*******/\n",GetFbVar(GPIOREAD0),GetFbVar(ADCREAD0)/100.0,GetFbVar(IX100ST));
    printf("/*********iw100=%d*******/\n",GetFbVar(IW100ST));
    printf("/*/\n");
    printf("/**/\n");
    printf("/***/\n");
  }
elsif tcpGet = 2 then
  tcpGet := 0;
  
  ledSet := 0;
  gpioSet :=0;
  
  dacSet := 3072;
  
  qx100 := 0;
  qx100_1 := 0;
  qw100 := 78;
  qw101 := 78;
  
  gpioRead0 := gpioRead;
  adcRead0 := adcRead;
  ix100st := ix100;
  iw100st := iw100;
  {
    printf("/***/\n");
    printf("/**/\n");
    printf("/*/\n");
    printf("/*********gpio10=%d, adc=%f, ix100.0=%d*******/\n",GetFbVar(GPIOREAD0),GetFbVar(ADCREAD0)/100.0,GetFbVar(IX100ST));
    printf("/*********iw100=%d*******/\n",GetFbVar(IW100ST));
    printf("/*/\n");
    printf("/**/\n");
    printf("/***/\n");
  }
end_if;
  1. modbus rtu从机设备测试。

下载 MThings-下载

配置串口信息

相关推荐
chlk12318 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑19 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件19 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统