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

配置串口信息

相关推荐
Android系统攻城狮34 分钟前
Linux FFmpeg深度解析之avcodec_default_get_encode_buffer调用流程与实战(二十八)
linux·运维·服务器·ffmpeg·车载音视频·ffmpeg音视频
程序员初一36 分钟前
8080 打不开的四层定位:监听地址、ufw、DOCKER 链、安全组
linux·ssh
程序开发阿元38 分钟前
swappiness 60 和 10 差在哪:一台 1C1G 的三轮对比
linux·ssh
无足鸟ICT1 小时前
【RHCA+】mpstat命令(监控CPU)
linux
GeW2 小时前
新质生产力Linux和数据库为啥这么关键
linux
番茄啊3 小时前
linux 开启xftp连接
linux·运维·服务器
CodeYp20193 小时前
第1讲:Linux 基础指令
linux·指令
李松桃3 小时前
基于端口号的服务配置
linux·nginx-核心模块配置
CodeYp20198 小时前
第14讲:mmap 实现文件 LRU 缓存
linux·lru·mmap
程序开发阿元8 小时前
一台 20G 的 VPS 被日志吃掉一半:我按这个顺序查了二十分钟
linux·ssh