[英]Have to write a client for poll RS485 by Modbus RTU over Modbus TCP?
我想通過 ethe.net 發送轉換器請求。 我寫了一小段php.代碼:
public function actionModbus()
{
$errors = array();
$warnings = array();
$connection = BinaryStreamConnection::getBuilder()
->setPort(80)
->setHost('192.168.56.205')
->setReadTimeoutSec(3) // increase read timeout to 3 seconds
->build();
$startAddress = 2165;
$quantity = 1;
$slaveId = 1; // RTU packet slave id equivalent is Modbus TCP unitId
$tcpPacket = new ReadHoldingRegistersRequest($startAddress, $quantity, $slaveId);
$rtuPacket = RtuConverter::toRtu($tcpPacket);
try {
$binaryData = $connection->connect()->sendAndReceive($rtuPacket);
$warnings[] = 'RTU Binary received (in hex): ' . unpack('H*', $binaryData)[1] . PHP_EOL;
$response = RtuConverter::fromRtu($binaryData);
$warnings[] = 'Parsed packet (in hex): ' . $response->toHex() . PHP_EOL;
$warnings[] ='Data parsed from packet (bytes):' . PHP_EOL;
print_r($response->getData());
}catch (\Exception $exception)
{
$errors[] = $exception->getMessage();
$errors[] = $exception->getLine();
}finally {
$connection->close();
}
$result = array('errors'=>$errors,'warnings'=>$warnings);
Yii::$app->response->format = Response::FORMAT_JSON;
Yii::$app->response->data = $result;
}
但我想在C#寫一個。請告訴我C#中的庫或示例
有很多可用的庫,包括EasyModbus和NModbus4 ,它們都有很好的文檔和示例(並且在最近的 stackoverflow 問題中提到)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.