簡體   English   中英

如何使用Jamod連接到設備並解釋數據

[英]How do I connect to device using jamod and interpret the data

我的客戶希望通過自定義解決方案控制安裝在其站點中的HVAC系統。 HVAC設備提供MODBUS TCP / IP連接。 我是該領域的新手,對MODBUS不了解。 我在網上搜索,發現jamod是MODBUS的Java庫。 現在,我想使用jamod編寫程序。 但是我的困惑是如何獲取要連接的設備的地址。 我的第二個問題是,即使我設法連接設備,也如何從MODBUS獲取所需的數據(以溫度為單位的工程單位)。 我的問題聽起來很糟糕,但由於我是該領域的新手,請原諒我。

如何獲取要連接的設備的地址?

這種類型取決於您是通過Modbus RTU還是Modbus TCP進行連接。 當tcp更直接時,RTU(串行)將具有您要指定的從站ID,並且從站ID應該始終為1。

如何從MODBUS獲得所需的數據(以溫度為單位的工程單位)?

希望數據已經以工程單位格式化。 檢查設備手冊,並且應該有一個表或圖表將寄存器映射到值。

例:

String portname = "COM1"; //the name of the serial port to be used
int unitid = 1; //the unit identifier we will be talking to, see the first question
int ref = 0; //the reference, where to start reading from
int count = 0; //the count of IR's to read
int repeat = 1; //a loop for repeating the transaction

// setup the modbus master
ModbusCoupler.createModbusCoupler(null);
ModbusCoupler.getReference().setUnitID(1); <-- this is the master id and it doesn't really matter

// setup serial parameters
SerialParameters params = new SerialParameters();
params.setPortName(portname);
params.setBaudRate(9600);
params.setDatabits(8);
params.setParity("None");
params.setStopbits(1);
params.setEncoding("ascii");
params.setEcho(false);

// open the connection
con = new SerialConnection(params);
con.open();

// prepare a request
req = new ReadInputRegistersRequest(ref, count);
req.setUnitID(unitid); // <-- remember, this is the slave id from the first connection
req.setHeadless();

// prepare a transaction
trans = new ModbusSerialTransaction(con);
trans.setRequest(req);

// execute the transaction repeat times because serial connections arn't exactly trustworthy...
int k = 0;
do {
  trans.execute();
  res = (ReadInputRegistersResponse) trans.getResponse();
  for (int n = 0; n < res.getWordCount(); n++) {
    System.out.println("Word " + n + "=" + res.getRegisterValue(n));
  }
  k++;
} while (k < repeat);

// close the connection
con.close();  

首先,當您使用Modbus / TCP時,“地址”是模棱兩可的,因為存在從站的IP地址,要與之通信的單元的編號(對於Modbus / TCP,通常為0)以及任何寄存器。

對於“工程單位”問題,您想要的是Modbus寄存器映射,其中包括任何單位或轉換系數。 您可能還需要了解數據類型,因為所有Modbus寄存器均為16位。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM