简体   繁体   English

如何使用jamod库在Java中实例化Register对象?

[英]How do I instantiate a Register object in Java using the jamod library?

I'm currently working with jamod in order to set up a small control system for work. 我目前正在与jamod合作,以建立一个小型的工作控制系统。 We are working with several PLCs and I need to use the MODBUS protocol for communication. 我们正在使用多个PLC,我需要使用MODBUS协议进行通讯。 I have been able to read the values that are measured by the controllers, however I am unsuccessful in writing to the controller (adjusting amperage). 我已经能够读取控制器所测量的值,但是无法写入控制器(调整安培数)。

My question is, how do I instantiate a Register object using jamod? 我的问题是,如何使用jamod实例化Register对象?

Register[] reg_1 = new Register[5];
        reg_1[0].setValue(16000);

This doesn't work. 这行不通。 Essentially I would like to set the value of the register at position 0 to the integer 16000. I have also tried using 本质上,我想将位置0处的寄存器的值设置为整数16000。我也尝试过使用

reg_1[0].setValue(Integer.parseInt("16000"));

I've been looking through the jamod documentation and can't find any way of creating a proper register object nor any examples of how to set a proper register to write. 我一直在浏览jamod文档,找不到创建适当寄存器对象的任何方法,也找不到如何设置要写入的适当寄存器的任何示例。

If anyone has any ideas, I'd be most grateful. 如果有人有任何想法,我将不胜感激。 :) :)

I figured it out. 我想到了。 The proper way to set up a Register[] for writing, in my case, was setting up several SimpleRegisters made up of UINT_16s,then throwing them into the Register[] array like so: 在我的情况下,设置Register []进行写入的正确方法是设置几个由UINT_16组成的SimpleRegisters,然后将它们放入Register []数组中,如下所示:

        Register reg1 = new SimpleRegister(48911);
        Register reg2 = new SimpleRegister(23593);
        Register reg3 = new SimpleRegister(48911);
        Register reg4 = new SimpleRegister(23593);

        WriteMultipleRegistersRequest req = new WriteMultipleRegistersRequest(41200,new Register[]{reg1,reg2,reg3,reg4});
        WriteMultipleRegistersResponse res = new WriteMultipleRegistersResponse();

Where 41200 was the reference point to which the register writing starts. 其中41200是寄存器写入开始的参考点。 You can do this with multiple amounts, even 1 or 100, and adjust your register amounts accordingly. 您可以使用多个金额(甚至1或100)执行此操作,并相应地调整您的注册金额。 In my case I was sending and receiving two 8bit words from the modbus so I had two registers per value. 在我的情况下,我正在从Modbus发送和接收两个8位字,因此每个值有两个寄存器。

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

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