Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC30-AutoInOutStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 7b083fb1
由
gujlg
编写于
2019-05-16 15:08:11 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
修改IO
1 个父辈
d469e222
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
108 行增加
和
67 行删除
source/DeviceLibrary/DeviceLibrary/IO/AIOBOX/BLL.cs
source/DeviceLibrary/DeviceLibrary/IO/AIOBOX/BLL.cs
查看文件 @
7b083fb
...
...
@@ -34,7 +34,8 @@ namespace Asa.IOModule
private
int
_readDOSleep
;
//自动读取DO间隔
private
List
<
string
>
_log
;
//日志
private
List
<
string
>
_logRxTx
;
//日志
private
List
<
byte
[
]>
_send
;
//发送的命令
//private List<byte[]> _send; //发送的命令
private
System
.
Collections
.
Concurrent
.
ConcurrentQueue
<
byte
[
]>
_send
;
private
List
<
byte
[
]>
_receive
;
//接收的数据
private
Thread
tSend
;
//发送命令处理
...
...
@@ -117,7 +118,8 @@ namespace Asa.IOModule
_sta
=
new
Box_Sta
[
32
];
_log
=
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
[
]>
();
Type
=
Box_Type
.
DIO_32
;
...
...
@@ -288,7 +290,10 @@ namespace Asa.IOModule
_unrevd
=
0
;
_unrevdRemote
=
0
;
_flag
=
0
;
_send
.
Clear
();
//_send.Clear();
while
(
_send
.
TryDequeue
(
out
byte
[]
aa
))
{
}
_receive
.
Clear
();
_log
.
Clear
();
_logRxTx
.
Clear
();
...
...
@@ -482,7 +487,9 @@ namespace Asa.IOModule
_log
.
Add
(
s
);
}
_send
.
Add
(
buff
);
//_send.Add(buff);
_send
.
Enqueue
(
buff
);
if
(
_unrevdRemote
==
0
)
ErrInfo
=
"OK"
;
return
true
;
}
...
...
@@ -524,33 +531,59 @@ namespace Asa.IOModule
while
(
true
)
{
if
(
_send
.
Count
>
0
)
//if (_send.Count > 0)
//{
// 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
)
{
if
(
_send
[
0
]
!=
null
)
try
{
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
)
_client
.
Send
(
result
);
if
(
LogOut
)
{
ErrInfo
=
ex
.
Message
;
LogUtil
.
error
(
ex
.
ToString
());
_unrevdRemote
=
1
;
break
;
byte
[]
bb
=
new
byte
[
2
];
bb
[
0
]
=
result
[
1
];
bb
[
1
]
=
result
[
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
+
","
+
result
[
7
]);
}
}
catch
(
Exception
ex
)
{
ErrInfo
=
ex
.
Message
;
LogUtil
.
error
(
ex
.
ToString
());
_unrevdRemote
=
1
;
break
;
}
}
Thread
.
Sleep
(
SEND_SLEEP
);
...
...
@@ -861,7 +894,8 @@ namespace Asa.IOModule
buff
[
11
]
=
8
;
//个数
else
if
(
_type
==
Box_Type
.
DIO_32
)
buff
[
11
]
=
16
;
//个数
_send
.
Add
(
buff
);
//_send.Add(buff);
_send
.
Enqueue
(
buff
);
}
Thread
.
Sleep
(
_readDISleep
);
}
...
...
@@ -887,7 +921,8 @@ namespace Asa.IOModule
buff
[
11
]
=
16
;
//个数
else
if
(
_type
==
Box_Type
.
DO_16
)
buff
[
11
]
=
16
;
//个数
_send
.
Add
(
buff
);
//_send.Add(buff);
_send
.
Enqueue
(
buff
);
}
Thread
.
Sleep
(
_readDOSleep
);
}
...
...
@@ -944,62 +979,68 @@ namespace Asa.IOModule
try
{
if
(
IsConn
)
{
if
(
_unrevd
>
10000
||
_unrevdRemote
>
0
)
//断开10s后重连
{
if
(
_unrevd
>
10000
||
_unrevdRemote
>
0
)
//断开10s后重连
{
//临时
Dictionary
<
string
,
string
>
dic
=
new
Dictionary
<
string
,
string
>();
foreach
(
System
.
Reflection
.
PropertyInfo
info
in
_client
.
GetType
().
GetProperties
())
try
{
dic
.
Add
(
info
.
Name
,
info
.
GetValue
(
_client
)
==
null
?
"null"
:
info
.
GetValue
(
_client
).
ToString
());
}
catch
(
Exception
ex
)
//临时
Dictionary
<
string
,
string
>
dic
=
new
Dictionary
<
string
,
string
>();
dic
.
Add
(
"send.Count = "
,
_send
.
Count
.
ToString
());
foreach
(
System
.
Reflection
.
PropertyInfo
info
in
_client
.
GetType
().
GetProperties
())
{
dic
.
Add
(
"错误"
+
info
.
Name
,
ex
.
Message
);
}
try
{
dic
.
Add
(
info
.
Name
,
info
.
GetValue
(
_client
)
==
null
?
"null"
:
info
.
GetValue
(
_client
).
ToString
());
}
catch
(
Exception
ex
)
{
dic
.
Add
(
"错误"
+
info
.
Name
,
ex
.
Message
);
}
}
CloseConn
();
Thread
.
Sleep
(
100
);
if
(
Reconnect_Event
!=
null
)
{
loop
=
false
;
conn
=
false
;
do
CloseConn
();
Thread
.
Sleep
(
100
);
if
(
Reconnect_Event
!=
null
)
{
if
(!
loop
)
loop
=
false
;
conn
=
false
;
do
{
if
(
_unrevdRemote
==
0
)
ErrInfo
=
"本地缓存连续10s未收到数据"
;
}
times
++;
Reconnect_Event
.
Invoke
(
this
,
times
,
ref
conn
,
dic
);
if
(
conn
)
{
rtn
=
Connect
();
if
(
rtn
)
if
(!
loop
)
{
loop
=
false
;
times
=
0
;
if
(
_unrevdRemote
==
0
)
ErrInfo
=
"本地缓存连续10s未收到数据"
;
}
times
++;
Reconnect_Event
.
Invoke
(
this
,
times
,
ref
conn
,
dic
);
if
(
conn
)
{
rtn
=
Connect
();
if
(
rtn
)
{
loop
=
false
;
times
=
0
;
}
else
{
conn
=
false
;
loop
=
true
;
}
}
else
{
conn
=
false
;
loop
=
true
;
loop
=
false
;
}
}
else
{
loop
=
false
;
}
}
while
(
loop
);
}
while
(
loop
);
}
}
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"Reconn出错:"
+
ex
.
ToString
());
LogUtil
.
error
(
"Reconn出错:"
+
ex
.
ToString
());
}
Thread
.
Sleep
(
1000
);
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论