Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
MIMO
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 03248b0f
由
刘韬
编写于
2022-08-01 11:30:58 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加socket扫码
1 个父辈
3df3ad9e
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
137 行增加
和
14 行删除
Common/Setting_Init.cs
DeviceLibrary/DeviceLibrary.csproj
DeviceLibrary/DeviceLibrary/SocketScanner.cs
DeviceLibrary/theMachine/MainMachine_Clamp.cs
DeviceLibrary/theMachine/RobotManage.cs
TheMachine/Program.cs
Common/Setting_Init.cs
查看文件 @
03248b0
...
...
@@ -49,6 +49,19 @@ namespace OnlineStore.Common
public
static
MyConfig
<
bool
>
Device_SingleInSingleOut
=
false
;
[
MyConfigComment
(
"允许单料口单盘入库"
)]
public
static
MyConfig
<
bool
>
Device_Allow_SingleIn
=
false
;
[
MyConfigComment
(
"是否启用socket扫码"
)]
public
static
MyConfig
<
bool
>
SocketScanner_enable
=
false
;
[
MyConfigComment
(
"socket uri=socket://127.0.0.1:7930"
)]
public
static
MyConfig
<
string
>
SocketScanner_uri
=
"socket://127.0.0.1:7930"
;
[
MyConfigComment
(
"socket 扫码等待超时"
)]
public
static
MyConfig
<
int
>
SocketScanner_receiver_timeout
=
10000
;
[
MyConfigComment
(
"socket 扫码触发代码"
)]
public
static
MyConfig
<
string
>
SocketScanner_trigger_code
=
"trigger"
;
[
MyConfigComment
(
"socket 扫码接收匹配正则表达式"
)]
public
static
MyConfig
<
string
>
SocketScanner_pattern_code
=
"reel:(.+?)!"
;
/// <summary>
/// 摄像机名称
/// </summary>
...
...
DeviceLibrary/DeviceLibrary.csproj
查看文件 @
03248b0
...
...
@@ -86,6 +86,7 @@
<Compile Include="DeviceLibrary\OKLEController.cs" />
<Compile Include="DeviceLibrary\ServerCommunication.cs" />
<Compile Include="DeviceLibrary\AxisBean.cs" />
<Compile Include="DeviceLibrary\SocketScanner.cs" />
<Compile Include="theMachine\BoxTransport.cs" />
<Compile Include="theMachine\Common.cs" />
<Compile Include="theMachine\JobList.cs" />
...
...
DeviceLibrary/DeviceLibrary/SocketScanner.cs
0 → 100644
查看文件 @
03248b0
using
ConfigHelper
;
using
OnlineStore.Common
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net.Sockets
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
namespace
DeviceLibrary
{
public
class
SocketScanner
:
ICustEditor
{
static
SocketScanner
()
{
AdvanceConfigForm
.
AddCustomEditor
<
SocketScanner
>(
Setting_Init
.
SocketScanner_uri
.
Key
);
}
public
object
ValueEdit
(
object
value
)
{
var
r
=
RobotManage
.
socketScanner
.
Scan
(
Setting_Init
.
SocketScanner_trigger_code
,
Setting_Init
.
SocketScanner_pattern_code
,
out
string
code
);
MessageBox
.
Show
(
$
"Scan Result:{r},code:{code}"
);
return
value
;
}
public
SocketScanner
()
{
}
Uri
server
;
int
Timeout
;
private
TcpClient
socket
=
null
;
public
SocketScanner
(
string
uri
,
int
timeout
)
{
server
=
new
Uri
(
uri
);
Timeout
=
timeout
;
}
public
bool
StartConnect
(
out
string
msg
)
{
msg
=
""
;
if
(
socket
==
null
)
socket
=
new
TcpClient
();
try
{
if
(
socket
.
Connected
)
return
true
;
socket
.
Close
();
socket
=
new
TcpClient
();
socket
.
ReceiveTimeout
=
Timeout
;
var
stask
=
socket
.
ConnectAsync
(
server
.
Host
,
server
.
Port
);
var
result
=
stask
.
Wait
(
3000
);
LogUtil
.
error
(
"SocketScanner Connect:"
+
result
);
return
result
;
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"SocketScanner 出错:"
+
ex
.
ToString
());
msg
=
ex
.
Message
;
return
false
;
}
}
~
SocketScanner
()
{
if
(
socket
!=
null
&&
socket
.
Connected
)
socket
.
Close
();
}
public
bool
Scan
(
string
trigger
,
string
pattern
,
out
string
result
)
{
result
=
""
;
if
(!
StartConnect
(
out
_
))
{
return
false
;
}
var
bf
=
Encoding
.
ASCII
.
GetBytes
(
trigger
);
socket
.
Client
.
Send
(
bf
);
var
buff
=
new
byte
[
200
];
int
i
;
try
{
i
=
socket
.
Client
.
Receive
(
buff
);
}
catch
{
return
false
;
}
if
(
i
==
0
)
return
false
;
var
recv
=
Encoding
.
ASCII
.
GetString
(
buff
,
0
,
i
);
var
m
=
Regex
.
Match
(
recv
,
pattern
);
if
(
m
.
Success
)
{
var
index
=
m
.
Groups
.
Count
-
1
;
result
=
m
.
Groups
[
index
].
Value
;
return
true
;
}
return
false
;
}
}
}
DeviceLibrary/theMachine/MainMachine_Clamp.cs
查看文件 @
03248b0
...
...
@@ -416,18 +416,18 @@ namespace DeviceLibrary
IOMove
(
IO_Type
.
Camera_Led
,
IO_VALUE
.
HIGH
);
//Task.Delay(10).Wait();
List
<
CodeInfo
>
LastCodeList
;
LastCodeList
=
CodeManager
.
CameraScan
(
CodeManager
.
hikNameList
);
//BoxParam labelParam = new BoxParam
();
//labelParam.codeInfos = new List<CodeInfo>(LastCodeList);
//if (!Common.codeProcess(labelParam, out _))
//{
// Task.Delay(500).Wait();
// LastCodeList2 = CodeManager.CameraScan(new List<string> { Config.CameraName });
// LastCodeList.AddRange(LastCodeList2
);
//
}
//IOMove(IO_Type.Camera_Led, IO_VALUE.LOW);
if
(
Setting_Init
.
SocketScanner_enable
)
{
LastCodeList
=
new
List
<
CodeInfo
>
();
if
(
RobotManage
.
socketScanner
.
Scan
(
Setting_Init
.
SocketScanner_trigger_code
,
Setting_Init
.
SocketScanner_pattern_code
,
out
string
code
))
{
LastCodeList
.
Add
(
new
CodeInfo
(
code
,
0
,
0
));
}
}
else
{
LastCodeList
=
CodeManager
.
CameraScan
(
CodeManager
.
hikNameList
);
}
return
LastCodeList
;
}));
...
...
DeviceLibrary/theMachine/RobotManage.cs
查看文件 @
03248b0
...
...
@@ -40,7 +40,7 @@ namespace DeviceLibrary
static
Thread
mainThread
;
public
static
bool
haveFixpos
=
false
;
public
static
SocketScanner
socketScanner
;
public
static
HIKCamera
CameraA
=
new
HIKCamera
();
public
static
void
Init
()
{
string
msg
=
""
;
...
...
@@ -78,6 +78,14 @@ namespace DeviceLibrary
IsLoadOk
=
false
;
msg
+=
crc
.
GetString
(
L
.
iocard_init_fail
,
"IO板卡初始化失败"
)+
"\n"
;
}
if
(
Setting_Init
.
SocketScanner_enable
)
{
socketScanner
=
new
SocketScanner
(
Setting_Init
.
SocketScanner_uri
,
Setting_Init
.
SocketScanner_receiver_timeout
);
if
(!
socketScanner
.
StartConnect
(
out
string
msg1
))
{
IsLoadOk
=
false
;
msg
+=
"连接Socket扫码服务失败:"
+
msg1
+
"\r\n"
;
}
}
if
(!
CameraA
.
LoadCameraConfig
(
"CameraA"
,
out
string
errmsg
))
{
IsLoadOk
=
false
;
...
...
TheMachine/Program.cs
查看文件 @
03248b0
...
...
@@ -22,6 +22,7 @@ namespace TheMachine
[
STAThread
]
static
void
Main
()
{
_
=
new
Mutex
(
true
,
Application
.
ProductName
,
out
bool
ret
);
if
(!
ret
)
{
...
...
@@ -47,7 +48,6 @@ namespace TheMachine
}
Config
.
LoadMyConfig
(
new
Setting_Init
().
GetType
());
Application
.
ThreadException
+=
Application_ThreadException
;
Application
.
SetUnhandledExceptionMode
(
UnhandledExceptionMode
.
CatchException
);
AppDomain
.
CurrentDomain
.
UnhandledException
+=
CurrentDomain_UnhandledException
;
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论