Commit 7b083fb1 gujlg

修改IO

1 个父辈 d469e222
...@@ -34,7 +34,8 @@ namespace Asa.IOModule ...@@ -34,7 +34,8 @@ namespace Asa.IOModule
private int _readDOSleep; //自动读取DO间隔 private int _readDOSleep; //自动读取DO间隔
private List<string> _log; //日志 private List<string> _log; //日志
private List<string> _logRxTx; //日志 private List<string> _logRxTx; //日志
private List<byte[]> _send; //发送的命令 //private List<byte[]> _send; //发送的命令
private System.Collections.Concurrent.ConcurrentQueue<byte[]> _send;
private List<byte[]> _receive; //接收的数据 private List<byte[]> _receive; //接收的数据
private Thread tSend; //发送命令处理 private Thread tSend; //发送命令处理
...@@ -117,7 +118,8 @@ namespace Asa.IOModule ...@@ -117,7 +118,8 @@ namespace Asa.IOModule
_sta = new Box_Sta[32]; _sta = new Box_Sta[32];
_log = new List<string>(); _log = new List<string>();
_logRxTx = new List<string>(); _logRxTx = new List<string>();
_send = new List<byte[]>(); //_send = new List<byte[]>();
_send = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
_receive = new List<byte[]>(); _receive = new List<byte[]>();
Type = Box_Type.DIO_32; Type = Box_Type.DIO_32;
...@@ -288,7 +290,10 @@ namespace Asa.IOModule ...@@ -288,7 +290,10 @@ namespace Asa.IOModule
_unrevd = 0; _unrevd = 0;
_unrevdRemote = 0; _unrevdRemote = 0;
_flag = 0; _flag = 0;
_send.Clear(); //_send.Clear();
while (_send.TryDequeue(out byte[] aa))
{ }
_receive.Clear(); _receive.Clear();
_log.Clear(); _log.Clear();
_logRxTx.Clear(); _logRxTx.Clear();
...@@ -482,7 +487,9 @@ namespace Asa.IOModule ...@@ -482,7 +487,9 @@ namespace Asa.IOModule
_log.Add(s); _log.Add(s);
} }
_send.Add(buff); //_send.Add(buff);
_send.Enqueue(buff);
if (_unrevdRemote == 0) ErrInfo = "OK"; if (_unrevdRemote == 0) ErrInfo = "OK";
return true; return true;
} }
...@@ -524,24 +531,51 @@ namespace Asa.IOModule ...@@ -524,24 +531,51 @@ namespace Asa.IOModule
while (true) while (true)
{ {
if (_send.Count > 0) //if (_send.Count > 0)
{ //{
if (_send[0] != null) // if (_send[0] != null)
// {
// try
// {
// _client.Send(_send[0]);
// if (LogOut)
// {
// byte[] bb = new byte[2];
// bb[0] = _send[0][1];
// bb[1] = _send[0][0];
// flag = BitConverter.ToUInt16(bb, 0);
// s = string.Format("{0:HH:mm:ss:fff} Send {1}", DateTime.Now, flag);
// _log.Add(s);
// _logRxTx.Add(flag + "," + _send[0][7]);
// }
// _send.RemoveAt(0);
// }
// catch (Exception ex)
// {
// ErrInfo = ex.Message;
// LogUtil.error(ex.ToString());
// _unrevdRemote = 1;
// break;
// }
// }
//}
bool rtn = _send.TryDequeue(out byte[] result);
if (rtn)
{ {
try try
{ {
_client.Send(_send[0]); _client.Send(result);
if (LogOut) if (LogOut)
{ {
byte[] bb = new byte[2]; byte[] bb = new byte[2];
bb[0] = _send[0][1]; bb[0] = result[1];
bb[1] = _send[0][0]; bb[1] = result[0];
flag = BitConverter.ToUInt16(bb, 0); flag = BitConverter.ToUInt16(bb, 0);
s = string.Format("{0:HH:mm:ss:fff} Send {1}", DateTime.Now, flag); s = string.Format("{0:HH:mm:ss:fff} Send {1}", DateTime.Now, flag);
_log.Add(s); _log.Add(s);
_logRxTx.Add(flag + "," + _send[0][7]); _logRxTx.Add(flag + "," + result[7]);
} }
_send.RemoveAt(0);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -551,7 +585,6 @@ namespace Asa.IOModule ...@@ -551,7 +585,6 @@ namespace Asa.IOModule
break; break;
} }
} }
}
Thread.Sleep(SEND_SLEEP); Thread.Sleep(SEND_SLEEP);
} }
...@@ -861,7 +894,8 @@ namespace Asa.IOModule ...@@ -861,7 +894,8 @@ namespace Asa.IOModule
buff[11] = 8; //个数 buff[11] = 8; //个数
else if (_type == Box_Type.DIO_32) else if (_type == Box_Type.DIO_32)
buff[11] = 16; //个数 buff[11] = 16; //个数
_send.Add(buff); //_send.Add(buff);
_send.Enqueue(buff);
} }
Thread.Sleep(_readDISleep); Thread.Sleep(_readDISleep);
} }
...@@ -887,7 +921,8 @@ namespace Asa.IOModule ...@@ -887,7 +921,8 @@ namespace Asa.IOModule
buff[11] = 16; //个数 buff[11] = 16; //个数
else if (_type == Box_Type.DO_16) else if (_type == Box_Type.DO_16)
buff[11] = 16; //个数 buff[11] = 16; //个数
_send.Add(buff); //_send.Add(buff);
_send.Enqueue(buff);
} }
Thread.Sleep(_readDOSleep); Thread.Sleep(_readDOSleep);
} }
...@@ -950,14 +985,20 @@ namespace Asa.IOModule ...@@ -950,14 +985,20 @@ namespace Asa.IOModule
//临时 //临时
Dictionary<string, string> dic = new Dictionary<string, string>(); Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("send.Count = ", _send.Count.ToString());
foreach (System.Reflection.PropertyInfo info in _client.GetType().GetProperties()) foreach (System.Reflection.PropertyInfo info in _client.GetType().GetProperties())
try { {
try
{
dic.Add(info.Name, info.GetValue(_client) == null ? "null" : info.GetValue(_client).ToString()); dic.Add(info.Name, info.GetValue(_client) == null ? "null" : info.GetValue(_client).ToString());
} catch(Exception ex) }
catch (Exception ex)
{ {
dic.Add("错误"+info.Name, ex.Message); dic.Add("错误" + info.Name, ex.Message);
}
} }
CloseConn(); CloseConn();
Thread.Sleep(100); Thread.Sleep(100);
...@@ -999,7 +1040,7 @@ namespace Asa.IOModule ...@@ -999,7 +1040,7 @@ namespace Asa.IOModule
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("Reconn出错:"+ex.ToString()); LogUtil.error("Reconn出错:" + ex.ToString());
} }
Thread.Sleep(1000); Thread.Sleep(1000);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!