27 lines
820 B
C#
27 lines
820 B
C#
using System.IO.Ports;
|
|
|
|
namespace Modbus.Net.Modbus
|
|
{
|
|
/// <summary>
|
|
/// Modbus/Rtu协议连接器
|
|
/// </summary>
|
|
public class ModbusRtuProtocalLinker : ComProtocalLinker
|
|
{
|
|
public ModbusRtuProtocalLinker(string com, int slaveAddress)
|
|
: base(com, 9600, Parity.None, StopBits.One, 8, slaveAddress)
|
|
{
|
|
}
|
|
|
|
public override bool? CheckRight(byte[] content)
|
|
{
|
|
if (!base.CheckRight(content).Value) return false;
|
|
//CRC校验失败
|
|
if (!Crc16.GetInstance().CrcEfficacy(content))
|
|
throw new ModbusProtocalErrorException(501);
|
|
//Modbus协议错误
|
|
if (content[1] > 127)
|
|
throw new ModbusProtocalErrorException(content[2]);
|
|
return true;
|
|
}
|
|
}
|
|
} |