2014-08-27 update 1

This commit is contained in:
parallelbgls@outlook.com
2014-08-27 15:57:25 +08:00
parent aa1cbf85ba
commit ca030c8f59
24 changed files with 1159 additions and 2371 deletions

View File

@@ -9,62 +9,16 @@ namespace ModBus.Net
/// <summary>
/// 连接对象
/// </summary>
private TcpSocket _socket;
protected TcpProtocalLinker()
{
//初始化连对象
_socket = new TcpSocket(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
_baseConnector = new TcpSocket(ConfigurationManager.IP, int.Parse(ConfigurationManager.Port), false);
}
protected TcpProtocalLinker(string IP)
protected TcpProtocalLinker(string ip)
{
_socket = new TcpSocket(IP, int.Parse(ConfigurationManager.Port), false);
_baseConnector = new TcpSocket(ip, int.Parse(ConfigurationManager.Port), false);
}
public override byte[] SendReceive(byte[] content)
{
//接收数据
byte[] receiveBytes = BytesDecact(_socket.SendMsg(BytesExtend(content)));
//容错处理
if (!CheckRight(receiveBytes)) return null;
//返回数据
return receiveBytes;
}
public override bool SendOnly(byte[] content)
{
return _socket.SendMsgWithoutReturn(BytesExtend(content));
}
}
public class ProtocalErrorException : Exception
{
public ProtocalErrorException(string message):base(message)
{
}
}
public class ModbusProtocalErrorException : ProtocalErrorException
{
public int ErrorMessageNumber { get; private set; }
private static readonly Dictionary<int, string> ProtocalErrorDictionary = new Dictionary<int, string>()
{
{1, "ILLEGAL_FUNCTION"},
{2, "ILLEGAL_DATA_ACCESS"},
{3, "ILLEGAL_DATA_VALUE"},
{4, "SLAVE_DEVICE_FAILURE"},
{5, "ACKNOWLWDGE"},
{6, "SLAVE_DEVICE_BUSY"},
};
public ModbusProtocalErrorException(int messageNumber) : base(ProtocalErrorDictionary[messageNumber])
{
ErrorMessageNumber = messageNumber;
}
}
}
}