Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
Line-Smart-Workstation
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit d963703c
由
LN
编写于
2024-06-13 15:49:09 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
26df9ae0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
94 行增加
和
58 行删除
DeviceLibrary/deviceLibrary/IO/NanjingSDotIO.cs
TSA-V/workForm/FrmAOICheck.cs
DeviceLibrary/deviceLibrary/IO/NanjingSDotIO.cs
查看文件 @
d963703
...
...
@@ -4,7 +4,7 @@ using System.Linq;
using
System.Net.Sockets
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
TSA_V.DeviceLibrary
;
class
NanjingSDotIO
:
IOBase
...
...
@@ -145,13 +145,15 @@ class NanjingSDotIO : IOBase
/// <returns></returns>
public
bool
WriteDO
(
int
donum
,
bool
state
)
{
byte
funCode
=
0x0F
;
//批量写圈
byte
startAddress
=
(
byte
)(
64
+
donum
);
//写圈起始地址
byte
startLength
=
1
;
var
seqhead
=
BitConverter
.
GetBytes
(
seq
);
byte
iostate
=
(
byte
)(
state
?
1
:
0
);
byte
[]
by
=
new
byte
[]
try
{
byte
funCode
=
0x0F
;
//批量写圈
byte
startAddress
=
(
byte
)(
64
+
donum
);
//写圈起始地址
byte
startLength
=
1
;
var
seqhead
=
BitConverter
.
GetBytes
(
seq
);
byte
iostate
=
(
byte
)(
state
?
1
:
0
);
byte
[]
by
=
new
byte
[]
{
//事物标识符
seqhead
[
0
],
seqhead
[
1
],
...
...
@@ -171,41 +173,48 @@ class NanjingSDotIO : IOBase
startLength
,
//读个数
0x01
,
iostate
};
by
[
5
]
=
(
byte
)(
by
.
Length
-
6
);
bool
check
=
true
;
lock
(
tcpClient
)
{
try
};
by
[
5
]
=
(
byte
)(
by
.
Length
-
6
);
bool
check
=
true
;
lock
(
tcpClient
)
{
seqadd
();
tcpClient
.
Client
.
Send
(
by
);
byte
[]
result
=
new
byte
[
100
];
var
ulength
=
tcpClient
.
Client
.
Receive
(
result
);
var
newResult
=
result
.
ToList
().
Take
(
ulength
).
ToArray
();
if
(
newResult
[
0
]
==
seqhead
[
0
]
&&
newResult
[
1
]
==
seqhead
[
1
])
try
{
check
=
true
;
seqadd
();
tcpClient
.
Client
.
Send
(
by
);
byte
[]
result
=
new
byte
[
100
];
var
ulength
=
tcpClient
.
Client
.
Receive
(
result
);
var
newResult
=
result
.
ToList
().
Take
(
ulength
).
ToArray
();
if
(
newResult
[
0
]
==
seqhead
[
0
]
&&
newResult
[
1
]
==
seqhead
[
1
])
{
check
=
true
;
}
else
{
return
false
;
}
}
else
catch
{
return
false
;
}
}
catch
{
return
false
;
}
}
/*
var newResult = result.ToList().Take(ulength).ToArray();
//输出报文
var output = string.Join(" ", newResult.Select(x => x.ToString("X2")));
/*
var newResult = result.ToList().Take(ulength).ToArray();
//输出报文
var output = string.Join(" ", newResult.Select(x => x.ToString("X2")));
*/
*/
return
check
;
return
check
;
}
catch
(
Exception
ex
)
{
TSA_V
.
Common
.
LogUtil
.
error
(
"出错:"
+
ex
.
ToString
());
}
return
false
;
}
/// <summary>
/// 所有DI状态
...
...
TSA-V/workForm/FrmAOICheck.cs
查看文件 @
d963703
...
...
@@ -164,7 +164,7 @@ namespace TSA_V
return
0
;
}
chbAllShow
.
Enabled
=
false
;
string
camera
=
Setting_NInit
.
Device_CameraName
;
if
(
camera
==
""
)
{
...
...
@@ -172,36 +172,61 @@ namespace TSA_V
}
DateTime
startTime
=
DateTime
.
Now
;
LogUtil
.
info
(
"AOICheck : 开始获取图片"
);
Image
currImage
=
CameraManager
.
GetCamerImage
(
camera
);
if
(
currImage
==
null
)
string
theImagePath
=
""
;
using
(
Bitmap
currImage
=
CameraManager
.
GetCamerImage
(
camera
))
{
string
file
=
defFile
;
if
(
File
.
Exists
(
file
))
{
//从本地加载图片
Bitmap
aa
=
new
Bitmap
(
file
);
currImage
=
ImageManager
.
DeepClone
(
aa
);
if
(
currImage
==
null
)
{
string
file
=
defFile
;
if
(
File
.
Exists
(
file
))
{
theImagePath
=
file
;
////从本地加载图片
//Bitmap aa = new Bitmap(file);
//currImage = ImageManager.DeepClone(aa);
}
}
}
if
(
currImage
!=
null
)
{
TimeSpan
span1
=
DateTime
.
Now
-
startTime
;
LogUtil
.
info
(
$
"AOICheck : 图片获取完成, {Math.Round( span1.TotalMilliseconds,1)}ms, 开始check"
);
if
(
Setting_NInit
.
Work_SaveAOIImg
)
if
(
currImage
!=
null
)
{
ImageUtilM
.
SaveImageToFile
(
"AOI"
,
"Source"
,
Eyemlib
.
DeepClone
(
currImage
));
if
(
Setting_NInit
.
Work_SaveAOIImg
)
{
theImagePath
=
ImageUtilM
.
SaveImageToFile
(
"AOI"
,
"Source"
,
currImage
);
}
else
{
string
filePath
=
Application
.
StartupPath
+
@"\image\"
;
Directory
.
CreateDirectory
(
filePath
);
string
fileName
=
@"\test.bmp"
;
string
path
=
Path
.
GetFullPath
(
filePath
);
if
(!
Directory
.
Exists
(
path
))
{
Directory
.
CreateDirectory
(
path
);
}
theImagePath
=
filePath
+
fileName
;
currImage
.
Save
(
filePath
+
fileName
,
ImageFormat
.
Bmp
);
}
}
}
if
(
theImagePath
!=
""
&&
File
.
Exists
(
theImagePath
))
{
TimeSpan
span1
=
DateTime
.
Now
-
startTime
;
LogUtil
.
info
(
$
"AOICheck : 图片获取{theImagePath}完成, {Math.Round(span1.TotalMilliseconds, 1)}ms, 开始check"
);
var
bmp
=
new
Bitmap
(
theImagePath
);
Image
TestImage
=
Eyemlib
.
DeepClone
(
bmp
);
bmp
.
Dispose
();
//Bitmap bitmap = new Bitmap(currImage);
Image
outImage
=
null
;
List
<
ResultBean
>
resultBean
=
CurrProject
.
CheckAll
(
curr
Image
,
out
outImage
);
List
<
ResultBean
>
resultBean
=
CurrProject
.
CheckAll
(
Test
Image
,
out
outImage
);
span1
=
DateTime
.
Now
-
startTime
;
LogUtil
.
info
(
$
"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms"
);
currImage
.
Dispose
();
ResultList
=
resultBean
;
if
(
outImage
!=
null
)
{
{
this
.
picResult
.
Image
=
outImage
;
if
(
Setting_NInit
.
Work_SaveAOIResult
)
{
...
...
@@ -210,7 +235,7 @@ namespace TSA_V
}
else
{
this
.
picResult
.
Image
=
currImage
;
this
.
picResult
.
Image
=
Eyemlib
.
DeepClone
(
TestImage
)
;
}
result
=
1
;
endTime
=
DateTime
.
Now
;
...
...
@@ -224,21 +249,22 @@ namespace TSA_V
result
=
2
;
// break;
listErrorView
.
Items
.
Add
(
GetShowName
(
bean
));
}
else
if
(
chbAllShow
.
Checked
)
{
}
else
if
(
chbAllShow
.
Checked
)
{
listErrorView
.
Items
.
Add
(
GetShowName
(
bean
));
}
}
if
(
listErrorView
.
Items
.
Count
>
0
)
{
listErrorView
.
Items
[
0
].
Selected
=
true
;
listErrorView
.
Items
[
0
].
Selected
=
true
;
}
chbAllShow
.
Enabled
=
true
;
if
(
result
.
Equals
(
1
))
{
lblError
.
Visible
=
false
;
lblError
.
Visible
=
false
;
lblInfo
.
Text
=
AccAOI
.
ControlUtil
.
GetResultsStr
(
resultBean
);
lblInfo
.
Visible
=
true
;
LogUtil
.
info
(
"AOI检测OK:"
+
lblInfo
.
Text
);
...
...
@@ -250,6 +276,7 @@ namespace TSA_V
lblError
.
Visible
=
true
;
LogUtil
.
info
(
"AOI检测NG:"
+
ngList
);
}
TestImage
.
Dispose
();
}
else
{
...
...
@@ -258,7 +285,7 @@ namespace TSA_V
LogUtil
.
error
(
"AOI检测:获取相机图片失败:"
+
CameraManager
.
ErrorMsg
);
return
0
;
}
chbAllShow
.
Enabled
=
true
;
chbAllShow
.
Enabled
=
true
;
}
catch
(
AccessViolationException
e
)
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论