使用jamod读取正确的schneider momentum plc寄存器或线圈地址

dnph8jn4  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(430)

为了在工作中节省一些钱,我想我会创建一个java程序来对momentum plc进行正确的/写入值,而不必从schneider购买wonderware许可证,但我似乎无法理解plc端的寻址。通讯模式是modbus/tcp,为了在家里测试,我下载了一个plc模拟器,但我也不能让它工作。我很好地连接到它,只是,再一次,似乎不能投票的正确地址。
我试图读取的线圈输出在工作时plc端有400012地址,我试图复制它。
这是我用maven构建的javafx代码,它连接到plc,我可以读取值,但我似乎永远都找不到正确的值。

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import net.wimpi.modbus.io.ModbusTCPTransaction;
import net.wimpi.modbus.msg.ReadCoilsRequest;
import net.wimpi.modbus.msg.ReadCoilsResponse;
import net.wimpi.modbus.net.TCPMasterConnection;

import java.net.InetAddress;

public class PrimaryController {

@FXML
private Label labelValue;

@FXML
private Button primaryButton;

@FXML
void handleGetData(ActionEvent event) {
    try {
        getData();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void getData() throws Exception {

    // Connection
    TCPMasterConnection con = null;
    ModbusTCPTransaction trans = null;
    ReadCoilsRequest req = null;
    ReadCoilsResponse res = null;

    InetAddress ipAddress = null;

    try {
        ipAddress = InetAddress.getByName("localhost");
        con = new TCPMasterConnection(ipAddress);
        con.setPort(502);
        System.out.println("Connecting...");

        con.connect();

        req = new ReadCoilsRequest(12, 1);
        trans = new ModbusTCPTransaction(con);
        trans.setRequest(req);
        trans.execute();
        res = (ReadCoilsResponse) trans.getResponse();
        System.out.println("Response: " + res.getCoils().toString());
        con.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

  }

}

依赖性:

<dependency>
        <groupId>net.wimpi</groupId>
        <artifactId>jamod</artifactId>
        <version>1.2</version>
    </dependency>

这是我正在使用的plc模拟器。
modbus模拟器
我总是得到回复:00000000
是否有人有plc(施耐德动量)和java之间的通信经验?
谢谢!

q3qa4bjr

q3qa4bjr1#

40012或400012类型的地址(使用6位寻址时)对应于“保持寄存器”字段中的16位寄存器,它们不是线圈。
另外,由于第一个线圈在地址00001处,当向读取方法传递偏移量时,您应该传递11而不是12来读取线圈00012
您的代码很可能在“coils”字段中返回coil 00013的值。

相关问题