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-下载

配置串口信息

相关推荐
ice___Cpu12 分钟前
Linux 基本使用和 web 程序部署 ( 8000 字 Linux 入门 )
linux·运维·前端
z2023050814 分钟前
linux 之0号进程、1号进程、2号进程
linux·运维·服务器
狐心kitsune1 小时前
erlang学习:Linux常用命令1
linux·学习·erlang
DREAM依旧2 小时前
《深入了解 Linux 操作系统》
linux
阿赭ochre2 小时前
Linux环境变量&&进程地址空间
linux·服务器
Iceberg_wWzZ2 小时前
数据结构(Day14)
linux·c语言·数据结构·算法
可儿·四系桜2 小时前
如何在多台Linux虚拟机上安装和配置Zookeeper集群
linux·服务器·zookeeper
Flying_Fish_roe2 小时前
linux-软件包管理-包管理工具(Debian 系)
linux·运维·debian
大广-全栈开发3 小时前
centos 7 安装gitlab
linux·git·centos
666786663 小时前
Mysql高级篇(中)—— SQL优化
linux·运维·服务器·数据库·sql·mysql