Commit d963703c LN

1

1 个父辈 26df9ae0
......@@ -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状态
......
......@@ -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(currImage, out outImage);
List<ResultBean> resultBean = CurrProject.CheckAll(TestImage, 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!