[英]Have to write a client for poll RS485 by Modbus RTU over Modbus TCP?
I want to send a converter request via ethe.net.我想通过 ethe.net 发送转换器请求。 I write a small piece of php. code:
我写了一小段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;
}
But I want to write one in C#. Please tell me a library or an example in C#但我想在C#写一个。请告诉我C#中的库或示例
There are quite a few libraries available including EasyModbus and NModbus4 both of which have good documentation and samples (and are mentioned in recent stackoverflow questions).有很多可用的库,包括EasyModbus和NModbus4 ,它们都有很好的文档和示例(并且在最近的 stackoverflow 问题中提到)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.