Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
1069_MIMO_PlUS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 0bc3a2d7
由
LN
编写于
2024-12-23 10:53:57 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加异常处理
1 个父辈
d91c34b0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
160 行增加
和
128 行删除
DeviceLibrary/DeviceLibrary/ServerCommunication.cs
DeviceLibrary/DeviceLibrary/weightSensor/OKLE_WeightSensor.cs
DeviceLibrary/theMachine/MainMachine.cs
TheMachine/Form1.cs
DeviceLibrary/DeviceLibrary/ServerCommunication.cs
查看文件 @
0bc3a2d
...
@@ -115,7 +115,13 @@ namespace DeviceLibrary
...
@@ -115,7 +115,13 @@ namespace DeviceLibrary
{
{
if
(
RobotManage
.
InoutDebugMode
)
if
(
RobotManage
.
InoutDebugMode
)
{
return
;
return
;
}
if
(
RobotManage
.
mainMachine
.
runStatus
!=
RunStatus
.
Running
)
{
return
;
}
lock
(
serverclock
)
lock
(
serverclock
)
{
{
var
code
=
ProcessCode
(
codelist
,
reel
.
PlateW
,
reel
.
PlateH
);
var
code
=
ProcessCode
(
codelist
,
reel
.
PlateW
,
reel
.
PlateH
);
...
@@ -133,7 +139,7 @@ namespace DeviceLibrary
...
@@ -133,7 +139,7 @@ namespace DeviceLibrary
operation
.
data
.
Add
(
"singleIn"
,
"false"
);
operation
.
data
.
Add
(
"singleIn"
,
"false"
);
}
}
Operation
resultOperation
=
HttpHelper
.
Post
(
GetPostApi
(),
operation
,
5000
,
printlog
);
Operation
resultOperation
=
HttpHelper
.
Post
(
GetPostApi
(),
operation
,
5000
,
printlog
);
if
(
operation
.
seq
!=
resultOperation
?.
seq
)
if
(
resultOperation
!=
null
&&
resultOperation
.
seq
>
0
&&
operation
.
seq
!=
resultOperation
?.
seq
)
{
{
Thread
.
Sleep
(
1000
);
Thread
.
Sleep
(
1000
);
SendInStoreRequest
(
codelist
,
reel
,
printlog
);
SendInStoreRequest
(
codelist
,
reel
,
printlog
);
...
...
DeviceLibrary/DeviceLibrary/weightSensor/OKLE_WeightSensor.cs
查看文件 @
0bc3a2d
...
@@ -220,53 +220,62 @@ namespace DeviceLibrary
...
@@ -220,53 +220,62 @@ namespace DeviceLibrary
}
}
byte
[]
SendAndReceive
(
byte
[]
buff
,
string
cmdname
=
""
)
byte
[]
SendAndReceive
(
byte
[]
buff
,
string
cmdname
=
""
)
{
{
lock
(
port
)
try
{
{
byte
[]
restr
=
new
byte
[
0
];
lock
(
port
)
if
(
port
==
null
||
!
port
.
IsOpen
)
{
{
if
(!
Open
(
PortName
,
out
string
msg
))
byte
[]
restr
=
new
byte
[
0
];
if
(
port
==
null
||
!
port
.
IsOpen
)
{
{
log
(
PortName
+
"未初始化,或已断开连接"
);
if
(!
Open
(
PortName
,
out
string
msg
))
return
restr
;
{
log
(
PortName
+
"未初始化,或已断开连接"
);
return
restr
;
}
}
}
}
var
t
=
Task
.
Run
(
delegate
var
t
=
Task
.
Run
(
delegate
{
byte
[]
recv
=
new
byte
[
256
];
try
{
{
port
.
Write
(
buff
,
0
,
buff
.
Length
);
byte
[]
recv
=
new
byte
[
256
];
//port.DiscardInBuffer();
try
Thread
.
Sleep
(
60
);
{
int
r
=
port
.
Read
(
recv
,
0
,
recv
.
Length
);
port
.
Write
(
buff
,
0
,
buff
.
Length
);
var
recvdata
=
recv
.
Take
(
r
).
ToArray
();
//port.DiscardInBuffer();
port
.
DiscardOutBuffer
();
Thread
.
Sleep
(
60
);
port
.
DiscardInBuffer
();
int
r
=
port
.
Read
(
recv
,
0
,
recv
.
Length
);
CalculateCRC
(
recvdata
,
recvdata
.
Length
-
2
,
out
ushort
checksun
);
var
recvdata
=
recv
.
Take
(
r
).
ToArray
();
var
crcbyte
=
BitConverter
.
GetBytes
(
checksun
);
port
.
DiscardOutBuffer
();
debuglog
(
cmdname
+
"\trecvdata: "
+
BitConverter
.
ToString
(
recvdata
).
Replace
(
"-"
,
" "
)
+
" crc:"
+
BitConverter
.
ToString
(
crcbyte
).
Replace
(
"-"
,
" "
));
port
.
DiscardInBuffer
();
if
(
recvdata
.
Length
>
5
CalculateCRC
(
recvdata
,
recvdata
.
Length
-
2
,
out
ushort
checksun
);
&&
recvdata
[
1
]
==
buff
[
1
]
var
crcbyte
=
BitConverter
.
GetBytes
(
checksun
);
&&
recvdata
[
recvdata
.
Length
-
2
]
==
crcbyte
[
0
]
debuglog
(
cmdname
+
"\trecvdata: "
+
BitConverter
.
ToString
(
recvdata
).
Replace
(
"-"
,
" "
)
+
" crc:"
+
BitConverter
.
ToString
(
crcbyte
).
Replace
(
"-"
,
" "
));
&&
recvdata
[
recvdata
.
Length
-
1
]
==
crcbyte
[
1
])
if
(
recvdata
.
Length
>
5
&&
recvdata
[
1
]
==
buff
[
1
]
&&
recvdata
[
recvdata
.
Length
-
2
]
==
crcbyte
[
0
]
&&
recvdata
[
recvdata
.
Length
-
1
]
==
crcbyte
[
1
])
{
return
recvdata
;
}
return
restr
;
}
catch
(
SocketException
e
)
{
{
return
recvdata
;
log
(
string
.
Format
(
"{0} Error code: {1}."
,
e
.
Message
,
e
.
ErrorCode
))
;
}
}
return
restr
;
return
restr
;
}
});
catch
(
SocketException
e
)
t
.
Wait
(
2000
);
{
if
(
t
.
IsCompleted
)
log
(
string
.
Format
(
"{0} Error code: {1}."
,
e
.
Message
,
e
.
ErrorCode
));
return
t
.
Result
;
}
else
return
restr
;
return
new
byte
[
0
];
});
}
t
.
Wait
(
2000
);
if
(
t
.
IsCompleted
)
return
t
.
Result
;
else
return
new
byte
[
0
];
}
}
catch
(
Exception
ex
)
{
error
(
"SendAndReceive , "
+
cmdname
+
", error :"
+
ex
.
ToString
());
}
return
new
byte
[
0
];
}
}
/// <summary>
/// <summary>
/// 初始化设置
/// 初始化设置
...
...
DeviceLibrary/theMachine/MainMachine.cs
查看文件 @
0bc3a2d
...
@@ -276,83 +276,90 @@ namespace DeviceLibrary
...
@@ -276,83 +276,90 @@ namespace DeviceLibrary
public
void
Run
()
public
void
Run
()
{
{
mstart
=
true
;
mstart
=
true
;
while
(
mstart
)
try
{
{
try
while
(
mstart
)
{
{
canRunning
=
DeviceCheck
();
try
if
(
canRunning
)
{
{
BtnProcess
();
canRunning
=
DeviceCheck
();
canRunning
=
SafeCheck
();
if
(
canRunning
)
//if (canRunning && !lastSafeCheckStatus){}
//lastSafeCheckStatus = canRunning;
}
Thread
.
Sleep
(
200
);
if
(!
canRunning
||
!
mstart
)
continue
;
if
(
runStatus
==
RunStatus
.
Running
)
{
ioMonitor
();
AGVProcess
();
StringProcess
();
ClampProcess
();
SelfAuditProcess
();
boxTransport
.
Process
();
if
(!
InSelfAudit
())
{
{
if
(
AutoInOutTest
)
BtnProcess
();
AutoInOutTestProcess
();
canRunning
=
SafeCheck
();
else
//if (canRunning && !lastSafeCheckStatus){}
StoreProcess
()
;
//lastSafeCheckStatus = canRunning
;
}
}
}
Thread
.
Sleep
(
200
);
else
if
(
runStatus
==
RunStatus
.
HomeReset
)
if
(!
canRunning
||
!
mstart
)
{
continue
;
HomeReset
();
if
(
runStatus
==
RunStatus
.
Running
)
}
}
catch
(
Exception
ex
)
{
Msg
.
add
(
ex
.
ToString
(),
MsgLevel
.
warning
);
Msg
.
setlogones
();
}
finally
{
var
m
=
Msg
.
get
();
ProcessMsgEvent
?.
Invoke
(
m
);
ServerCM
.
ProcessMsg
(
m
);
StoreStatus
currnetstoreStatus
=
StoreStatus
.
None
;
if
(
m
.
Find
((
aa
)
=>
aa
.
msgLevel
==
MsgLevel
.
alarm
)
==
null
)
{
hasAlarm
=
false
;
AlarmBuzzer
.
OFF
();
if
(
ServerCM
.
storeStatus
!=
StoreStatus
.
InStoreExecute
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
OutStoreExecute
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
ResetMove
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
StoreOnline
)
{
{
LogUtil
.
info
(
$
"test storeStatus is {ServerCM.storeStatus} change to StoreOnline"
);
ioMonitor
();
currnetstoreStatus
=
StoreStatus
.
StoreOnline
;
AGVProcess
();
StringProcess
();
ClampProcess
();
SelfAuditProcess
();
boxTransport
.
Process
();
if
(!
InSelfAudit
())
{
if
(
AutoInOutTest
)
AutoInOutTestProcess
();
else
StoreProcess
();
}
}
else
if
(
runStatus
==
RunStatus
.
HomeReset
)
{
HomeReset
();
}
}
}
}
else
catch
(
Exception
ex
)
{
{
hasAlarm
=
true
;
Msg
.
add
(
ex
.
ToString
(),
MsgLevel
.
warning
);
AlarmBuzzer
.
ON
();
Msg
.
setlogones
();
currnetstoreStatus
=
isInSuddenDown
?
StoreStatus
.
SuddenStop
:
StoreStatus
.
Warning
;
}
}
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
finally
if
(!
UserPause
&&
mstart
)
{
{
Msg
.
clear
();
var
m
=
Msg
.
get
();
}
ProcessMsgEvent
?.
Invoke
(
m
);
//else
ServerCM
.
ProcessMsg
(
m
);
// currnetstoreStatus = StoreStatus.Debugging;
StoreStatus
currnetstoreStatus
=
StoreStatus
.
None
;
if
(
m
.
Find
((
aa
)
=>
aa
.
msgLevel
==
MsgLevel
.
alarm
)
==
null
)
{
hasAlarm
=
false
;
AlarmBuzzer
.
OFF
();
if
(
ServerCM
.
storeStatus
!=
StoreStatus
.
InStoreExecute
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
OutStoreExecute
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
ResetMove
&&
ServerCM
.
storeStatus
!=
StoreStatus
.
StoreOnline
)
{
LogUtil
.
info
(
$
"test storeStatus is {ServerCM.storeStatus} change to StoreOnline"
);
currnetstoreStatus
=
StoreStatus
.
StoreOnline
;
}
}
else
{
hasAlarm
=
true
;
AlarmBuzzer
.
ON
();
currnetstoreStatus
=
isInSuddenDown
?
StoreStatus
.
SuddenStop
:
StoreStatus
.
Warning
;
}
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
if
(!
UserPause
&&
mstart
)
{
Msg
.
clear
();
}
//else
// currnetstoreStatus = StoreStatus.Debugging;
if
(
currnetstoreStatus
!=
StoreStatus
.
None
)
if
(
currnetstoreStatus
!=
StoreStatus
.
None
)
ServerCM
.
storeStatus
=
currnetstoreStatus
;
ServerCM
.
storeStatus
=
currnetstoreStatus
;
}
}
}
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"Run error :"
+
ex
.
ToString
());
}
RobotManage
.
isRunning
=
false
;
RobotManage
.
isRunning
=
false
;
RobotManage
.
UserPause
(
$
"isRunning = false"
,
false
);
RobotManage
.
UserPause
(
$
"isRunning = false"
,
false
);
LogUtil
.
info
(
"主线程已退出."
);
LogUtil
.
info
(
"主线程已退出."
);
...
@@ -364,20 +371,30 @@ namespace DeviceLibrary
...
@@ -364,20 +371,30 @@ namespace DeviceLibrary
}
}
public
void
Stop
()
public
void
Stop
()
{
{
LogUtil
.
info
(
"开始停止系统2."
);
try
mstart
=
false
;
{
AutoInOutTest
=
false
;
LogUtil
.
info
(
"开始停止系统2."
);
ClearOutJob
();
mstart
=
false
;
ServerCM
.
StopConnectServer
();
AutoInOutTest
=
false
;
Thread
.
Sleep
(
300
);
ClearOutJob
();
Alarm
(
AlarmType
.
None
);
ServerCM
.
StopConnectServer
();
StopMove
(
true
);
Thread
.
Sleep
(
300
);
IOMove
(
IO_Type
.
LineRun
,
IO_VALUE
.
LOW
);
Alarm
(
AlarmType
.
None
);
IOMove
(
IO_Type
.
LineRev
,
IO_VALUE
.
LOW
);
StopMove
(
true
);
LedProcess
(
null
);
IOMove
(
IO_Type
.
LineRun
,
IO_VALUE
.
LOW
);
CloseRgbLed
();
IOMove
(
IO_Type
.
LineRev
,
IO_VALUE
.
LOW
);
SoundsController
.
StopPlay
();
LedProcess
(
null
);
LogUtil
.
info
(
"开始停止系统3."
);
CloseRgbLed
();
SoundsController
.
StopPlay
();
runStatus
=
RunStatus
.
Stop
;
mstart
=
false
;
LogUtil
.
info
(
"开始停止系统3."
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"停止系统 Stop error :"
+
ex
.
ToString
());
}
}
}
public
void
BeginHomeReset
(
bool
firstRun
=
false
)
public
void
BeginHomeReset
(
bool
firstRun
=
false
)
{
{
...
...
TheMachine/Form1.cs
查看文件 @
0bc3a2d
...
@@ -605,6 +605,18 @@ namespace TheMachine
...
@@ -605,6 +605,18 @@ namespace TheMachine
if
(
RobotManage
.
isRunning
)
if
(
RobotManage
.
isRunning
)
{
{
btn_stop
.
Enabled
=
true
;
btn_stop
.
Enabled
=
true
;
if
(
e
)
{
(
btn_run
as
Button
).
Text
=
crc
.
GetString
(
L
.
device_resume
,
"恢复运行"
);
(
btn_run
as
Button
).
BackColor
=
Color
.
LightGreen
;
cb_IgnoreSafecheck
.
Enabled
=
true
;
}
else
{
(
btn_run
as
Button
).
Text
=
crc
.
GetString
(
L
.
device_pause
,
"暂停运行"
);
(
btn_run
as
Button
).
BackColor
=
Color
.
Yellow
;
cb_IgnoreSafecheck
.
Enabled
=
false
;
}
}
}
else
else
{
{
...
@@ -614,18 +626,6 @@ namespace TheMachine
...
@@ -614,18 +626,6 @@ namespace TheMachine
cb_IgnoreSafecheck
.
Enabled
=
true
;
cb_IgnoreSafecheck
.
Enabled
=
true
;
return
;
return
;
}
}
if
(
e
)
{
(
btn_run
as
Button
).
Text
=
crc
.
GetString
(
L
.
device_resume
,
"恢复运行"
);
(
btn_run
as
Button
).
BackColor
=
Color
.
LightGreen
;
cb_IgnoreSafecheck
.
Enabled
=
true
;
}
else
{
(
btn_run
as
Button
).
Text
=
crc
.
GetString
(
L
.
device_pause
,
"暂停运行"
);
(
btn_run
as
Button
).
BackColor
=
Color
.
Yellow
;
cb_IgnoreSafecheck
.
Enabled
=
false
;
}
}
}
private
void
btn_stop_Click
(
object
sender
,
EventArgs
e
)
private
void
btn_stop_Click
(
object
sender
,
EventArgs
e
)
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论