Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
SO664-AssemblyLine
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 8ff99d2c
由
LN
编写于
2023-09-07 13:43:09 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
扫码更新为最新版本。
1 个父辈
859314a0
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
256 行增加
和
67 行删除
source/AssemblyLineClient/FrmLineStore.cs
source/DeviceLibrary/deviceLibrary/halcon/RemoteDecodeHelper.cs
source/DeviceLibrary/deviceLibrary/halcon/RemoteDecodeHelperO.cs
source/AssemblyLineClient/FrmLineStore.cs
查看文件 @
8ff99d2
...
@@ -1301,7 +1301,9 @@ namespace OnlineStore.AssemblyLine
...
@@ -1301,7 +1301,9 @@ namespace OnlineStore.AssemblyLine
}
}
private
void
chbDisMove_CheckedChanged
(
object
sender
,
EventArgs
e
)
private
void
chbDisMove_CheckedChanged
(
object
sender
,
EventArgs
e
)
{
{
Test
();
//Test();
if
(!
LoadOk
)
if
(!
LoadOk
)
{
{
return
;
return
;
...
...
source/DeviceLibrary/deviceLibrary/halcon/RemoteDecodeHelper.cs
查看文件 @
8ff99d2
...
@@ -17,64 +17,78 @@ using System.Xml.Serialization;
...
@@ -17,64 +17,78 @@ using System.Xml.Serialization;
public
class
RemoteDecodeHelper
public
class
RemoteDecodeHelper
{
{
static
int
webclienttimeout
=
30
*
1000
;
static
Process
p
=
new
Process
();
private
static
int
webclienttimeout
=
30000
;
private
static
string
serverhost
=
ConfigAppSettings
.
GetValue
(
"ScanCodeServer"
);
private
static
Process
p
=
new
Process
();
private
const
string
serverhost
=
"http://127.0.0.1:58137/"
;
public
static
List
<
CodeInfo
>
DecodeRequest
(
HObject
hoimg
,
RemoteDecodeParam
remoteDecodeParam
)
public
static
List
<
CodeInfo
>
DecodeRequest
(
HObject
hoimg
,
RemoteDecodeParam
remoteDecodeParam
)
{
{
if
(
serverhost
.
Trim
().
Equals
(
""
))
{
serverhost
=
"http://127.0.0.1:58137/"
;
}
byte
[]
requestdata
;
byte
[]
requestdata
;
lock
(
hoimg
)
lock
(
hoimg
)
{
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
using
(
MemoryStream
m
emory
Stream
=
new
MemoryStream
())
{
{
hoimg
.
Serialize
(
mStream
);
hoimg
.
Serialize
(
m
emory
Stream
);
requestdata
=
mStream
.
ToArray
();
requestdata
=
m
emory
Stream
.
ToArray
();
mStream
.
Close
();
m
emory
Stream
.
Close
();
}
}
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
,
true
);
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
,
isHObject
:
true
);
}
}
public
static
List
<
CodeInfo
>
DecodeRequest
(
Bitmap
bitmap
,
RemoteDecodeParam
remoteDecodeParam
)
public
static
List
<
CodeInfo
>
DecodeRequest
(
Bitmap
bitmap
,
RemoteDecodeParam
remoteDecodeParam
)
{
{
if
(
bitmap
==
null
)
{
return
null
;
}
byte
[]
requestdata
;
byte
[]
requestdata
;
lock
(
bitmap
)
lock
(
bitmap
)
{
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
using
(
MemoryStream
m
emory
Stream
=
new
MemoryStream
())
{
{
BinaryFormatter
b
f
=
new
BinaryFormatter
();
BinaryFormatter
b
inaryFormatter
=
new
BinaryFormatter
();
b
f
.
Serialize
(
m
Stream
,
bitmap
);
b
inaryFormatter
.
Serialize
(
memory
Stream
,
bitmap
);
requestdata
=
mStream
.
ToArray
();
requestdata
=
m
emory
Stream
.
ToArray
();
mStream
.
Close
();
m
emory
Stream
.
Close
();
}
}
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
);
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
);
}
}
static
List
<
CodeInfo
>
DecodeRequest
(
byte
[]
requestdata
,
RemoteDecodeParam
remoteDecodeParam
,
bool
isHObject
=
false
)
private
static
List
<
CodeInfo
>
DecodeRequest
(
byte
[]
requestdata
,
RemoteDecodeParam
remoteDecodeParam
,
bool
isHObject
=
false
)
{
{
CheckAndRunServer
();
CheckAndRunServer
();
string
param
;
string
text
;
using
(
MemoryStream
m
Streampar
am
=
new
MemoryStream
())
using
(
MemoryStream
m
emoryStre
am
=
new
MemoryStream
())
{
{
XmlSerializer
x
f
=
new
XmlSerializer
(
typeof
(
RemoteDecodeParam
));
XmlSerializer
x
mlSerializer
=
new
XmlSerializer
(
typeof
(
RemoteDecodeParam
));
x
f
.
Serialize
(
mStreampar
am
,
remoteDecodeParam
);
x
mlSerializer
.
Serialize
(
memoryStre
am
,
remoteDecodeParam
);
param
=
base64UrlEncode
(
mStreampar
am
.
ToArray
());
text
=
base64UrlEncode
(
memoryStre
am
.
ToArray
());
m
Streampar
am
.
Close
();
m
emoryStre
am
.
Close
();
}
}
string
url
=
serverhost
+
"ProcessBitmap?param="
;
string
text2
=
"http://127.0.0.1:58137/ProcessBitmap?param="
;
if
(
isHObject
)
if
(
isHObject
)
url
=
serverhost
+
"Process?param="
;
{
byte
[]
resp
;
text2
=
"http://127.0.0.1:58137/Process?param="
;
}
byte
[]
bytes
;
try
try
{
{
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
MyWebClient
myWebClient
=
new
MyWebClient
(
webclienttimeout
);
resp
=
webClient
.
UploadData
(
url
+
param
,
requestdata
);
bytes
=
myWebClient
.
UploadData
(
text2
+
text
,
requestdata
);
webClient
.
Dispose
();
requestdata
=
null
;
myWebClient
.
Dispose
();
}
}
catch
(
WebException
we
)
catch
(
WebException
)
{
{
return
null
;
return
null
;
}
}
...
@@ -83,52 +97,62 @@ public class RemoteDecodeHelper
...
@@ -83,52 +97,62 @@ public class RemoteDecodeHelper
return
null
;
return
null
;
}
}
var
ss
=
Encoding
.
UTF8
.
GetString
(
resp
).
Trim
().
Trim
(
'"'
);
List
<
CodeInfo
>
result
=
null
;
var
bb
=
Convert
.
FromBase64String
(
ss
);
string
text3
=
Encoding
.
UTF8
.
GetString
(
bytes
).
Trim
().
Trim
(
'"'
);
List
<
CodeInfo
>
codeInfos
;
text3
=
text3
.
Replace
(
"\\/"
,
"/"
);
using
(
MemoryStream
mStreamResult
=
new
MemoryStream
(
bb
))
try
{
byte
[]
buffer
=
Convert
.
FromBase64String
(
text3
);
using
(
MemoryStream
stream
=
new
MemoryStream
(
buffer
))
{
XmlSerializer
xmlSerializer2
=
new
XmlSerializer
(
typeof
(
List
<
CodeInfo
>));
result
=
(
List
<
CodeInfo
>)
xmlSerializer2
.
Deserialize
(
stream
);
}
}
catch
{
{
XmlSerializer
xff
=
new
XmlSerializer
(
typeof
(
List
<
CodeInfo
>));
throw
new
Exception
(
text3
);
codeInfos
=
(
List
<
CodeInfo
>)
xff
.
Deserialize
(
mStreamResult
);
}
}
return
codeInfos
;
return
result
;
}
}
/// <summary>
private
static
string
base64UrlEncode
(
byte
[]
input
)
/// 在url中传递base64字符串需要替换加号等符号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
static
string
base64UrlEncode
(
byte
[]
input
)
{
{
return
Convert
.
ToBase64String
(
input
).
Replace
(
'+'
,
'-'
).
Replace
(
'/'
,
'_'
);
return
Convert
.
ToBase64String
(
input
).
Replace
(
'+'
,
'-'
).
Replace
(
'/'
,
'_'
);
}
}
/// <summary>
/// 检查并自动启动服务器
private
static
void
CheckAndRunServer
()
/// </summary>
static
void
CheckAndRunServer
()
{
{
lock
(
p
)
lock
(
p
)
{
{
var
pss
=
Process
.
GetProcessesByName
(
"ScanCodeServer"
);
Process
[]
processesByName
=
Process
.
GetProcessesByName
(
"ScanCodeServer"
);
if
(
pss
.
Length
>
0
)
if
(
processesByName
.
Length
!=
0
)
{
return
;
return
;
}
var
f
=
"ScanCodeServer\\ScanCodeServer.exe"
;
string
text
=
"ScanCodeServer\\ScanCodeServer.exe"
;
if
(!
File
.
Exists
(
f
))
if
(!
File
.
Exists
(
text
))
{
throw
new
Exception
(
"找不到扫码服务器文件"
);
throw
new
Exception
(
"找不到扫码服务器文件"
);
p
.
StartInfo
=
new
ProcessStartInfo
(
f
);
}
p
.
StartInfo
=
new
ProcessStartInfo
(
text
);
p
.
Start
();
p
.
Start
();
int
checkcount
=
5
;
int
num
=
5
;
while
(
checkcount
>
0
)
while
(
num
>
0
)
{
{
checkcount
--;
num
--;
Thread
.
Sleep
(
500
);
Thread
.
Sleep
(
500
);
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
MyWebClient
myWebClient
=
new
MyWebClient
(
webclienttimeout
);
var
s
=
webClient
.
DownloadString
(
serverhost
+
"alive"
);
string
text2
=
myWebClient
.
DownloadString
(
"http://127.0.0.1:58137/alive"
);
if
(
s
.
Trim
()
==
"\"1\""
)
if
(
text2
.
Trim
()
==
"\"1\""
)
{
return
;
return
;
}
}
}
throw
new
Exception
(
"扫码服务器打开失败"
);
throw
new
Exception
(
"扫码服务器打开失败"
);
}
}
}
}
...
@@ -137,24 +161,27 @@ public class RemoteDecodeHelper
...
@@ -137,24 +161,27 @@ public class RemoteDecodeHelper
public
struct
RemoteDecodeParam
public
struct
RemoteDecodeParam
{
{
public
string
[]
codeTypeList
;
public
string
[]
codeTypeList
;
public
int
codeCount
;
public
int
codeCount
;
public
int
timeout
;
public
int
timeout
;
}
}
public
class
MyWebClient
:
WebClient
public
class
MyWebClient
:
WebClient
{
{
private
int
_timeout
;
private
int
_timeout
;
public
MyWebClient
(
int
timeout
)
public
MyWebClient
(
int
timeout
)
{
{
this
.
_timeout
=
timeout
;
_timeout
=
timeout
;
}
}
protected
override
WebRequest
GetWebRequest
(
Uri
address
)
protected
override
WebRequest
GetWebRequest
(
Uri
address
)
{
{
var
resul
t
=
base
.
GetWebRequest
(
address
);
WebRequest
webReques
t
=
base
.
GetWebRequest
(
address
);
result
.
Timeout
=
this
.
_timeout
;
webRequest
.
Timeout
=
_timeout
;
return
resul
t
;
return
webReques
t
;
}
}
}
}
}
}
source/DeviceLibrary/deviceLibrary/halcon/RemoteDecodeHelperO.cs
0 → 100644
查看文件 @
8ff99d2
using
CodeLibrary
;
using
HalconDotNet
;
using
OnlineStore.Common
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Xml
;
using
System.Xml.Serialization
;
public
class
RemoteDecodeHelperO
{
static
int
webclienttimeout
=
30
*
1000
;
static
Process
p
=
new
Process
();
private
static
string
serverhost
=
ConfigAppSettings
.
GetValue
(
"ScanCodeServer"
);
public
static
List
<
CodeInfo
>
DecodeRequest
(
HObject
hoimg
,
RemoteDecodeParam
remoteDecodeParam
)
{
if
(
serverhost
.
Trim
().
Equals
(
""
))
{
serverhost
=
"http://127.0.0.1:58137/"
;
}
byte
[]
requestdata
;
lock
(
hoimg
)
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
{
hoimg
.
Serialize
(
mStream
);
requestdata
=
mStream
.
ToArray
();
mStream
.
Close
();
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
,
true
);
}
public
static
List
<
CodeInfo
>
DecodeRequest
(
Bitmap
bitmap
,
RemoteDecodeParam
remoteDecodeParam
)
{
byte
[]
requestdata
;
lock
(
bitmap
)
{
using
(
MemoryStream
mStream
=
new
MemoryStream
())
{
BinaryFormatter
bf
=
new
BinaryFormatter
();
bf
.
Serialize
(
mStream
,
bitmap
);
requestdata
=
mStream
.
ToArray
();
mStream
.
Close
();
}
}
return
DecodeRequest
(
requestdata
,
remoteDecodeParam
);
}
static
List
<
CodeInfo
>
DecodeRequest
(
byte
[]
requestdata
,
RemoteDecodeParam
remoteDecodeParam
,
bool
isHObject
=
false
)
{
CheckAndRunServer
();
string
param
;
using
(
MemoryStream
mStreamparam
=
new
MemoryStream
())
{
XmlSerializer
xf
=
new
XmlSerializer
(
typeof
(
RemoteDecodeParam
));
xf
.
Serialize
(
mStreamparam
,
remoteDecodeParam
);
param
=
base64UrlEncode
(
mStreamparam
.
ToArray
());
mStreamparam
.
Close
();
}
string
url
=
serverhost
+
"ProcessBitmap?param="
;
if
(
isHObject
)
url
=
serverhost
+
"Process?param="
;
byte
[]
resp
;
try
{
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
resp
=
webClient
.
UploadData
(
url
+
param
,
requestdata
);
webClient
.
Dispose
();
}
catch
(
WebException
we
)
{
return
null
;
}
catch
{
return
null
;
}
var
ss
=
Encoding
.
UTF8
.
GetString
(
resp
).
Trim
().
Trim
(
'"'
);
var
bb
=
Convert
.
FromBase64String
(
ss
);
List
<
CodeInfo
>
codeInfos
;
using
(
MemoryStream
mStreamResult
=
new
MemoryStream
(
bb
))
{
XmlSerializer
xff
=
new
XmlSerializer
(
typeof
(
List
<
CodeInfo
>));
codeInfos
=
(
List
<
CodeInfo
>)
xff
.
Deserialize
(
mStreamResult
);
}
return
codeInfos
;
}
/// <summary>
/// 在url中传递base64字符串需要替换加号等符号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
static
string
base64UrlEncode
(
byte
[]
input
)
{
return
Convert
.
ToBase64String
(
input
).
Replace
(
'+'
,
'-'
).
Replace
(
'/'
,
'_'
);
}
/// <summary>
/// 检查并自动启动服务器
/// </summary>
static
void
CheckAndRunServer
()
{
lock
(
p
)
{
var
pss
=
Process
.
GetProcessesByName
(
"ScanCodeServer"
);
if
(
pss
.
Length
>
0
)
return
;
var
f
=
"ScanCodeServer\\ScanCodeServer.exe"
;
if
(!
File
.
Exists
(
f
))
throw
new
Exception
(
"找不到扫码服务器文件"
);
p
.
StartInfo
=
new
ProcessStartInfo
(
f
);
p
.
Start
();
int
checkcount
=
5
;
while
(
checkcount
>
0
)
{
checkcount
--;
Thread
.
Sleep
(
500
);
MyWebClient
webClient
=
new
MyWebClient
(
webclienttimeout
);
var
s
=
webClient
.
DownloadString
(
serverhost
+
"alive"
);
if
(
s
.
Trim
()
==
"\"1\""
)
return
;
}
throw
new
Exception
(
"扫码服务器打开失败"
);
}
}
[
Serializable
]
public
struct
RemoteDecodeParam
{
public
string
[]
codeTypeList
;
public
int
codeCount
;
public
int
timeout
;
}
public
class
MyWebClient
:
WebClient
{
private
int
_timeout
;
public
MyWebClient
(
int
timeout
)
{
this
.
_timeout
=
timeout
;
}
protected
override
WebRequest
GetWebRequest
(
Uri
address
)
{
var
result
=
base
.
GetWebRequest
(
address
);
result
.
Timeout
=
this
.
_timeout
;
return
result
;
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论