From 86f899fa91e811415614dff1a699141144bfc802 Mon Sep 17 00:00:00 2001
From: quanzhou <quan.zhou@broconcentric.com>
Date: 星期五, 12 十二月 2025 13:25:37 +0800
Subject: [PATCH] S5上传mes逻辑修改及打印机逻辑修改和数据库存储数据增加
---
src/Bro.M141.Process/M141Process_ImageCheck.cs | 592 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 523 insertions(+), 69 deletions(-)
diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs
index 118ce5a..4d1f940 100644
--- a/src/Bro.M141.Process/M141Process_ImageCheck.cs
+++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -2,12 +2,15 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
+using Bro.DataBase.Model;
using Bro.M135.Common;
using Bro.M135.DBManager;
+using Bro.UI.Model.Winform;
using HalconDotNet;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.UserModel;
@@ -15,6 +18,7 @@
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
+using System.Drawing.Imaging;
using System.Net;
using System.Text;
using System.Text.Encodings.Web;
@@ -24,6 +28,7 @@
using static System.Net.Mime.MediaTypeNames;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
+using File = System.IO.File;
namespace Bro.M141.Process
{
@@ -34,7 +39,7 @@
ManualResetEvent set2 = new ManualResetEvent(false);
- public event Action<string> StartPrinter;
+
[ProcessMethod("ImageCheck", "ImageCheckOperation", "閫氱敤鍥剧墖妫�娴嬫搷浣�", InvokeType.TestInvoke)]
public ResponseMessage ImageCheckOperation(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -441,7 +446,7 @@
return msg;
}
-
+
@@ -449,7 +454,8 @@
public ResponseMessage ProductDataUpload(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
{
ResponseMessage msg = new ResponseMessage();
- string inputSequence = Plc1.Read(1536, 1, out _)[0].ToString();
+ int numplca = Plc1.Read(1536, 1, out _)[0];
+ string inputSequence = numplca.ToString();
var productList = new List<int>() { 1 }.Select(u =>
{
@@ -457,6 +463,10 @@
return FindProductBySequence(sequence, true);
}).ToList();
+ if (PlcNumForAll == -1)
+ {
+ PlcNumForAll = numplca;
+ }
int waitInterval = 300;
int repeatTime = M141Config.DetectTimeout / waitInterval;
@@ -481,31 +491,144 @@
} while (true);
- var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.IsDefault);
- productList.ForEach(p =>
- {
- if (Defaultclass == null)
- {
- if (string.IsNullOrEmpty(p.Result))
- {
- p.Result = "NG";
- }
- }
- else
- {
- if (string.IsNullOrEmpty(p.Result))
- {
- p.Result = Defaultclass.ClassName;
- }
- }
+ var Defaultclass = M141Config.DefectClassCollection.FirstOrDefault(u => u.ClassName == productList[0].Result);
- Plc1.WriteSingleAddress(1526, p.Result.ToUpper().Contains("NG") ? 2 : 1, out _);
- });
+ if (M141Config.StationCode == "S4" && productList[0].Result == "OK")
+ {
+ ////mysqlhelper.GetS2Result(productList[0].SEQUENCE);
+ Plc1.WriteSingleAddress(1526, mysqlhelper.GetS2Result(productList[0].SEQUENCE) ? 1 : 2, out _);
+
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{string.Join(",", productList.Select(u => u.PID))}妫�娴嬪弽棣坽mysqlhelper.GetS2Result(productList[0].SEQUENCE)}");
+ }
+ else
+ {
+ Plc1.WriteSingleAddress(1526, Defaultclass?.ClassValue ?? 2, out _);
+ }
+
Plc1.WriteSingleAddress(1516, 1, out _);
+
+ //if (M141Config.ISupMES && (M141Config.MESchannel == -1 || M141Config.MESchannel == 1))
+ //{
+ // if (M141Config.numpro >= 50)
+ // {
+ // M141Config.numpro = 0;
+ // }
+
+ // if (productList[0].Result == "OK")
+ // {
+ // M141Config.numpro++;
+ // }
+
+ // //mqtt.demes(productList[0], M141Config.zwoid);
+ // string Msgreceice = Task.Run(() => mqtt.MESForProduceAsync(productList[0], M141Config.zwoid, M141Config.numpro)).Result;
+ // if (Msgreceice == null)
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 杩斿洖鏁版嵁涓簄ull");
+ // }
+ // else
+ // {
+ // try
+ // {
+ // var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
+
+ // if (obj.zstatus == "200")
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES鎴愬姛 {Msgreceice}");
+ // }
+ // else
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES澶辫触 {Msgreceice}");
+ // }
+ // }
+ // catch
+ // {
+ // LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"浜у搧{productList[0].PID}鏁版嵁涓婁紶MES寮傚父 {Msgreceice}");
+ // }
+ // }
+
+
+
+ // lock (plcnumlock)
+ // {
+ // int differ = numplca - PlcNumForAll;
+ // if (differ > 1)
+ // {
+ // for (int i = PlcNumForAll + 1; i < numplca; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+ // }
+ // catch
+ // {
+
+ // }
+ // }
+ // }
+ // else if (differ != -29998)
+ // {
+ // for (int i = PlcNumForAll + 1; i <= 29999; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+ // }
+ // catch
+ // {
+
+ // }
+ // }
+
+
+
+ // for (int i = 1; i < numplca; i++)
+ // {
+ // try
+ // {
+ // var plist = mysqlhelper.GetProductList(i + "_1");
+ // ProductModel newp = new ProductModel();
+ // newp.SEQUENCE = plist[0].SEQUENCE;
+ // newp.PID = plist[0].PID;
+ // newp.BasketCode = plist[0].BasketCode;
+ // newp.Result = "NG";
+ // newp.SN = plist[0].SN;
+ // var tems = Task.Run(() => mqtt.MESForProduceAsync(newp, M141Config.zwoid, M141Config.numpro)).Result;
+
+ // }
+ // catch
+ // {
+
+ // }
+ // }
+
+
+ // }
+ // PlcNumForAll = numplca;
+ // }
+
+ //}
return msg;
}
+ object plcnumlock = new object();
+ int PlcNumForAll = -1;
private bool _isDemoStarted = false;
[ProcessMethod("OfflineDemo", "OfflineDemo", "绂荤嚎娴嬭瘯", InvokeType.CalibInvoke)]
@@ -520,14 +643,14 @@
else
{
_isDemoStarted = true;
- OfflineDemoAsync(opConfig.ImageFolder);
+ OfflineDemoAsync(opConfig.ImageFolder, opConfig.IsOK, opConfig.SaveImageTime);
}
}
return new ResponseMessage();
}
- private async void OfflineDemoAsync(string imageFolder)
+ private async void OfflineDemoAsync(string imageFolder, bool isok, int saveimagetime)
{
await Task.Run(() =>
{
@@ -539,24 +662,30 @@
{
return;
}
-
var imageFile = Path.GetFileNameWithoutExtension(imageFileNames[i]);
if (imageFile.EndsWith("Fit"))
{
continue;
}
-
- var nameDatas = imageFile.Split(new char[] { '_'}, StringSplitOptions.RemoveEmptyEntries).ToList();
+ if (imageFile.EndsWith("OK") & isok == false)
+ {
+ continue;
+ }
+ if (imageFile.EndsWith("NG") & isok == true)
+ {
+ continue;
+ }
+ var nameDatas = imageFile.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (nameDatas.Count != 5)
{
LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏂囦欢{imageFile}鍛藉悕涓嶇鍚堣鑼冿紝涓嶆墽琛岀绾挎祴璇�");
continue;
}
- var sn = nameDatas[0];
- var imageSeq = nameDatas[1];
-
+ var sn = nameDatas[0] + "_1";
+ var imageSeq = nameDatas[2][^1].ToString();
var measureBind = M141Config.MeasureBindCollection.FirstOrDefault(u => u.ImageSaveSeq == imageSeq);
+
if (measureBind == null || !measureBind.IsFixed)
{
LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"绂荤嚎娴嬭瘯锛屽伐浣峽(measureBind == null ? "鏈尮閰�" : $"{measureBind.WorkPosition}鏈紑鍚�")}");
@@ -565,51 +694,364 @@
LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"绂荤嚎娴嬭瘯锛屼骇鍝亄sn}寮�濮嬪伐浣峽measureBind.WorkPosition}绂荤嚎妫�娴�");
MLImageSet imgSet = new MLImageSet();
+
imgSet.HImage = new HalconDotNet.HImage(imageFileNames[i]);
imgSet.PID = sn;
var detectResults = ML.RunMLDetectionSync(imgSet, null, measureBind.DetectionId);
-
+ Thread.Sleep(saveimagetime);
imgSet.HImage?.Dispose();
imgSet.HImage = null;
-
-
- //var defectFields = M141Config.DefectLocationSettings.FirstOrDefault(u => u.PositionCode == measureBind.WorkPosition);
-
-
- //var list = detectResults.SelectMany(u => u.NetResults.SelectMany(m => m.DetectDetails)).ToList();
- ////if (list.Count > 0)
- ////{
- //// //list.ForEach(d =>
- //// //{
- //// // //if (defectFields == null)
- //// // //{
- //// // // d.Tag = "";
- //// // //}
- //// // //else
- //// // //{
- //// // // RectangleF rect = new RectangleF(d.Rect.Point_LU.X, d.Rect.Point_LU.Y, d.Rect.Width, d.Rect.Height);
- //// // // //var rectList = defectFields.Display.RectDict.Where(u => rect.IntersectsWith(u.Value)).ToList();
- //// // // //if (rectList.Count > 0)
- //// // // //{
- //// // // // d.Tag = string.Join(" ", rectList.Select(u => u.Key).OrderBy(u => u));
- //// // // //}
- //// // // //else
- //// // // //{
- //// // // // d.Tag = "";
- //// // // //}
- //// // //}
- //// //});
- ////}
-
- //Bitmap originImage = new Bitmap(imageFileNames[i]);
- //DetectResultSaveExcelAsync(detectResults, sn, originImage, DateTime.Now);
+ Bitmap originImage = new Bitmap(imageFileNames[i]);
+ DetectResultSaveExcelAsync(detectResults, sn, originImage, DateTime.Now);
}
});
}
-
+ object _excelOpLock = new object();
+ int _columnWidth = 0;
+ int _columnWidth1 = 0;
+
+ int _exportNum = 0;
+
+ public async void DetectResultSaveExcelAsync(List<DetectResult> detectResults, string sn, Bitmap originImage, DateTime dt)
+ {
+ await Task.Run(() =>
+ {
+ if (detectResults.All(u => u.ResultState == EnumHelper.ResultState.OK))
+ return;
+
+ try
+ {
+ string excel_Path = Path.Combine(CSVHelper.BaseDirectory, $"{DateTime.Now.ToString("yyyyMMdd")}");
+ if (!Directory.Exists(excel_Path))//濡傛灉涓嶅瓨鍦ㄥ氨鍒涘缓file鏂囦欢澶�
+ {
+ Directory.CreateDirectory(excel_Path);//鍒涘缓璇ユ枃浠跺す
+ }
+ excel_Path = Path.Combine(excel_Path, $"OfflineRecord_{DateTime.Now.ToString("yyyyMMdd")}.xlsx");
+ List<string> datas = new List<string>() { "妫�娴嬫椂闂�", "SN", "缂洪櫡鍚嶇О", "浣嶇疆", "缂洪櫡闈㈢Н", "瀹為檯闈㈢Н", "缂洪櫡鎴浘1", "缂洪櫡鎴浘2" };
+
+ NPOI.SS.UserModel.IRow irow;
+ NPOI.SS.UserModel.ICell icell;
+
+ Interlocked.Increment(ref _exportNum);
+ lock (_excelOpLock)
+ {
+ if (!File.Exists(excel_Path))
+ {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ ISheet sheet = wb.CreateSheet("DefectDetail");
+ irow = sheet.CreateRow(0);
+ for (int i = 0; i < datas.Count; i++)
+ {
+ icell = irow.CreateCell(i);
+ icell.SetCellValue(datas[i]);
+ }
+ FileStream fs = new FileStream(excel_Path, FileMode.OpenOrCreate, FileAccess.Write);
+ wb.Write(fs); fs.Close();
+ fs.Dispose();
+ }
+
+ using (FileStream newfs = new FileStream(excel_Path, FileMode.Open, FileAccess.ReadWrite))
+ {
+ //鍒涘缓宸ヤ綔绨垮璞�
+ XSSFWorkbook newwb = new XSSFWorkbook(newfs);
+ //鏍规嵁宸ヤ綔琛ㄥ悕鑾峰彇宸ヤ綔绨垮璞★紝涔熷彲閫氳繃绱㈠紩鑾峰彇宸ヤ綔琛╳b.GetSheetAt(int index)
+ ISheet newsheet = newwb.GetSheet("DefectDetail");
+ int countrow = newsheet.LastRowNum + 1;
+
+ //ICellStyle hlink_style = newwb.CreateCellStyle();
+ //IFont hlink_font = newwb.CreateFont();
+ //hlink_font.Underline = FontUnderlineType.Single;
+ //hlink_font.Color = HSSFColor.Blue.Index;
+ //hlink_style.SetFont(hlink_font);
+
+ XSSFDrawing patriarchDefectImageFile = (XSSFDrawing)newsheet.CreateDrawingPatriarch();
+
+ var details = detectResults.SelectMany(u => u.NetResults).SelectMany(u => u.DetectDetails).Where(u => u.FinalResult != EnumHelper.ResultState.OK).ToList();
+
+ details.ForEach(d =>
+ {
+ //"妫�娴嬫椂闂�", "SN", "缂洪櫡鍚嶇О", "浣嶇疆", "缂洪櫡闈㈢Н", "瀹為檯闈㈢Н", "缂洪櫡鎴浘1", "缂洪櫡鎴浘2"
+ List<string> data = new List<string>() { dt.ToString("HH:mm:ss.fff").ToString(), sn, d.ClassName, (d.Tag ?? "").ToString(), d.Area.ToString(), d.AreaInActual.ToString("f3") };
+
+ irow = newsheet.CreateRow(countrow);
+
+ for (int i = 0; i < datas.Count; i++)
+ {
+ icell = irow.CreateCell(i);
+
+ switch (i)
+ {
+ case 6:
+ {
+ byte[] bytesDefectImageFile = CaptureImage(originImage, (int)d.Rect.Width, (int)d.Rect.Height, (int)d.Rect.X, (int)d.Rect.Y, out int actWidth, out int actHeight);
+ int pictureIdxDefectImageFile = newwb.AddPicture(bytesDefectImageFile, NPOI.SS.UserModel.PictureType.JPEG);
+
+ // 鎻掑浘鐗囩殑浣嶇疆 HSSFClientAnchor锛坉x1,dy1,dx2,dy2,col1,row1,col2,row2) 鍚庨潰鍐嶄綔瑙i噴
+ XSSFClientAnchor anchorDefectImageFile = new XSSFClientAnchor(1, 1, 1, 1, i, countrow, i + 1, countrow + 1);
+ //鎶婂浘鐗囨彃鍒扮浉搴旂殑浣嶇疆
+ XSSFPicture pictDefectImageFile = (XSSFPicture)patriarchDefectImageFile.CreatePicture(anchorDefectImageFile, pictureIdxDefectImageFile);
+
+ ////int colWidth = actWidth * 32;
+ ////if (colWidth > _columnWidth)
+ ////{
+ //// _columnWidth = colWidth;
+ //// newsheet.SetColumnWidth(i, _columnWidth);
+ ////}
+
+ irow.Height = (short)(actHeight * 16);
+ //pictDefectImageFile.Resize();
+ }
+ break;
+ case 7:
+ {
+ byte[] bytesDefectImageFile = CaptureImage(originImage, (int)d.Rect.Width, (int)d.Rect.Height, (int)d.Rect.X, (int)d.Rect.Y, out int actWidth, out int actHeight, d);
+ int pictureIdxDefectImageFile = newwb.AddPicture(bytesDefectImageFile, NPOI.SS.UserModel.PictureType.JPEG);
+
+ XSSFClientAnchor anchorDefectImageFile = new XSSFClientAnchor(1, 1, 1, 1, i, countrow, i + 5, countrow + 1);
+ //鎶婂浘鐗囨彃鍒扮浉搴旂殑浣嶇疆
+ XSSFPicture pictDefectImageFile = (XSSFPicture)patriarchDefectImageFile.CreatePicture(anchorDefectImageFile, pictureIdxDefectImageFile);
+
+ //int colWidth = actWidth * 32;
+ //if (colWidth > _columnWidth1)
+ //{
+ // _columnWidth1 = colWidth;
+ // newsheet.SetColumnWidth(i, _columnWidth1);
+ //}
+ //pictDefectImageFile.Resize();
+ }
+ break;
+ default:
+ string strvalue = data[i];
+ icell.SetCellValue(strvalue);
+ break;
+ }
+ }
+ countrow++;
+
+ });
+
+ using (var temp = File.OpenWrite(excel_Path))
+ {
+ newwb.Write(temp);//鍚戞墦寮�鐨勮繖涓獂ls鏂囦欢涓啓鍏ユ暟鎹�
+ }
+ newfs.Close();
+ newfs.Dispose();
+ }
+ }
+ Interlocked.Decrement(ref _exportNum);
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"{detectResults[0].PID}Excel杈撳嚭瀹屾垚锛岃繕鏈墈_exportNum}鏉¤褰�");
+ }
+ catch (Exception ex)
+ {
+ LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{detectResults[0].PID}缂洪櫡鎻掑叆Excel鎶ラ敊锛歿ex.Message.ToString()}");
+ }
+ finally
+ {
+ originImage.Dispose();
+ originImage = null;
+ }
+ });
+ }
+
+ int _spaceRemain = 60;
+ //public byte[] CaptureImage(Bitmap originImage, int width, int height, int spaceX, int spaceY, out int actWidth, out int actHeight, DefectDetail defect = null)
+ //{
+ // spaceX -= _spaceRemain;
+ // spaceY -= _spaceRemain;
+
+ // width += _spaceRemain * 2;
+ // height += _spaceRemain * 2;
+
+ // if (spaceX < 0)
+ // {
+ // spaceX = 0;
+ // }
+
+ // if (spaceY < 0)
+ // {
+ // spaceY = 0;
+ // }
+
+ // if (spaceX + width > originImage.Width)
+ // {
+ // width = originImage.Width - spaceX;
+ // }
+
+ // if (spaceY + height > originImage.Height)
+ // {
+ // height = originImage.Height - spaceY;
+ // }
+
+ // actHeight = height;
+ // actWidth = width;
+
+ // Bitmap imageBack = originImage;
+
+ // if (defect != null)
+ // {
+ // PolygonResultDisplay display = new PolygonResultDisplay(defect, defect.ClassName, Color.Red, false, (int)(width * GlobalVar.WIDTH_RATIO));
+
+ // imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
+ // using (Graphics g = Graphics.FromImage(imageBack))
+ // {
+ // g.DrawImage(originImage, 0, 0);
+ // display.Draw(g);
+ // }
+ // }
+
+ // //鍒涘缓鏂板浘浣嶅浘
+ // Bitmap bitmap = new Bitmap(width, height, imageBack.PixelFormat);
+ // //鍒涘缓浣滃浘鍖哄煙
+ // using (Graphics graphic = Graphics.FromImage(bitmap))
+ // {
+ // //鎴彇鍘熷浘鐩稿簲鍖哄煙鍐欏叆浣滃浘鍖�
+ // graphic.DrawImage(imageBack, 0, 0, new Rectangle(spaceX, spaceY, width, height), GraphicsUnit.Pixel);
+ // }
+
+ // byte[] bt = null;
+ // using (MemoryStream mostream = new MemoryStream())
+ // {
+ // bitmap.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//灏嗗浘鍍忎互鎸囧畾鐨勬牸寮忓瓨鍏ョ紦瀛樺唴瀛樻祦
+ // bt = new byte[mostream.Length];
+ // mostream.Position = 0;//璁剧疆鐣欑殑鍒濆浣嶇疆
+ // mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
+ // }
+
+ // bitmap.Dispose();
+ // return bt;
+ //}
+
+ public byte[] CaptureImage(Bitmap originImage, int width, int height, int spaceX, int spaceY,
+ out int actWidth, out int actHeight, DefectDetail defect = null)
+ {
+ spaceX -= _spaceRemain;
+ spaceY -= _spaceRemain;
+
+ width += _spaceRemain * 2;
+ height += _spaceRemain * 2;
+
+ if (spaceX < 0)
+ {
+ spaceX = 0;
+ }
+
+ if (spaceY < 0)
+ {
+ spaceY = 0;
+ }
+
+ if (spaceX + width > originImage.Width)
+ {
+ width = originImage.Width - spaceX;
+ }
+
+ if (spaceY + height > originImage.Height)
+ {
+ height = originImage.Height - spaceY;
+ }
+
+ actHeight = height;
+ actWidth = width;
+
+ Bitmap imageBack = originImage;
+ bool needDisposeImageBack = false; // 鏂板锛氭爣璁版槸鍚﹂渶瑕侀噴鏀緄mageBack
+
+ if (defect != null)
+ {
+ PolygonResultDisplay display = new PolygonResultDisplay(defect, defect.ClassName, Color.Red, false, (int)(width * GlobalVar.WIDTH_RATIO));
+
+ // 淇敼鐐�1锛氱‘淇濆垱寤虹殑Bitmap鏀寔Graphics
+ // 浣跨敤Format24bppRgb鎴朏ormat32bppArgb
+ imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
+ needDisposeImageBack = true; // 鏍囪涓洪渶瑕侀噴鏀�
+
+ // 淇敼鐐�2锛氭鏌ュ師濮嬪浘鍍忔牸寮忥紝濡傛灉鏄储寮曟牸寮忛渶瑕佺壒娈婂鐞�
+ if (IsIndexedPixelFormat(originImage.PixelFormat))
+ {
+ // 鍒涘缓鏀寔Graphics鐨勬牸寮�
+ using (Bitmap tempImage = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb))
+ using (Graphics tempG = Graphics.FromImage(tempImage))
+ {
+ tempG.DrawImage(originImage, 0, 0);
+
+ using (Graphics g = Graphics.FromImage(imageBack))
+ {
+ g.DrawImage(tempImage, 0, 0);
+ display.Draw(g);
+ }
+ }
+ }
+ else
+ {
+ // 鍘熷浠g爜閫昏緫
+ using (Graphics g = Graphics.FromImage(imageBack))
+ {
+ g.DrawImage(originImage, 0, 0);
+ display.Draw(g);
+ }
+ }
+ }
+ else if (IsIndexedPixelFormat(originImage.PixelFormat))
+ {
+ // 淇敼鐐�3锛氬嵆浣挎病鏈塪efect锛屽鏋滄槸绱㈠紩鏍煎紡涔熼渶瑕佽浆鎹�
+ imageBack = new Bitmap(originImage.Width, originImage.Height, PixelFormat.Format24bppRgb);
+ needDisposeImageBack = true;
+
+ using (Graphics g = Graphics.FromImage(imageBack))
+ {
+ g.DrawImage(originImage, 0, 0);
+ }
+ }
+
+ // 淇敼鐐�4锛氱‘淇漛itmap鐨勫儚绱犳牸寮忔敮鎸丟raphics
+ PixelFormat bitmapFormat = imageBack.PixelFormat;
+ if (IsIndexedPixelFormat(bitmapFormat))
+ {
+ // 濡傛灉imageBack浠嶇劧鏄储寮曟牸寮忥紙鐞嗚涓婁笉搴旇锛夛紝杞崲涓烘敮鎸佹牸寮�
+ bitmapFormat = PixelFormat.Format24bppRgb;
+ }
+
+ //鍒涘缓鏂板浘浣嶅浘
+ Bitmap bitmap = new Bitmap(width, height, bitmapFormat);
+
+ //鍒涘缓浣滃浘鍖哄煙
+ using (Graphics graphic = Graphics.FromImage(bitmap))
+ {
+ //鎴彇鍘熷浘鐩稿簲鍖哄煙鍐欏叆浣滃浘鍖�
+ graphic.DrawImage(imageBack, 0, 0, new Rectangle(spaceX, spaceY, width, height), GraphicsUnit.Pixel);
+ }
+
+ byte[] bt = null;
+ using (MemoryStream mostream = new MemoryStream())
+ {
+ bitmap.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//灏嗗浘鍍忎互鎸囧畾鐨勬牸寮忓瓨鍏ョ紦瀛樺唴瀛樻祦
+ bt = new byte[mostream.Length];
+ mostream.Position = 0;//璁剧疆鐣欑殑鍒濆浣嶇疆
+ mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
+ }
+
+ bitmap.Dispose();
+
+ // 淇敼鐐�5锛氶噴鏀句复鏃跺垱寤虹殑imageBack
+ if (needDisposeImageBack && imageBack != originImage)
+ {
+ imageBack.Dispose();
+ }
+
+ return bt;
+ }
+
+ // 鏂板杈呭姪鏂规硶锛氭鏌ユ槸鍚︿负绱㈠紩鍍忕礌鏍煎紡
+ private bool IsIndexedPixelFormat(PixelFormat format)
+ {
+ return format == PixelFormat.Format1bppIndexed ||
+ format == PixelFormat.Format4bppIndexed ||
+ format == PixelFormat.Format8bppIndexed ||
+ format == PixelFormat.Indexed;
+ }
[ProcessMethod("printer", "printer", "鎵撳嵃鏈烘墦鍗�", InvokeType.TestInvoke)]
public ResponseMessage Printer(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -617,8 +1059,13 @@
ResponseMessage msg = new ResponseMessage();
Plc2 = invokeDevice as PLCBase;
- string message = "";
- StartPrinter.Invoke(message);
+ //string message = "nothing";
+ if (M141Config.MES_codes.Count >= 1)
+ {
+ string message = M141Config.MES_codes[0].Printers_code;
+ StartPrint(message, "Honeywell PX240S(300 dpi)1");
+ M141Config.MES_codes.RemoveAt(0);
+ }
return msg;
}
@@ -747,7 +1194,7 @@
UpdateDefectAsync(defects);
var defectClass = GetDefectClassFromDefectList(defects);
- UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "");
+ UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, "", p.ImagePaths);
//浜у搧搴忓彿+1
//Interlocked.Increment(ref _productIndex);
@@ -771,17 +1218,20 @@
- private void UpdateProductResultAsync(ProductModel p)
+ private void UpdateProductResultAsync(ProductModel p, string name)
{
UpdateProductResult(p, out bool isOK);
_taskFactory.StartNew(() =>
{
_csvHead = p.GetCSVHead(ref _specHeadList, ref _positionList);
- CSVRecordAsync($"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", p.GetCSVData(_specHeadList, _positionList), _csvHead);
+ //CSVRecordAsync($"ProductRecord_{DateTime.Now.ToString("yyyyMMdd")}.csv", p.GetCSVData(_specHeadList, _positionList), _csvHead);
+ CSVRecordAsync(name, p.GetCSVData(_specHeadList, _positionList), _csvHead);
//_manager_P_Product.UpdateProductResult(p.ID, p.PID, p.SN, p.Result);
});
+ //杩炵画NG鏁版嵁璁板綍
+ CheckContinuousNGAlarmAsync(p);
}
@@ -893,6 +1343,10 @@
+
+
+
+
}
}
--
Gitblit v1.8.0