我的客戶想要使用自定義解決方案來控制安裝在其站點中的HVAC系統。 HVAC設備提供MODBUS TCP/IP連接。我是這個領域的新手,對MODBUS沒有任何瞭解。我搜索了互聯網,並發現jamod作爲MODBUS的Java庫。現在我想用jamod編寫一個程序。但我的困惑是如何獲得我想連接的設備的地址。而我的第二個問題是即使我設法連接設備,如何從MODBUS獲得所需的數據(以工程單位,如溫度)。我的問題聽起來很糟糕,但請原諒我,因爲我是這個領域的新手。如何使用jamod連接到設備並解釋數據
0
A
回答
2
如何獲取要連接的設備的地址?
這種類型取決於您是否通過Modbus RTU或Modbus TCP進行連接。 RTU(串行)將有一個你要指定的從站ID,而tcp更直接,從站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();
1
首先,「地址」是不明確的,當你與Modbus/TCP協議的工作,因爲在從機的IP地址,你是事物的單元號與Modbus/TCP通信(通常爲0)以及任何寄存器的地址。
對於「工程單位」問題,您要的是Modbus寄存器映射,包含任何單位或轉換因子。您可能還需要了解數據類型,因爲所有Modbus寄存器都是16位。
相關問題
- 1. GPS跟蹤設備數據解釋
- 2. 從Android設備使用PHP連接到MySQL數據庫
- 3. 使用藍牙連接並從Android設備發送數據到計算機?
- 4. 如何從android設備連接到sql server數據庫
- 5. 如何連接到設備的SQLite數據庫
- 6. 我們如何連接到MySQL數據庫從其他設備
- 7. 發現並連接到BLE設備
- 8. 列出並連接到藍牙設備
- 9. 使用MAC連接到BLE設備ios
- 10. 使用c#連接到IOT設備#
- 11. 使用phpseclib連接到Sonicwall設備
- 12. 使用chrome.bluetooth API連接到設備
- 13. 如何找到連接到Android設備的設備列表?
- 14. 如何連接到藍牙a2dp設備?
- 15. 如何連接到其他設備?
- 16. chromecast如何連接到其他設備?
- 17. 如何將設備連接到Eclipse?
- 18. 如何使用PHP/Mysql使用備份數據庫連接
- 19. 使用Socket通過WiFi創建設備到設備的連接
- 20. 如何在GKSessionModeServer/GKSessionModeClient模型中找到並連接設備
- 21. 如何自動檢測並連接到USB設備?
- 22. 如何與連接到並行端口的設備通話?
- 23. 如何將iPhone設備連接到非iPhone設備?
- 24. 如何將iOS設備連接到自定義USB設備?
- 25. 如何使用Param通過Windows移動設備連接到Webservice?
- 26. 如何通過網絡設備連接到使用PDO的MySQL
- 27. 如何使用Meteor和Cordova BLE插件連接到BLE設備
- 28. 如何使用c連接到網絡上的設備#
- 29. 如何驗證使用opentok連接到系統的設備
- 30. 如何設置「RecordSet」,使用SQL連接到數據庫