Я хочу отправить запрос на конвертер через ethe rnet. Я пишу небольшой кусочек 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#