2017-2-8 update 1 Add interfaces.
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Modbus.Net.Modbus
|
|||||||
|
|
||||||
#region 读PLC数据
|
#region 读PLC数据
|
||||||
|
|
||||||
public class ReadDataModbusInputStruct : InputStruct
|
public class ReadDataModbusInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ReadDataModbusInputStruct(byte slaveAddress, string startAddress, ushort getCount,
|
public ReadDataModbusInputStruct(byte slaveAddress, string startAddress, ushort getCount,
|
||||||
AddressTranslator addressTranslator)
|
AddressTranslator addressTranslator)
|
||||||
@@ -85,7 +85,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ushort GetCount { get; }
|
public ushort GetCount { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReadDataModbusOutputStruct : OutputStruct
|
public class ReadDataModbusOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ReadDataModbusOutputStruct(byte slaveAddress, byte functionCode,
|
public ReadDataModbusOutputStruct(byte slaveAddress, byte functionCode,
|
||||||
int dataCount, byte[] dataValue)
|
int dataCount, byte[] dataValue)
|
||||||
@@ -107,14 +107,14 @@ namespace Modbus.Net.Modbus
|
|||||||
|
|
||||||
public class ReadDataModbusProtocal : ProtocalUnit
|
public class ReadDataModbusProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (ReadDataModbusInputStruct) message;
|
var r_message = (ReadDataModbusInputStruct) message;
|
||||||
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
||||||
r_message.StartAddress, r_message.GetCount);
|
r_message.StartAddress, r_message.GetCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
||||||
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
||||||
@@ -136,7 +136,7 @@ namespace Modbus.Net.Modbus
|
|||||||
|
|
||||||
#region 写PLC数据
|
#region 写PLC数据
|
||||||
|
|
||||||
public class WriteDataModbusInputStruct : InputStruct
|
public class WriteDataModbusInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public WriteDataModbusInputStruct(byte slaveAddress, string startAddress, object[] writeValue,
|
public WriteDataModbusInputStruct(byte slaveAddress, string startAddress, object[] writeValue,
|
||||||
AddressTranslator addressTranslator)
|
AddressTranslator addressTranslator)
|
||||||
@@ -165,7 +165,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public byte[] WriteValue { get; }
|
public byte[] WriteValue { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WriteDataModbusOutputStruct : OutputStruct
|
public class WriteDataModbusOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public WriteDataModbusOutputStruct(byte slaveAddress, byte functionCode,
|
public WriteDataModbusOutputStruct(byte slaveAddress, byte functionCode,
|
||||||
ushort startAddress, ushort writeCount)
|
ushort startAddress, ushort writeCount)
|
||||||
@@ -190,7 +190,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WriteDataModbusProtocal : ProtocalUnit
|
public class WriteDataModbusProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (WriteDataModbusInputStruct) message;
|
var r_message = (WriteDataModbusInputStruct) message;
|
||||||
var functionCode = r_message.FunctionCode;
|
var functionCode = r_message.FunctionCode;
|
||||||
@@ -207,7 +207,7 @@ namespace Modbus.Net.Modbus
|
|||||||
return formattingBytes;
|
return formattingBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int flag)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int flag)
|
||||||
{
|
{
|
||||||
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
@@ -222,7 +222,7 @@ namespace Modbus.Net.Modbus
|
|||||||
|
|
||||||
#region 读PLC时间
|
#region 读PLC时间
|
||||||
|
|
||||||
public class GetSystemTimeModbusInputStruct : InputStruct
|
public class GetSystemTimeModbusInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public GetSystemTimeModbusInputStruct(byte slaveAddress)
|
public GetSystemTimeModbusInputStruct(byte slaveAddress)
|
||||||
{
|
{
|
||||||
@@ -241,7 +241,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ushort GetCount { get; }
|
public ushort GetCount { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetSystemTimeModbusOutputStruct : OutputStruct
|
public class GetSystemTimeModbusOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public GetSystemTimeModbusOutputStruct(byte slaveAddress, byte functionCode,
|
public GetSystemTimeModbusOutputStruct(byte slaveAddress, byte functionCode,
|
||||||
byte writeByteCount, ushort year, byte day, byte month, ushort hour, byte second, byte minute,
|
byte writeByteCount, ushort year, byte day, byte month, ushort hour, byte second, byte minute,
|
||||||
@@ -267,14 +267,14 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class GetSystemTimeModbusProtocal : ProtocalUnit
|
public class GetSystemTimeModbusProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (GetSystemTimeModbusInputStruct) message;
|
var r_message = (GetSystemTimeModbusInputStruct) message;
|
||||||
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
||||||
r_message.StartAddress, r_message.GetCount);
|
r_message.StartAddress, r_message.GetCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int flag)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int flag)
|
||||||
{
|
{
|
||||||
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
@@ -295,7 +295,7 @@ namespace Modbus.Net.Modbus
|
|||||||
|
|
||||||
#region 写PLC时间
|
#region 写PLC时间
|
||||||
|
|
||||||
public class SetSystemTimeModbusInputStruct : InputStruct
|
public class SetSystemTimeModbusInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public SetSystemTimeModbusInputStruct(byte slaveAddress, DateTime time)
|
public SetSystemTimeModbusInputStruct(byte slaveAddress, DateTime time)
|
||||||
{
|
{
|
||||||
@@ -338,7 +338,7 @@ namespace Modbus.Net.Modbus
|
|||||||
public ushort Millisecond { get; }
|
public ushort Millisecond { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SetSystemTimeModbusOutputStruct : OutputStruct
|
public class SetSystemTimeModbusOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public SetSystemTimeModbusOutputStruct(byte slaveAddress, byte functionCode,
|
public SetSystemTimeModbusOutputStruct(byte slaveAddress, byte functionCode,
|
||||||
ushort startAddress, ushort writeCount)
|
ushort startAddress, ushort writeCount)
|
||||||
@@ -363,7 +363,7 @@ namespace Modbus.Net.Modbus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SetSystemTimeModbusProtocal : ProtocalUnit
|
public class SetSystemTimeModbusProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (SetSystemTimeModbusInputStruct) message;
|
var r_message = (SetSystemTimeModbusInputStruct) message;
|
||||||
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
return Format(r_message.SlaveAddress, r_message.FunctionCode,
|
||||||
@@ -372,7 +372,7 @@ namespace Modbus.Net.Modbus
|
|||||||
r_message.Month, r_message.Hour, r_message.Second, r_message.Minute, r_message.Millisecond);
|
r_message.Month, r_message.Hour, r_message.Second, r_message.Minute, r_message.Millisecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int flag)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int flag)
|
||||||
{
|
{
|
||||||
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var slaveAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
var functionCode = BigEndianValueHelper.Instance.GetByte(messageBytes, ref flag);
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tcp协议字节伸缩
|
/// Tcp协议字节伸缩
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModbusTcpProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
|
public class ModbusTcpProtocalLinkerBytesExtend : IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
public override byte[] BytesExtend(byte[] content)
|
public byte[] BytesExtend(byte[] content)
|
||||||
{
|
{
|
||||||
//Modbus/Tcp协议扩张,前面加6个字节,前面4个为0,后面两个为协议整体内容的长度
|
//Modbus/Tcp协议扩张,前面加6个字节,前面4个为0,后面两个为协议整体内容的长度
|
||||||
var newFormat = new byte[6 + content.Length];
|
var newFormat = new byte[6 + content.Length];
|
||||||
@@ -22,7 +22,7 @@ namespace Modbus.Net.Modbus
|
|||||||
return newFormat;
|
return newFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] BytesDecact(byte[] content)
|
public byte[] BytesDecact(byte[] content)
|
||||||
{
|
{
|
||||||
//Modbus/Tcp协议收缩,抛弃前面6个字节的内容
|
//Modbus/Tcp协议收缩,抛弃前面6个字节的内容
|
||||||
var newContent = new byte[content.Length - 6];
|
var newContent = new byte[content.Length - 6];
|
||||||
@@ -31,9 +31,9 @@ namespace Modbus.Net.Modbus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModbusRtuProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
|
public class ModbusRtuProtocalLinkerBytesExtend : IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
public override byte[] BytesExtend(byte[] content)
|
public byte[] BytesExtend(byte[] content)
|
||||||
{
|
{
|
||||||
var crc = new byte[2];
|
var crc = new byte[2];
|
||||||
//Modbus/Rtu协议扩张,增加CRC校验
|
//Modbus/Rtu协议扩张,增加CRC校验
|
||||||
@@ -44,7 +44,7 @@ namespace Modbus.Net.Modbus
|
|||||||
return newFormat;
|
return newFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] BytesDecact(byte[] content)
|
public byte[] BytesDecact(byte[] content)
|
||||||
{
|
{
|
||||||
//Modbus/Rtu协议收缩,抛弃后面2个字节的内容
|
//Modbus/Rtu协议收缩,抛弃后面2个字节的内容
|
||||||
var newContent = new byte[content.Length - 2];
|
var newContent = new byte[content.Length - 2];
|
||||||
@@ -53,9 +53,9 @@ namespace Modbus.Net.Modbus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModbusAsciiProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
|
public class ModbusAsciiProtocalLinkerBytesExtend : IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
public override byte[] BytesExtend(byte[] content)
|
public byte[] BytesExtend(byte[] content)
|
||||||
{
|
{
|
||||||
//Modbus/Ascii协议扩张,前面增加:,后面增加LRC校验和尾字符
|
//Modbus/Ascii协议扩张,前面增加:,后面增加LRC校验和尾字符
|
||||||
var newContent = new List<byte>();
|
var newContent = new List<byte>();
|
||||||
@@ -70,7 +70,7 @@ namespace Modbus.Net.Modbus
|
|||||||
return newContent.ToArray();
|
return newContent.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] BytesDecact(byte[] content)
|
public byte[] BytesDecact(byte[] content)
|
||||||
{
|
{
|
||||||
//Modbus/Ascii协议收缩,抛弃头尾。
|
//Modbus/Ascii协议收缩,抛弃头尾。
|
||||||
var newContent = new List<byte>();
|
var newContent = new List<byte>();
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.2.0")]
|
[assembly: AssemblyVersion("1.2.2")]
|
||||||
[assembly: AssemblyFileVersion("1.2.0")]
|
[assembly: AssemblyFileVersion("1.2.2")]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Modbus.Net.OPC
|
|||||||
|
|
||||||
#region 读数据
|
#region 读数据
|
||||||
|
|
||||||
public class ReadRequestOpcInputStruct : InputStruct
|
public class ReadRequestOpcInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ReadRequestOpcInputStruct(string tag)
|
public ReadRequestOpcInputStruct(string tag)
|
||||||
{
|
{
|
||||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.OPC
|
|||||||
public string Tag { get; }
|
public string Tag { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReadRequestOpcOutputStruct : OutputStruct
|
public class ReadRequestOpcOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ReadRequestOpcOutputStruct(byte[] value)
|
public ReadRequestOpcOutputStruct(byte[] value)
|
||||||
{
|
{
|
||||||
@@ -34,15 +34,15 @@ namespace Modbus.Net.OPC
|
|||||||
public byte[] GetValue { get; private set; }
|
public byte[] GetValue { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReadRequestOpcProtocal : SpecialProtocalUnit
|
public class ReadRequestOpcProtocal : ProtocalUnit, ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (ReadRequestOpcInputStruct) message;
|
var r_message = (ReadRequestOpcInputStruct) message;
|
||||||
return Format((byte) 0x00, Encoding.UTF8.GetBytes(r_message.Tag));
|
return Format((byte) 0x00, Encoding.UTF8.GetBytes(r_message.Tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
return new ReadRequestOpcOutputStruct(messageBytes);
|
return new ReadRequestOpcOutputStruct(messageBytes);
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ namespace Modbus.Net.OPC
|
|||||||
|
|
||||||
#region 写数据
|
#region 写数据
|
||||||
|
|
||||||
public class WriteRequestOpcInputStruct : InputStruct
|
public class WriteRequestOpcInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public WriteRequestOpcInputStruct(string tag, object setValue)
|
public WriteRequestOpcInputStruct(string tag, object setValue)
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ namespace Modbus.Net.OPC
|
|||||||
public object SetValue { get; }
|
public object SetValue { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WriteRequestOpcOutputStruct : OutputStruct
|
public class WriteRequestOpcOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public WriteRequestOpcOutputStruct(bool writeResult)
|
public WriteRequestOpcOutputStruct(bool writeResult)
|
||||||
{
|
{
|
||||||
@@ -74,9 +74,9 @@ namespace Modbus.Net.OPC
|
|||||||
public bool WriteResult { get; private set; }
|
public bool WriteResult { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WriteRequestOpcProtocal : SpecialProtocalUnit
|
public class WriteRequestOpcProtocal : ProtocalUnit, ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (WriteRequestOpcInputStruct) message;
|
var r_message = (WriteRequestOpcInputStruct) message;
|
||||||
var tag = Encoding.UTF8.GetBytes(r_message.Tag);
|
var tag = Encoding.UTF8.GetBytes(r_message.Tag);
|
||||||
@@ -84,7 +84,7 @@ namespace Modbus.Net.OPC
|
|||||||
return Format((byte) 0x01, tag, 0x00ffff00, fullName, 0x00ffff00, r_message.SetValue);
|
return Format((byte) 0x01, tag, 0x00ffff00, fullName, 0x00ffff00, r_message.SetValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
var ansByte = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
var ansByte = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
||||||
var ans = ansByte != 0;
|
var ans = ansByte != 0;
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.2.0")]
|
[assembly: AssemblyVersion("1.2.2")]
|
||||||
[assembly: AssemblyFileVersion("1.2.0")]
|
[assembly: AssemblyFileVersion("1.2.2")]
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
// 方法是按如下所示使用“*”: :
|
// 方法是按如下所示使用“*”: :
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.2.0")]
|
[assembly: AssemblyVersion("1.2.2")]
|
||||||
[assembly: AssemblyFileVersion("1.2.0")]
|
[assembly: AssemblyFileVersion("1.2.2")]
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Modbus.Net.Siemens
|
|||||||
return await base.SendReceiveAsync(isLittleEndian, content);
|
return await base.SendReceiveAsync(isLittleEndian, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OutputStruct> ForceSendReceiveAsync(ProtocalUnit unit, InputStruct content)
|
private async Task<IOutputStruct> ForceSendReceiveAsync(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
return await base.SendReceiveAsync(unit, content);
|
return await base.SendReceiveAsync(unit, content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 串口连接建立
|
#region 串口连接建立
|
||||||
|
|
||||||
internal class ComCreateReferenceSiemensInputStruct : InputStruct
|
internal class ComCreateReferenceSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ComCreateReferenceSiemensInputStruct(byte slaveAddress, byte masterAddress)
|
public ComCreateReferenceSiemensInputStruct(byte slaveAddress, byte masterAddress)
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public byte MasterAddress { get; set; }
|
public byte MasterAddress { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ComCreateReferenceSiemensOutputStruct : OutputStruct
|
internal class ComCreateReferenceSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ComCreateReferenceSiemensOutputStruct(byte slaveAddress, byte masterAddress, byte confirmMessage)
|
public ComCreateReferenceSiemensOutputStruct(byte slaveAddress, byte masterAddress, byte confirmMessage)
|
||||||
{
|
{
|
||||||
@@ -137,9 +137,9 @@ namespace Modbus.Net.Siemens
|
|||||||
public byte ConfirmMessage { get; set; }
|
public byte ConfirmMessage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ComCreateReferenceSiemensProtocal : SpecialProtocalUnit
|
internal class ComCreateReferenceSiemensProtocal : ProtocalUnit, ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (ComCreateReferenceSiemensInputStruct) message;
|
var r_message = (ComCreateReferenceSiemensInputStruct) message;
|
||||||
var crc = (r_message.SlaveAddress + r_message.MasterAddress + 0x49)%256;
|
var crc = (r_message.SlaveAddress + r_message.MasterAddress + 0x49)%256;
|
||||||
@@ -147,7 +147,7 @@ namespace Modbus.Net.Siemens
|
|||||||
(byte) 0x16);
|
(byte) 0x16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
pos = 1;
|
pos = 1;
|
||||||
var masterAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
var masterAddress = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
||||||
@@ -161,7 +161,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 以太网建立连接
|
#region 以太网建立连接
|
||||||
|
|
||||||
internal class CreateReferenceSiemensInputStruct : InputStruct
|
internal class CreateReferenceSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public byte TdpuSize;
|
public byte TdpuSize;
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ namespace Modbus.Net.Siemens
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CreateReferenceSiemensOutputStruct : OutputStruct
|
internal class CreateReferenceSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public CreateReferenceSiemensOutputStruct(byte tdpuSize, ushort srcTsap, ushort dstTsap)
|
public CreateReferenceSiemensOutputStruct(byte tdpuSize, ushort srcTsap, ushort dstTsap)
|
||||||
{
|
{
|
||||||
@@ -191,9 +191,9 @@ namespace Modbus.Net.Siemens
|
|||||||
public ushort TsapDst { get; private set; }
|
public ushort TsapDst { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CreateReferenceSiemensProtocal : SpecialProtocalUnit
|
internal class CreateReferenceSiemensProtocal : ProtocalUnit, ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (CreateReferenceSiemensInputStruct) message;
|
var r_message = (CreateReferenceSiemensInputStruct) message;
|
||||||
const ushort head = 0x0300;
|
const ushort head = 0x0300;
|
||||||
@@ -213,7 +213,7 @@ namespace Modbus.Net.Siemens
|
|||||||
srcTsapCode, srcTsapContent, dstTsapCode, dstTsapContent);
|
srcTsapCode, srcTsapContent, dstTsapCode, dstTsapContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
pos = 11;
|
pos = 11;
|
||||||
byte tdpuSize = 0;
|
byte tdpuSize = 0;
|
||||||
@@ -247,7 +247,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 串口消息确认
|
#region 串口消息确认
|
||||||
|
|
||||||
public class ComConfirmMessageSiemensInputStruct : InputStruct
|
public class ComConfirmMessageSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ComConfirmMessageSiemensInputStruct(byte slaveAddress, byte masterAddress)
|
public ComConfirmMessageSiemensInputStruct(byte slaveAddress, byte masterAddress)
|
||||||
{
|
{
|
||||||
@@ -259,7 +259,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public byte MasterAddress { get; set; }
|
public byte MasterAddress { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ComConfirmMessageSiemensOutputStruct : OutputStruct
|
public class ComConfirmMessageSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ComConfirmMessageSiemensOutputStruct(byte confirmByte)
|
public ComConfirmMessageSiemensOutputStruct(byte confirmByte)
|
||||||
{
|
{
|
||||||
@@ -269,9 +269,9 @@ namespace Modbus.Net.Siemens
|
|||||||
public byte ConfirmByte { get; set; }
|
public byte ConfirmByte { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ComConfirmMessageSiemensProtocal : SpecialProtocalUnit
|
public class ComConfirmMessageSiemensProtocal : ProtocalUnit, ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (ComConfirmMessageSiemensInputStruct) message;
|
var r_message = (ComConfirmMessageSiemensInputStruct) message;
|
||||||
var crc = r_message.SlaveAddress + r_message.MasterAddress + 0x5c%256;
|
var crc = r_message.SlaveAddress + r_message.MasterAddress + 0x5c%256;
|
||||||
@@ -279,7 +279,7 @@ namespace Modbus.Net.Siemens
|
|||||||
(byte) 0x16);
|
(byte) 0x16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
var confirmByte = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
var confirmByte = BigEndianValueHelper.Instance.GetByte(messageBytes, ref pos);
|
||||||
return new ComConfirmMessageSiemensOutputStruct(confirmByte);
|
return new ComConfirmMessageSiemensOutputStruct(confirmByte);
|
||||||
@@ -290,7 +290,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 以太网连接确认
|
#region 以太网连接确认
|
||||||
|
|
||||||
internal class EstablishAssociationSiemensInputStruct : InputStruct
|
internal class EstablishAssociationSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public EstablishAssociationSiemensInputStruct(ushort pduRef, ushort maxCalling, ushort maxCalled, ushort maxPdu)
|
public EstablishAssociationSiemensInputStruct(ushort pduRef, ushort maxCalling, ushort maxCalled, ushort maxPdu)
|
||||||
{
|
{
|
||||||
@@ -306,7 +306,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public ushort MaxPdu { get; }
|
public ushort MaxPdu { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class EstablishAssociationSiemensOutputStruct : OutputStruct
|
internal class EstablishAssociationSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public EstablishAssociationSiemensOutputStruct(ushort pduRef, ushort maxCalling, ushort maxCalled, ushort maxPdu)
|
public EstablishAssociationSiemensOutputStruct(ushort pduRef, ushort maxCalling, ushort maxCalled, ushort maxPdu)
|
||||||
{
|
{
|
||||||
@@ -324,7 +324,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
internal class EstablishAssociationSiemensProtocal : ProtocalUnit
|
internal class EstablishAssociationSiemensProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (EstablishAssociationSiemensInputStruct) message;
|
var r_message = (EstablishAssociationSiemensInputStruct) message;
|
||||||
const byte protoId = 0x32;
|
const byte protoId = 0x32;
|
||||||
@@ -342,7 +342,7 @@ namespace Modbus.Net.Siemens
|
|||||||
maxCalled, maxPdu);
|
maxCalled, maxPdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
pos = 4;
|
pos = 4;
|
||||||
var pduRef = BigEndianValueHelper.Instance.GetUShort(messageBytes, ref pos);
|
var pduRef = BigEndianValueHelper.Instance.GetUShort(messageBytes, ref pos);
|
||||||
@@ -358,7 +358,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 读数据请求
|
#region 读数据请求
|
||||||
|
|
||||||
public class ReadRequestSiemensInputStruct : InputStruct
|
public class ReadRequestSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ReadRequestSiemensInputStruct(byte slaveAddress, byte masterAddress, ushort pduRef,
|
public ReadRequestSiemensInputStruct(byte slaveAddress, byte masterAddress, ushort pduRef,
|
||||||
SiemensTypeCode getType, string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
SiemensTypeCode getType, string startAddress, ushort getCount, AddressTranslator addressTranslator)
|
||||||
@@ -385,7 +385,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public int Offset { get; }
|
public int Offset { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReadRequestSiemensOutputStruct : OutputStruct
|
public class ReadRequestSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ReadRequestSiemensOutputStruct(ushort pduRef, SiemensAccessResult accessResult, SiemensDataType dataType,
|
public ReadRequestSiemensOutputStruct(ushort pduRef, SiemensAccessResult accessResult, SiemensDataType dataType,
|
||||||
ushort getLength, byte[] value)
|
ushort getLength, byte[] value)
|
||||||
@@ -406,7 +406,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
public class ReadRequestSiemensProtocal : ProtocalUnit
|
public class ReadRequestSiemensProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (ReadRequestSiemensInputStruct) message;
|
var r_message = (ReadRequestSiemensInputStruct) message;
|
||||||
var slaveAddress = r_message.SlaveAddress;
|
var slaveAddress = r_message.SlaveAddress;
|
||||||
@@ -434,7 +434,7 @@ namespace Modbus.Net.Siemens
|
|||||||
offsetBitBytes.Skip(1).ToArray());
|
offsetBitBytes.Skip(1).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
pos = 4;
|
pos = 4;
|
||||||
var pduRef = BigEndianValueHelper.Instance.GetUShort(messageBytes, ref pos);
|
var pduRef = BigEndianValueHelper.Instance.GetUShort(messageBytes, ref pos);
|
||||||
@@ -454,7 +454,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 写数据请求
|
#region 写数据请求
|
||||||
|
|
||||||
public class WriteRequestSiemensInputStruct : InputStruct
|
public class WriteRequestSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public WriteRequestSiemensInputStruct(byte slaveAddress, byte masterAddress, ushort pduRef, string startAddress,
|
public WriteRequestSiemensInputStruct(byte slaveAddress, byte masterAddress, ushort pduRef, string startAddress,
|
||||||
object[] writeValue, AddressTranslator addressTranslator)
|
object[] writeValue, AddressTranslator addressTranslator)
|
||||||
@@ -479,7 +479,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public object[] WriteValue { get; }
|
public object[] WriteValue { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WriteRequestSiemensOutputStruct : OutputStruct
|
public class WriteRequestSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public WriteRequestSiemensOutputStruct(ushort pduRef, SiemensAccessResult accessResult)
|
public WriteRequestSiemensOutputStruct(ushort pduRef, SiemensAccessResult accessResult)
|
||||||
{
|
{
|
||||||
@@ -493,7 +493,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
public class WriteRequestSiemensProtocal : ProtocalUnit
|
public class WriteRequestSiemensProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
var r_message = (WriteRequestSiemensInputStruct) message;
|
var r_message = (WriteRequestSiemensInputStruct) message;
|
||||||
var valueBytes = BigEndianValueHelper.Instance.ObjectArrayToByteArray(r_message.WriteValue);
|
var valueBytes = BigEndianValueHelper.Instance.ObjectArrayToByteArray(r_message.WriteValue);
|
||||||
@@ -525,7 +525,7 @@ namespace Modbus.Net.Siemens
|
|||||||
offsetBitBytes.Skip(1).ToArray(), reserved, type, numberOfWriteBits, valueBytes);
|
offsetBitBytes.Skip(1).ToArray(), reserved, type, numberOfWriteBits, valueBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
if (messageBytes.Length == 1)
|
if (messageBytes.Length == 1)
|
||||||
{
|
{
|
||||||
@@ -548,7 +548,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
#region 读时间请求
|
#region 读时间请求
|
||||||
public class ReadTimeSiemensInputStruct : InputStruct
|
public class ReadTimeSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public ReadTimeSiemensInputStruct(ushort pduRef)
|
public ReadTimeSiemensInputStruct(ushort pduRef)
|
||||||
{
|
{
|
||||||
@@ -558,7 +558,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public ushort PduRef { get; private set; }
|
public ushort PduRef { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReadTimeSiemensOutputStruct : OutputStruct
|
public class ReadTimeSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public ReadTimeSiemensOutputStruct(ushort pduRef, DateTime dateTime, TodClockStatus todClockStatus)
|
public ReadTimeSiemensOutputStruct(ushort pduRef, DateTime dateTime, TodClockStatus todClockStatus)
|
||||||
{
|
{
|
||||||
@@ -574,12 +574,12 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
public class ReadTimeSiemensProtocal : ProtocalUnit
|
public class ReadTimeSiemensProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -589,7 +589,7 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
#region 写时间请求
|
#region 写时间请求
|
||||||
|
|
||||||
public class WriteTimeSiemensInputStruct : InputStruct
|
public class WriteTimeSiemensInputStruct : IInputStruct
|
||||||
{
|
{
|
||||||
public WriteTimeSiemensInputStruct(ushort pduRef, DateTime dateTime, TodClockStatus todClockStatus)
|
public WriteTimeSiemensInputStruct(ushort pduRef, DateTime dateTime, TodClockStatus todClockStatus)
|
||||||
{
|
{
|
||||||
@@ -603,7 +603,7 @@ namespace Modbus.Net.Siemens
|
|||||||
public TodClockStatus TodClockStatus { get; private set; }
|
public TodClockStatus TodClockStatus { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WriteTimeSiemensOutputStruct : OutputStruct
|
public class WriteTimeSiemensOutputStruct : IOutputStruct
|
||||||
{
|
{
|
||||||
public WriteTimeSiemensOutputStruct(ushort pduRef, byte errCod)
|
public WriteTimeSiemensOutputStruct(ushort pduRef, byte errCod)
|
||||||
{
|
{
|
||||||
@@ -617,12 +617,12 @@ namespace Modbus.Net.Siemens
|
|||||||
|
|
||||||
public class WriteTimeSiemensProtocal : ProtocalUnit
|
public class WriteTimeSiemensProtocal : ProtocalUnit
|
||||||
{
|
{
|
||||||
public override byte[] Format(InputStruct message)
|
public override byte[] Format(IInputStruct message)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct Unformat(byte[] messageBytes, ref int pos)
|
public override IOutputStruct Unformat(byte[] messageBytes, ref int pos)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 西门子Tcp协议扩展
|
/// 西门子Tcp协议扩展
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiemensTcpProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
|
public class SiemensTcpProtocalLinkerBytesExtend : IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
public override byte[] BytesExtend(byte[] content)
|
public byte[] BytesExtend(byte[] content)
|
||||||
{
|
{
|
||||||
Array.Copy(new byte[] {0x03, 0x00, 0x00, 0x00, 0x02, 0xf0, 0x80}, 0, content, 0, 7);
|
Array.Copy(new byte[] {0x03, 0x00, 0x00, 0x00, 0x02, 0xf0, 0x80}, 0, content, 0, 7);
|
||||||
Array.Copy(BigEndianValueHelper.Instance.GetBytes((ushort) content.Length), 0, content, 2, 2);
|
Array.Copy(BigEndianValueHelper.Instance.GetBytes((ushort) content.Length), 0, content, 2, 2);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] BytesDecact(byte[] content)
|
public byte[] BytesDecact(byte[] content)
|
||||||
{
|
{
|
||||||
var newContent = new byte[content.Length - 7];
|
var newContent = new byte[content.Length - 7];
|
||||||
Array.Copy(content, 7, newContent, 0, newContent.Length);
|
Array.Copy(content, 7, newContent, 0, newContent.Length);
|
||||||
@@ -25,9 +25,9 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 西门子Ppi协议扩展
|
/// 西门子Ppi协议扩展
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiemensPpiProtocalLinkerBytesExtend : ProtocalLinkerBytesExtend
|
public class SiemensPpiProtocalLinkerBytesExtend : IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
public override byte[] BytesExtend(byte[] content)
|
public byte[] BytesExtend(byte[] content)
|
||||||
{
|
{
|
||||||
var newContent = new byte[content.Length + 2];
|
var newContent = new byte[content.Length + 2];
|
||||||
Array.Copy(content, 0, newContent, 0, content.Length);
|
Array.Copy(content, 0, newContent, 0, content.Length);
|
||||||
@@ -44,7 +44,7 @@ namespace Modbus.Net.Siemens
|
|||||||
return newContent;
|
return newContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] BytesDecact(byte[] content)
|
public byte[] BytesDecact(byte[] content)
|
||||||
{
|
{
|
||||||
var newContent = new byte[content.Length - 9];
|
var newContent = new byte[content.Length - 9];
|
||||||
Array.Copy(content, 7, newContent, 0, newContent.Length);
|
Array.Copy(content, 7, newContent, 0, newContent.Length);
|
||||||
|
|||||||
@@ -55,12 +55,12 @@ namespace Modbus.Net.Siemens
|
|||||||
return await base.SendReceiveAsync(isLittleEndian, content);
|
return await base.SendReceiveAsync(isLittleEndian, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
public override IOutputStruct SendReceive(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => SendReceiveAsync(unit, content));
|
return AsyncHelper.RunSync(() => SendReceiveAsync(unit, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<OutputStruct> SendReceiveAsync(ProtocalUnit unit, InputStruct content)
|
public override async Task<IOutputStruct> SendReceiveAsync(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
if (ProtocalLinker != null && ProtocalLinker.IsConnected) return await base.SendReceiveAsync(unit, content);
|
if (ProtocalLinker != null && ProtocalLinker.IsConnected) return await base.SendReceiveAsync(unit, content);
|
||||||
if (_connectTryCount > 10) return null;
|
if (_connectTryCount > 10) return null;
|
||||||
@@ -71,7 +71,7 @@ namespace Modbus.Net.Siemens
|
|||||||
.ContinueWith(answer => answer.Result ? base.SendReceiveAsync(unit, content) : null);
|
.ContinueWith(answer => answer.Result ? base.SendReceiveAsync(unit, content) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OutputStruct> ForceSendReceiveAsync(ProtocalUnit unit, InputStruct content)
|
private async Task<IOutputStruct> ForceSendReceiveAsync(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
return await base.SendReceiveAsync(unit, content);
|
return await base.SendReceiveAsync(unit, content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ namespace Modbus.Net
|
|||||||
var preAddress = continusAddresses[index];
|
var preAddress = continusAddresses[index];
|
||||||
continusAddresses.RemoveAt(index);
|
continusAddresses.RemoveAt(index);
|
||||||
continusAddresses.RemoveAt(index);
|
continusAddresses.RemoveAt(index);
|
||||||
//变为新的地址段
|
//合并两个已有的地址段,变为一个新的地址段
|
||||||
var newAddress = new CommunicationUnit
|
var newAddress = new CommunicationUnit
|
||||||
{
|
{
|
||||||
Area = nowAddress.Area,
|
Area = nowAddress.Area,
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="unit">协议的实例</param>
|
/// <param name="unit">协议的实例</param>
|
||||||
/// <param name="content">输入信息的结构化描述</param>
|
/// <param name="content">输入信息的结构化描述</param>
|
||||||
/// <returns>输出信息的结构化描述</returns>
|
/// <returns>输出信息的结构化描述</returns>
|
||||||
public virtual OutputStruct SendReceive(ProtocalUnit unit, InputStruct content)
|
public virtual IOutputStruct SendReceive(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
return AsyncHelper.RunSync(() => SendReceiveAsync(unit, content));
|
return AsyncHelper.RunSync(() => SendReceiveAsync(unit, content));
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="unit">协议的实例</param>
|
/// <param name="unit">协议的实例</param>
|
||||||
/// <param name="content">输入信息的结构化描述</param>
|
/// <param name="content">输入信息的结构化描述</param>
|
||||||
/// <returns>输出信息的结构化描述</returns>
|
/// <returns>输出信息的结构化描述</returns>
|
||||||
public virtual async Task<OutputStruct> SendReceiveAsync(ProtocalUnit unit, InputStruct content)
|
public virtual async Task<IOutputStruct> SendReceiveAsync(ProtocalUnit unit, IInputStruct content)
|
||||||
{
|
{
|
||||||
var t = 0;
|
var t = 0;
|
||||||
var formatContent = unit.Format(content);
|
var formatContent = unit.Format(content);
|
||||||
@@ -121,7 +121,7 @@ namespace Modbus.Net
|
|||||||
{
|
{
|
||||||
byte[] receiveContent;
|
byte[] receiveContent;
|
||||||
//如果为特别处理协议的话,跳过协议扩展收缩
|
//如果为特别处理协议的话,跳过协议扩展收缩
|
||||||
if (unit is SpecialProtocalUnit)
|
if (unit is ISpecialProtocalUnit)
|
||||||
{
|
{
|
||||||
receiveContent = await ProtocalLinker.SendReceiveWithoutExtAndDecAsync(formatContent);
|
receiveContent = await ProtocalLinker.SendReceiveWithoutExtAndDecAsync(formatContent);
|
||||||
}
|
}
|
||||||
|
|||||||
43
Modbus.Net/Modbus.Net/IProtocal.cs
Normal file
43
Modbus.Net/Modbus.Net/IProtocal.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net
|
||||||
|
{
|
||||||
|
public interface IProtocal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 发送协议内容并接收,一般方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isLittleEndian">是否是小端格式</param>
|
||||||
|
/// <param name="content">写入的内容,使用对象数组描述</param>
|
||||||
|
/// <returns>从设备获取的字节流</returns>
|
||||||
|
byte[] SendReceive(bool isLittleEndian, params object[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送协议内容并接收,一般方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isLittleEndian">是否是小端格式</param>
|
||||||
|
/// <param name="content">写入的内容,使用对象数组描述</param>
|
||||||
|
/// <returns>从设备获取的字节流</returns>
|
||||||
|
Task<byte[]> SendReceiveAsync(bool isLittleEndian, params object[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送协议,通过传入需要使用的协议内容和输入结构
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unit">协议的实例</param>
|
||||||
|
/// <param name="content">输入信息的结构化描述</param>
|
||||||
|
/// <returns>输出信息的结构化描述</returns>
|
||||||
|
IOutputStruct SendReceive(ProtocalUnit unit, IInputStruct content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送协议,通过传入需要使用的协议内容和输入结构
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unit">协议的实例</param>
|
||||||
|
/// <param name="content">输入信息的结构化描述</param>
|
||||||
|
/// <returns>输出信息的结构化描述</returns>
|
||||||
|
Task<IOutputStruct> SendReceiveAsync(ProtocalUnit unit, IInputStruct content);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">结构化的输入数据</param>
|
/// <param name="message">结构化的输入数据</param>
|
||||||
/// <returns>格式化后的字节流</returns>
|
/// <returns>格式化后的字节流</returns>
|
||||||
byte[] Format(InputStruct message);
|
byte[] Format(IInputStruct message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从对象的参数数组格式化
|
/// 从对象的参数数组格式化
|
||||||
@@ -25,6 +25,6 @@
|
|||||||
/// <param name="messageBytes">返回数据的字节流</param>
|
/// <param name="messageBytes">返回数据的字节流</param>
|
||||||
/// <param name="pos">转换标记位</param>
|
/// <param name="pos">转换标记位</param>
|
||||||
/// <returns>结构化的输出数据</returns>
|
/// <returns>结构化的输出数据</returns>
|
||||||
OutputStruct Unformat(byte[] messageBytes, ref int pos);
|
IOutputStruct Unformat(byte[] messageBytes, ref int pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
60
Modbus.Net/Modbus.Net/IProtocalLinker.cs
Normal file
60
Modbus.Net/Modbus.Net/IProtocalLinker.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Modbus.Net
|
||||||
|
{
|
||||||
|
public interface IProtocalLinker
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 发送并接收数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">发送协议的内容</param>
|
||||||
|
/// <returns>接收协议的内容</returns>
|
||||||
|
byte[] SendReceive(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送并接收数据
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">发送协议的内容</param>
|
||||||
|
/// <returns>接收协议的内容</returns>
|
||||||
|
Task<byte[]> SendReceiveAsync(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送并接收数据,不进行协议扩展和收缩,用于特殊协议
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">发送协议的内容</param>
|
||||||
|
/// <returns>接收协议的内容</returns>
|
||||||
|
byte[] SendReceiveWithoutExtAndDec(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送并接收数据,不进行协议扩展和收缩,用于特殊协议
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">发送协议的内容</param>
|
||||||
|
/// <returns>接收协议的内容</returns>
|
||||||
|
Task<byte[]> SendReceiveWithoutExtAndDecAsync(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查接收的数据是否正确
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">接收协议的内容</param>
|
||||||
|
/// <returns>协议是否是正确的</returns>
|
||||||
|
bool? CheckRight(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 协议内容扩展,发送时根据需要扩展
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">扩展前的基本协议内容</param>
|
||||||
|
/// <returns>扩展后的协议内容</returns>
|
||||||
|
byte[] BytesExtend(byte[] content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 协议内容缩减,接收时根据需要缩减
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">缩减前的完整协议内容</param>
|
||||||
|
/// <returns>缩减后的协议内容</returns>
|
||||||
|
byte[] BytesDecact(byte[] content);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,20 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 协议字节伸缩
|
/// 协议字节伸缩
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ProtocalLinkerBytesExtend
|
public interface IProtocalLinkerBytesExtend
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 协议扩展,协议内容发送前调用
|
/// 协议扩展,协议内容发送前调用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">扩展前的原始协议内容</param>
|
/// <param name="content">扩展前的原始协议内容</param>
|
||||||
/// <returns>扩展后的协议内容</returns>
|
/// <returns>扩展后的协议内容</returns>
|
||||||
public abstract byte[] BytesExtend(byte[] content);
|
byte[] BytesExtend(byte[] content);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 协议收缩,协议内容接收后调用
|
/// 协议收缩,协议内容接收后调用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">收缩前的完整协议内容</param>
|
/// <param name="content">收缩前的完整协议内容</param>
|
||||||
/// <returns>收缩后的协议内容</returns>
|
/// <returns>收缩后的协议内容</returns>
|
||||||
public abstract byte[] BytesDecact(byte[] content);
|
byte[] BytesDecact(byte[] content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,9 +68,11 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="BaseConnector.cs" />
|
<Compile Include="BaseConnector.cs" />
|
||||||
<Compile Include="CRC16.cs" />
|
<Compile Include="CRC16.cs" />
|
||||||
|
<Compile Include="IProtocal.cs" />
|
||||||
<Compile Include="IProtocalFormatting.cs" />
|
<Compile Include="IProtocalFormatting.cs" />
|
||||||
|
<Compile Include="IProtocalLinker.cs" />
|
||||||
<Compile Include="ProtocalLinker.cs" />
|
<Compile Include="ProtocalLinker.cs" />
|
||||||
<Compile Include="ProtocalLinkerBytesExtend.cs" />
|
<Compile Include="IProtocalLinkerBytesExtend.cs" />
|
||||||
<Compile Include="ProtocalUnit.cs" />
|
<Compile Include="ProtocalUnit.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TaskManager.cs" />
|
<Compile Include="TaskManager.cs" />
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
|
|||||||
// 方法是按如下所示使用“*”:
|
// 方法是按如下所示使用“*”:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion("1.2.0")]
|
[assembly: AssemblyVersion("1.2.2")]
|
||||||
[assembly: AssemblyFileVersion("1.2.0")]
|
[assembly: AssemblyFileVersion("1.2.2")]
|
||||||
@@ -113,7 +113,7 @@ namespace Modbus.Net
|
|||||||
//自动查找相应的协议放缩类,命令规则为——当前的实际类名(注意是继承后的)+"BytesExtend"。
|
//自动查找相应的协议放缩类,命令规则为——当前的实际类名(注意是继承后的)+"BytesExtend"。
|
||||||
var bytesExtend =
|
var bytesExtend =
|
||||||
Assembly.Load(GetType().Assembly.FullName).CreateInstance(GetType().FullName + "BytesExtend") as
|
Assembly.Load(GetType().Assembly.FullName).CreateInstance(GetType().FullName + "BytesExtend") as
|
||||||
ProtocalLinkerBytesExtend;
|
IProtocalLinkerBytesExtend;
|
||||||
return bytesExtend?.BytesExtend(content);
|
return bytesExtend?.BytesExtend(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ namespace Modbus.Net
|
|||||||
//自动查找相应的协议放缩类,命令规则为——当前的实际类名(注意是继承后的)+"BytesExtend"。
|
//自动查找相应的协议放缩类,命令规则为——当前的实际类名(注意是继承后的)+"BytesExtend"。
|
||||||
var bytesExtend =
|
var bytesExtend =
|
||||||
Assembly.Load(GetType().Assembly.GetName().Name).CreateInstance(GetType().FullName + "BytesExtend") as
|
Assembly.Load(GetType().Assembly.GetName().Name).CreateInstance(GetType().FullName + "BytesExtend") as
|
||||||
ProtocalLinkerBytesExtend;
|
IProtocalLinkerBytesExtend;
|
||||||
return bytesExtend?.BytesDecact(content);
|
return bytesExtend?.BytesDecact(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">结构化的输入数据</param>
|
/// <param name="message">结构化的输入数据</param>
|
||||||
/// <returns>格式化后的字节流</returns>
|
/// <returns>格式化后的字节流</returns>
|
||||||
public abstract byte[] Format(InputStruct message);
|
public abstract byte[] Format(IInputStruct message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从对象的参数数组格式化
|
/// 从对象的参数数组格式化
|
||||||
@@ -35,7 +35,7 @@ namespace Modbus.Net
|
|||||||
/// <param name="messageBytes">返回数据的字节流</param>
|
/// <param name="messageBytes">返回数据的字节流</param>
|
||||||
/// <param name="pos">转换标记位</param>
|
/// <param name="pos">转换标记位</param>
|
||||||
/// <returns>结构化的输出数据</returns>
|
/// <returns>结构化的输出数据</returns>
|
||||||
public abstract OutputStruct Unformat(byte[] messageBytes, ref int pos);
|
public abstract IOutputStruct Unformat(byte[] messageBytes, ref int pos);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换静态方法,把对象数组转换为字节数组。
|
/// 转换静态方法,把对象数组转换为字节数组。
|
||||||
@@ -52,23 +52,23 @@ namespace Modbus.Net
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 特殊协议单元,继承这个类的协议不会执行BytesExtend和BytesDecact
|
/// 特殊协议单元,写入这个协议不会执行BytesExtend和BytesDecact
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SpecialProtocalUnit : ProtocalUnit
|
public interface ISpecialProtocalUnit
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输入结构
|
/// 输入结构
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InputStruct
|
public interface IInputStruct
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输出结构
|
/// 输出结构
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OutputStruct
|
public interface IOutputStruct
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -551,9 +551,9 @@ Remember subpos system cannot cross a byte in current version. If you want to cr
|
|||||||
* New Samples (Complete)
|
* New Samples (Complete)
|
||||||
|
|
||||||
###Version 1.2.2
|
###Version 1.2.2
|
||||||
* Address Utility (In Road)
|
* Address Utility (Not Test)
|
||||||
* More functions in TaskManager (In Road)
|
* More functions in TaskManager (Not Test)
|
||||||
* More interfaces (In Road)
|
* More interfaces (Not Test)
|
||||||
|
|
||||||
###Version 1.2.3
|
###Version 1.2.3
|
||||||
* OPC UA Support (In Road)
|
* OPC UA Support (In Road)
|
||||||
|
|||||||
Reference in New Issue
Block a user