Commit dc9b6c0a LN

io修改,减少读取次数

1 个父辈 505a7838
......@@ -337,26 +337,26 @@ namespace Asa.IOModule
buff = GetReadDI_Command();
time = 0;
}
else
{
if (writeTimer >= 3) //连续发送WriteDO3次,强制发送DO
{
buff = GetReadDO_Command();
writeTimer = 0;
}
else
{
if (_writeDO.TryDequeue(out buff))
{
writeTimer++;
}
else
{
buff = GetReadDO_Command();
writeTimer = 0;
}
}
}
//else
//{
// 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
......@@ -383,10 +383,10 @@ namespace Asa.IOModule
}
else
{
if (shift)
buff = GetReadDI_Command();
else
buff = GetReadDO_Command();
//if (shift)
// buff = GetReadDI_Command();
//else
// buff = GetReadDO_Command();
shift = !shift;
writeTimer = 0;
}
......@@ -580,9 +580,18 @@ namespace Asa.IOModule
LogUtil.LOGGER.Debug(LogName + " DI_Changed_Event ["+index+"] " + msg);
}
DI_Changed_Event?.Invoke(this, staDI);
}
}
else if (cmd[7] == 5)
{
idx = Array.FindIndex(_addressOutput, s => s == cmd[9]);
if (idx != -1)
{
Box_Sta[] staDO = new Box_Sta[_stateDO.Length];
_stateDO[idx] = cmd[10] == 0xFF ? Box_Sta.On : Box_Sta.Off;
Array.Copy(_stateDO, staDO, staDO.Length);
DO_Changed_Event?.Invoke(this, staDO);
//System.Threading.Tasks.Task.Run(() => DO_Changed_Event?.Invoke(this, staDO));
}
}
}
catch (Exception ex)
......@@ -628,14 +637,19 @@ namespace Asa.IOModule
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500);
_client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
_client.Connect(IPAddress.Parse(IP), PORT);
Thread.Sleep(100); //需要等待一会才能获取连接状态
Thread.Sleep(100); //需要等待一会才能获取连接状态
IsConn = true;
log.Info(LogName+ "Socket Connect");
byte[] buff = GetReadDI_Command();
SendToDevice(buff);
buff = GetReadDO_Command();
SendToDevice(buff);
log.Info(LogName + "Socket Connect");
}
catch (Exception ex)
{
IsConn = false;
log.Error(LogName+ "Open ", ex);
log.Error(LogName + "Open ", ex);
LogUtil.error(LogName + "Open ", ex);
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!