Commit 1040b75b 顾剑亮

Handle WriteDO Not SendDO

1 个父辈 cc200872
此文件类型无法预览
......@@ -41,7 +41,7 @@ namespace Asa.IOModule
private readonly Box_Type _typeOutput; //输出类型
private readonly byte[] _addressInput; //输入地址
private readonly byte[] _addressOutput; //输出地址
private const int SEND_SLEEP = 50; //每条命令发送的间隔,不能小于15,会出现IO接收不到的情况,小于30时,会出现接收数据连包的情况
private const int SEND_SLEEP = 50; //每条命令发送的间隔
private const int PORT = 502; //端口
private const int UPLOAD_TIME = 8000; //8秒
......@@ -339,58 +339,77 @@ namespace Asa.IOModule
}
else
{
if (writeTimer >= 3) //连续发送WriteDO3次,强制发送DO
if (_writeDO.TryDequeue(out buff))
{
buff = GetReadDO_Command();
writeTimer = 0;
}
else
else
{
if (_writeDO.TryDequeue(out buff))
{
writeTimer++;
}
else
{
buff = GetReadDO_Command();
writeTimer = 0;
}
continue;
}
//2020年5月23日
// if (writeTimer >= 3) //连续发送WriteDO3次,强制发送DO
// {
// buff = GetReadDO_Command();
// writeTimer = 0;
// }
// else
// {
// if (_writeDO.TryDequeue(out buff))
// {
// writeTimer++;
// }
// else
// {
// buff = GetReadDO_Command();
// writeTimer = 0;
// }
// }
}
time += SEND_SLEEP;
}
else
{
if (writeTimer >= 3) //连续发送WriteDO3次,强制发送DI和DO
if (_writeDO.TryDequeue(out buff))
{
if (shift)
buff = GetReadDI_Command();
else
buff = GetReadDO_Command();
shift = !shift;
if (writeStop)
writeTimer = 0;
else
writeStop = true;
}
else
{
if (_writeDO.TryDequeue(out buff))
{
writeTimer++;
writeStop = false;
}
else
{
if (shift)
buff = GetReadDI_Command();
else
buff = GetReadDO_Command();
shift = !shift;
writeTimer = 0;
}
buff = GetReadDI_Command();
}
//2020年5月23日
//if (writeTimer >= 3) //连续发送WriteDO3次,强制发送DI和DO
//{
// if (shift)
// buff = GetReadDI_Command();
// else
// buff = GetReadDO_Command();
// shift = !shift;
// if (writeStop)
// writeTimer = 0;
// else
// writeStop = true;
//}
//else
//{
// if (_writeDO.TryDequeue(out buff))
// {
// writeTimer++;
// writeStop = false;
// }
// else
// {
// if (shift)
// buff = GetReadDI_Command();
// else
// buff = GetReadDO_Command();
// shift = !shift;
// writeTimer = 0;
// }
//}
}
......@@ -465,19 +484,16 @@ namespace Asa.IOModule
byte[] temp = new byte[count];
Array.Copy(buff, 0, temp, 0, count);
lock (_receive)
_receive.AddRange(temp);
while (_receive.Count > 6) //分解连包
{
_receive.AddRange(temp);
while (_receive.Count > 6) //分解连包
{
int len = _receive[5] + 6;
if (len > _receive.Count) break;
byte[] cmd = new byte[len];
_receive.CopyTo(0, cmd, 0, len);
_receive.RemoveRange(0, len);
log.Debug("Receive: " + HexBuff(cmd));
System.Threading.Tasks.Task.Run(() => CommandProcess(cmd));
}
int len = _receive[5] + 6;
if (len > _receive.Count) break;
byte[] cmd = new byte[len];
_receive.CopyTo(0, cmd, 0, len);
_receive.RemoveRange(0, len);
log.Debug("Receive: " + HexBuff(cmd));
System.Threading.Tasks.Task.Run(() => CommandProcess(cmd));
}
}
}
......@@ -557,6 +573,17 @@ namespace Asa.IOModule
}
else if (cmd[7] == 5)
{
idx = Array.FindIndex(_addressOutput, s => s == cmd[9]);
if (idx != -1)
{
Box_Sta[] staDO = new Box_Sta[_stateDO.Length];
lock (_stateDO)
{
_stateDO[idx] = cmd[10] == 0xFF ? Box_Sta.On : Box_Sta.Off;
Array.Copy(_stateDO, staDO, staDO.Length);
}
DO_Changed_Event?.Invoke(this, staDO);
}
}
}
catch (Exception ex)
......
......@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: AssemblyVersion("2.4.0.2")]
[assembly: AssemblyFileVersion("2.4.0.2")]
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!