From e254b1f4efa18b3c84ce75e9da2aeff64a1c7cbe Mon Sep 17 00:00:00 2001
From: zhengqifeng <zhengqifeng@hnkhzn.com>
Date: 星期二, 30 十二月 2025 11:18:01 +0800
Subject: [PATCH] 添加前端
---
代码管理/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs | 68 ++++++++++++---------------------
1 files changed, 25 insertions(+), 43 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
index a1b8461..03c0398 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
@@ -46,18 +46,6 @@
private readonly string set = "0x16,0x4D,0x0D,0x30,0x34,0x30,0x31,0x44,0x30,0x35,0x2E";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
private readonly string Text = "寮�鍚壂鐮�";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
private readonly string command = "0x16,0x54,0x0D";//鍙戦�佸紑濮嬭В鐮佸懡浠わ紱"0x16,0x55,0x0D"鍙戦�佸仠姝㈣В鐮佸懡浠�
- SerialPortCommunicator portCommunicator1 = new SerialPortCommunicator("COM1", 9600, "涓婄嚎鎵爜鏋�");
- static bool IsConnected1 = false;
- SerialPortCommunicator portCommunicator2 = new SerialPortCommunicator("COM2", 9600, "涓婄嚎鎵爜鏋�");
- static bool IsConnected2 = false;
- SerialPortCommunicator portCommunicator17 = new SerialPortCommunicator("COM17", 9600, "鍘嬭鎵爜鏋�");
- static bool IsConnected17 = false;
- SerialPortCommunicator portCommunicator18 = new SerialPortCommunicator("COM18", 9600, "鍘嬭鎵爜鏋�");
- static bool IsConnected18 = false;
- SerialPortCommunicator portCommunicator19 = new SerialPortCommunicator("COM19", 9600, "鍘嬭鎵爜鏋�");
- static bool IsConnected19 = false;
- SerialPortCommunicator portCommunicator20 = new SerialPortCommunicator("COM20", 9600, "鍘嬭鎵爜鏋�");
- static bool IsConnected20 = false;
public Task Execute(IJobExecutionContext context)
{
@@ -116,6 +104,10 @@
if (Location1ScanStart && !Location1ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
{
#region 涓插彛杩炴帴
+ SerialPortCommunicator portCommunicator1 = new SerialPortCommunicator("COM1", 9600, "涓婄嚎鎵爜鏋�");
+ bool IsConnected1 = false;
+ SerialPortCommunicator portCommunicator2 = new SerialPortCommunicator("COM2", 9600, "涓婄嚎鎵爜鏋�");
+ bool IsConnected2 = false;
if (!IsConnected1) IsConnected1 = portCommunicator1.Connect();
if (!IsConnected2) IsConnected2 = portCommunicator2.Connect();
byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
@@ -137,8 +129,7 @@
var boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
if (boxing == null)
{
- WriteInfo(device.DeviceName, "绌烘墭鐩�");
- device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+ WriteError(device.DeviceName, "绌烘墭鐩�");
return;
}
List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == boxing.Id);
@@ -146,7 +137,6 @@
if (dt_Formula == null)
{
WriteError(device.DeviceName, "鏃犳垚鍝侀厤鏂�");
- device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
return;
}
List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == dt_Formula.Id);
@@ -154,7 +144,6 @@
if (!_boxingDetailService.IsComponentCodesEqual(dt_BoxingDetails, dt_FormulaDetails))
{
WriteError(device.DeviceName, "闆朵欢鏈夐棶棰橈紝璇峰鐞�");
- device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
return;
}
}
@@ -192,6 +181,10 @@
{
#region MyRegion
#region 涓插彛杩炴帴
+ SerialPortCommunicator portCommunicator17 = new SerialPortCommunicator("COM17", 9600, "鍘嬭鎵爜鏋�");
+ bool IsConnected17 = false;
+ SerialPortCommunicator portCommunicator18 = new SerialPortCommunicator("COM18", 9600, "鍘嬭鎵爜鏋�");
+ bool IsConnected18 = false;
if (!IsConnected17) IsConnected17 = portCommunicator17.Connect();
if (!IsConnected18) IsConnected18 = portCommunicator18.Connect();
byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
@@ -208,12 +201,6 @@
if (PalletCode.IsNotEmptyOrNull())
{
Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
- if (dt_Boxing == null)
- {
- WriteInfo(device.DeviceName, "绌烘墭鐩�");
- device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
- return;
- }
Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
//鍐欏叆PLC
device.SetValue(W_PLCDBName.wrealProductLength, dt_Formula.ProductLength);
@@ -277,6 +264,10 @@
{
#region MyRegion
#region 涓插彛杩炴帴
+ SerialPortCommunicator portCommunicator19 = new SerialPortCommunicator("COM19", 9600, "妫�娴嬫壂鐮佹灙");
+ bool IsConnected19 = false;
+ SerialPortCommunicator portCommunicator20 = new SerialPortCommunicator("COM20", 9600, "妫�娴嬫壂鐮佹灙");
+ bool IsConnected20 = false;
if (!IsConnected19) IsConnected19 = portCommunicator19.Connect();
if (!IsConnected20) IsConnected20 = portCommunicator20.Connect();
byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
@@ -294,12 +285,6 @@
if (PalletCode.IsNotEmptyOrNull())
{
Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
- if (dt_Boxing == null)
- {
- WriteInfo(device.DeviceName, "绌烘墭鐩�");
- device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
- return;
- }
Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
//鍐欏叆PLC
device.SetValue(W_PLCDBName.wrealXDirectionDistance1, dt_Formula.XDirectionDistance1);
@@ -361,15 +346,19 @@
var Location4ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation4ScanDone);
if (Location4ScanStart && !Location4ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
{
- if (!IsConnected17) IsConnected17 = portCommunicator17.Connect();
- if (!IsConnected18) IsConnected18 = portCommunicator18.Connect();
+ SerialPortCommunicator portCommunicator21 = new SerialPortCommunicator("COM21", 9600, "涓嬬嚎鎵爜鏋�");
+ bool IsConnected21 = false;
+ SerialPortCommunicator portCommunicator22 = new SerialPortCommunicator("COM22", 9600, "涓嬬嚎鎵爜鏋�");
+ bool IsConnected22 = false;
+ if (!IsConnected21) IsConnected21 = portCommunicator21.Connect();
+ if (!IsConnected22) IsConnected22 = portCommunicator22.Connect();
byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
- portCommunicator17.Write(dataToSend1);
- string receiveData = portCommunicator18.ToString(Encoding.UTF8);
+ portCommunicator21.Write(dataToSend1);
+ string receiveData = portCommunicator22.ToString(Encoding.UTF8);
byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
- portCommunicator18.Write(dataToSend2);
+ portCommunicator22.Write(dataToSend2);
//}
- string PalletCode = portCommunicator17.ToString(Encoding.UTF8);
+ string PalletCode = portCommunicator21.ToString(Encoding.UTF8);
using (var uow = _unitOfWorkManage.CreateUnitOfWork())
{
try
@@ -377,13 +366,6 @@
if (PalletCode.IsNotEmptyOrNull())
{
Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
- if (dt_Boxing == null)
- {
- WriteInfo(device.DeviceName, "璇ユ墭鐩樹负绌烘墭鐩�");
- device.SetValue(W_PLCDBName.wboolLocation4ScanDone, true);
- return;
- }
-
_boxingService.Repository.DeleteData(dt_Boxing);
List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
foreach (Dt_BoxingDetail dt_BoxingDetail in dt_BoxingDetails)
@@ -394,8 +376,8 @@
//涓嬬嚎鎵爜瀹屾垚
device.SetValue(W_PLCDBName.wboolLocation4ScanDone, true);
}
- IsConnected17 = !portCommunicator17.Disconnect();
- IsConnected18 = !portCommunicator18.Disconnect();
+ IsConnected21 = !portCommunicator21.Disconnect();
+ IsConnected22 = !portCommunicator22.Disconnect();
}
catch (Exception ex)
{
--
Gitblit v1.9.3