Fix
This commit is contained in:
@@ -18,7 +18,6 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensPpiProtocol(byte slaveAddress, byte masterAddress)
|
||||
: this(ConfigurationManager.AppSettings["COM"], slaveAddress, masterAddress)
|
||||
{
|
||||
ProtocolLinker = new SiemensPpiProtocolLinker(_com, SlaveAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,6 +30,7 @@ namespace Modbus.Net.Siemens
|
||||
: base(slaveAddress, masterAddress)
|
||||
{
|
||||
_com = com;
|
||||
ProtocolLinker = new SiemensPpiProtocolLinker(_com, SlaveAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,10 +79,14 @@ namespace Modbus.Net.Siemens
|
||||
(await (await
|
||||
ForceSendReceiveAsync(this[typeof(ComCreateReferenceSiemensProtocol)],
|
||||
inputStruct)).
|
||||
SendReceiveAsync(this[typeof(ComConfirmMessageSiemensProtocol)], answer =>
|
||||
|
||||
new ComConfirmMessageSiemensInputStruct(SlaveAddress, MasterAddress)
|
||||
)).Unwrap<ComConfirmMessageSiemensOutputStruct>();
|
||||
SendReceiveAsync(this[typeof(ComConfirmMessageSiemensProtocol)], answer =>
|
||||
answer != null
|
||||
? new ComConfirmMessageSiemensInputStruct(SlaveAddress, MasterAddress)
|
||||
: null)).Unwrap<ComConfirmMessageSiemensOutputStruct>();
|
||||
if (outputStruct == null && ProtocolLinker.IsConnected)
|
||||
{
|
||||
ProtocolLinker.Disconnect();
|
||||
}
|
||||
return outputStruct != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Modbus.Net.Siemens
|
||||
public SiemensPpiProtocolLinker(string com, int slaveAddress)
|
||||
: base(com, 9600, Parity.Even, StopBits.One, 8, slaveAddress)
|
||||
{
|
||||
((BaseConnector)BaseConnector).AddController(new MatchController(new ICollection<(int,int)>[] { new List<(int,int)> { (4,5) }, new List<(int,int)> {(5,4) }, new List<(int,int)> { (11 ,11), (12,12) } }, 0));
|
||||
((BaseConnector)BaseConnector).AddController(new FifoController(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,6 +37,7 @@ namespace Modbus.Net.Siemens
|
||||
new ComConfirmMessageSiemensProtocol().Format(inputStruct2));
|
||||
}
|
||||
var receiveBytes = await SendReceiveWithoutExtAndDecAsync(extBytes);
|
||||
if (receiveBytes == null) return null;
|
||||
if (content.Length > 6 && receiveBytes.Length == 1 && receiveBytes[0] == 0xe5)
|
||||
{
|
||||
var inputStruct2 = new ComConfirmMessageSiemensInputStruct(content[4], content[5]);
|
||||
@@ -56,7 +57,7 @@ namespace Modbus.Net.Siemens
|
||||
public override async Task<byte[]> SendReceiveWithoutExtAndDecAsync(byte[] content)
|
||||
{
|
||||
var ans = await base.SendReceiveWithoutExtAndDecAsync(content);
|
||||
while (ans.Length == 1 && ans[0] == 0xf9)
|
||||
while (ans?.Length == 1 && ans[0] == 0xf9)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
if (content.Length <= 6)
|
||||
|
||||
@@ -152,10 +152,15 @@ namespace Modbus.Net.Siemens
|
||||
//先建立连接,然后建立设备的引用
|
||||
(await (await
|
||||
ForceSendReceiveAsync(this[typeof(CreateReferenceSiemensProtocol)], inputStruct)).SendReceiveAsync(
|
||||
this[typeof(EstablishAssociationSiemensProtocol)], answer =>
|
||||
this[typeof(EstablishAssociationSiemensProtocol)], answer =>
|
||||
answer != null ?
|
||||
new EstablishAssociationSiemensInputStruct(0x0101, _maxCalling,
|
||||
_maxCalled,
|
||||
_maxPdu))).Unwrap<EstablishAssociationSiemensOutputStruct>();
|
||||
_maxPdu) : null)).Unwrap<EstablishAssociationSiemensOutputStruct>();
|
||||
if (outputStruct == null && ProtocolLinker.IsConnected)
|
||||
{
|
||||
ProtocolLinker.Disconnect();
|
||||
}
|
||||
return outputStruct != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,11 @@ namespace Modbus.Net
|
||||
return bytesExtend?.BytesDecact(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查接收的数据是否正确
|
||||
/// </summary>
|
||||
/// <param name="content">接收协议的内容</param>
|
||||
/// <returns>协议是否是正确的</returns>
|
||||
public override bool? CheckRight(byte[] content)
|
||||
{
|
||||
if (content == null)
|
||||
|
||||
Reference in New Issue
Block a user