Commit d963703c LN

1

1 个父辈 26df9ae0
...@@ -4,7 +4,7 @@ using System.Linq; ...@@ -4,7 +4,7 @@ using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using TSA_V.DeviceLibrary; using TSA_V.DeviceLibrary;
class NanjingSDotIO : IOBase class NanjingSDotIO : IOBase
...@@ -145,13 +145,15 @@ class NanjingSDotIO : IOBase ...@@ -145,13 +145,15 @@ class NanjingSDotIO : IOBase
/// <returns></returns> /// <returns></returns>
public bool WriteDO(int donum, bool state) public bool WriteDO(int donum, bool state)
{ {
byte funCode = 0x0F;//批量写圈 try
byte startAddress = (byte)(64 + donum);//写圈起始地址
byte startLength = 1;
var seqhead = BitConverter.GetBytes(seq);
byte iostate = (byte)(state ? 1 : 0);
byte[] by = new byte[]
{ {
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[0],
seqhead[1], seqhead[1],
...@@ -171,41 +173,48 @@ class NanjingSDotIO : IOBase ...@@ -171,41 +173,48 @@ class NanjingSDotIO : IOBase
startLength, //读个数 startLength, //读个数
0x01, 0x01,
iostate iostate
}; };
by[5] = (byte)(by.Length - 6); by[5] = (byte)(by.Length - 6);
bool check = true; bool check = true;
lock (tcpClient) lock (tcpClient)
{
try
{ {
seqadd(); try
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; 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; return false;
} }
} }
catch
{
return false;
}
}
/* /*
var newResult = result.ToList().Take(ulength).ToArray(); var newResult = result.ToList().Take(ulength).ToArray();
//输出报文 //输出报文
var output = string.Join(" ", newResult.Select(x => x.ToString("X2"))); 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> /// <summary>
/// 所有DI状态 /// 所有DI状态
......
...@@ -164,7 +164,7 @@ namespace TSA_V ...@@ -164,7 +164,7 @@ namespace TSA_V
return 0; return 0;
} }
chbAllShow.Enabled = false; chbAllShow.Enabled = false;
string camera = Setting_NInit.Device_CameraName; string camera = Setting_NInit.Device_CameraName;
if (camera == "") if (camera == "")
{ {
...@@ -172,36 +172,61 @@ namespace TSA_V ...@@ -172,36 +172,61 @@ namespace TSA_V
} }
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
LogUtil.info("AOICheck : 开始获取图片"); LogUtil.info("AOICheck : 开始获取图片");
Image currImage = CameraManager.GetCamerImage(camera); string theImagePath = "";
using (Bitmap currImage = CameraManager.GetCamerImage(camera))
if (currImage == null)
{ {
string file = defFile;
if (File.Exists(file)) if (currImage == null)
{ {
//从本地加载图片 string file = defFile;
Bitmap aa = new Bitmap(file); if (File.Exists(file))
currImage = ImageManager.DeepClone(aa); {
theImagePath = file;
////从本地加载图片
//Bitmap aa = new Bitmap(file);
//currImage = ImageManager.DeepClone(aa);
}
} }
}
if (currImage != null) if (currImage != null)
{
TimeSpan span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : 图片获取完成, {Math.Round( span1.TotalMilliseconds,1)}ms, 开始check");
if (Setting_NInit.Work_SaveAOIImg)
{ {
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); //Bitmap bitmap = new Bitmap(currImage);
Image outImage = null; Image outImage = null;
List<ResultBean> resultBean = CurrProject.CheckAll(currImage, out outImage); List<ResultBean> resultBean = CurrProject.CheckAll(TestImage, out outImage);
span1 = DateTime.Now - startTime; span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms"); LogUtil.info($"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms");
currImage.Dispose();
ResultList = resultBean; ResultList = resultBean;
if (outImage != null) if (outImage != null)
{ {
this.picResult.Image = outImage; this.picResult.Image = outImage;
if (Setting_NInit.Work_SaveAOIResult) if (Setting_NInit.Work_SaveAOIResult)
{ {
...@@ -210,7 +235,7 @@ namespace TSA_V ...@@ -210,7 +235,7 @@ namespace TSA_V
} }
else else
{ {
this.picResult.Image = currImage; this.picResult.Image = Eyemlib.DeepClone(TestImage);
} }
result = 1; result = 1;
endTime = DateTime.Now; endTime = DateTime.Now;
...@@ -224,21 +249,22 @@ namespace TSA_V ...@@ -224,21 +249,22 @@ namespace TSA_V
result = 2; result = 2;
// break; // break;
listErrorView.Items.Add(GetShowName(bean)); listErrorView.Items.Add(GetShowName(bean));
}else if (chbAllShow.Checked) }
{ else if (chbAllShow.Checked)
{
listErrorView.Items.Add(GetShowName(bean)); listErrorView.Items.Add(GetShowName(bean));
} }
} }
if (listErrorView.Items.Count > 0) if (listErrorView.Items.Count > 0)
{ {
listErrorView.Items[0].Selected = true ; listErrorView.Items[0].Selected = true;
} }
chbAllShow.Enabled = true; chbAllShow.Enabled = true;
if (result.Equals(1)) if (result.Equals(1))
{ {
lblError.Visible = false ; lblError.Visible = false;
lblInfo.Text = AccAOI.ControlUtil.GetResultsStr(resultBean); lblInfo.Text = AccAOI.ControlUtil.GetResultsStr(resultBean);
lblInfo.Visible = true; lblInfo.Visible = true;
LogUtil.info("AOI检测OK:" + lblInfo.Text); LogUtil.info("AOI检测OK:" + lblInfo.Text);
...@@ -250,6 +276,7 @@ namespace TSA_V ...@@ -250,6 +276,7 @@ namespace TSA_V
lblError.Visible = true; lblError.Visible = true;
LogUtil.info("AOI检测NG:" + ngList); LogUtil.info("AOI检测NG:" + ngList);
} }
TestImage.Dispose();
} }
else else
{ {
...@@ -258,7 +285,7 @@ namespace TSA_V ...@@ -258,7 +285,7 @@ namespace TSA_V
LogUtil.error("AOI检测:获取相机图片失败:" + CameraManager.ErrorMsg); LogUtil.error("AOI检测:获取相机图片失败:" + CameraManager.ErrorMsg);
return 0; return 0;
} }
chbAllShow.Enabled = true ; chbAllShow.Enabled = true;
} }
catch (AccessViolationException e) catch (AccessViolationException e)
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!