using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using HslCommunication.LogNet;
using MainForm.FaForm;
using Sunny.UI;
using MainForm.ClassFile.XiaomiAPI;
using System.Diagnostics;
using MainForm.Models;
using SqlSugar;
using EasyModbus;
using ModBusClientSimple.Util;
using csharp_networkprotocol_hpsocket;
using MqttnetServerWin;
using Sunny.UI.Win32;
using MainForm.ClassFile.XiaomiAPI_AGV;
using MainForm.ClassFile.XiaomiAPI_RouteCom;
using HslCommunication.Controls;
using EIP_Protocol;
using MainForm.ClassFile.XiaomiAPI_MES;
using NPOI.Util;
using static MainForm.SQLHelper;
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationInbound;
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound;
using MainForm.ClassFile.ProjectClass;
using CommonLib;
using Org.BouncyCastle.Asn1.IsisMtt;
using System.Web.Services.Description;
using System.Numerics;
using MathNet.Numerics.RootFinding;
using HslCommunication.Enthernet;
using BZFAStandardLib;
using MainForm.ClassFile;
using NPOI.SS.Formula.Functions;
using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
using System.Net.Http;
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_UpLoadFile;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
using System.Reflection;
using static MainForm.ClassFile.XiaomiAPI_MES.XiaomiMESHttp_StationOutbound.XmMES_StationOutRequest_Body;
using FaFrameUI;
using System.Security.Policy;
/*
* 注:本源码对外提供,所以有些地方使用中文命名方法及变量
*/
namespace MainForm
{
///
/// 记录日志的委托
///
/// 日志类型
/// 日志信息
public delegate void HomeMessageHandler(LogType logType, string message);
///
/// 主页窗体
///
public partial class Form_Home : Form
{
#region 常量
//文本常量
private const string Head = "开始采集";
private const string Tail = "采集完成";
private const string Body = "工位出站数据";
private const string BodyCheck = "工位点检数据";
private const string BodyRun = "整线运行数据";
private const string BodyAlarm = "整线报警数据";
#endregion 常量
#region 变量
///
/// 委托-记录日志的方法
///
public event HomeMessageHandler MessageEvent;
///
/// 日志接口
///
ILogNet _PLCLogNet;
///
/// 用于记录IOT MQTT日志
///
ILogNet _IOTMqttLogNet;
///
/// 用于记录AGV MQTT日志
///
ILogNet _AGVMqttLogNet;
//private int DataSwitch = 1; // 1-SQLServer;2-Excel
// 定义信号量,index0给MES(true有信号,false无信号;set()让被控线程运行,Reset()让被控线程停止;WaitOne(等待时间)等待线程运行)
// 间隔时间
private int IntervalReadPLC = 300; //ms 读PLC
private int IntervalMonitorMES = 1000; //ms MES心跳
private int IntervalAlarm = 1000; //ms 数据(报警)查询与设备运行信息
///
/// 设备报警数据
///
uint[] _FaultDatas = { };
uint[] _FaultDatas_Old = { };
// 软件状态
private bool IsRun = true;
#region PLC 与 TCP对象
// 定义一个字典,存plc对象(通讯)
ModbusClientHelper plc1Alarm; // PLC‘运行数据’与‘报警数据’线程用ModbusTCP
Dictionary Funs = new Dictionary();
// 定义TCPClient对象列表
Dictionary
_HPSocket_TcpClients = new Dictionary();
// 定义MQTTHelper对象
MQTTHelper _MQTTHelper = new MQTTHelper();
#endregion PLC 与 TCP对象
///
/// 上次的设备运行信息
///
private string lineWorkingData1_OldStr = string.Empty;
///
/// 设备报警字典-当前结果
/// Dictionary<工位代码,List<报警信息>>
///
private Dictionary> DicAlarms_Cur = new Dictionary>();
Dictionary FunsEip = new Dictionary();
///
/// 单机用-设备状态
///
//XiaomiDeviceState xmDeviceState = XiaomiDeviceState.Uninitialized;
XiaomiDeviceStateData xmDeviceStateData = new XiaomiDeviceStateData();
private int test_item_num = 0;//iot 过站数据序号
private string uuid = "";
private bool inpass = false;//保存进站测试状态
public string _deviceCode="";//装备编码
public string _stationCode="";//工站ID
public string _workstation="";//工位编码
#endregion 变量
#region 窗体基础事件
///
/// 初始化
///
public Form_Home()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false; // 不检查跨线程访问
_PLCLogNet = new LogNetDateTime(GlobalContext.PlcLogDir, GenerateMode.ByEveryDay); // 按天记录日志
_IOTMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
_AGVMqttLogNet = new LogNetDateTime(GlobalContext.MqttLogDir, GenerateMode.ByEveryDay); // 按天记录日志
GlobalContext.Set += new Action(UpdateProductInfo); // 产品信息变化时更新UI
}
///
/// 窗体加载事件
///
private void Form_Home_Load(object sender, EventArgs e)
{
try
{
AddMessage(LogType.Info, "开始初始化程序");
//组建plc对象字典
//plc1Alarm = new ModbusClientHelper(GlobalContext.Machine1Address, GlobalContext.MachinePort);
//plc1Alarm = new Inovance_EIP(GlobalContext.PCAddress, GlobalContext.Machine1Address);
//上传操作记录
operateToIot("startup","开启");
if (GlobalContext.IsUsePLC1)
{
GlobalContext.IsUsePLCNow = 1;
GlobalContext.IsUseStationName = "[OP10]壳体清洁上料";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC1Address, GlobalContext.Machine1Address)); //OP10 壳体清洁上料装备
}
if (GlobalContext.IsUsePLC2)
{
GlobalContext.IsUsePLCNow = 2;
GlobalContext.IsUseStationName = "[OP20]上盖板上料装备";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC2Address, GlobalContext.Machine2Address)); //OP20 顶盖上料设备
}
if (GlobalContext.IsUsePLC3)
{
GlobalContext.IsUsePLCNow = 3;
GlobalContext.IsUseStationName = "[OP30]点散热胶装备";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC3Address, GlobalContext.Machine3Address)); //OP30 点胶设备
}
if (GlobalContext.IsUsePLC4)
{
GlobalContext.IsUsePLCNow = 4;
GlobalContext.IsUseStationName = "[OP40]胶线检测";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC4Address, GlobalContext.Machine4Address)); //OP40 3D胶线检测
}
if (GlobalContext.IsUsePLC5)
{
GlobalContext.IsUsePLCNow = 5;
GlobalContext.IsUseStationName = "[OP50]ADD板上料组装装备";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC5Address, GlobalContext.Machine5Address)); //OP50 ADD PCB板上料
}
if (GlobalContext.IsUsePLC6)
{
GlobalContext.IsUsePLCNow = 6;
GlobalContext.IsUseStationName = "[OP60]组上盖板";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC6Address, GlobalContext.Machine6Address)); //OP60 顶盖装配
}
if (GlobalContext.IsUsePLC7)
{
GlobalContext.IsUsePLCNow = 7;
GlobalContext.IsUseStationName = "[OP70]上盖板锁螺丝";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC7Address, GlobalContext.Machine7Address)); //OP70 锁螺丝
}
if (GlobalContext.IsUsePLC8)
{
GlobalContext.IsUsePLCNow = 8;
GlobalContext.IsUseStationName = "[OP80]NG下料";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC8Address, GlobalContext.Machine8Address)); //OP80 3D螺丝高度检测,NG出料站
}
if (GlobalContext.IsUsePLC9)
{
GlobalContext.IsUsePLCNow = 9;
GlobalContext.IsUseStationName = "[OP90]半成品下料";
FunsEip.Add(GlobalContext.IsUsePLCNow, new Inovance_EIP(GlobalContext.PC9Address, GlobalContext.Machine9Address)); //OP90 下料站
}
(bool,string)DicResult=InitalDicAlarm(); // 实例化报警字典
AddMessage(LogType.Info, DicResult.Item2);
foreach (Inovance_EIP plcEIP in FunsEip.Values)
{
if (plcEIP != null)
{
try
{
(int, string) result = plcEIP.Connect();
}
catch (Exception ex)
{
MessageBox.Show($"PLC[{plcEIP._pcIPStr}]连接失败!失败信息:" + ex.Message,
"PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification);
}
}
}
/*
//plc1Alarm.Connect();
foreach (ModbusClientHelper modbusClient in Funs.Values)
{
if (modbusClient != null)
{
try
{
modbusClient.Connect();
}
catch (Exception ex)
{
MessageBox.Show($"PLC[{modbusClient.IPAddress}:{modbusClient.Port}]连接失败!失败信息:" + ex.Message,
"PLC连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
}
}
}
*/
// 采集任务
Task TaskReadAlarm = new Task(ReadAlarmAllPLC); // 线程-获取线体报警数据
List TaskReadProcess = new List(); // 线程-触发点位(PLC)的线程
//TaskReadProcess.Add(new Task(() => { ReadStation_DownOrderInfo(1); })); // 下发机种
if (GlobalContext.IsUsePLC1)
TaskReadProcess.Add(new Task(() => { ReadStation_S1(1); })); //OP10 壳体清洁上料装备
if (GlobalContext.IsUsePLC2)
TaskReadProcess.Add(new Task(() => { ReadStation_S2(2); })); //OP20 顶盖上料设备
if (GlobalContext.IsUsePLC3)
TaskReadProcess.Add(new Task(() => { ReadStation_S3(3); })); //OP30 点胶设备
if (GlobalContext.IsUsePLC4)
TaskReadProcess.Add(new Task(() => { ReadStation_S4(4); })); //OP40 点胶检测设备
if (GlobalContext.IsUsePLC5)
TaskReadProcess.Add(new Task(() => { ReadStation_S5(5); })); //OP50 ADD PCB板上料设备
if (GlobalContext.IsUsePLC6)
TaskReadProcess.Add(new Task(() => { ReadStation_S6(6); })); //OP60 顶盖装配设备
if (GlobalContext.IsUsePLC7)
TaskReadProcess.Add(new Task(() => { ReadStation_S7(7); })); //OP70 锁螺丝设备
if (GlobalContext.IsUsePLC8)
TaskReadProcess.Add(new Task(() => { ReadStation_S8(8); })); //OP80 3D螺丝高度检测设备
if (GlobalContext.IsUsePLC9)
TaskReadProcess.Add(new Task(() => { ReadStation_S9(9); }));
#region 初始化
try
{
// 开启边线MES(绑定/查询数据)
//int mesRoute = XiaomiMES_RouteCommunication.Init();
//if (mesRoute == 0)
//{
// //picMESStatus.Image = imageListState.Images[1];
// //GlobalContext.MESIsConnect = true;
// AddMessage(LogType.Info, "小米MES边线初始连接成功!");
//}
//else
//{
// //picMESStatus.Image = imageListState.Images[0];
// //GlobalContext.MESIsConnect = false;
// AddMessage(LogType.Info, $"小米MES边线初始连接失败!");
//}
// 开启MES(Http)
if (GlobalContext.IsUseMES)
{
bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
if (mesret)
{
picMESStatus.Image = imageListState.Images[1];
GlobalContext.MESIsConnect = true;
AddMessage(LogType.Info, "小米MES初始连接成功!");
}
else
{
picMESStatus.Image = imageListState.Images[0];
GlobalContext.MESIsConnect = false;
AddMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]初始连接失败!");
}
}
// 开启IOT(MQTT)
if (GlobalContext.IsUseIot)
{
string addr = GlobalContext.MQTTServerHost;
int port = GlobalContext.MQTTServerPort;
//生产环境需要修改
(int, string) qmttResult = XiaomiMqttClient_Extend.OpenWithMqttServer("127.0.0.1", 6666, GlobalContext.MqttServerPath, GlobalContext.MqttServerName);
XiaomiMqttResponse_ErrCode response_ErrCode = (XiaomiMqttResponse_ErrCode)qmttResult.Item1;
if (response_ErrCode == XiaomiMqttResponse_ErrCode.OK)
{
picIot.Image = imageListState.Images[1];
AddMessage(LogType.Info, "小米IOT MQTT初始连接成功!");
// 设置回调函数
//XiaomiMqttClient_Extend.SetCallbackWithDataId(CallbackWithDataId);
// 配置参数
XiaomiMqttLoginFunAndParam param = new XiaomiMqttLoginFunAndParam();
// fds
param.parameter.fds.address = GlobalContext.address;
param.parameter.fds.appId = GlobalContext.appId;
param.parameter.fds.appKey = GlobalContext.appKey;
// mes
param.parameter.mes.address = GlobalContext.ServerIp;
param.parameter.mes.appId = GlobalContext.MESAppId;
param.parameter.mes.appKey = GlobalContext.MESAppKey;
// mqtt
param.parameter.mqtt.address = GlobalContext.MQTTServerHost;
param.parameter.mqtt.port = GlobalContext.MQTTServerPort;
param.parameter.mqtt.username = GlobalContext.MQTTAppId;
param.parameter.mqtt.password = GlobalContext.MQTTAppPwd;
// 设备配置
param.parameter.equipment.factoryCode = GlobalContext.Factory_Code;
if (GlobalContext.IsUsePLC1)
{
param.parameter.equipment.deviceCode = GlobalContext.S1_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.S1_station; // ⼯位Id
_workstation= GlobalContext.S1_work_station;//工站
}
if (GlobalContext.IsUsePLC2)
{
param.parameter.equipment.deviceCode = GlobalContext.S2_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.S2_station; // ⼯位Id
_workstation= GlobalContext.S2_work_station;//工站
}
if (GlobalContext.IsUsePLC3)
{
param.parameter.equipment.deviceCode = GlobalContext.s3_1_device_code; // 装备编码
//param.parameter.equipment.stationCode = GlobalContext.s3_1_station; // ⼯位Id
}
if (GlobalContext.IsUsePLC4)
{
param.parameter.equipment.deviceCode = GlobalContext.s4_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.s4_station; // ⼯位Id
_workstation= GlobalContext.s4_work_station;//工站
}
if (GlobalContext.IsUsePLC5)
{
param.parameter.equipment.deviceCode = GlobalContext.s5_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.s5_station; // ⼯位Id
_workstation= GlobalContext.s5_work_station;//工站
}
if (GlobalContext.IsUsePLC6)
{
param.parameter.equipment.deviceCode = GlobalContext.s6_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.s6_station; // ⼯位Id
_workstation= GlobalContext.s6_work_station;//工站
}
if (GlobalContext.IsUsePLC7)
{
param.parameter.equipment.deviceCode = GlobalContext.s7_1_device_code; // 装备编码
//param.parameter.equipment.stationCode = GlobalContext.s7_1_station; // ⼯位Id
}
if (GlobalContext.IsUsePLC8)
{
param.parameter.equipment.deviceCode = GlobalContext.s8_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.s8_station; // ⼯位Id
_workstation= GlobalContext.s8_work_station;//工站
}
if (GlobalContext.IsUsePLC9)
{
param.parameter.equipment.deviceCode = GlobalContext.s9_device_code; // 装备编码
param.parameter.equipment.stationCode = GlobalContext.s9_station; // ⼯位Id
_workstation= GlobalContext.s9_work_station;//工站
}
param.parameter.equipment.project = GlobalContext.Project_Code;
param.parameter.equipment.productMode = "debug";
param.parameter.other.logLevel = 0;
param.parameter.other.LogPath = GlobalContext.MqttLogDir;
XiaomiMqttClient_Extend.ParameterConfig(param);
//保存全局变量
_stationCode = param.parameter.equipment.deviceCode;
_deviceCode = param.parameter.equipment.stationCode;
}
else
{
picIot.Image = imageListState.Images[0];
AddMessage(LogType.Info,
$"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]初始连接失败!--- {response_ErrCode.ToString()}");
}
}
// 开启AGV(Http与MQTT)
if (GlobalContext.IsUseAGV)
{
// AGV HTTP
bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
if (mesret1)
{
picAgvHttp.Image = imageListState.Images[1];
AddMessage(LogType.Info, "AGV Http初始连接成功!");
}
else
{
picAgvHttp.Image = imageListState.Images[0];
AddMessage(LogType.Info, $"AGV Http[{GlobalContext.AGVHttpHost}]初始连接失败!");
}
string agvMqttIp = GlobalContext.MQTTServerHost;
int agvMqttPort = GlobalContext.MQTTServerPort;
Action callback = AGVMqttShowLog;
ResultData_MQTT result_MQTT = _MQTTHelper
.CreateMQTTClientAndStart(agvMqttIp, agvMqttPort, null, null, callback).Result; // 连接MQTT服务器
// AGV MQTT
if (result_MQTT.ResultCode == 1)
{
picAgvMqtt.Image = imageListState.Images[1];
GlobalContext.AGVMQTTIsConnect = true;
AddMessage(LogType.Info, "小米AGV MQTT初始连接成功!");
ResultData_MQTT result =
XiaomiAGVMQTT_Base.DeviceTopicAGV(ref _MQTTHelper, GlobalContext.AGVMQTTDeviceCode);
AddMessage(LogType.Info,
$"小米AGV MQTT订阅{GlobalContext.AGVMQTTDeviceCode}--- [{result.ResultCode}]{result.ResultMsg}!");
}
else
{
picAgvMqtt.Image = imageListState.Images[0];
GlobalContext.AGVMQTTIsConnect = false;
AddMessage(LogType.Info,
$"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]初始连接失败!--- [{result_MQTT.ResultCode}]{result_MQTT.ResultMsg}");
}
}
// 持续监视MES、IOT、AGV HTTP、AGV MQTT连接状态
Task.Run(MonitorMESConnect);
// 查询PLC连接状态
foreach (int plcNo in FunsEip.Keys)
{
bool connected = FunsEip[plcNo].IsConnected;
if (connected)
{
string msg = plcNo.ToString() + "工位初始连接成功---" + FunsEip[plcNo]._pcIPStr;
AddMessage(LogType.Info, msg);
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI
}
else
{
string msg = plcNo.ToString() + "工位初始连接失败---" + FunsEip[plcNo]._pcIPStr;
AddMessage(LogType.Info, msg);
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
}
}
// PLC4时 初始化扫码器TCP
//if (GlobalContext.IsUsePLC4)
// HpTCPClientInit();
// 开启PLC的业务处理线程-监听PLC点位+状态
foreach (Task task in TaskReadProcess)
{
if (task != null)
task.Start();
}
//// 开启iot的线程
TaskReadAlarm.Start();
////下传MES信息给1工位(先判断下plc对象数量)
//if (Funs.Count > 1)
// DownLoadProductInfo(1);
if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
{
state_l.Text = "设备状态(左):";
state_r.Text = "设备状态(右):";
state_r.Visible = true;
lblDeviceStates2.Visible = true;
}
AddMessage(LogType.Info, "程序初始化完成");
}
catch (Exception ex)
{
string str = ex.StackTrace;
this.BeginInvoke(new Action(() =>
{
AddMessage(LogType.Error,
"初始化PLC连接失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
}));
}
#endregion
}
catch (Exception ex)
{
string str = ex.StackTrace;
OnMessage(LogType.Info,
"主窗体的首页初始化出错!异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" +
ex.Message.ToString());
if (ex.Message != null && ex.Message.Contains("timed out"))
MessageBox.Show("主窗体的首页初始化出错!异常信息:PLC连接超时!" + ex.Message);
else
MessageBox.Show("主窗体的首页初始化出错!异常信息:" + ex.Message);
}
}
///
/// 窗体关闭事件
///
private void Form_Home_FormClosed(object sender, FormClosedEventArgs e)
{
Closed2();
}
public void Closed2()
{
try
{
IsRun = false;
Thread.Sleep(IntervalReadPLC);
// 断开TCP
int count = _HPSocket_TcpClients.Count();
for (int i = 0; i < count; i++)
{
try
{
if (_HPSocket_TcpClients[i] != null && _HPSocket_TcpClients[i]._client.IsConnected)
{
_HPSocket_TcpClients[i].Stop();
_HPSocket_TcpClients[i]._client.OnPrepareConnect -= OnPrepareConnect; // 准备连接了事件
_HPSocket_TcpClients[i]._client.OnConnect -= OnConnect; // 连接事件
_HPSocket_TcpClients[i]._client.OnSend -= OnSend; // 数据包发送事件
_HPSocket_TcpClients[i]._client.OnReceive -= OnReceive; // 数据包到达事件
_HPSocket_TcpClients[i]._client.OnClose -= OnClose; // TCP连接关闭事件
}
}
catch
{
}
}
// 关闭Iot
try
{
XiaomiMqttClient_Extend.CloseWithMqttServer(GlobalContext.MqttServerPath,
GlobalContext.MqttServerName);
}
catch
{
}
// 关闭AGV Mqtt
try
{
_MQTTHelper.DisconnectAsync_Client().Wait();
}
catch
{
}
}
catch
{
}
}
#endregion 窗体基础事件
#region 监控MES状态
///
/// 监控MES连接状态
///
private void MonitorMESConnect()
{
while (IsRun) // 运行被控线程
{
try
{
// 开启MES(Http)
if (GlobalContext.IsUseMES)
{
bool mesret = HttpUitls.PingIP(GlobalContext.ServerIp);
if (mesret)
{
picMESStatus.Image = imageListState.Images[1];
GlobalContext.MESIsConnect = true;
}
else
{
picMESStatus.Image = imageListState.Images[0];
GlobalContext.MESIsConnect = false;
OnMessage(LogType.Info, $"小米MES[{GlobalContext.ServerHost}]连接失败");
}
}
// 开启IOT(MQTT)
if (GlobalContext.IsUseIot)
{
bool iIot = XiaomiMqttClient.IsOpen;
if (iIot)
picIot.Image = imageListState.Images[1];
else
{
picIot.Image = imageListState.Images[0];
OnMessage(LogType.Info,
$"小米IOT MQTT[{GlobalContext.MQTTServerHost}:{GlobalContext.MQTTServerPort}]连接失败");
}
}
// 开启AGV(Http与MQTT)
if (GlobalContext.IsUseAGV)
{
// AGV Http
bool mesret1 = HttpUitls.PingIP(GlobalContext.AGVHttpIp);
if (mesret1)
picAgvHttp.Image = imageListState.Images[1];
else
{
picAgvHttp.Image = imageListState.Images[0];
OnMessage(LogType.Info, $"小米AGV Http[{GlobalContext.AGVHttpHost}]连接失败");
}
// AGV MQTT
if (GlobalContext.AGVMQTTIsConnect)
picAgvMqtt.Image = imageListState.Images[1];
else
{
picAgvMqtt.Image = imageListState.Images[0];
OnMessage(LogType.Info,
$"小米AGV MQTT[{GlobalContext.AGVMQTTHost}:{GlobalContext.AGVMQTTPort}]连接失败");
}
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
"监控MES心跳失败!异常信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
}
Thread.Sleep(IntervalMonitorMES);
}
}
#endregion 监控MES连接状态
#region 采集设备状态、运行数据、报警数据
///
/// 请求设备状态 5000
///
/// 1
///
/// 0:证明未连接到PLC;1,代表设备控制状态处于运行状态;2,代表设备控制状态处于故障状态;3,代表设备控制状态处于缺料状态;4,代表设备控制状态处于待机状态;5,代表设备控制状态处于维修状态;
public int GetDeviceStatus(int plcNo, string stationNameStr = "[S0]壳体上料")
{
try
{
if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
{
short result = Funs[plcNo].ReadHoldingRegisters(5000); // 5000
return result;
}
else
{
return 0;
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
"请求设备状态失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
return 0;
}
}
///
/// 检查是否可采集点检数据 - 不取新值
/// 5000不为1时可点检
///
///
public bool CheckCanSpotcheck1(int deviceState)
{
//return true;
//D5000 = 1,代表设备控制状态处于运行状态
//D5000 = 2, 代表设备控制状态处于故障状态
//D5000 = 3,代表设备控制状态处于缺料状态
//D5000 = 4, 代表设备控制状态处于待机状态
//D5000 = 5,代表设备控制状态处于维修状态
return deviceState != 1;
}
///
/// 检查是否可采集产品数据 - 不取新值
///
///
public bool CheckCanCollData(int deviceState)
{
return deviceState == 0; // 点检时该值不为0
}
///
/// 采集到的设备状态
///
private string _DeviceStates = "未知状态";
private string _DeviceStates_Old = "未知状态";
private string _DeviceStates2 = "未知状态";
private string _DeviceStates_Old2 = "未知状态";
///
/// 获取设备报警数据与获取设备运行信息
///
private async void ReadAlarmAllPLC()
{
/// 获取设备报警数据与状态信息
string stationNameStr = "获取设备报警数据与状态信息";
// 已连接到PLC
while (IsRun)
{
try
{
#region 报警数据
try
{
//_FaultDatas = new uint[] { 4, 0, 30, 10 };
if (_FaultDatas.Length>0)
{
ReadPLCAlarmToIot(_FaultDatas, stationNameStr);
}
else
{
AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!" );
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error, $"【报警日志】{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 报警数据
#region 设备状态
//if (!GlobalContext._IsCon_plc1Alarm)
//{
// UpdatePLCMonitor(1, -2, 0);
// continue;
//}
foreach (Inovance_EIP plcEIP in FunsEip.Values)
{
if (plcEIP != null)
{
if (plcEIP.IsConnected)
{
#region 主页展示设备运行状态并上传到IOT中,有双工位left就是左工位,没有双工位left就是单工位
switch (xmDeviceStateData.left)
{
case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
_DeviceStates = "未初始化状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
_DeviceStates = "初始化状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
_DeviceStates = "初始化完成状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Running: // 运行状态(正常运行中)
_DeviceStates = "运行状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
_DeviceStates = "暂停状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
_DeviceStates = "故障状态";
lblDeviceStates.Text = _DeviceStates;
break;
case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
_DeviceStates = "警报状态";
lblDeviceStates.Text = _DeviceStates;
break;
}
if (!_DeviceStates.Equals(_DeviceStates_Old))
{
var iotResult =
SaveDeviceStateData(stationNameStr, xmDeviceStateData.left, "left"); // 上传+保存
if (iotResult.Item1 == 1)
{
_DeviceStates_Old = _DeviceStates;
AddMessage_Station(stationNameStr, LogType.Info,
"【设备状态】" + stationNameStr + $"_上传设备状态到Iot成功!");
}
else
AddMessage_Station(stationNameStr, LogType.Info,
"【设备状态】"+stationNameStr +
$"_上传设备状态到Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
}
#endregion 主页展示设备运行状态并上传到IOT中
#region 右工位
if (GlobalContext.IsUsePLC3 || GlobalContext.IsUsePLC7)
{
switch (xmDeviceStateData.right)
{
case XiaomiDeviceState.Uninitialized: // 未初始化状态(未初始状态,需先初始化装备才能运行)
_DeviceStates2 = "未初始化状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Initializing: // 初始化状态(初始化进行中)
_DeviceStates2 = "初始化状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Initialized: // 初始化完成状态(初始化完成)
_DeviceStates2 = "初始化完成状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Running: // 运行状态(正常运行中)
_DeviceStates2 = "运行状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Paused: // 暂停状态(设备运行中人工操作暂停,进入此状态)
_DeviceStates2 = "暂停状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Fault: // 故障状态(发生故障后进入此状态,同时停止运行)
_DeviceStates2 = "故障状态";
lblDeviceStates.Text = _DeviceStates2;
break;
case XiaomiDeviceState.Alarm: // 警报状态(产生报警后进入此状态,同时停止运行)
_DeviceStates2 = "警报状态";
lblDeviceStates.Text = _DeviceStates2;
break;
}
if (!_DeviceStates2.Equals(_DeviceStates_Old2))
{
var iotResult = SaveDeviceStateData(stationNameStr, xmDeviceStateData.left,
"right"); // 上传+保存
if (iotResult.Item1 == 1)
{
_DeviceStates_Old2 = _DeviceStates2;
AddMessage_Station(stationNameStr, LogType.Info,
"【设备状态】" + stationNameStr + $"_上传Iot成功!");
}
else
AddMessage_Station(stationNameStr, LogType.Info,
"【设备状态】" + stationNameStr +
$"_上传Iot失败!报错信息:[{iotResult.Item1}]_{iotResult.Item2}");
}
}
#endregion 右工位
}
}
}
#endregion
//if (plc1Alarm.IsConnected) // 检查PLC是否已连接上
//{
// DateTime dtNow = DateTime.Now;
// //#region 获取设备运行信息
// //try
// //{
// // LineWorkingData_ThisTime lineWorkingData1 = new LineWorkingData_ThisTime();
// // lineWorkingData1.GUID = Guid.NewGuid().ToString();
// // lineWorkingData1.LineName = GlobalContext.LineCode;
// // //
// // lineWorkingData1.BootTimeLong = plc1Alarm.ReadHoldingRegisters(5500); // 本次开机时间(整线)D5500 h
// // lineWorkingData1.NormalTimeLong = plc1Alarm.ReadHoldingRegisters(5502); // 本次开机运行时间(整线)D5502 h
// // lineWorkingData1.StandbyTimeLong = plc1Alarm.ReadHoldingRegisters(5504); // 本次开机待机时间(整线)D5504 h
// // lineWorkingData1.FaultTimeLong = plc1Alarm.ReadHoldingRegisters(5506); // 本次开机故障时间(整线)D5506 h
// // lineWorkingData1.MaterialShortageTimeLong = plc1Alarm.ReadHoldingRegisters(5508); // 本次开机缺料时间(整线)D5508 h
// // lineWorkingData1.MaintenanceTimeLong = plc1Alarm.ReadHoldingRegisters(5510); // 本次开机维修时间(整线)D5510 h
// // lineWorkingData1.FaultNumber = plc1Alarm.ReadHoldingRegisters(5514); // 本次开机故障停机次数(整线)D5514
// // lineWorkingData1.OutputNumber = plc1Alarm.ReadHoldingRegisters(5700); // 本次开机产量(整线) D5700
// // lineWorkingData1.QualifiedNumber = plc1Alarm.ReadHoldingRegisters(5704); // 本次开机合格数量(整线) D5704
// // lineWorkingData1.QualifiedRate = plc1Alarm.ReadHoldingRegisters(5710); // 本次开机合格率(整线) D5710
// // lineWorkingData1.DesignRhythm = plc1Alarm.ReadHoldingRegisters(5714); // 设计节拍(整线) D5714
// // lineWorkingData1.RealityRhythm = plc1Alarm.ReadHoldingRegisters(5716); // 本次开机实际节拍(整线) D5716
// // lineWorkingData1.CreateTime = DateTime.Now;
// // string lineWorkingData1_Str = JsonConvert.SerializeObject(lineWorkingData1);
// // // UI展示-展示到设备状态页
// // if (string.IsNullOrEmpty(lineWorkingData1_OldStr)) // 软件启动后第一次运行
// // {
// // // 查询数据库最新一条数据,确定是不是更新
// // string qSql = @"SELECT top(1) [GUID]
// // ,[LineName]
// // ,[BootTimeLong]
// // ,[NormalTimeLong]
// // ,[StandbyTimeLong]
// // ,[FaultTimeLong]
// // ,[MaterialShortageTimeLong]
// // ,[MaintenanceTimeLong]
// // ,[FaultNumber]
// // ,[OutputNumber]
// // ,[QualifiedNumber]
// // ,[QualifiedRate]
// // ,[DesignRhythm]
// // ,[RealityRhythm]
// // ,[CreateTime]
// // FROM [LineWorkingData]
// // where [CreateTime] > '{0}'
// // and [LineName]='{1}'
// // order by [CreateTime] desc
// // ";
// // qSql = string.Format(qSql, DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00", lineWorkingData1.LineName);
// // var ds = SQLHelper_New.Query(qSql, null);
// // if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
// // {
// // var dataDBlast = new LineWorkingData_ThisTime();
// // dataDBlast.GUID = ds.Tables[0].Rows[0][0].ToString(); // 主键
// // dataDBlast.LineName = ds.Tables[0].Rows[0][1].ToString(); // 线体名称
// // dataDBlast.BootTimeLong = Convert.ToSingle(ds.Tables[0].Rows[0][2].ToString()); // 本次开机时间(整线)
// // dataDBlast.CreateTime = Convert.ToDateTime(ds.Tables[0].Rows[0][14].ToString()); // 创建时间
// // if (lineWorkingData1.BootTimeLong > dataDBlast.BootTimeLong) // 需要更新的情况;不需要更新的走后面的插入
// // {
// // dataDBlast.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
// // dataDBlast.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
// // dataDBlast.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
// // dataDBlast.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
// // dataDBlast.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
// // dataDBlast.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
// // dataDBlast.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
// // dataDBlast.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
// // dataDBlast.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
// // dataDBlast.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
// // dataDBlast.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
// // dataDBlast.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
// // string usql = dataDBlast.ToStringUpdate();
// // SQLHelper_New.ExecuteSQL(usql, null);
// // lineWorkingData1_OldStr = JsonConvert.SerializeObject(dataDBlast);
// // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
// // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
// // }
// // }
// // else
// // {
// // // 插入
// // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
// // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
// // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
// // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
// // }
// // }
// // else if (!lineWorkingData1_Str.Equals(lineWorkingData1_OldStr)) // 非“软件启动后第一次运行”
// // {
// // LineWorkingData_ThisTime lineWorkingData1_Old = string.IsNullOrEmpty(lineWorkingData1_OldStr) ? lineWorkingData1 : JsonConvert.DeserializeObject(lineWorkingData1_OldStr); // 上次的状态信息
// // //// 本次开机设备运行情况
// // //LineWorkingData1_ThisTime lineWorkingData_UI = JsonConvert.DeserializeObject(lineWorkingData1_OldStr);
// // //Task.Run(() =>
// // //{
// // // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
// // // {
// // // Form_Main.formDevAlarm.UpdDeviceStatus_ThisTime(lineWorkingData_UI); // UI更新
// // // }
// // //});
// // // 本日设备运行情况
// // // 存数据库(开机时间>上次的开机时间,则更新上次记录;<则作为新数据插入)
// // if (lineWorkingData1.BootTimeLong > lineWorkingData1_Old.BootTimeLong)
// // {
// // // 更新
// // lineWorkingData1_Old.BootTimeLong = lineWorkingData1.BootTimeLong; // 本次开机时间(整线)
// // lineWorkingData1_Old.NormalTimeLong = lineWorkingData1.NormalTimeLong; // 本次开机运行时间(整线)
// // lineWorkingData1_Old.StandbyTimeLong = lineWorkingData1.StandbyTimeLong; // 本次开机待机时间(整线)
// // lineWorkingData1_Old.FaultTimeLong = lineWorkingData1.FaultTimeLong; // 本次开机故障时间(整线)
// // lineWorkingData1_Old.MaterialShortageTimeLong = lineWorkingData1.MaterialShortageTimeLong; // 本次开机缺料时间(整线)
// // lineWorkingData1_Old.MaintenanceTimeLong = lineWorkingData1.MaintenanceTimeLong; // 本次开机维修时间(整线)
// // lineWorkingData1_Old.FaultNumber = lineWorkingData1.FaultNumber; // 本次开机故障停机次数(整线)
// // lineWorkingData1_Old.OutputNumber = lineWorkingData1.OutputNumber; // 本次开机产量(整线)
// // lineWorkingData1_Old.QualifiedNumber = lineWorkingData1.QualifiedNumber; // 本次开机合格数量(整线)
// // lineWorkingData1_Old.QualifiedRate = lineWorkingData1.QualifiedRate; // 本次开机合格率(整线)
// // lineWorkingData1_Old.DesignRhythm = lineWorkingData1.DesignRhythm; // 设计节拍(整线)
// // lineWorkingData1_Old.RealityRhythm = lineWorkingData1.RealityRhythm; // 本次开机实际节拍(整线)
// // SQLHelper_New.ExecuteSQL(lineWorkingData1_Old.ToStringUpdate(), null);
// // lineWorkingData1_OldStr = JsonConvert.SerializeObject(lineWorkingData1_Old);
// // AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕![{lineWorkingData1_OldStr}]");
// // //AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyRun}完毕!");
// // }
// // else if (lineWorkingData1.BootTimeLong < lineWorkingData1_Old.BootTimeLong)
// // {
// // // 插入
// // SQLHelper_New.ExecuteSQL(lineWorkingData1.ToStringInsert(), null);
// // lineWorkingData1_OldStr = String.Copy(lineWorkingData1_Str);
// // AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕![{lineWorkingData1_OldStr}]");
// // //AddMessage_Station(stationNameStr, LogType.Info, $"保存{BodyRun}完毕!");
// // }
// // await Task.Run(() =>
// // {
// // try
// // {
// // if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed && Form_Main.formDevAlarm.Visible)
// // {
// // Form_Main.formDevAlarm.UpdDeviceStatus_Today(); // UI更新
// // }
// // }
// // catch { }
// // });
// // }
// //}
// //catch (Exception ex)
// //{
// // string str = ex.StackTrace;
// // AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取设备运行信息出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// //}
// //#endregion 获取设备运行信息
// #region 报警数据
// try
// {
// List deviceAlarm_Curs = new List(); // 同步到报警页面用传输载体
// bool isNeedUpdUI = false; // 是否需要更新历史报警UI
// // 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
// var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.LineCode];
// for (int i = 0; i < dicAlarms_Cur_PLC1.Count; i++) // 读取
// {
// short shortBuf = plc1Alarm.ReadHoldingRegisters(dicAlarms_Cur_PLC1[i].关联的PLC地址);
// dicAlarms_Cur_PLC1[i].是否报警 = shortBuf != 0;
// if (dicAlarms_Cur_PLC1[i].上次的运行状态 != dicAlarms_Cur_PLC1[i].是否报警)
// {
// isNeedUpdUI = true; // 需要更新历史报警UI信息
// // 记录
// dicAlarms_Cur_PLC1[i].上次的运行状态 = dicAlarms_Cur_PLC1[i].是否报警;
// switch (dicAlarms_Cur_PLC1[i].是否报警)
// {
// case true: // 报警
// dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
// {
// GUID = Guid.NewGuid().ToString(),
// LineName = GlobalContext.LineCode, // 线体
// AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
// AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
// StartTime = dtNow // 开始时间
// };
// // 传输到页面
// deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
// {
// 线体名称 = dicAlarms_Cur_PLC1[i].报警数据.LineName,
// 报警类型 = dicAlarms_Cur_PLC1[i].报警数据.AlarmType,
// 报警内容 = dicAlarms_Cur_PLC1[i].报警数据.AlarmDesc,
// 开始时间 = dtNow
// });
// // 新增到数据库
// var data1 = dicAlarms_Cur_PLC1[i].报警数据;
// SaveAlarmDataByDB(stationNameStr, data1, false);
// AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
// break;
// case false: // 消除报警
// if (dicAlarms_Cur_PLC1[i].报警数据 == null || string.IsNullOrEmpty(dicAlarms_Cur_PLC1[i].报警数据.GUID))
// {
// dicAlarms_Cur_PLC1[i].报警数据 = new AlarmData()
// {
// GUID = Guid.NewGuid().ToString(),
// LineName = GlobalContext.LineCode, // 线体
// AlarmType = dicAlarms_Cur_PLC1[i].报警类型, // 报警类型
// AlarmDesc = dicAlarms_Cur_PLC1[i].报警详情, // 报警内容
// StartTime = dtNow, // 开始时间
// EndTime = dtNow, // 开始时间
// PersistTime = 1, // 耗时1s
// };
// // 新增
// var data2 = dicAlarms_Cur_PLC1[i].报警数据;
// SaveAlarmDataByDB(stationNameStr, data2, false);
// AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
// }
// else
// {
// dicAlarms_Cur_PLC1[i].报警数据.EndTime = dtNow; // 开始时间
// dicAlarms_Cur_PLC1[i].报警数据.PersistTime = Convert.ToInt32((dicAlarms_Cur_PLC1[i].报警数据.EndTime
// - dicAlarms_Cur_PLC1[i].报警数据.StartTime).TotalSeconds); // 耗时s
// // 修改
// var data3 = dicAlarms_Cur_PLC1[i].报警数据;
// SaveAlarmDataByDB(stationNameStr, data3, true);
// AddMessage_Station(stationNameStr, LogType.Info, $"更新{BodyAlarm}完毕!");
// }
// break;
// default:
// break;
// }
// }
// }
// DicAlarms_Cur[GlobalContext.LineCode] = dicAlarms_Cur_PLC1;
// // 有新报警则更新
// if (isNeedUpdUI)
// {
// // UI展示 - 展示到设备状态页
// await Task.Run(() =>
// {
// try
// {
// if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
// {
// Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
// if (Form_Main.formDevAlarm.Visible)
// {
// Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
// }
// }
// }
// catch { }
// });
// }
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 报警数据
// UpdatePLCMonitor(1, -2, 1);
//}
//else
//{
// UpdatePLCMonitor(1, -2, 0);
//}
}
catch (Exception ex)
{
//AddMessage_Station(stationNameStr, LogType.Error, $"PLC1_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC1_{stationNameStr}_采集运行数据与报警数据出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalAlarm);
}
}
#endregion 轮询PLC
#region 下发订单信息
/////
///// 壳体上料(下发工单)的交互逻辑
/////
/////
/////
//private void ReadStation_DownOrderInfo(int plcNo)
//{
// // [S1] Tray盘上料装备(板测)
// // [S2] FCT(板测)
// // [S3] 值板机
// // [S4] 取放桁架
// // [S5] Tray盘下料装备
// /// 上位机心跳
// /// 获取设备报警数据与状态信息
// string stationNameStr = "[S0]壳体上料";
// while (IsRun)
// {
// try
// {
// if (!GlobalContext._IsCon_Funs1)
// {
// UpdatePLCMonitor(plcNo, 0);
// continue;
// }
// if (Funs[plcNo].isConnected) // 检查PLC是否已连接上
// {
// #region 壳体上料(下发工单)
// try
// {
// Funs[plcNo].Read_Int_Tag("500", 1, out short[] iiMes0);
// Funs[plcNo].Read_Int_Tag("501", 1, out short[] iiPlc0);
// bool mES_FLAG_1 = iiMes0[0] == 1 ? true : false; // MES_FLAG_1
// bool pLC_Flag_1 = iiPlc0[0] == 1 ? true : false; // PLC_FLAG_1
// // 重置数据和信号
// if (mES_FLAG_1 && pLC_Flag_1) // 1 1
// {
// // 清空写给PLC的数据
// int[] i497 = new int[1] { 0 };
// Funs[plcNo].Write_DInt_Tag("497", 1, i497); // SN号(数字部分)重置信号
// // MES_Flag重置为0
// int[] i500 = new int[1] { 0 };
// Funs[plcNo].Write_DInt_Tag("500", 1, i500); // MES_FLAG_1
// }
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}下发订单信息运行出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 壳体上料(下发工单)
// UpdatePLCMonitor(plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
// }
// else
// {
// UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
//
// Funs[plcNo].Connect();
// }
// }
// catch (Exception ex)
// {
// UpdatePLCMonitor(plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
//
// Funs[plcNo].ReConnect();
// }
// Thread.Sleep(IntervalReadPLC);
// }
//}
/////
///// 下发订单信息到PLC
/////
///// PLC编号
//private void DownLoadProductInfo(int plcNo, string stationNameStr = "[S0]壳体上料")
//{
// try
// {
// if (!string.IsNullOrEmpty(GlobalContext.Mtltmrk))
// {
// Funs[plcNo].Write_String_Tag("568", 1, GlobalContext.Mtltmrk); // 产品型号(mtltmrk)
// WritePLCLog(LogType.Debug, GlobalContext.Mtltmrk);
// }
// Funs[plcNo].Write_DInt_Tag("500", 1, new Int32[1] { 1 }); // MES_FLAG_1
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, "下发订单信息到PLC失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
//}
///
/// 下发清料信号
///
/// PLC编号
public bool ClearProducts(int plcNo, string stationNameStr = "[S0]壳体上料")
{
try
{
//Funs[plcNo].ReadHoldingRegisters(496); //
AddMessage_Station(stationNameStr, LogType.Info, "下发了清料信号!");
return true;
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
"下发清料信号失败!" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
return false;
}
}
#endregion 下发订单信息
#region Xiaomi 贲流
#region 公共方法
private static bool ProgressState = false;
private static readonly object lockObj = new object(); // 锁对象
private static bool isCollectingFlagLeft;
private static bool isCollectingFlagRight;
private bool OpenDailogFalg = true;//是否开启扫码弹窗标识
///
/// float[]转为string
///
public string FloatArrayToString(float[] nScrewResults)
{
// 使用 "R" 格式说明符来保证浮点数的往返精度,不添加 'f' 后缀
return string.Join(",", Array.ConvertAll(nScrewResults, element => element.ToString("R")));
}
///
/// short[]转为string
///
public string ShortArrayToString(short[] nScrewResults)
{
// 使用 string.Join 来连接数组元素,并使用逗号作为分隔符
return string.Join(",", nScrewResults);
}
///
/// 写入PLC重复三次
///
public (int, string) WriteResultToPlc(int plcNo, string stationNameStr, string strTagName, int nCount,
T inObj)
{
int i = 0;
int nRet = 0;
string strRet = "";
try
{
while (i < 3) // 最多上传三次
{
(nRet, strRet) = FunsEip[plcNo].Write_SingleTag(strTagName, nCount, inObj);
if (nRet == 0) //成功
{
break;
}
else
{
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 进站结果写入PLC出错!错误信息:" + strRet);
i++;
}
}
return (nRet, strRet);
}
catch (Exception ex)
{
return (1, ex.Message);
}
}
public (int, string) SaveScrewDataToTxt(string direction, string ProductBarcode, float[] fScrewTimes,
short[] nScrewOrders, short[] nScrewResults)
{
try
{
// 获取当前日期
string dateFolder = DateTime.Now.ToString("yyyyMMdd");
// 构建保存路径
string basePath = AppDomain.CurrentDomain.BaseDirectory; // 获取执行文件的目录
string savePath = Path.Combine(basePath, "screw", dateFolder, ProductBarcode, direction, "螺丝Mes数据");
// 确保目录存在
Directory.CreateDirectory(savePath);
// 文件名
string fileName = $"{ProductBarcode}_{DateTime.Now.ToString("HHmmss")}.txt";
string filePath = Path.Combine(savePath, fileName);
// 确保不会超出数组长度,只取前14个或数组的实际长度
int count = Math.Min(14, fScrewTimes.Length);
using (StreamWriter sw = new StreamWriter(filePath))
{
for (int i = 0; i < count; i++)
{
sw.WriteLine($"{ProductBarcode}{"_"}{i + 1}");
sw.WriteLine($"锁附时间:{fScrewTimes[i]}");
sw.WriteLine($"锁附顺序:{nScrewOrders[i]}");
sw.WriteLine($"锁附结果:{nScrewResults[i]}");
sw.WriteLine(); // 空行分隔不同螺丝的信息
}
}
return (0, "");
}
catch (Exception ex)
{
return (1, ex.Message);
}
}
public Dictionary GetLastLineCompensation(string path, string direction, string sn)
{
// 创建字典存储补偿点及其对应的值
Dictionary compensationDict = new Dictionary();
try
{
//string path = GlobalContext.MESLaserRPath;
// 获取当前日期并格式化为 "yyyy-MM-dd" 格式
string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
string filename = $"Laser-{currentDate}-W0.txt";
// 拼接完整路径
string fullPath = Path.Combine(path, filename);
string lastNonEmptyLine = "";
// 判断文件是否存在
if (File.Exists(fullPath))
{
//读取文件内容
string[] lines = File.ReadAllLines(fullPath);
// 获取最后一行数据(忽略标题行)
if (lines.Length > 1)
{
string lastLine = "";
for (int i = lines.Length - 1; i > 0; i--)
{
if (!string.IsNullOrEmpty(lines[i]))
{
lastLine = lines[i];
break;
}
}
// 将最后一行按逗号分隔
string[] values = lastLine.Split(',');
values[1] = sn;
string key = "三点激光_" + direction; // 构造键名
string value = string.Join(",", values); // 获取值并去除多余空格
compensationDict[key] = value;
//// 提取“1点补偿”到“6点补偿”的值
//for (int i = 2; i <= 7 && i < values.Length; i++) // 从索引2开始,最多提取6个值
//{
// string key = $"{i - 1}点补偿"; // 构造键名
// string value = values[i].Trim(); // 获取值并去除多余空格
// compensationDict[key] = value;
//}
}
}
else
{
Console.WriteLine($"文件不存在: {fullPath}");
}
}
catch (Exception ex)
{
// 捕获异常并输出错误信息
Console.WriteLine($"发生错误: {ex.Message}");
}
return compensationDict;
}
///
/// 调用进站接口并保存进站数据
///
/// 工站信息
/// 工单号
/// 型号(物料号)
/// 产品SN
/// 进站数据
/// 1成功;5MES报警;6上位机报警
public int SaveStationInData(string stationNameStr, string workorder_code, string mtltmrk, string sn,
List items, string MachineId, string StationId,bool pass)
{
int result = 0;
XmMES_StationInRequest_Body inRequest_Body = new XmMES_StationInRequest_Body();
inRequest_Body.machineId = MachineId; // 装备ID(可配置)
inRequest_Body.stationId = StationId; // ⼯位ID(可配置)
inRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
inRequest_Body.clientTime =
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
inRequest_Body.unitSn = sn; // 产品SN
inRequest_Body.uuidInspection = uuid;
inRequest_Body.state = pass ? "PASS" : "FAIL";
inRequest_Body.userId = GlobalContext.MESUserId; // 用户ID;
inRequest_Body.factoryId = GlobalContext.Factory_Code; // 工厂ID;
string json_Body = JsonConvert.SerializeObject(inRequest_Body);
StationIn stationIn = new StationIn()
{
Workorder_code = workorder_code, // 车间订单号
Mtltmrk = mtltmrk, // 产品型号(物料号)
Sn = sn, // SN
StationIn_body = json_Body, // 进站接口Json数据 - Body
Parameter_values = items, // 进站数据
Write_user = inRequest_Body.userId, // 员工Id
Test_time = inRequest_Body.clientTime // 进站时间
};
// 本地数据
string sql = stationIn.ToStringInsert(0);
string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
result = ret == "成功" ? 1 : 6;
//await Task.Delay(200);
// 上传MES
if (GlobalContext.IsSendStationIn)
{
try
{
XmMES_StationInResponse response = new XmMES_StationInResponse();
string resultJson = "";
string mesRet = string.Empty;
int i = 0;
while (i < 2) // 1009会多次尝试上传
{
response = XiaomiMESHttp_StationInbound.StationIn(inRequest_Body);
resultJson = JsonConvert.SerializeObject(response);
if (response != null && response.header.code == "200")
break;
else if (!mesRet.Contains("1009")) // 1009是未知错误
i++;
i++;
mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
// 记录失败原因
OnMessage(LogType.Error, $"上传出站数据到MES服务器---失败!正在重新上传!请求参数:{json_Body},接口报错信息:" + mesRet);
}
if (response?.header?.code == "200")
{
string sql_Upd = stationIn.ToStringUpdateStatusByID(1);
string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
result = ret_Upd == "成功" ? 1 : 6;
AddMessage( LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---成功,请求参数:{json_Body},返回参数:{resultJson}");
}
else
{
result = 5;
AddMessage(LogType.Info, $"【进站数据 SN {stationIn.Sn}】上传MES服务器---失败!请求参数:{json_Body},接口报错信息:" + mesRet);
}
string sql_response =
stationIn.ToStringUpdateStationInReturn_body(JsonConvert.SerializeObject(response));
SQLHelper_New.ExecuteNonQuery(sql_response, null);
}
catch (Exception ex)
{
result = 6;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC上传进站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
}
#region IOT
string slot = "01-SLOT-01";
//过站结果
if (GlobalContext.IsMqttSendProcessData)
{
PassStationResultRequest request = new PassStationResultRequest();
request.project_code = GlobalContext.Project_Code; // 项⽬编码
request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
request.line_code = GlobalContext.LineCode; // 线体编码
request.work_station = _workstation; // ⼯站ID
request.device_code = _deviceCode; // 装备编码
request.station = _stationCode;
request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
request.slot = slot; // 槽位编码
request.sn = sn; // 产品SN
// request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
request.enter_status = pass ? "PASS" : "FAIL"; // 进站状态
request.result = ""; // 出站条件 PASS或FAIL; // 过站结果
request.work_type = "OUT_STATION"; // 作业类型
// 上传过站结果
(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
if (iotResult.Item1 != 0)
{
OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
}
}
#endregion
return result;
}
///
/// 选择如何记录出站数据
///
/// 出站数据
/// 设备编号
/// 测试项目
/// 车间订单号
/// 批次号
/// 型号
/// 日期
/// 供应商代码
/// 产品序列号的 数字序列部分
/// 上传成功时返回1;失败返回0
private int SwitctProcessData(string stationNameStr, List items, string equipmentCode,
string processItem,
string workorder_code, string batch_num, string mtltmrk, string proDate,
string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string MachineId, string StationId, string PartBarcode,string jsonParm, string direction="")
{
return SaveProcessDataByDB(stationNameStr, items, equipmentCode, processItem, workorder_code, batch_num, mtltmrk,
proDate, supplierCode, sn, pass, vehicleSn, vehicleSlot, MachineId, StationId, PartBarcode, jsonParm, direction);
}
///
/// 添加出站数据(提交到MES+本地保存到数据库)
///
/// 出站数据
/// 设备编号
/// 测试项目
/// 车间订单号
/// 批次号
/// 型号
/// 日期
/// 供应商代码
/// 产品序列号的 数字序列部分
/// 上传成功时返回1;失败返回0
public int SaveProcessDataByDB(string stationNameStr, List items, string equipmentCode,
string processItem, string workorder_code, string batch_num, string mtltmrk,
string proDate, string supplierCode, string sn, bool pass, string vehicleSn, string vehicleSlot, string machineId, string stationId, string partBarcode,string jsonParm,string direction="")
{
int upload = 0;
int result = 0;
ProcessData processData = new ProcessData()
{
Equipment_code = equipmentCode,
Workorder_code = workorder_code,
Batch_number = batch_num,
Sn = sn, // SN
Testitem = processItem,
Parameter_values = items,
Write_user = GlobalContext.CurrentUser,
Test_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
};
// 本地数据
string sql = processData.ToStringInsert(upload);
string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
//AddMessage_Station(stationNameStr, LogType.Info, string.Concat("[[", equipmentCode, "]", stationNameStr, "]保存本地出站数据---" + ret));
#region MES
if (GlobalContext.IsSendProcessData)
{
try
{
string id = processData.ID.Copy();
XmMES_StationOutRequest_Body outRequest_Body = new XmMES_StationOutRequest_Body();
outRequest_Body.uuidInspection = uuid;
outRequest_Body.machineId = machineId; // 装备id(可配置)
outRequest_Body.stationId = stationId; // ⼯位ID(可配置)
outRequest_Body.clientMac = GlobalContext.MacStr; // 客⼾端本机MAC地址,格式:XX-XX-XX-XX-XX-XX
outRequest_Body.clientTime = processData.Test_time; // 客⼾端请求时间,格式yyyy-MM-dd HH:mm:ss.fff
outRequest_Body.unitSn = sn; // 产品SN
outRequest_Body.state = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL
outRequest_Body.userId = GlobalContext.MESUserId; // ⽤⼾ID
outRequest_Body.factoryId = GlobalContext.Factory_Code; // ⼯⼚id
outRequest_Body.unitData.vehicleData.vehicleSn = vehicleSn;
outRequest_Body.unitData.vehicleData.vehicleType = string.Empty;
outRequest_Body.unitData.vehicleData.slot = vehicleSlot;
if (!string.IsNullOrEmpty(partBarcode))
{
outRequest_Body.unitData.keyMaterial.Add(
new XmMES_StationOutRequest_Body.XmStationOut_KeyMaterial()
{
bindSort = 1,
materialSn = partBarcode
}); // 设备数据 - 部件码
}
//OP30站读txt数据
if (stationNameStr.Contains("CPAPHD"))
{
string path = "";
if (direction == "Left")
path = GlobalContext.MESLaserLPath;
else
path = GlobalContext.MESLaserRPath;
//字典存储数据
Dictionary compensationDict = GetLastLineCompensation(path, direction, sn);
foreach (var kvp in compensationDict)
{
outRequest_Body.unitData.processData.Add(
new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
{
dataName = kvp.Key.ToString(),
dataValue = kvp.Value.ToString()
});
}
}
//过站明细
if (GlobalContext.IsSendProcessDetail)
{
if (jsonParm.Length > 0)
{
// 解析JSON字符串为字典
var dictionary = JsonConvert.DeserializeObject>(jsonParm);
foreach (var kvp in dictionary)
{
outRequest_Body.unitData.processData.Add(
new XmMES_StationOutRequest_Body.XmStationOut_ProcessData()
{
dataName = kvp.Key.ToString(),
dataValue = kvp.Value.ToString()
});
}
}
}
string jsonstr1 = JsonConvert.SerializeObject(outRequest_Body);
if (GlobalContext.IsSendProcessData)
{
XmMES_StationOutResponse response = new XmMES_StationOutResponse();
string mesRet = string.Empty;
int i = 0;
while (i < 2) // 1009会多次尝试上传
{
response = XiaomiMESHttp_StationOutbound.StationOut(outRequest_Body);
if (response != null && response.header.code == "200")
{
OnMessage(LogType.Info,
$"【出站数据 SN {sn}】上传出站数据到MES服务器---成功!请求信息:" + jsonstr1 + "返回信息:" +
JsonConvert.SerializeObject(response.body));
break;
}
else if (!mesRet.Contains("1009")) // 1009是未知错误
i++;
i++;
mesRet = $"[{response?.header?.code}]{response?.header?.desc}";
// 记录失败原因
OnMessage(LogType.Error, $"【出站数据 SN {sn}】上传出站数据到MES服务器---失败!正在重新上传!接口报错信息:" + mesRet + "参数:" + jsonstr1);
}
if (response?.header?.code == "200")
{
string sql_Upd = ProcessData.ToStringUpdateStatusByID(1, id);
string ret_Upd = SQLHelper_New.ExecuteNonQuery(sql_Upd, null);
result = 1;
//AddMessage_Station(stationNameStr, LogType.Info, $"更新【出站数据 id {id}】上传状态---" + ret_Upd);
AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---成功");
}
else
{
AddMessage(LogType.Info, $"【出站数据 SN {sn}】上传MES服务器---失败!接口报错信息:" + mesRet);
}
string sql_UpStationout = ProcessData.ToStringUpdateStationOut_body(
JsonConvert.SerializeObject(outRequest_Body),
JsonConvert.SerializeObject(response), id);
SQLHelper_New.ExecuteNonQuery(sql_UpStationout, null);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC上传出站数据MES报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
}
#endregion
#region IOT
string slot = "01-SLOT-01";
//过站明细
if (GlobalContext.IsMqttSendProcessData)
{
test_item_num += 1;
PassStationDetailRequest request = new PassStationDetailRequest();
request.pass_station_id = uuid;
request.sn = sn; // 产品SN
request.slot = slot; // 槽位编码
request.test_item_num = test_item_num.ToString();
request.function_name = "Machine_加⼯模块";
request.status = "PASS";
(int, string) iotResult = (0, "");
if (jsonParm.Length > 0)
{
// 解析JSON字符串为字典
var dictionary = JsonConvert.DeserializeObject>(jsonParm);
foreach (var kvp in dictionary)
{
request.test_item = kvp.Key.ToString();
request.result_val = kvp.Value.ToString();
request.description = request.test_item;
// 上传过站明细
iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
if (iotResult.Item1 != 0)
{
OnMessage(LogType.Info, $"【IOT过站明细】上传失败!错误原因:{iotResult.Item2},过站明细;产品码[{sn}] 测试项目[{request.test_item}] 测试值[{request.result_val}]");
}
}
}
}
//过站结果
if (GlobalContext.IsMqttSendProcessData)
{
PassStationResultRequest request = new PassStationResultRequest();
request.project_code = GlobalContext.Project_Code; // 项⽬编码
request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
request.line_code = GlobalContext.LineCode; // 线体编码
request.work_station = _workstation; // ⼯站ID
request.device_code = _deviceCode; // 装备编码
request.station = _stationCode;
request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
request.slot = slot; // 槽位编码
request.sn = sn; // 产品SN
// request.enter_status = inpass ? "PASS" : "FAIL"; // 进站状态
request.enter_status = ""; // 进站状态
request.result = pass ? "PASS" : "FAIL"; // 出站条件 PASS或FAIL; // 过站结果
request.work_type = "OUT_STATION"; // 作业类型
// 上传过站结果
(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
if (iotResult.Item1 != 0)
{
OnMessage(LogType.Info, $"【IOT过站结果】上传失败!错误原因:{iotResult.Item2},过站结果;产品码[{sn}] 进站结果[{request.enter_status}] 出站结果[{request.result}]");
}
}
#endregion
return result;
}
//private void CollectAndProcessDataLeft(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
//{
// Stopwatch stopwatch = new Stopwatch();
// stopwatch.Start();
// try
// {
// // 初始化 AtlasScrew 实例
// AtlasScrew atlasScrew1 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
// atlasScrew1.Initial();
// // 存储结果的列表
// List<(double Angle, double Torque, double StartTorque, double MaxTorque)> results = new List<(double, double, double, double)>();
// // 存储角度和扭力的字符串列表
// List angleStrs = new List();
// List torqueStrs = new List();
// // 上一次获取的数据
// (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
// while (isExitAtlasLeft) // 检查是否收集数据
// {
// // 获取当前数据
// var currentResult = atlasScrew1.GetResults();
// // 判断是否为新数据
// if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
// {
// OnMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
// // 更新角度和扭力的字符串列表
// angleStrs.Add(currentResult.JD_MEAN.ToString());
// torqueStrs.Add(currentResult.NL_MEAN.ToString());
// // 计算角度、扭力、起始扭力和最大扭力
// double[] angles = angleStrs.Select(a => double.Parse(a)).ToArray();
// double[] torques = torqueStrs.Select(a => double.Parse(a)).ToArray();
// double startTorque = torques.Length > 0 ? torques[0] : -1; // 起始扭力
// double maxTorque = torques.Length > 0 ? torques.Max() : -1; // 最大扭力
// // 将新数据添加到结果列表
// results.Add((angles.Last(), torques.Last(), startTorque, maxTorque));
// // 更新上一次获取的数据
// lastResult = currentResult;
// }
// // 等待一段时间后再次检查
// Thread.Sleep(20); // 轮询间隔时间
// // 如果触发了出站,则退出循环
// if (!isExitAtlasLeft)
// {
// break;
// }
// }
// // 生成文件名
// string fileName = $"{sn}_{direction}_{DateTime.Now:yyyyMMddHHmmss}.txt";
// // 写入数据到文件
// using (StreamWriter writer = new StreamWriter(fileName))
// {
// // 写入标题行
// writer.WriteLine("角度, 扭力, 起始扭力, 最大扭力");
// // 写入每一行数据
// foreach (var result in results)
// {
// writer.WriteLine($"{result.Angle}, {result.Torque}, {result.StartTorque}, {result.MaxTorque}");
// }
// }
// stopwatch.Stop();
// AddMessage(LogType.Info, $"数据采集完成并保存到文件 {fileName}; 总用时 {stopwatch.ElapsedMilliseconds}ms");
// }
// catch (Exception ex)
// {
// AddMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
// }
// finally
// {
// // 重置标志变量
// isExitAtlasLeft = false;
// }
//}
//private void CollectAndProcessDataRight(string sn, string direction, string ip, string port, int connectTimeOut, int sendDataTimeOut)
//{
// Stopwatch stopwatch = new Stopwatch();
// stopwatch.Start();
// try
// {
// // 初始化 AtlasScrew 实例
// AtlasScrew atlasScrew2 = new AtlasScrew(ip, port, connectTimeOut, sendDataTimeOut);
// atlasScrew2.Initial();
// // 存储结果的列表
// List<(double JD_MEAN, double NL_MEAN)> results = new List<(double JD_MEAN, double NL_MEAN)>();
// // 上一次获取的数据
// (double JD_MEAN, double NL_MEAN) lastResult = (-1, -1);
// while (isExitAtlasRight) // 检查是否收集数据
// {
// // 获取当前数据
// var currentResult = atlasScrew2.GetResults();
// // 判断是否为新数据
// if (currentResult.JD_MEAN != lastResult.JD_MEAN || currentResult.NL_MEAN != lastResult.NL_MEAN)
// {
// AddMessage(LogType.Info, $"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
// // 将新数据写入PLC
// //WriteDataToPlc(plcNo, stationNameStr, tagMesCommName, currentResult.JD_MEAN, currentResult.NL_MEAN);
// // 将新数据添加到结果列表
// results.Add(currentResult);
// // 更新上一次获取的数据
// lastResult = currentResult;
// }
// // 等待一段时间后再次检查
// Thread.Sleep(20); // 轮询间隔时间
// // 如果触发了出站,则退出循环
// if (!isExitAtlasRight)
// {
// break;
// }
// }
// // 将所有数据写入文件
// //WriteDataToFile(sn, direction, results);
// stopwatch.Stop();
// OnMessage(LogType.Info, $"螺丝数据采集完成;总用时{stopwatch.ElapsedMilliseconds}ms");
// }
// catch (Exception ex)
// {
// OnMessage(LogType.Error, $"螺丝数据采集过程中发生错误: {ex.Message}");
// }
// finally
// {
// // 重置标志变量
// isExitAtlasRight = false;
// }
//}
private void CollectAndProcessDataLeft(AtlasScrew atlasScrew, string sn, string direction)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
int nRet = 0;
string strRet = "";
try
{
int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
while (isCollectingFlagLeft)
{
// 从缓存中获取所有未处理的数据
var cachedData = atlasScrew.GetCachedDataLeft();
foreach (var currentResult in cachedData)
{
if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
{
continue; // 跳过无效数据
}
OnMessage(LogType.Info,
$"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
// 写入PLC
OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
{
fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
fCircles = float.Parse(currentResult.JD_MEAN.ToString())
};
(nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
if (nRet != 0)
{
OnMessage(LogType.Info,
$"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
}
else
{
OnMessage(LogType.Info,
$"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
}
// 构建保存路径
string dateFolder = DateTime.Now.ToString("yyyyMMdd");
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
Directory.CreateDirectory(savePath); // 确保目录存在
// 构建文件名(以 SN + 序号命名)
string fileName = $"{sn}_{fileCounter}.txt";
string filePath = Path.Combine(savePath, fileName);
// 写入文件
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.WriteLine("精度, 扭力");
// 遍历 Pearkdegree 和 PearkTorque 的所有值
for (int i = 0;
i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
i++)
{
double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
writer.WriteLine($"{precision}, {torque}");
}
}
OnMessage(LogType.Info, $"保存文件成功: {filePath}");
// 增加文件计数器
fileCounter++;
}
// 如果没有更多数据,则短暂休眠以节省资源
if (!cachedData.Any())
{
Thread.Sleep(10); // 根据需要调整休眠时间
}
// 如果触发了出站,则退出循环
if (!isCollectingFlagLeft)
{
break;
}
}
stopwatch.Stop();
OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
}
catch (Exception ex)
{
OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
}
finally
{
isCollectingFlagLeft = false;
}
}
private void CollectAndProcessDataRight(AtlasScrew atlasScrew, string sn, string direction)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
int nRet = 0;
string strRet = "";
try
{
int fileCounter = 1; // 文件计数器,用于生成文件名中的序号
while (isCollectingFlagRight)
{
// 从缓存中获取所有未处理的数据
var cachedData = atlasScrew.GetCachedDataLeft();
foreach (var currentResult in cachedData)
{
if (currentResult.JD_MEAN == 0 || currentResult.NL_MEAN == 0)
{
continue; // 跳过无效数据
}
OnMessage(LogType.Info,
$"检测到新数据: JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN}");
// 写入PLC
OP70_ScrewDataSet_t resultToPlC = new OP70_ScrewDataSet_t
{
fTorque = float.Parse(currentResult.NL_MEAN.ToString()),
fCircles = float.Parse(currentResult.JD_MEAN.ToString())
};
(nRet, strRet) = WriteResultToPlc(7, "", $"g_OP70_MES.{direction}.screwDriver", 1, resultToPlC);
if (nRet != 0)
{
OnMessage(LogType.Info,
$"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC失败");
}
else
{
OnMessage(LogType.Info,
$"SN:{sn}, JD_MEAN={currentResult.JD_MEAN}, NL_MEAN={currentResult.NL_MEAN} 写入PLC成功");
}
// 构建保存路径
string dateFolder = DateTime.Now.ToString("yyyyMMdd");
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string savePath = Path.Combine(basePath, "screw", dateFolder, sn, direction, "曲线");
Directory.CreateDirectory(savePath); // 确保目录存在
// 构建文件名(以 SN + 序号命名)
string fileName = $"{sn}_{fileCounter}.txt";
string filePath = Path.Combine(savePath, fileName);
// 写入文件
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.WriteLine("精度, 扭力");
// 遍历 Pearkdegree 和 PearkTorque 的所有值
for (int i = 0;
i < currentResult.Pearkdegree.Length && i < currentResult.PearkTorque.Length;
i++)
{
double precision = Math.Round(currentResult.Pearkdegree[i]); // 精度
double torque = Math.Round(currentResult.PearkTorque[i], 2); // 扭力
writer.WriteLine($"{precision}, {torque}");
}
}
OnMessage(LogType.Info, $"保存文件成功: {filePath}");
// 增加文件计数器
fileCounter++;
}
// 如果没有更多数据,则短暂休眠以节省资源
if (!cachedData.Any())
{
Thread.Sleep(10); // 根据需要调整休眠时间
}
// 如果触发了出站,则退出循环
if (!isCollectingFlagRight)
{
break;
}
}
stopwatch.Stop();
OnMessage(LogType.Info, $"数据采集完成; 总用时 {stopwatch.ElapsedMilliseconds}ms");
}
catch (Exception ex)
{
OnMessage(LogType.Error, $"数据采集过程中发生错误: {ex.Message}");
}
finally
{
isCollectingFlagRight = false;
}
}
///
/// 上传文件
///
/// 条码集合
/// 工站编号
/// 工站名称
/// 文件路径
public async Task<(int, string)> SaveDBbyFileInfo(BarcodeSet_t BarcodeSet, string stationCode, string stationName,string path)
{
string sql, filename = "";
Guid guid;
int result = 0;
var formData = new MultipartFormDataContent();
// 获取所有图片文件
List imageFiles = GetAllImageFiles(path);
try
{
if (imageFiles.Count>0)
{
foreach (string imageFile in imageFiles)
{
guid = Guid.NewGuid();
filename = Path.GetFileName(imageFile);
sql = string.Format("INSERT INTO [dbo].[DataFiles](stationCode,stationName,CarrierBarcode,ProductBarcode,bucket,fileName,fileContext,uuid,fileUrl,status,submitTime,createTime) " +
"VALUES('{0}','{1}','{2}' ,'{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')"
, stationCode
, stationName
, BarcodeSet.strCarrierBarcode
, BarcodeSet.strProductBarcode
, "/mesCommToPC/pic/left"
, filename
, ""
, guid.ToString()
, ""
, 0
, ""
, DateTime.Now
);
string ret = SQLHelper_New.ExecuteNonQuery(sql, null);
FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
string bucket = string.Empty;
//bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
bucket = "/mesCommToPC/pic/left";
fileUpload_X5.bucket = bucket;
fileUpload_X5.name = filename;
fileUpload_X5.uuid = guid.ToString();
///需要上传文件
FileInfo file = new FileInfo(imageFile);
string fileMd5Hex = GetMD5Hex(file);
fileUpload_X5.md5 = fileMd5Hex;
fileUpload_X5.uploadCloud = true;
fileUpload_X5.informMqtt = true;
FileMqttPayload fileMqttPayload = new FileMqttPayload();
//fileMqttPayload.factory = "";
//fileMqttPayload.project_name = "";
//fileMqttPayload.product_mode = "";
//fileMqttPayload.line_no = "";
//fileMqttPayload.work_station_no = "";
//fileMqttPayload.equipment_no = "";
//fileMqttPayload.station_no = "";
//fileMqttPayload.file_id = "";
//fileMqttPayload.file_name = "";
//fileMqttPayload.sn = "";
//fileMqttPayload.opt_time = "";
//fileMqttPayload.file_type = "";
//fileMqttPayload.file_category = "";
//fileMqttPayload.tag = "";
//fileMqttPayload.pass_station_id = "";
//FileUpload_X5 fileUpload_X5 = new FileUpload_X5();
//FileMqttPayload fileMqttPayload = new FileMqttPayload();
//fileUpload_X5.bucket = "IMAGE/IMAGE/N3/debug/online/PASS/M0002PA-0001/P320N000006B/382f55e9-c2bb";
//fileUpload_X5.name = "test";
//fileUpload_X5.md5 = "";
//fileUpload_X5.uploadCloud = true;
//fileUpload_X5.informMqtt = true;
var fileresult = XiaomiMESHttp_UpLoadFile.FileUoladToMes(imageFile, fileUpload_X5, fileMqttPayload);
if (fileresult.Result.Item1 == 0)
{
return (1, fileresult.Result.Item2);
}
sql = string.Format("UPDATE [dbo].[DataFiles] SET status='{0}' WHERE uuid='{1}'", 1, guid);
string retnew = SQLHelper_New.ExecuteNonQuery(sql, null);
return fileresult.Result;
}
return (1, "程序错误!");
}
else
{
return (1,"文件不存在!");
}
}
catch (Exception e)
{
return (1, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode},错误原因:" + e.Message);
//AddMessage_Station(stationName, LogType.Error, filename + $"图片保存失败!载具码:{BarcodeSet.strCarrierBarcode}产品码{BarcodeSet.strProductBarcode}");
}
}
///
/// 获取路径下的所有图片
///
///
///
public List GetAllImageFiles(string directoryPath)
{
var imageExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff" };
var imageFiles = new List();
try
{
// 遍历目录及子目录中的所有文件
foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
{
// 获取文件扩展名并检查是否为图片格式
string extension = Path.GetExtension(file);
if (imageExtensions.Contains(extension))
{
imageFiles.Add(file);
}
}
}
catch (Exception ex)
{
OnMessage(LogType.Error, $"图片查询发生错误: {ex.Message}");
}
return imageFiles;
}
///
/// 实例化报警字典
///
private (bool, string) InitalDicAlarm()
{
#region 加载报警表
string excelPath = "";
switch (GlobalContext.IsUsePLCNow)
{
case 1:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_10_壳体清洁上料.xlsx";
break;
case 2:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_20_上盖板上料装备.xlsx";
break;
case 3:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_30_点散热胶装备.xlsx";
break;
case 4:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_40_胶线检测.xlsx";
break;
case 5:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_50_ADD板上料组装装备.xlsx";
break;
case 6:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_60_组上盖板.xlsx";
break;
case 7:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_70_上盖板锁螺丝.xlsx";
break;
case 8:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_80_NG下料.xlsx";
break;
case 9:
excelPath = AppDomain.CurrentDomain.BaseDirectory + "DBFile\\小米-IoT报警字典_90_半成品下料.xlsx";
break;
default:
return (false, $"不支持当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请在设置页切换到正确的plc后重启该软件!");
}
if (!File.Exists(excelPath))
return (false, $"未找到当前PLC[{GlobalContext.IsUsePLCNow}]的报警点位表!请检查文件路径:'{excelPath}'。");
DataTable DtModel = NPOIHelper.ReadExcel(excelPath);
if (DtModel == null || DtModel.Rows.Count < 1)
return (false, $"报警点位表未包含任何报警数据!请检查‘{excelPath}’文件!");
// 检查列名
List isNeedParms = new List() {"设备分类名称","设备分类编码","分类层级1","分类层级2","分类层级3" ,"分类层级4","事件名称"
,"事件ID","描述","标签","PLC地址","工位"}; // 必须要有的列
// 指定列名 + 检查列是否完整
DataRow dtRowName = DtModel.Rows[0];
int count = DtModel.Columns.Count;
for (int i = 0; i < count; i++)
{
string columeName = dtRowName[i]?.ToString();
if (!string.IsNullOrEmpty(columeName))
DtModel.Columns[i].ColumnName = columeName;
if ((!string.IsNullOrEmpty(columeName)) && isNeedParms.Count > 0 && isNeedParms.Contains(columeName))
isNeedParms.Remove(columeName);
}
DtModel.Rows.RemoveAt(0);
if (isNeedParms.Count > 0)
{
string msg1 = string.Join(",", isNeedParms);
return (false, $"报警点位表未包含列:{msg1}!请检查‘{excelPath}’文件!");
}
#endregion 加载报警表
List keyValues1 = new List();
for (int i = 0; i < DtModel.Rows.Count; i++)
{
Alarm alarm = new Alarm();
alarm.plcName = DtModel.Rows[i]["设备分类名称"]?.ToString(); // 设备名;
string type1Str = DtModel.Rows[i]["分类层级1"]?.ToString(); // 分类层级1;
alarm.type1CH = type1Str; // 分类层级1 中文
alarm.type1 = type1Str; // 分类层级1
if (!string.IsNullOrEmpty(type1Str) && type1Str.Contains("\n"))
{
string[] type1Strs = type1Str.Split('\n');
if (type1Strs.Length >= 2)
{
alarm.type1CH = type1Strs[0].Trim(); // 分类层级1 中文
alarm.type1 = type1Strs[1].Trim(); // 分类层级1
if (string.IsNullOrEmpty(alarm.type1))
alarm.type1 = alarm.type1CH;
}
}
string type2Str = DtModel.Rows[i]["分类层级2"]?.ToString(); // 分类层级2;电气控制 electric_control
alarm.type2CH = type2Str; // 分类层级2 中文
alarm.type2 = type2Str; // 分类层级2
if (!string.IsNullOrEmpty(type2Str) && type2Str.Contains("\n"))
{
string[] type2Strs = type2Str.Split('\n');
if (type2Strs.Length >= 2)
{
alarm.type2CH = type2Strs[0].Trim(); // 分类层级2 中文
alarm.type2 = type2Strs[1].Trim(); // 分类层级2
if (string.IsNullOrEmpty(alarm.type2))
alarm.type2 = alarm.type2CH;
}
}
string type3Str = DtModel.Rows[i]["分类层级3"]?.ToString(); // 分类层级3;故障 Fault
alarm.type3CH = type3Str; // 分类层级3 中文
alarm.type3 = type3Str; // 分类层级3
if (!string.IsNullOrEmpty(type3Str) && type3Str.Contains("\n"))
{
string[] type3Strs = type3Str.Split('\n');
if (type3Strs.Length >= 2)
{
alarm.type3CH = type3Strs[0].Trim(); // 分类层级3 中文
alarm.type3 = type3Strs[1].Trim(); // 分类层级3
if (string.IsNullOrEmpty(alarm.type3))
alarm.type3 = alarm.type3CH;
}
}
string faultStr = DtModel.Rows[i]["分类层级4"]?.ToString(); // 故障部件;overall_module
alarm.type4 = faultStr; // 分类层级4 中文
alarm.type4CH = faultStr; // 分类层级4
if (!string.IsNullOrEmpty(faultStr) && faultStr.Contains("\n"))
{
string[] faultStrs = faultStr.Split('\n');
if (faultStrs.Length >= 2)
{
alarm.type4CH = faultStrs[0].Trim(); // 故障部件;overall_module
alarm.type4 = faultStrs[1].Trim(); // 故障部件
if (string.IsNullOrEmpty(alarm.type4))
alarm.type4 = alarm.type4CH;
}
}
alarm.fault_code = DtModel.Rows[i]["事件ID"]?.ToString(); // 故障编码;A40001
alarm.fault_name = DtModel.Rows[i]["事件名称"]?.ToString(); // 故障名称;AL[1000]_系统_HMI急停故障
alarm.fault_desc = alarm.fault_name; // 故障描述;AL[1000]_系统_HMI急停故障
string plcAdress = DtModel.Rows[i]["PLC地址"]?.ToString();
alarm.PLC地址 = plcAdress;
plcAdress = plcAdress.Replace("fault_codes[", "");
plcAdress = plcAdress.Replace("]", "");
alarm.group_index = Convert.ToInt32(plcAdress.Split(".")[0]);
keyValues1.Add(alarm);
}
DicAlarms_Cur.Add(GlobalContext.IsUseStationName, keyValues1); // 这里使用线体代替工位
return (true, "报警字典表初始化成功!");
}
private async void ReadPLCAlarmToIot(uint[] FaultData,string stationNameStr)
{
DateTime dtNow = DateTime.Now;
try
{
List deviceAlarm_Curs = new List(); // 同步到报警页面用传输载体
List<(int, int)> AlarmIndexList = new List<(int, int)>();//收集所有报警信息的位置
AlarmData alarmData = new AlarmData();
bool isNeedUpdUI = false; // 是否需要更新历史报警UI
bool isNoAlarm = false;//是否有报警
string binaryString = "";
bool isNoNewAlarm = false;//是否有新的报警
if (FaultData.Length > 0)
{
}
foreach (var item in FaultData)
{
isNoAlarm = item > 0 ? true : false;
}
if (!FaultData.SequenceEqual(_FaultDatas_Old))
{
isNoNewAlarm = true;
isNeedUpdUI = true;
}
if (FaultData.Length > 0 && isNoAlarm && isNoNewAlarm)
{
//解析报警信息,分析当前报警在字典中的定位
for (int i = 0; i <= FaultData.Length - 1; i++)
{
var num = 0;
if (FaultData[i] > 0)
{
//转换二进制
binaryString = Convert.ToString(FaultData[i], 2);
for (int j = binaryString.Length - 1; j >= 0; j--)
{
num++;
char s = binaryString[j];
if (binaryString[j] == '1')
{
//记录1的位置
AlarmIndexList.Add((i, num - 1));
}
}
}
}
// 同步“设备报警信息”到“设备报警临时字典DicAlarms_Cur”
var dicAlarms_Cur_PLC1 = DicAlarms_Cur[GlobalContext.IsUseStationName];
foreach ((int index, int row) in AlarmIndexList)
{
var tempDic = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList();
for (int i = 0; i < tempDic.Count - 1; i++) // 读取
{
//若报警字典第[group_index]个数据,第[i]行与AlarmIndexList中的定位匹配,则添加进对应行的报警数据
if (tempDic[i].group_index == index && i == row)
{
dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据 = new AlarmData()
{
GUID = Guid.NewGuid().ToString(),
LineName = GlobalContext.IsUseStationName, // 工站
PlcStation = tempDic[i].plcName, // 工站全称;[S1]
Type1 = tempDic[i].type1, // 故障层级1
Type2 = tempDic[i].type2, // 故障层级2
Type3 = tempDic[i].type3, // 故障层级3
Type4 = tempDic[i].type4, // 故障层级4
AlarmType = tempDic[i].fault_code, // 报警类型
AlarmDesc = tempDic[i].fault_name, // 报警内容
StartTime = dtNow // 开始时间
};
// 传输到页面
deviceAlarm_Curs.Add(new DeviceAlarm_Cur()
{
线体名称 = tempDic[i].plcName,
报警类型 = tempDic[i].fault_code,
报警内容 = tempDic[i].fault_name,
开始时间 = dtNow
});
// 新增到数据库
//var data1 = dicAlarms_Cur_PLC1.Where(x => x.group_index == index).ToList()[row].报警数据;
//SaveAlarmDataByDB(stationNameStr, data1, false);
//OnMessage(LogType.Info, $"更新{BodyAlarm}完毕!");
}
}
}
//筛选含报警数据的字典
var dicAlarms_Cur = dicAlarms_Cur_PLC1.Where(x => x.报警数据 != null).ToList();
if (dicAlarms_Cur.Count > 0)
{
foreach (var item in dicAlarms_Cur)
{
//上传
SaveAlarmDataByDB(GlobalContext.IsUseStationName, item.报警数据, false);
}
}
// 有新报警则更新
if (isNeedUpdUI)
// UI展示 - 展示到设备状态页
await Task.Run(() =>
{
try
{
if (Form_Main.formDevAlarm != null && !Form_Main.formDevAlarm.IsDisposed)
{
Form_Main.formDevAlarm.UpdDeviceAlarm_Cur(deviceAlarm_Curs); // 报警UI 更新
if (Form_Main.formDevAlarm.Visible)
Form_Main.formDevAlarm.UpdDeviceAlarm_History_48H(); // 历史报警UI 更新
}
}
catch { }
});
_FaultDatas_Old = FaultData.ToArray();
}
//FaultLogRequest request = new FaultLogRequest();
//request.station = mesStation; // 工位
//request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
//request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
//request.fault_cmpnt = xmFaultCmpnt; // 故障部件
//request.fault_desc = xmFaultDesc; // 故障描述
//request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发生时间 2022-06-01 14:27:57.283
// // 上传
//(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request, type1, type2, type3, request.fault_cmpnt, deciveCode);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error, $"{stationNameStr}_获取报警数据出错!错误信息:" + ex.Message.ToString() + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
}
public void operateToIot(string action, string stationNameStr)
{
OperateLogRequest request = new OperateLogRequest();
request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
request.operate_action = action; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
//request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
request.current_process = Application.ProductName;
request.operate_desc = stationNameStr; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
request.operate_result = "success"; // 操作结果
request.operator_name = "default"; // 操作账号名;填当前操作⽤⼾,如⽆则填default
// 上传
(int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
if (iotResult.Item1 != 0)
{
AddMessage(LogType.Info, "【操作记录】上传失败!错误原因:"+ iotResult.Item2+"操作状态:"+stationNameStr);
}
}
#endregion
#region S1
///
/// [S1] 壳体清洁上料装备
///
/// PLC编号
private void ReadStation_S1(int plcNo)
{
string stationCode = "[OP10]";
string stationName = "壳体清洁上料";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP10_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s1PLCSignal_Old.Add("a1OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
OP10_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
//设备状态
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
// 物料码(物料码还未绑定载具SN时必填)
s1PLCData["a1OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode;
// 载具SN
s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode;
// 节拍
s1PLCData["a1OEEType"] = stPLC_MesData.iotData.BeatAction;
//报警信息
_FaultDatas = stPLC_MesData.iotData.fault_codes;
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
uuid = Guid.NewGuid().ToString();
ProgressState = true;
Task.Run(() => S1进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S1出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
uuid = "";
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a10EEType = (int)s1PLCData["a10EEType"];
int a10EETypeGOld = (int)s1PLCSignal_Old["a10EEType"];
//若设备紧急复原后节拍重置
if (a10EEType == 1)
{
a10EETypeGOld = 0;
}
if (a10EEType != a10EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a10EETypeGOld == 1 && a10EEType != 2) || (a10EETypeGOld == 3 && a10EEType != 4) ||
(a10EETypeGOld == 5 && a10EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a10EEType}],未上传节拍[{a10EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S1节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s1PLCSignal_Old["a10EEType"] = s1PLCData["a10EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S1] 壳体清洁上料 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S1进站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有OP10和OP50返回
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S1_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S1_StationId; // 工位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
if (string.IsNullOrEmpty(sn))
{
ProgressState = false;
return;
}
//正式生产就用PLC中取的
//sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode;
//测试先用9码,正式直接用PLC得到的SN码,截取成9位码
sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
//绑定载具和产品
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertCarrierBind(CarrierBarcode, sn);
if (message.result == false)
{
AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
}
// 产品SN进站
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId,pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb==1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0;
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S1] 壳体清洁上料 - 出站接口
///
private void S1出站(int plcNo, string stationNameStr, OP10_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
test_item_num = 0;//iot 过站明细序号
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号 现在没用上
string batch_num = GlobalContext.BatchNumber; // 批次号 现在没用上
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号 现在没用上
string sn = string.Empty;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S1_MachineId; // 装备id(可配置)
string StationId = GlobalContext.S1_StationId; // ⼯位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
//a1Result = 1;
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
#region 转换过站明细字符串
//创建字典
var dic = new Dictionary();
// 获取结构体类型
FieldInfo[] fields = typeof(OP10_DataSet_t).GetFields();
// 遍历变量名转换成字典描述
foreach (FieldInfo field in fields)
{
//获取枚举描述
string name = XiaomiMESEnumMethod.GetEnumDescriptionByName(field.Name, typeof(XiaomiMESEnum_ProcessData.Enum_10_ProcessData));
//获取过站明细的值
object valueObj = field.GetValue(stPLC_MesData.mesData);
dic.Add(name, valueObj.ToString());
}
string paramJson = JsonConvert.SerializeObject(dic);
#endregion
//出站接口
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertOp10Data(CarrierBarcode, sn, 1,
stPLC_MesData.mesData.nThrowCount, stPLC_MesData.mesData.fCleanAirPress,
stPLC_MesData.mesData.fCleanSpeed,
stPLC_MesData.mesData.fWindBladeHeight, stPLC_MesData.mesData.fCleanTime,
stPLC_MesData.mesData.nCleanCount,
stPLC_MesData.mesData.nRemainCount);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
AddMessage(LogType.Info, stationNameStr + "_保存出站数据结束");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
#endregion
#region S2
///
/// [S2] 上盖板上料装备
///
/// PLC编号
private void ReadStation_S2(int plcNo)
{
string stationCode = "[OP20]";
string stationName = "上盖板上料装备";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP20_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s2PLCSignal_Old.Add("a2OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s2PLCData.Add("a2OEEType", 0); // 节拍类型(plc写入)
s2PLCData.Add("a2OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s2PLCData.Add("a2OEEVehicleCode", ""); // 载具SN
OP20_MesData_t stPLC_MesData; //PLC的MES数据
IoT_DataSet_t iot_data;
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs2)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
//设备状态
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s2PLCData["a2OEEPartNo"] =
stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s2PLCData["a2OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s2PLCData["a2OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S2进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S2出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0; //清除入站申请
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a20EEType = (int)s2PLCData["a20EEType"];
int a20EETypeGOld = (int)s2PLCSignal_Old["a20EEType"];
//若设备紧急复原后节拍重置
if (a20EEType == 1)
{
a20EETypeGOld = 0;
}
if (a20EEType != a20EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a20EETypeGOld == 1 && a20EEType != 2) || (a20EETypeGOld == 3 && a20EEType != 4) ||
(a20EETypeGOld == 5 && a20EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a20EEType}],未上传节拍[{a20EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S2节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s2PLCSignal_Old["a20EEType"] = s2PLCData["a20EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect();
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
//Funs[plcNo].ReConnect();
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S2] 上盖板上料装备
///
/// PLC编号
/// 工站全称
private void S2进站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码),现在PLC只有10和50返回
//sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
string MachineId = GlobalContext.S2_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S2_StationId; // 工位ID(可配置)
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
//这个地方之后PLC可能会返回SN码,到时用返回的和数据库中的比较下对错,结果faalse怎么办现在不知道
//if (sn != strProductBarcode)
//{
// AddMessage(LogType.Info, $"进站产品码错误!与载具绑定的产品码不匹配,进站产品码:{sn};载具绑定产品码:{strProductBarcode}");
//}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId,pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S2] 上盖板上料装备 - 出站接口
///
private void S2出站(int plcNo, string stationNameStr, OP20_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; //部件码
string MachineId = GlobalContext.S2_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S2_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "部件码",
Parameter_value = PartBarcode,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertOp20Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
stPLC_MesData.mesData.nRemainCount);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
if (!string.IsNullOrEmpty(PartBarcode))
{
message = SQLHelper.InsertOp20Product(CarrierBarcode, sn, PartBarcode);
if (message.result == false)
{
AddMessage(LogType.Error, message.text);
}
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
#endregion
#region S3
///
/// [S3] 点散热胶装备
///
/// PLC编号
private void ReadStation_S3(int plcNo)
{
string stationCode = "[OP30]";
string stationName = "点散热胶装备";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP30_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s3PLCSignal_Old.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
s3PLCSignal_Old.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s3PLCData.Add("a3OEEType_left", 0); // 节拍类型(plc写入)
s3PLCData.Add("a3OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
s3PLCData.Add("a3OEEVehicleCode_left", ""); // 载具SN
s3PLCData.Add("a3OEEType_right", 0); // 节拍类型(plc写入)
s3PLCData.Add("a3OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
s3PLCData.Add("a3OEEVehicleCode_right", ""); // 载具SN
OP30_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs2)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt_L;
xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt_R;
s1PLCData["a1OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s1PLCData["a1OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
s1PLCData["a1OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
s1PLCData["a1OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
s1PLCData["a1OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 左边进站
try
{
if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Left,
tagBaseName + ".Left." + tagMesCommName,
tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 左边进站
#region 左边出站
try
{
if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Left,
tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
out ProgressState));
stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 左边出站
#region 右边进站
try
{
if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S3进站(plcNo, stationNameStr, stPLC_MesData.Right,
tagBaseName + ".Right." + tagMesCommName,
tagBaseName + ".Right." + tagBarsetName, "Right", out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 右边进站
#region 右边出站
try
{
if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S3出站(plcNo, stationNameStr, stPLC_MesData.Right,
tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
out ProgressState));
stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 右边出站
#region 节拍接口
try
{
#region 左工位 节拍
int a30EEType_left = (int)s3PLCData["a30EEType_left"];
int a30EETypeGOld_left = (int)s3PLCSignal_Old["a30EEType_left"];
//若设备紧急复原后节拍重置
if (a30EEType_left == 1)
{
a30EETypeGOld_left = 0;
}
if (a30EEType_left != a30EETypeGOld_left)
{
stationNameStr = stationNameStr + "_Left";
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a30EETypeGOld_left == 1 && a30EEType_left != 2) || (a30EETypeGOld_left == 3 && a30EEType_left != 4) ||
(a30EETypeGOld_left == 5 && a30EEType_left != 6))
{
//写入PLC
stPLC_MesData.Left.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a30EEType_left}],未上传节拍[{a30EETypeGOld_left}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
}
s3PLCSignal_Old["a30EEType_left"] = s3PLCData["a30EEType_left"];
}
#endregion 左工位 节拍
#region 右工位 节拍
int a30EEType_right = (int)s3PLCData["a30EEType_right"];
int a30EETypeGOld_right = (int)s3PLCSignal_Old["a30EEType_right"];
//若设备紧急复原后节拍重置
if (a30EEType_right == 1)
{
a30EETypeGOld_right = 0;
}
if (a30EEType_right != a30EETypeGOld_right)
{
stationNameStr = stationNameStr + "_Right";
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a30EETypeGOld_right == 1 && a30EEType_right != 2) || (a30EETypeGOld_right == 3 && a30EEType_right != 4) ||
(a30EETypeGOld_right == 5 && a30EEType_right != 6))
{
//写入PLC
stPLC_MesData.Right.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a30EEType_right}],未上传节拍[{a30EETypeGOld_right}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
}
s3PLCSignal_Old["a30EEType_right"] = s3PLCData["a30EEType_right"];
}
#endregion 右工位 节拍
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect();
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
//Funs[plcNo].ReConnect();
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S3] 点散热胶装备 - 进站
///
/// PLC编号
/// 工站全称
private void S3进站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, string direction, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S3_MachineId; // 装备ID(可配置)
string StationId = string.Empty;
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
if (direction == "Left")
{
StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
}
if (direction == "Right")
{
StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
}
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strProductBarcode};产品码:{sn}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId,pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S3] 点散热胶装备 - 出站
///
private void S3出站(int plcNo, string stationNameStr, OP30_stnDataSet_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, string direction, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S3_MachineId; // 装备id(可配置)
string StationId = string.Empty;
if (direction == "Left")
{
StationId = GlobalContext.S3_StationId_1; // 工位ID(可配置)
}
if (direction == "Right")
{
StationId = GlobalContext.S3_StationId_2; // 工位ID(可配置)
}
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
//if (direction == "Right")
//{
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson, direction);
//}
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
if (direction == "Left")
{
string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
message = SQLHelper.InsertOp301Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
strMesHeightInfos, strIntervalWeights, strRemainGlues);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
}
if (direction == "Right")
{
string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fMesHeightInfos);
string strIntervalWeights = FloatArrayToString(stPLC_MesData.mesData.fIntervalWeights);
string strRemainGlues = FloatArrayToString(stPLC_MesData.mesData.fRemainGlues);
message = SQLHelper.InsertOp302Data(CarrierBarcode, sn, stPLC_MesData.mesData.fGlueSupplySpeed,
stPLC_MesData.mesData.fAB_AirPress, stPLC_MesData.mesData.fAB_AirPressDiff,
strMesHeightInfos, strIntervalWeights, strRemainGlues);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
#endregion S3
#region S4
///
/// [S4] 点胶检测设备
///
/// PLC编号
private void ReadStation_S4(int plcNo)
{
string stationCode = "[OP40]";
string stationName = "胶线检测";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP40_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s4PLCSignal_Old.Add("a4OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s4PLCData.Add("a4OEEType", 0); // 节拍类型(plc写入)
s4PLCData.Add("a4OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s4PLCData.Add("a4OEEVehicleCode", ""); // 载具SN
OP40_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s4PLCData["a4OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s4PLCData["a4OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s4PLCData["a4OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S4进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S4出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a40EEType = (int)s4PLCData["a40EEType"];
int a40EETypeGOld = (int)s4PLCSignal_Old["a40EEType"];
//若设备紧急复原后节拍重置
if (a40EEType == 1)
{
a40EETypeGOld = 0;
}
if (a40EEType != a40EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a40EETypeGOld == 1 && a40EEType != 2) || (a40EETypeGOld == 3 && a40EEType != 4) ||
(a40EETypeGOld == 5 && a40EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a40EEType}],未上传节拍[{a40EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S4节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s4PLCSignal_Old["a40EEType"] = s4PLCData["a40EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S4] 点胶检测设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S4进站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S4_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S4_StationId; // 工位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId,pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S4] 点胶检测设备 - 出站接口
///
private void S4出站(int plcNo, string stationNameStr, OP40_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S4_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S4_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
string strGluePosX = FloatArrayToString(stPLC_MesData.mesData.fGluePosX);
string strGluePosY = FloatArrayToString(stPLC_MesData.mesData.fGluePosY);
string strGlue_Areas = FloatArrayToString(stPLC_MesData.mesData.fGlue_Areas);
string strGlue_Heights = FloatArrayToString(stPLC_MesData.mesData.fGlue_Heights);
message = SQLHelper.InsertOp40Data(CarrierBarcode, sn, strGluePosX,
strGluePosY, strGlue_Areas, strGlue_Heights, stPLC_MesData.mesData.nResult, "");
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S4节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a4OEEType"]).ToString(); // 节拍类型(plc写入)
string a40EEPartNo = (string)s1PLCData["a40EEPartNo"]; // 物料码
a40EEPartNo = a40EEPartNo.Replace("\0", "");
string a50EEVehicleCode = (string)s1PLCData["a50EEVehicleCode"]; // 载具SN
a50EEVehicleCode = a50EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a40EEPartNo) && string.IsNullOrEmpty(a50EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a50EEVehicleCode}][{a40EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a40EEPartNo, a50EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#region S5
///
/// [S5] 点胶检测设备
///
/// PLC编号
private void ReadStation_S5(int plcNo)
{
string stationCode = "[OP50]";
string stationName = "ADD板上料组装装备";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP50_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s5PLCSignal_Old.Add("a5OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s5PLCData.Add("a5OEEType", 0); // 节拍类型(plc写入)
s5PLCData.Add("a5OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s5PLCData.Add("a5OEEVehicleCode", ""); // 载具SN
OP50_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s5PLCData["a5OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s5PLCData["a5OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s5PLCData["a5OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S5进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S5出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a50EEType = (int)s5PLCData["a50EEType"];
int a50EETypeGOld = (int)s5PLCSignal_Old["a50EEType"];
//若设备紧急复原后节拍重置
if (a50EEType == 1)
{
a50EETypeGOld = 0;
}
if (a50EEType != a50EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a50EETypeGOld == 1 && a50EEType != 2) || (a50EETypeGOld == 3 && a50EEType != 4) ||
(a50EETypeGOld == 5 && a50EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a50EEType}],未上传节拍[{a50EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S5节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s5PLCSignal_Old["a50EEType"] = s5PLCData["a50EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S5] 点胶检测设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S5进站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
//sn = sn.Substring(sn.Length - 11, 4) + sn.Substring(sn.Length - 5, 5);
string MachineId = GlobalContext.S5_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S5_StationId; // 工位ID(可配置)
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码
string pcbBarcode = (string)stPLC_MesData.BarcodeSet.strPCBBarcode;
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//绑定载具和产品
ResponseMessage message = new ResponseMessage();
message = SQLHelper.PCBCarrierBind(strCarrierBarcode, pcbBarcode);
if (message.result == false)
{
AddMessage(LogType.Error, stationNameStr + "_载具码与产品码绑定失败,错误:" + message.text);
}
//载具码验证产品码 //载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn};PCB码:{pcbBarcode}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId, pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S5] 点胶检测设备 - 出站接口
///
private void S5出站(int plcNo, string stationNameStr, OP50_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string PartBarcode = (string)stPLC_MesData.BarcodeSet.strPartBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S5_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S5_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, PartBarcode, paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertOp50Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsAddPCBAsmOK,
stPLC_MesData.mesData.nHaveAddPCB, stPLC_MesData.mesData.fForceAddPCB,
stPLC_MesData.mesData.nRemainCount, "");
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
//保存部件码信息
if (!string.IsNullOrEmpty(PartBarcode))
{
message = SQLHelper.InsertOp50Product(CarrierBarcode, sn, PartBarcode);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存部件码信息失败");
}
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S5节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a5OEEType"]).ToString(); // 节拍类型(plc写入)
string a50EEPartNo = (string)s1PLCData["a50EEPartNo"]; // 物料码
a50EEPartNo = a50EEPartNo.Replace("\0", "");
string a40EEVehicleCode = (string)s1PLCData["a40EEVehicleCode"]; // 载具SN
a40EEVehicleCode = a40EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a50EEPartNo) && string.IsNullOrEmpty(a40EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a50EEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a40EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a40EEVehicleCode}][{a50EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a50EEPartNo, a40EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#region S6
private Dictionary s6PLCData = new Dictionary();
private Dictionary s6PLCSignal_Old = new Dictionary();
///
/// [S6] 顶盖装配设备
///
/// PLC编号
private void ReadStation_S6(int plcNo)
{
string stationCode = "[OP60]";
string stationName = "组上盖板";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP60_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s6PLCSignal_Old.Add("a6OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s6PLCData.Add("a6OEEType", 0); // 节拍类型(plc写入)
s6PLCData.Add("a6OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s6PLCData.Add("a6OEEVehicleCode", ""); // 载具SN
OP60_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s6PLCData["a6OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s6PLCData["a6OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s6PLCData["a6OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S6进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
;
Task.Run(() => S6出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a60EEType = (int)s6PLCData["a60EEType"];
int a60EETypeGOld = (int)s6PLCSignal_Old["a60EEType"];
//若设备紧急复原后节拍重置
if (a60EEType == 1)
{
a60EETypeGOld = 0;
}
if (a60EEType != a60EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a60EETypeGOld == 1 && a60EEType != 2) || (a60EETypeGOld == 3 && a60EEType != 4) ||
(a60EETypeGOld == 5 && a60EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a60EEType}],未上传节拍[{a60EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S6节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s6PLCSignal_Old["a60EEType"] = s6PLCData["a60EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S6] 顶盖装配设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S6进站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S6_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S6_StationId; // 工位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//strCarrierBarcode = "N801A-003";
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
if (OpenDailogFalg)
{
using (var dialog = new BandBarodeDialog())
{
dialog._CarrierBarcode = strCarrierBarcode;
dialog._ProductBarcode = sn;
var rs = dialog.ShowDialog();
if (rs == DialogResult.OK)
{
AddMessage(LogType.Info, $"扫码校验通过,载具码:{strCarrierBarcode};产品码:{sn};产品码:{sn}");
OpenDailogFalg = false;//关闭扫码
}
else {
ProgressState = false;
return;
}
}
}
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId, pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
OpenDailogFalg = true; //开启下一个物料的扫码
}
///
/// [S6] 顶盖装配设备 - 出站接口
///
private void S6出站(int plcNo, string stationNameStr, OP60_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S6_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S6_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertOp60Data(CarrierBarcode, sn, stPLC_MesData.mesData.nIsTopCoverAsmOK,
stPLC_MesData.mesData.nHaveTopCover, stPLC_MesData.mesData.fForceTopCover, "");
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S6节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a6OEEType"]).ToString(); // 节拍类型(plc写入)
string a60EEPartNo = (string)s1PLCData["a60EEPartNo"]; // 物料码
a60EEPartNo = a60EEPartNo.Replace("\0", "");
string a60EEVehicleCode = (string)s1PLCData["a60EEVehicleCode"]; // 载具SN
a60EEVehicleCode = a60EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a60EEPartNo) && string.IsNullOrEmpty(a60EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a60EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a60EEVehicleCode}][{a60EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a60EEPartNo, a60EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#region S7
private Dictionary s7PLCSignal_Old = new Dictionary();
private Dictionary s7PLCData = new Dictionary();
///
/// [S7] 锁螺丝设备
///
/// PLC编号
private void ReadStation_S7(int plcNo)
{
string stationCode = "[OP70]";
string stationName = "上盖板锁螺丝";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP70_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
string tagScrewDataset = "screwDataset";
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s7PLCSignal_Old.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
s7PLCSignal_Old.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s7PLCData.Add("a7OEEType_left", 0); // 节拍类型(plc写入)
s7PLCData.Add("a7OEEPartNo_left", ""); // 物料码(物料码还未绑定载具SN时必填)
s7PLCData.Add("a7OEEVehicleCode_left", ""); // 载具SN
s7PLCData.Add("a7OEEType_right", 0); // 节拍类型(plc写入)
s7PLCData.Add("a7OEEPartNo_right", ""); // 物料码(物料码还未绑定载具SN时必填)
s7PLCData.Add("a7OEEVehicleCode_right", ""); // 载具SN
OP70_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
AtlasScrew atlasScrewLeft = new AtlasScrew(GlobalContext.AtlasAddressLeft, GlobalContext.AtlasAddressPort,
3000, 3000, "Left");
atlasScrewLeft.Initial();
AtlasScrew atlasScrewRight = new AtlasScrew(GlobalContext.AtlasAddressRight, GlobalContext.AtlasAddressPort,
3000, 3000, "Right");
atlasScrewRight.Initial();
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt_L = stPLC_MesData.Left.iotData.machineState;
int xmDeviceStateInt_R = stPLC_MesData.Right.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt_L;
xmDeviceStateData.right = (xmDeviceStateInt_L < 0 || xmDeviceStateInt_L > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt_R;
s7PLCData["a7OEEPartNo"] =stPLC_MesData.Left.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s7PLCData["a7OEEVehicleCode"] = stPLC_MesData.Left.BarcodeSet.strCarrierBarcode; // 载具SN
s7PLCData["a7OEEType"] = stPLC_MesData.Left.iotData.BeatAction; // 节拍
s7PLCData["a7OEEVehicleCode_right"] = stPLC_MesData.Right.BarcodeSet.strCarrierBarcode; // 载具SN
s7PLCData["a7OEEType_right"] = stPLC_MesData.Right.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 左边进站
try
{
if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Left,
tagBaseName + ".Left." + tagMesCommName,
tagBaseName + ".Left." + tagBarsetName, "Left", out ProgressState,
atlasScrewLeft));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 左边进站
#region 左边出站
try
{
if (stPLC_MesData.Left.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Left,
tagBaseName + ".Left." + tagMesCommName, stationCode, stationName, "Left",
out ProgressState));
stPLC_MesData.Left.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 左边出站
#region 右边进站
try
{
if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S7进站(plcNo, stationNameStr, stPLC_MesData.Right,
tagBaseName + ".Right." + tagMesCommName,
tagBaseName + ".Right" + tagBarsetName, "Right", out ProgressState,
atlasScrewRight));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 右边进站
#region 右边出站
try
{
if (stPLC_MesData.Right.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S7出站(plcNo, stationNameStr, stPLC_MesData.Right,
tagBaseName + ".Right." + tagMesCommName, stationCode, stationName, "Right",
out ProgressState));
stPLC_MesData.Right.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 右边出站
#region 节拍接口
try
{
#region 左工位 节拍
int a70EEType_left = (int)s7PLCData["a70EEType_left"];
int a70EETypeGOld_left = (int)s7PLCSignal_Old["a70EEType_left"];
//若设备紧急复原后节拍重置
if (a70EEType_left == 1)
{
a70EETypeGOld_left = 0;
}
if (a70EEType_left != a70EETypeGOld_left)
{
stationNameStr = stationNameStr + "_Left";
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a70EETypeGOld_left == 1 && a70EEType_left != 2) || (a70EETypeGOld_left == 3 && a70EEType_left != 4) ||
(a70EETypeGOld_left == 5 && a70EEType_left != 6))
{
//写入PLC
stPLC_MesData.Left.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a70EEType_left}],未上传节拍[{a70EETypeGOld_left}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Left." + tagMesCommName,
stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
}
s7PLCSignal_Old["a70EEType_left"] = s7PLCData["a70EEType_left"];
}
#endregion 左工位 节拍
#region 右工位 节拍
int a70EEType_right = (int)s7PLCData["a70EEType_right"];
int a70EETypeGOld_right = (int)s7PLCSignal_Old["a70EEType_right"];
//若设备紧急复原后节拍重置
if (a70EEType_right == 1)
{
a70EETypeGOld_right = 0;
}
if (a70EEType_right != a70EETypeGOld_right)
{
stationNameStr = stationNameStr + "_Right";
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a70EETypeGOld_right == 1 && a70EEType_right != 2) || (a70EETypeGOld_right == 3 && a70EEType_right != 4) ||
(a70EETypeGOld_right == 5 && a70EEType_right != 6))
{
//写入PLC
stPLC_MesData.Right.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName, 1, stPLC_MesData.Left.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a70EEType_right}],未上传节拍[{a70EETypeGOld_right}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S3节拍接口(plcNo, stationNameStr, tagBaseName + ".Right." + tagMesCommName,
stPLC_MesData.Left.iotData)); // MreTasks[4].Set();
}
s7PLCSignal_Old["a70EEType_right"] = s7PLCData["a70EEType_right"];
}
#endregion 右工位 节拍
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S7] 锁螺丝设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S7进站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, string direction, out bool ProgressState, AtlasScrew atlasScrew)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string atlasSn = string.Empty;
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S7_MachineId; // 装备ID(可配置)
string StationId = string.Empty; // 工位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
if (direction == "Left")
{
StationId = GlobalContext.S7_StationId_1;
}
if (direction == "Right")
{
StationId = GlobalContext.S7_StationId_2;
}
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
atlasSn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
if (direction == "Left")
{
isCollectingFlagLeft = false; //采集螺丝数据结束
}
if (direction == "Right")
{
isCollectingFlagRight = false; //采集螺丝数据结束
}
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId, pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_" + direction + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
//开始采集螺丝数据
if (direction == "Left")
{
isCollectingFlagLeft = true;
CollectAndProcessDataLeft(atlasScrew, atlasSn, direction);
}
if (direction == "Right")
{
isCollectingFlagRight = true;
CollectAndProcessDataRight(atlasScrew, atlasSn, direction);
}
}
///
/// [S7] 锁螺丝设备 - 出站
///
private void S7出站(int plcNo, string stationNameStr, OP70_stnDataSet_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, string direction, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S7_MachineId; // 装备id(可配置)
string StationId = string.Empty; // 工位ID(可配置)
if (direction == "Left")
{
StationId = GlobalContext.S7_StationId_1;
}
if (direction == "Right")
{
StationId = GlobalContext.S7_StationId_2;
}
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
a1Result = 1;
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
//if (direction == "Right")
//{
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem , workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode
, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
//}
//if (direction == "Left")
//{
// isCollectingFlagLeft = false;//采集螺丝数据结束
//}
//if (direction == "Right")
//{
// isCollectingFlagRight = false;//采集螺丝数据结束
//}
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
if (direction == "Left")
{
string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
message = SQLHelper.InsertOp701Data(CarrierBarcode, sn, strMesHeightInfos,
strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_Left_保存加工数据失败");
}
}
if (direction == "Right")
{
string strMesHeightInfos = FloatArrayToString(stPLC_MesData.mesData.fScrewTimes);
string strScrewOrders = ShortArrayToString(stPLC_MesData.mesData.nScrewOrders);
string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
message = SQLHelper.InsertOp702Data(CarrierBarcode, sn, strMesHeightInfos,
strScrewOrders, strScrewResults, stPLC_MesData.mesData.nRemainCount);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "__Right_保存加工数据失败");
}
}
//保存螺丝数据到txt
(int, string) result = SaveScrewDataToTxt(direction, sn, stPLC_MesData.mesData.fScrewTimes,
stPLC_MesData.mesData.nScrewOrders, stPLC_MesData.mesData.nScrewResults);
if (result.Item1 != 0)
{
AddMessage(LogType.Error, $"{stationNameStr}螺丝数据保存失败 " + message.text);
}
AddMessage(LogType.Info, stationNameStr + "_" + direction + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S7节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a7OEEType"]).ToString(); // 节拍类型(plc写入)
string a7OEEPartNo = (string)s1PLCData["a7OEEPartNo"]; // 物料码
a7OEEPartNo = a7OEEPartNo.Replace("\0", "");
string a7OEEVehicleCode = (string)s1PLCData["a7OEEVehicleCode"]; // 载具SN
a7OEEVehicleCode = a7OEEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a7OEEPartNo) && string.IsNullOrEmpty(a7OEEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a7OEEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a7OEEVehicleCode}][{a7OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a7OEEPartNo, a7OEEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#region S8
private Dictionary s8PLCData = new Dictionary();
private Dictionary s8PLCSignal_Old = new Dictionary();
///
/// [S8] 3D螺丝高度检测设备
///
/// PLC编号
private void ReadStation_S8(int plcNo)
{
string stationCode = "[OP80]";
string stationName = "NG下料";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP80_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s8PLCSignal_Old.Add("a8OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s8PLCData.Add("a8OEEType", 0); // 节拍类型(plc写入)
s8PLCData.Add("a8OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s8PLCData.Add("a8OEEVehicleCode", ""); // 载具SN
OP80_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s8PLCData["a8OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s8PLCData["a8OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s8PLCData["a8OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S8进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S8出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a80EEType = (int)s9PLCData["a80EEType"];
int a80EETypeGOld = (int)s9PLCSignal_Old["a80EEType"];
//若设备紧急复原后节拍重置
if (a80EEType == 1)
{
a80EETypeGOld = 0;
}
if (a80EEType != a80EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a80EETypeGOld == 1 && a80EEType != 2) || (a80EETypeGOld == 3 && a80EEType != 4) ||
(a80EETypeGOld == 5 && a80EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a80EEType}],未上传节拍[{a80EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S8节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s8PLCSignal_Old["a80EEType"] = s8PLCData["a80EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S8] 3D螺丝高度检测设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S8进站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S8_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S8_StationId; // 工位ID(可配置)
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId, pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S8] 3D螺丝高度检测设备 - 出站接口
///
private void S8出站(int plcNo, string stationNameStr, OP80_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S8_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S8_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
string strScrewHeights = FloatArrayToString(stPLC_MesData.mesData.fScrewHeights);
string strScrewResults = ShortArrayToString(stPLC_MesData.mesData.nScrewResults);
message = SQLHelper.InsertOp80Data(CarrierBarcode, sn, strScrewHeights, strScrewResults);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S8节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a8OEEType"]).ToString(); // 节拍类型(plc写入)
string a80EEPartNo = (string)s1PLCData["a80EEPartNo"]; // 物料码
a80EEPartNo = a80EEPartNo.Replace("\0", "");
string a80EEVehicleCode = (string)s1PLCData["a80EEVehicleCode"]; // 载具SN
a80EEVehicleCode = a80EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a80EEPartNo) && string.IsNullOrEmpty(a80EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a80EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a80EEVehicleCode}][{a80EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a80EEPartNo, a80EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#region S9
private Dictionary s9PLCData = new Dictionary();
private Dictionary s9PLCSignal_Old = new Dictionary();
///
/// [S9] 下料设备
///
/// PLC编号
private void ReadStation_S9(int plcNo)
{
string stationCode = "[OP90]";
string stationName = "半成品下料";
string stationNameStr = stationCode + stationName;
string tagBaseName = "g_OP90_MES"; //标签变量名称
string tagMesCommName = "mesCommToPC"; //标签变量名称
string tagAgvCommName = "agvCommFrmPC";
string tagBarsetName = "BarcodeSet";
// 触发信号字典
//s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
s9PLCSignal_Old.Add("a9OEEType", 0); // 节拍类型(plc写入)
// PLC数据字典 赋值
s9PLCData.Add("a9OEEType", 0); // 节拍类型(plc写入)
s9PLCData.Add("a9OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
s9PLCData.Add("a9OEEVehicleCode", ""); // 载具SN
OP90_MesData_t stPLC_MesData; //PLC的MES数据
(int, string) result;
while (true)
{
try
{
if (!GlobalContext._IsCon_Funs1)
{
UpdatePLCMonitor(1, plcNo, 0);
continue;
}
if (FunsEip[plcNo].IsConnected) // 检查PLC是否已连接上
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
stopwatch1.Start();
stopwatch2.Start();
#region 一次性读取所有数据
// 一次性读取所有数据
result = FunsEip[plcNo]
.Read_SingleTag(tagBaseName, 1, out stPLC_MesData, this); //读取单个结构体数据
if (result.Item1 != 0)
{
//richTextBox1.AppendText("\n" + strRet);
}
else
{
//richTextBox1.AppendText("\n" + "读取成功");
int xmDeviceStateInt = stPLC_MesData.iotData.machineState;
xmDeviceStateData.left = (xmDeviceStateInt < 0 || xmDeviceStateInt > 7)
? XiaomiDeviceState.Unknown
: (XiaomiDeviceState)xmDeviceStateInt;
s9PLCData["a9OEEPartNo"] = stPLC_MesData.BarcodeSet.strProductBarcode; // 物料码(物料码还未绑定载具SN时必填)
s9PLCData["a9OEEVehicleCode"] = stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具SN
s9PLCData["a9OEEType"] = stPLC_MesData.iotData.BeatAction; // 节拍
}
#endregion 一次性读取所有数据
stopwatch2.Stop();
#region 进站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.InStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S9进站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, tagBaseName + "." + tagBarsetName,
out ProgressState));
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 进站
#region 出站
try
{
if (stPLC_MesData.mesCommFrmPLC.cmd == (byte)eMesCmd.OutStation)
{
lock (lockObj)
{
if (!ProgressState)
{
ProgressState = true;
Task.Run(() => S9出站(plcNo, stationNameStr, stPLC_MesData,
tagBaseName + "." + tagMesCommName, stationCode, stationName,
out ProgressState));
stPLC_MesData.mesCommFrmPLC.cmd = 0;
}
}
}
}
catch (Exception ex)
{
ProgressState = false;
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion 出站
#region 节拍接口
try
{
int a90EEType = (int)s9PLCData["a90EEType"];
int a90EETypeGOld = (int)s9PLCSignal_Old["a90EEType"];
//若设备紧急复原后节拍重置
if (a90EEType == 1)
{
a90EETypeGOld = 0;
}
if (a90EEType != a90EETypeGOld)
{
//节拍需要成双成对,有开始就要有结束,例如有1上料开始就必须有2上料结束
if ((a90EETypeGOld == 1 && a90EEType != 2) || (a90EETypeGOld == 3 && a90EEType != 4) ||
(a90EETypeGOld == 5 && a90EEType != 6))
{
//写入PLC
stPLC_MesData.iotData.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, stPLC_MesData.iotData);
AddMessage(LogType.Info,
stationNameStr +
$"_节拍接口-- 设备本次上传节拍[{a90EEType}],未上传节拍[{a90EETypeGOld}]的结束信号,请检查;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;写入用时" + stopwatch2.ElapsedMilliseconds +
"ms");
return;
}
else
{
Task.Run(() =>
S9节拍接口(plcNo, stationNameStr, tagBaseName,
stPLC_MesData.iotData)); // MreTasks[4].Set();
}
s9PLCSignal_Old["a90EEType"] = s9PLCData["a90EEType"];
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
#endregion
UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
stopwatch1.Stop();
//OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
}
else
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Info,
"PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
FunsEip[plcNo].Connect(); // 重连
}
}
catch (Exception ex)
{
UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
}
Thread.Sleep(IntervalReadPLC);
}
}
///
/// [S9] 下料设备 - 进站
///
/// PLC编号
/// 工站全称
///
///
private void S9进站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
string tagBarsetName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_进站开始");
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品SN(物料码)
string MachineId = GlobalContext.S9_MachineId; // 装备ID(可配置)
string StationId = GlobalContext.S9_StationId; // 工位ID(可配置)
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
string strCarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 产品SN(物料码)
//载具码验证产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(strCarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{strCarrierBarcode};产品码:{sn}");
// 产品SN(物料码)校验
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, MachineId, StationId, pass);
stopwatch2.Stop();
//指令执行结果 1:OK 110:失败
byte mesResultFrmWeb = (byte)(result == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_进站检测结果:FAIL");
}
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1,
str.Length - str.LastIndexOf("\\") - 1));
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
}
stopwatch1.Stop();
AddMessage(LogType.Info, stationNameStr + "_进站结束");
AddMessage(LogType.Info,
stationNameStr + "_进站;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
///
/// [S9] 下料设备 - 出站接口
///
private void S9出站(int plcNo, string stationNameStr, OP90_MesData_t stPLC_MesData, string tagMesCommName,
string stationCode, string stationName, out bool ProgressState)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
AddMessage(LogType.Info, stationNameStr + "_出站开始");
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string processItem = stationName; // 测试项目
string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string supplierCode = ""; // 供应商代码
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
string sn = (string)stPLC_MesData.BarcodeSet.strProductBarcode; // 产品条码;
string CarrierBarcode = (string)stPLC_MesData.BarcodeSet.strCarrierBarcode; // 载具条码;
string MachineId = GlobalContext.S9_MachineId; // 装备id(可配置) // ZS
string StationId = GlobalContext.S9_StationId; // ⼯位ID(可配置) // ZS
int a1Result = (int)stPLC_MesData.iotData.testStatus; // 产品结果
bool pass = a1Result == 1;
//根据载具码获取产品码
string strProductBarcode = SQLHelper.GetProductBarcodeByCarrierCode(CarrierBarcode);
if (string.IsNullOrEmpty(strProductBarcode))
{
AddMessage(LogType.Error, $"{stationNameStr}_未能查到已绑定的载具信息,无法进行载具绑定产品验证");
}
sn = strProductBarcode;
AddMessage(LogType.Info, $"载具码:{CarrierBarcode};产品码:{sn}");
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = CarrierBarcode,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品码",
Parameter_value = sn,
Parameter_unit = ""
});
string paramJson = JsonConvert.SerializeObject(stPLC_MesData.mesData);
int result1 = SwitctProcessData(stationNameStr, items, equipmentCode, processItem
, workorder_code, batch_num, mtltmrk, plcDate_YMD, supplierCode, sn, pass, CarrierBarcode, "1", MachineId, StationId, "", paramJson);
byte mesResultFrmWeb = (byte)(result1 == 1 ? 1 : 110);
if (mesResultFrmWeb == 1)
{
mesResultFrmWeb = (byte)(a1Result == 1 ? 1 : 110); //检测NG
AddMessage(LogType.Info, stationNameStr + "_出站检测结果:FAIL");
}
stopwatch2.Start();
//进站结果写入PLC
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = mesResultFrmWeb;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
AddMessage(LogType.Info, stationNameStr + "_出站结束");
//保存PLC返回MES数据到本地
ResponseMessage message = new ResponseMessage();
message = SQLHelper.InsertOp90Data(CarrierBarcode, sn, stPLC_MesData.mesData.nThrowCount,
stPLC_MesData.mesData.nRemainCount);
if (message.result == false)
{
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地失败");
}
AddMessage(LogType.Info, stationNameStr + "_保存加工数据到本地成功");
if (result1 == 1)
{
//载具码解除绑定
message = SQLHelper.DelCarrierBind(CarrierBarcode);
if (message.result == false)
{
AddMessage(LogType.Error, message.text);
}
}
}
catch (Exception ex)
{
stopwatch2.Start();
CommandFromPLC resultToPlC = new CommandFromPLC();
resultToPlC.cmd = 0;
resultToPlC.cmdParam = 0; //指令参数
resultToPlC.cmdResult = 110;
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, resultToPlC);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage(LogType.Error,
$"{stationNameStr}_上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
ProgressState = false;
}
private void S9节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a9OEEType"]).ToString(); // 节拍类型(plc写入)
string a90EEPartNo = (string)s1PLCData["a90EEPartNo"]; // 物料码
a90EEPartNo = a90EEPartNo.Replace("\0", "");
string a90EEVehicleCode = (string)s1PLCData["a90EEVehicleCode"]; // 载具SN
a90EEVehicleCode = a90EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a90EEPartNo) && string.IsNullOrEmpty(a90EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a90EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a90EEVehicleCode}][{a90EEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a90EEPartNo, a90EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion
#endregion Xiaomi
#region PLC1 张超凡
#region [S1] Tray盘上料装备(板测)
///
/// S1工位的数据- 触发信号上次的值
///
private Dictionary s1PLCSignal_Old = new Dictionary();
///
/// S1工位的数据(含触发信号)
///
private Dictionary s1PLCData = new Dictionary();
///
/// S1工位的数据- 回写点位
///
private Dictionary s1PLCWriteData = new Dictionary();
/////
///// 触发信号
/////
//private ManualResetEvent[] MreTasks;
///
/// [S1] Tray盘上料装备(板测)
///
/// PLC编号
//private void ReadStation_S1(int plcNo)
//{
// // [S1] Tray盘上料装备
// // [S2] FCT
// // [S3] 值板机
// // [S4_1] 载具下线装备 [S4_5] 载具上线装备
// // [S5] Tray盘下料装备
// string stationCode = "[S1]";
// string stationName = "Tray盘上料装备";
// string stationNameStr = stationCode + stationName;
// #region 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
// // 触发信号字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
// s1PLCSignal_Old.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
// s1PLCSignal_Old.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
// s1PLCSignal_Old.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s1PLCSignal_Old.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
// s1PLCSignal_Old.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s1PLCSignal_Old.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
// s1PLCSignal_Old.Add("a1AGVUpEnd", 0); // AGV上料完成信号 AGV上料
// s1PLCSignal_Old.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
// s1PLCSignal_Old.Add("a1AGVDownEnd", 0); // AGV下料完成信号 AGV下料
// // PLC数据字典 赋值 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
// s1PLCData.Add("a1PLC_FLAG_VehicleStates", 0); // PLC_FLAG 载具进站查询状态
// s1PLCData.Add("a1MES_FLAG_VehicleStates", 0); // MES_FLAG
// s1PLCData.Add("a1ProductSN_VehicleStates", ""); // 产品SN(载具码)
// s1PLCData.Add("a1PLC_FLAG_Check", 0); // PLC_FLAG 上料进站校验
// s1PLCData.Add("a1MES_FLAG_Check", 0); // MES_FLAG
// s1PLCData.Add("a1ProductSN_Check", ""); // 产品SN(物料码)
// s1PLCData.Add("a1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s1PLCData.Add("a1MES_FLAG", 0); // MES_FLAG
// s1PLCData.Add("a1ProductSN", ""); // 产品SN(载具SN)
// s1PLCData.Add("a1PartNo1", ""); // 物料码1(穴位1)
// s1PLCData.Add("a1PartNo2", ""); // 物料码2(穴位2)
// s1PLCData.Add("a1Result", 0); // 产品结果
// s1PLCData.Add("a1PLC_FLAG_ICT", 0); // PLC_FLAG 将SN发给ICT标机(串口)
// s1PLCData.Add("a1MES_FLAG_ICT", 0); // MES_FLAG
// s1PLCData.Add("a1ProductSN_ICT", ""); // 产品SN(载具SN)
// s1PLCData.Add("a1PartNo1_ICT", ""); // 物料码1(穴位1)
// s1PLCData.Add("a1PartNo2_ICT", ""); // 物料码2(穴位2)
// s1PLCData.Add("a1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s1PLCData.Add("a1OEEMES_FLAG", 0); // MES_FLAG
// s1PLCData.Add("a1OEEPartNo", ""); // 物料码(物料码还未绑定载具SN时必填)
// s1PLCData.Add("a1OEEVehicleCode", ""); // 载具SN
// s1PLCData.Add("a1OEEPartNum", 0); // 穴位号
// s1PLCData.Add("a1OEEType", 0); // 节拍类型(plc写入)
// s1PLCData.Add("a1AGVUpCall", 0); // AGV上料叫agv信号 AGV上料
// s1PLCData.Add("a1AGVUpStart", 0); // AGV上料开始信号
// s1PLCData.Add("a1AGVUpEnd", 0); // AGV上料完成信号
// s1PLCData.Add("a1AGVDownCall", 0); // AGV下料叫agv信号 AGV下料
// s1PLCData.Add("a1AGVDownStart", 0); // AGV下料开始信号
// s1PLCData.Add("a1AGVDownEnd", 0); // AGV下料完成信号
// #endregion 创建字典 - 赛米可以放在while中,add前查询下存不存在,存在就赋值不存在就add
// while (IsRun)
// {
// try
// {
// if (!GlobalContext._IsCon_Funs1)
// {
// UpdatePLCMonitor(1, plcNo, 0);
// continue;
// }
// if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
// {
// Stopwatch stopwatch1 = new Stopwatch();
// Stopwatch stopwatch2 = new Stopwatch();
// stopwatch1.Start();
// stopwatch2.Start();
// #region 一次性读取所有数据
// // 一次性读取所有数据
// int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
// int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
// int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
// int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 33);
// int[] datas = data1.Concat(data2).ToArray();
// datas = datas.Concat(data3).ToArray();
// datas = datas.Concat(data4).ToArray();
// s1PLCData["a1PLC_FLAG_VehicleStates"] = datas[2]; // 载具进站查询状态
// s1PLCData["a1MES_FLAG_VehicleStates"] = datas[3];
// int[] a1ProductSN_VehicleStatesData = datas.Skip(4).Take(20).ToArray();
// s1PLCData["a1ProductSN_VehicleStates"] = ModbusClient.ConvertRegistersToString(a1ProductSN_VehicleStatesData, 0, 40);
// s1PLCData["a1PLC_FLAG_Check"] = datas[76]; // 上料进站校验
// s1PLCData["a1MES_FLAG_Check"] = datas[77];
// int[] a1ProductSN_CheckData = datas.Skip(78).Take(20).ToArray();
// s1PLCData["a1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(a1ProductSN_CheckData, 0, 40);
// s1PLCData["a1PLC_FLAG"] = datas[108]; // 出站接口
// s1PLCData["a1MES_FLAG"] = datas[109];
// int[] a1ProductSNData = datas.Skip(110).Take(20).ToArray();
// s1PLCData["a1ProductSN"] = ModbusClient.ConvertRegistersToString(a1ProductSNData, 0, 40);
// int[] a1PartNo1Data = datas.Skip(130).Take(20).ToArray();
// s1PLCData["a1PartNo1"] = ModbusClient.ConvertRegistersToString(a1PartNo1Data, 0, 40);
// int[] a1PartNo2Data = datas.Skip(150).Take(20).ToArray();
// s1PLCData["a1PartNo2"] = ModbusClient.ConvertRegistersToString(a1PartNo2Data, 0, 40);
// s1PLCData["a1Result"] = datas[170];
// s1PLCData["a1PLC_FLAG_ICT"] = datas[181]; // 将SN发给ICT标机(串口)
// s1PLCData["a1MES_FLAG_ICT"] = datas[182];
// int[] a1ProductSN_ICTData = datas.Skip(183).Take(20).ToArray();
// s1PLCData["a1ProductSN_ICT"] = ModbusClient.ConvertRegistersToString(a1ProductSN_ICTData, 0, 40);
// int[] a1PartNo1_ICTData = datas.Skip(203).Take(20).ToArray();
// s1PLCData["a1PartNo1_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo1_ICTData, 0, 40);
// int[] a1PartNo2_ICTData = datas.Skip(223).Take(20).ToArray();
// s1PLCData["a1PartNo2_ICT"] = ModbusClient.ConvertRegistersToString(a1PartNo2_ICTData, 0, 40);
// s1PLCData["a1OEEPLC_FLAG"] = datas[253]; // 节拍接口
// s1PLCData["a1OEEMES_FLAG"] = datas[254];
// int[] a1OEEPartNoData = datas.Skip(255).Take(20).ToArray();
// s1PLCData["a1OEEPartNo"] = ModbusClient.ConvertRegistersToString(a1OEEPartNoData, 0, 40); // 物料码(物料码还未绑定载具SN时必填)
// int[] a1OEEVehicleCodeData = datas.Skip(275).Take(20).ToArray();
// s1PLCData["a1OEEVehicleCode"] = ModbusClient.ConvertRegistersToString(a1OEEVehicleCodeData, 0, 40); // 载具SN
// s1PLCData["a1OEEPartNum"] = datas[295]; // 穴位号
// s1PLCData["a1OEEType"] = datas[296]; // 节拍类型(plc写入)
// s1PLCData["a1AGVUpCall"] = datas[307]; // AGV上料
// s1PLCData["a1AGVUpStart"] = datas[308];
// s1PLCData["a1AGVUpEnd"] = datas[309];
// s1PLCData["a1AGVDownCall"] = datas[320]; // AGV下料
// s1PLCData["a1AGVDownStart"] = datas[321];
// s1PLCData["a1AGVDownEnd"] = datas[322];
// #endregion 一次性读取所有数据
// stopwatch2.Stop();
// #region 回写操作,写后清空flag
// PLCWriteData(Funs[plcNo], ref s1PLCData, ref s1PLCWriteData);
// #endregion 回写操作,写后清空flag
// #region 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
// try
// {
// int a1PLC_FLAG_VehicleStates = (int)s1PLCData["a1PLC_FLAG_VehicleStates"];
// int a1MES_FLAG_VehicleStates = (int)s1PLCData["a1MES_FLAG_VehicleStates"];
// int a1PLC_FLAG_VehicleStatesOld = (int)s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"];
// if (a1PLC_FLAG_VehicleStates != a1PLC_FLAG_VehicleStatesOld)
// {
// if (a1PLC_FLAG_VehicleStates == 1 && a1MES_FLAG_VehicleStates == 0) // 0->1
// Task.Run(() => S1载具进站查询状态(plcNo, stationNameStr)); // MreTasks[1].Set();
// else if (a1PLC_FLAG_VehicleStates == 0 && a1MES_FLAG_VehicleStates != 0)
// Funs[plcNo].WriteMultipleRegisters(2003, (short)0);
// s1PLCSignal_Old["a1PLC_FLAG_VehicleStates"] = s1PLCData["a1PLC_FLAG_VehicleStates"];
// }
// }
// catch (Exception ex)
// {
// // 6代表上位机报警
// Funs[plcNo].WriteMultipleRegisters(2003, (short)6);
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 载具进站查询状态(有假产品的拿下来,有产品的穴位不放产品)
// #region 上料进站校验
// try
// {
// int a1PLC_FLAG_Check = (int)s1PLCData["a1PLC_FLAG_Check"];
// int a1MES_FLAG_Check = (int)s1PLCData["a1MES_FLAG_Check"];
// int a1PLC_FLAG_CheckOld = (int)s1PLCSignal_Old["a1PLC_FLAG_Check"];
// if (a1PLC_FLAG_Check != a1PLC_FLAG_CheckOld)
// {
// if (a1PLC_FLAG_Check == 1 && a1MES_FLAG_Check == 0) // 0->1
// Task.Run(() => S1上料进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (a1PLC_FLAG_Check == 0 && a1MES_FLAG_Check != 0)
// Funs[plcNo].WriteMultipleRegisters(2077, (short)0);
// s1PLCSignal_Old["a1PLC_FLAG_Check"] = s1PLCData["a1PLC_FLAG_Check"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2077, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 上料进站校验
// #region Tray盘上料装备-出站接口
// try
// {
// int a1PLC_FLAG = (int)s1PLCData["a1PLC_FLAG"];
// int a1MES_FLAG = (int)s1PLCData["a1MES_FLAG"];
// int a1PLC_FLAGOld = (int)s1PLCSignal_Old["a1PLC_FLAG"];
// if (a1PLC_FLAG != a1PLC_FLAGOld)
// {
// if (a1PLC_FLAG == 1 && a1MES_FLAG == 0) // 0->1
// Task.Run(() => S1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
// else if (a1PLC_FLAG == 0 && a1MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2109, (short)0);
// s1PLCSignal_Old["a1PLC_FLAG"] = s1PLCData["a1PLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2109, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站数据出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion Tray盘上料装备-出站接口
// #region Tray盘上料装备-将SN发给ICT标机
// try
// {
// int a1PLC_FLAG_ICT = (int)s1PLCData["a1PLC_FLAG_ICT"];
// int a1MES_FLAG_ICT = (int)s1PLCData["a1MES_FLAG_ICT"];
// int a1PLC_FLAG_ICTOld = (int)s1PLCSignal_Old["a1PLC_FLAG_ICT"];
// if (a1PLC_FLAG_ICT != a1PLC_FLAG_ICTOld)
// {
// if (a1PLC_FLAG_ICT == 1 && a1MES_FLAG_ICT == 0) // 0->1
// Task.Run(() => S1将SN发给ICT标机(plcNo, stationNameStr)); // MreTasks[3].Set();
// else if (a1PLC_FLAG_ICT == 0 && a1MES_FLAG_ICT != 0)
// Funs[plcNo].WriteMultipleRegisters(2182, (short)0);
// s1PLCSignal_Old["a1PLC_FLAG_ICT"] = s1PLCData["a1PLC_FLAG_ICT"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2182, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion Tray盘上料装备-将SN发给ICT标机
// #region Tray盘上料装备-点检数据
// //try
// //{
// // Funs[plcNo].Read_Int_Tag("828", 1, out short[] iPLC_Flag); // PLC_Flag
// // Funs[plcNo].Read_Int_Tag("829", 1, out short[] iMES_Flag); // MES_Flag
// // bool pLC_Flag = iPLC_Flag[0] == 1 ? true : false; // PLC_Flag
// // bool mES_Flag = iMES_Flag[0] == 1 ? true : false; // MES_Flag
// // if (pLC_Flag && !mES_Flag) // 1 0
// // {
// // AddMessage_Station(stationNameStr, LogType.Info, Head + stationNameStr + BodyCheck);
// // await Task.Run(() => { DoOneCheckData_Tray盘上料装备(plcNo, stationCode, stationName); });
// // AddMessage_Station(stationNameStr, LogType.Info, stationNameStr + BodyCheck + Tail);
// // }
// // else if (!pLC_Flag && mES_Flag) // 0 1
// // {
// // // 清空写给PLC的数据
// // // MES_Flag重置为0
// // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 0 });
// // }
// //}
// //catch (Exception ex)
// //{
// // // MES_Flag 为2上位机报错
// // Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
// // string str = ex.StackTrace;
// // AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}点检运行出错!错误信息:" + ex.Message + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// //}
// #endregion Tray盘上料装备-点检数据
// #region 节拍接口
// try
// {
// int a1OEEPLC_FLAG = (int)s1PLCData["a1OEEPLC_FLAG"];
// int a1OEEMES_FLAG = (int)s1PLCData["a1OEEMES_FLAG"];
// int a1OEEPLC_FLAGOld = (int)s1PLCSignal_Old["a1OEEPLC_FLAG"];
// if (a1OEEPLC_FLAG != a1OEEPLC_FLAGOld)
// {
// if (a1OEEPLC_FLAG == 1 && a1OEEMES_FLAG == 0) // 0->1
// Task.Run(() => S1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
// else if (a1OEEPLC_FLAG == 0 && a1OEEMES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2254, (short)0); //
// s1PLCSignal_Old["a1OEEPLC_FLAG"] = s1PLCData["a1OEEPLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2254, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 节拍接口
// #region AGV上料
// // AGV上料叫AGV信号
// try
// {
// int a1AGVUpCall = (int)s1PLCData["a1AGVUpCall"];
// int a1AGVUpCallOld = (int)s1PLCSignal_Old["a1AGVUpCall"];
// if (a1AGVUpCall != a1AGVUpCallOld)
// {
// if (a1AGVUpCall == 1) // 0->1
// Task.Run(() => S1AGV上料叫agv(plcNo, stationNameStr)); // MreTasks[5].Set();
// s1PLCSignal_Old["a1AGVUpCall"] = s1PLCData["a1AGVUpCall"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2307, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// // AGV上料完成信号
// try
// {
// int a1AGVUpEnd = (int)s1PLCData["a1AGVUpEnd"];
// int a1AGVUpEndOld = (int)s1PLCSignal_Old["a1AGVUpEnd"];
// if (a1AGVUpEnd != a1AGVUpEndOld)
// {
// if (a1AGVUpEnd == 1) // 0->1
// Task.Run(() => S1AGV上料完成(plcNo, stationNameStr)); // MreTasks[6].Set();
// s1PLCSignal_Old["a1AGVUpEnd"] = s1PLCData["a1AGVUpEnd"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2309, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV上料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion AGV上料
// #region AGV下料
// // AGV下料叫agv信号
// try
// {
// int a1AGVDownCall = (int)s1PLCData["a1AGVDownCall"];
// int a1AGVDownCallOld = (int)s1PLCSignal_Old["a1AGVDownCall"];
// if (a1AGVDownCall != a1AGVDownCallOld)
// {
// if (a1AGVDownCall == 1) // 0->1
// Task.Run(() => S1AGV下料叫agv(plcNo, stationNameStr)); // MreTasks[7].Set();
// s1PLCSignal_Old["a1AGVDownCall"] = s1PLCData["a1AGVDownCall"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2320, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料叫agv信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// // AGV下料完成信号
// try
// {
// int a1AGVDownEnd = (int)s1PLCData["a1AGVDownEnd"];
// int a1AGVDownEndOld = (int)s1PLCSignal_Old["a1AGVDownEnd"];
// if (a1AGVDownEnd != a1AGVDownEndOld)
// {
// if (a1AGVDownEnd == 1) // 0->1
// Task.Run(() => S1AGV下料完成(plcNo, stationNameStr)); // MreTasks[8].Set();
// s1PLCSignal_Old["a1AGVDownEnd"] = s1PLCData["a1AGVDownEnd"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2322, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} AGV下料完成信号出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion AGV下料
// #region 心跳
// try
// {
// short states = 0;
// Funs[plcNo].WriteMultipleRegisters(2000, states);
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 心跳
// UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
// stopwatch1.Stop();
// //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
// OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
// }
// else
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
// Funs[plcNo].Connect(); // 重连
// }
// }
// catch (Exception ex)
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
// Funs[plcNo].ReConnect();
// }
// Thread.Sleep(IntervalReadPLC);
// }
//}
///
/// [S1] Tray盘上料装备(板测)- 载具进站查询状态
///
/// PLC编号
/// 工站全称
private void S1载具进站查询状态(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string sn = (string)s1PLCData["a1ProductSN_VehicleStates"]; // 产品SN(载具码)
sn = sn.Replace("\0", "");
#region 查询载具上的产品信息
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "a1MES_FLAG_VehicleStates";
writeToPLC_Flag1.Adress = 2003;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_载具进站查询状态失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
"ms");
return;
}
#endregion 查询载具上的产品信息
string[] cavitySNs = cavityData.Split('.');
string a1CavitySN1_VehicleStates = ""; // 穴位1物料SN(上位机写入)
string a1CavitySN2_VehicleStates = ""; // 穴位2物料SN(上位机写入)
short a1CavityResult1_VehicleStates = 1; // 1空;2ng;3假产品;
short a1CavityResult2_VehicleStates = 1; // 1空;2ng;3假产品;
if (cavitySNs != null && cavitySNs.Length >= 2)
{
a1CavitySN1_VehicleStates = cavitySNs[0];
a1CavitySN2_VehicleStates = cavitySNs[1];
a1CavityResult1_VehicleStates = 2;
a1CavityResult2_VehicleStates = 2;
}
if (a1CavitySN1_VehicleStates == "假产品")
a1CavityResult1_VehicleStates = 3;
if (a1CavitySN2_VehicleStates == "假产品")
a1CavityResult2_VehicleStates = 3;
short mES_Flag = 1; // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
// 回写
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2024, a1CavitySN1_VehicleStates, 20);
//Funs[plcNo].WriteMultipleRegisters(2044, a1CavitySN2_VehicleStates, 20);
//Funs[plcNo].WriteMultipleRegisters(2064, a1CavityResult1_VehicleStates);
//Funs[plcNo].WriteMultipleRegisters(2065, a1CavityResult2_VehicleStates);
//// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2003, mES_Flag);
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = mES_Flag;
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位1物料SN(上位机写入)
{
Name = "a1CavitySN1_VehicleStates",
Adress = 2024,
ValueType = PLCValueType.String,
ValueTypeStrLength = 20,
Value = a1CavitySN1_VehicleStates
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 穴位2物料SN(上位机写入)
{
Name = "a1CavitySN2_VehicleStates",
Adress = 2044,
ValueType = PLCValueType.String,
ValueTypeStrLength = 20,
Value = a1CavitySN2_VehicleStates
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
{
Name = "a1CavityResult1_VehicleStates",
Adress = 2064,
ValueType = PLCValueType.Short,
Value = a1CavityResult1_VehicleStates
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data() // 1空;2ng;3假产品;
{
Name = "a1CavityResult2_VehicleStates",
Adress = 2065,
ValueType = PLCValueType.Short,
Value = a1CavityResult2_VehicleStates
});
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 载具进站查询状态出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2003, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_VehicleStates";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_VehicleStates", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_载具进站查询状态;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- 上料进站校验
///
/// PLC编号
/// 工站全称
private void S1上料进站校验(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string sn = (string)s1PLCData["a1ProductSN_Check"]; // 产品SN(物料码)
sn = sn.Replace("\0", "");
// 保存进站数据+调用进站MES接口
List item = new List();
stopwatch2.Start();
int result = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn,
item, out string errorMsg);
stopwatch2.Stop();
short a1MES_FLAG_Check = (short)result;
//Funs[plcNo].WriteMultipleRegisters(2077, a1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2077;
writeToPLC_Flag.Value = a1MES_FLAG_Check;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2077, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2077;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_Check", writeToPLC_Flag);
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- 出站接口
///
///
///
///
private void S1出站接口(int plcNo, string stationCode, string stationName)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string stationNameStr = stationCode + stationName;
string processItem = stationName; // 测试项目
try
{
stopwatch1.Start();
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
//string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
//string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string sn = (string)s1PLCData["a1ProductSN"]; // 产品SN(载具SN码)
sn = sn.Replace("\0", "");
string partNo1 = (string)s1PLCData["a1PartNo1"]; // 物料码1(穴位1)
partNo1 = partNo1.Replace("\0", "");
string partNo2 = (string)s1PLCData["a1PartNo2"]; // 物料码2(穴位2)
partNo2 = partNo2.Replace("\0", "");
int a1Result = (int)s1PLCData["a1Result"]; // 产品结果
bool pass = a1Result == 1;
stopwatch2.Start();
// 产品1
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "1",
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品结果",
Parameter_value = a1Result == 1 ? "OK" : "NG",
Parameter_unit = ""
});
int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
, workorder_code, mtltmrk, partNo1, pass, sn, "1");
// 产品2
items = new List();
items.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "2",
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品结果",
Parameter_value = a1Result == 1 ? "OK" : "NG",
Parameter_unit = ""
});
int result2 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
, workorder_code, mtltmrk, partNo2, pass, sn, "2");
short result = 0;
List results = new List() { result1, result2 };
if (result1 == 1 && result2 == 1)
result = 1;
else if (results.Contains(3))
result = 3;
else if (results.Contains(2))
result = 2;
else if (results.Contains(4))
result = 4;
else
result = 4;
stopwatch2.Stop();
#region 存储绑定数据到 边线MES系统中
if (result == 1)
{
string data = string.Concat(partNo1, ".", partNo2);
int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
if (resultMesR != 0)
{
result = 4;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
}
}
#endregion 存储绑定数据到 边线MES系统中
// MES_Flag 为MES报错
// 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
//Funs[plcNo].WriteMultipleRegisters(2109, result); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG";
writeToPLC_Flag.Adress = 2109;
writeToPLC_Flag.Value = result;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
}
catch (Exception ex)
{
stopwatch2.Restart();
// MES_Flag 为4上位机报错
//Funs[plcNo].WriteMultipleRegisters(2109, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG";
writeToPLC_Flag.Adress = 2109;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG", writeToPLC_Flag);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_[{equipmentCode}]{processItem}上传加工报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
//// 上传点检数据_ [S1] Tray盘上料装备(板测)
//private void DoOneCheckData_Tray盘上料装备(int plcNo, string stationCode, string stationName)
//{
// string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
// string stationNameStr = stationCode + stationName;
// string processItem = stationName; // 测试项目
// try
// {
// string workorder_code = GlobalContext.WorkOrderCode; // 工单号
// string accno = "1"; // 工序编号
// Funs[plcNo].Read_Real_Tag("896", 1, out float[] float0);
// float travelLimitUp = float0[0]; // 胶圈装配行程设定上限
// List items = new List()
// {
// new OneCheckItem()
// {
// Onecheck_name="胶圈装配行程设定上限",
// Onecheck_content="上限值",
// Onecheck_result=$"正常|胶圈装配行程设定上限{travelLimitUp} mm"
// },
// };
// OneCheckData oneCheckData = new OneCheckData()
// {
// Line_code = GlobalContext.LineCode,
// Line_name = GlobalContext.LineName,
// Equipment_code = equipmentCode,
// Equipment_name = equipmentCode,
// Workorder_code = workorder_code,
// Procedure_code = accno,
// Procedure_name = processItem,
// Oneckeck_values = items,
// Onecheck_empcode = "",
// Onecheck_empname = "",
// Onecheck_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
// };
// int result1 = SaveOneCheckDataByDBAndSubmit(oneCheckData, equipmentCode, processItem);
// //int result = result1 == 1 ? 1 : (GlobalContext.IsSendCheckOneData ? 4 : 1);
// short result = result1 == 1 ? (short)1 : (short)2;
// // MES_Flag 为4MES报错
// Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { result });
// WritePLCLog(LogType.Debug, $"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
// }
// catch (Exception ex)
// {
// // MES_Flag 为2上位机报错
// Funs[plcNo].Write_DInt_Tag("829", 1, new Int32[1] { 2 });
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_[{equipmentCode}]{processItem}点检报错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
//}
// ReadStation_S1_2 节拍接口+AGV
///
/// [S1] Tray盘上料装备(板测)- 将SN发给ICT标机(串口)
///
/// PLC编号
/// 工站全称
private void S1将SN发给ICT标机(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string a1ProductSN_ICT = (string)s1PLCData["a1ProductSN_ICT"]; // 产品SN(载具SN)
a1ProductSN_ICT = a1ProductSN_ICT.Replace("\0", "");
string a1PartNo1_ICT = (string)s1PLCData["a1PartNo1_ICT"]; // 物料码1(穴位1)
a1PartNo1_ICT = a1PartNo1_ICT.Replace("\0", "");
string a1PartNo2_ICT = (string)s1PLCData["a1PartNo2_ICT"]; // 物料码2(穴位2)
a1PartNo2_ICT = a1PartNo2_ICT.Replace("\0", "");
// ZS 将SN发给ICT标机(串口)
short a1MES_FLAG_ICT = 1;
stopwatch2.Start();
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2182, a1MES_FLAG_ICT); // 上位机发送1代表OK;2代表失败;4代表上位机报警;
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
writeToPLC_Flag.Adress = 2182;
writeToPLC_Flag.Value = a1MES_FLAG_ICT;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 将SN发给ICT标机出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
stopwatch2.Start();
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2182, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1MES_FLAG_ICT";
writeToPLC_Flag.Adress = 2182;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1MES_FLAG_ICT", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_将SN发给ICT标机;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- 节拍接口
///
/// PLC编号
/// 工站全称
private void S1节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a1OEEType"]).ToString(); // 节拍类型(plc写入)
string a1OEEPartNo = (string)s1PLCData["a1OEEPartNo"]; // 物料码
a1OEEPartNo = a1OEEPartNo.Replace("\0", "");
string a1OEEVehicleCode = (string)s1PLCData["a1OEEVehicleCode"]; // 载具SN
a1OEEVehicleCode = a1OEEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a1OEEPartNo) && string.IsNullOrEmpty(a1OEEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a1OEEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a1OEEVehicleCode}][{a1OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a1OEEPartNo, a1OEEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else {
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr );
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- AGV上料叫agv
///
/// PLC编号
/// 工站全称
private void S1AGV上料叫agv(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
// ZS 呼叫AGV
short a1AGVUpCall = 2;
stopwatch2.Start();
// a1AGVUpCall
//Funs[plcNo].WriteMultipleRegisters(2307, a1AGVUpCall); // 1:plc请求上料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVUpCall";
writeToPLC_Flag.Adress = 2307;
writeToPLC_Flag.Value = a1AGVUpCall;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} AGV上料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// a1AGVUpCall
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2307, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVUpCall";
writeToPLC_Flag.Adress = 2307;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpCall", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_AGV上料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- AGV上料完成
///
/// PLC编号
/// 工站全称
private void S1AGV上料完成(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
// ZS AGV上料完成,让小车离开
short a1AGVUpEnd = 2;
stopwatch2.Start();
// a1AGVUpEnd
//Funs[plcNo].WriteMultipleRegisters(2309, a1AGVUpEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVUpEnd";
writeToPLC_Flag.Adress = 2309;
writeToPLC_Flag.Value = a1AGVUpEnd;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} AGV上料完成出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// a1AGVUpEnd
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2309, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVUpEnd";
writeToPLC_Flag.Adress = 2309;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVUpEnd", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_AGV上料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- AGV下料叫agv
///
/// PLC编号
/// 工站全称
private void S1AGV下料叫agv(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
// ZS 呼叫AGV
short a1AGVDownCall = 2;
stopwatch2.Start();
// a1AGVDownCall
//Funs[plcNo].WriteMultipleRegisters(2320, a1AGVDownCall); // 1:plc请求下料(plc请求);10秒响应清证明上位机掉线;2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVDownCall";
writeToPLC_Flag.Adress = 2320;
writeToPLC_Flag.Value = a1AGVDownCall;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} AGV下料叫agv出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// a1AGVDownCall
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2320, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVDownCall";
writeToPLC_Flag.Adress = 2320;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownCall", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_AGV下料叫agv;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S1] Tray盘上料装备(板测)- AGV下料完成
///
/// PLC编号
/// 工站全称
private void S1AGV下料完成(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
// ZS AGV上料完成,让小车离开
short a1AGVDownEnd = 2;
stopwatch2.Start();
// a1AGVDownEnd
//Funs[plcNo].WriteMultipleRegisters(2322, a1AGVDownEnd); // 1:plc通知完成结果(plc请求);2:调用成功(上位机返回);3:AGV报警(上位机返回);4:上位机报警(上位机返回);
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVDownEnd";
writeToPLC_Flag.Adress = 2322;
writeToPLC_Flag.Value = a1AGVDownEnd;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} AGV下料完成出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// a1AGVDownEnd
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2322, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "a1AGVDownEnd";
writeToPLC_Flag.Adress = 2322;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s1PLCWriteData, "a1AGVDownEnd", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_AGV下料完成;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion [S1] Tray盘上料装备(板测)
#endregion PLC1 张超凡
#region PLC2 李晓奇
#region [S2] FCT(板测)
///
/// S2工位的数据- 触发信号上次的值
///
private Dictionary s2PLCSignal_Old = new Dictionary();
///
/// S2工位的数据(含触发信号)
///
private Dictionary s2PLCData = new Dictionary();
///
/// S2工位的数据- 回写点位
///
private Dictionary s2PLCWriteData = new Dictionary();
///
/// [S2] FCT(板测)
///
/// PLC编号
//private void ReadStation_S2(int plcNo)
//{
// // [S1] Tray盘上料装备
// // [S2] FCT
// // [S3] 值板机
// // [S4_1] 载具下线装备 [S4_5] 载具上线装备
// // [S5] Tray盘下料装备
// /// 上位机心跳
// /// 获取设备报警数据与状态信息
// string stationCode = "[S2]";
// string stationName = "FCT";
// string stationNameStr = stationCode + stationName;
// #region 创建字典
// // 触发信号字典 赋值
// s2PLCSignal_Old.Add("b1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
// s2PLCSignal_Old.Add("b1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑/绑定(产品换载具)
// s2PLCSignal_Old.Add("b1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s2PLCSignal_Old.Add("b1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// // PLC数据字典 赋值
// s2PLCData.Add("b1PLC_FLAG_Check", 0); // 进站校验
// s2PLCData.Add("b1MES_FLAG_Check", 0);
// s2PLCData.Add("b1ProductSN_Check", 0);
// s2PLCData.Add("b1PLC_FLAG_Unbind", 0); // 二穴载具解绑/绑定(产品换载具)
// s2PLCData.Add("b1MES_FLAG_Unbind", 0);
// s2PLCData.Add("b1ProductSN_Unbind", "");
// s2PLCData.Add("b1ProductSN_Bind", "");
// s2PLCData.Add("b1Part1SN_Bind", "");
// s2PLCData.Add("b1Part2SN_Bind", "");
// s2PLCData.Add("b1PLC_FLAG", 0); // 出站接口
// s2PLCData.Add("b1MES_FLAG", 0);
// s2PLCData.Add("b1ProductSN", 0);
// s2PLCData.Add("b1Part1Result", 0);
// s2PLCData.Add("b1Part2Result", 0);
// s2PLCData.Add("b1OEEPLC_FLAG", 0); // 节拍接口
// s2PLCData.Add("b1OEEMES_FLAG", 0);
// s2PLCData.Add("b1OEEProductSN", "");
// s2PLCData.Add("b1OEEType", 0);
// #endregion 创建字典
// while (IsRun)
// {
// try
// {
// if (!GlobalContext._IsCon_Funs2)
// {
// UpdatePLCMonitor(1, plcNo, 0);
// continue;
// }
// if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
// {
// Stopwatch stopwatch1 = new Stopwatch();
// Stopwatch stopwatch2 = new Stopwatch();
// stopwatch1.Start();
// stopwatch2.Start();
// #region 一次性读取所有数据
// // 一次性读取所有数据
// int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100); //
// int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100); //
// int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 35); //
// int[] datas = data1.Concat(data2).ToArray();
// datas = datas.Concat(data3).ToArray();
// s2PLCData["b1PLC_FLAG_Check"] = datas[2]; // 进站校验
// s2PLCData["b1MES_FLAG_Check"] = datas[3];
// int[] b1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
// s2PLCData["b1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(b1ProductSN_CheckData, 0, 40);
// s2PLCData["b1PLC_FLAG_Unbind"] = datas[76]; // 二穴载具解绑/绑定(产品换载具)
// s2PLCData["b1MES_FLAG_Unbind"] = datas[77];
// int[] b1ProductSN_UnbindData = datas.Skip(78).Take(20).ToArray();
// s2PLCData["b1ProductSN_Unbind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_UnbindData, 0, 40);
// int[] b1ProductSN_BindData = datas.Skip(98).Take(20).ToArray();
// s2PLCData["b1ProductSN_Bind"] = ModbusClient.ConvertRegistersToString(b1ProductSN_BindData, 0, 40);
// int[] b1Part1SN_BindData = datas.Skip(118).Take(20).ToArray();
// s2PLCData["b1Part1SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part1SN_BindData, 0, 40);
// int[] b1Part2SN_BindData = datas.Skip(138).Take(20).ToArray();
// s2PLCData["b1Part2SN_Bind"] = ModbusClient.ConvertRegistersToString(b1Part2SN_BindData, 0, 40);
// s2PLCData["b1PLC_FLAG"] = datas[168]; // 出站接口
// s2PLCData["b1MES_FLAG"] = datas[169];
// int[] b1ProductSNData = datas.Skip(170).Take(20).ToArray();
// s2PLCData["b1ProductSN"] = ModbusClient.ConvertRegistersToString(b1ProductSNData, 0, 40);
// s2PLCData["b1Part1Result"] = datas[190];
// s2PLCData["b1Part2Result"] = datas[191];
// s2PLCData["b1OEEPLC_FLAG"] = datas[202]; // 节拍接口
// s2PLCData["b1OEEMES_FLAG"] = datas[203];
// int[] b1OEEProductSNData = datas.Skip(204).Take(20).ToArray();
// s2PLCData["b1OEEProductSN"] = ModbusClient.ConvertRegistersToString(b1OEEProductSNData, 0, 40);
// s2PLCData["b1OEEType"] = datas[224];
// #endregion 一次性读取所有数据
// stopwatch2.Stop();
// #region 回写操作,写后清空flag
// PLCWriteData(Funs[plcNo], ref s2PLCData, ref s2PLCWriteData);
// #endregion 回写操作,写后清空flag
// #region 进站校验
// try
// {
// int b1PLC_FLAG_Check = (int)s2PLCData["b1PLC_FLAG_Check"];
// int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
// int b1PLC_FLAG_CheckOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Check"];
// if (b1PLC_FLAG_Check != b1PLC_FLAG_CheckOld)
// {
// if (b1PLC_FLAG_Check == 1 && b1MES_FLAG_Check == 0) // 0->1
// Task.Run(() => S2进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (b1PLC_FLAG_Check == 0 && b1MES_FLAG_Check != 0)
// Funs[plcNo].WriteMultipleRegisters(2003, (short)0);
// s2PLCSignal_Old["b1PLC_FLAG_Check"] = s2PLCData["b1PLC_FLAG_Check"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2003, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 进站校验
// #region 二穴载具解绑/绑定(产品换载具)
// try
// {
// int b1PLC_FLAG_Unbind = (int)s2PLCData["b1PLC_FLAG_Unbind"];
// int b1MES_FLAG_Check = (int)s2PLCData["b1MES_FLAG_Check"];
// int b1PLC_FLAG_UnbindOld = (int)s2PLCSignal_Old["b1PLC_FLAG_Unbind"];
// if (b1PLC_FLAG_Unbind != b1PLC_FLAG_UnbindOld)
// {
// if (b1PLC_FLAG_Unbind == 1 && b1MES_FLAG_Check == 0) // 0->1
// Task.Run(() => S2二穴载具解绑绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (b1PLC_FLAG_Unbind == 0 && b1MES_FLAG_Check != 0)
// Funs[plcNo].WriteMultipleRegisters(2077, (short)0);
// s2PLCSignal_Old["b1PLC_FLAG_Unbind"] = s2PLCData["b1PLC_FLAG_Unbind"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2077, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 二穴载具解绑/绑定(产品换载具)
// #region FCT-出站接口
// try
// {
// int b1PLC_FLAG = (int)s2PLCData["b1PLC_FLAG"];
// int b1MES_FLAG = (int)s2PLCData["b1MES_FLAG"];
// int b1PLC_FLAGOld = (int)s2PLCSignal_Old["b1PLC_FLAG"];
// if (b1PLC_FLAG != b1PLC_FLAGOld)
// {
// if (b1PLC_FLAG == 1 && b1MES_FLAG == 0) // 0->1
// Task.Run(() => S2出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
// else if (b1PLC_FLAG == 0 && b1MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2169, (short)0);
// }
// }
// catch (Exception ex)
// {
// // MES_Flag 为6上位机报错
// Funs[plcNo].WriteMultipleRegisters(2169, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}上传出站数据出错!错误信息:" + ex.Message.ToString() + ";异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion FCT-出站接口
// #region 节拍接口
// try
// {
// int b1OEEPLC_FLAG = (int)s2PLCData["b1OEEPLC_FLAG"];
// int b1OEEMES_FLAG = (int)s2PLCData["b1OEEMES_FLAG"];
// int b1OEEPLC_FLAGOld = (int)s2PLCSignal_Old["b1OEEPLC_FLAG"];
// if (b1OEEPLC_FLAG != b1OEEPLC_FLAGOld)
// {
// if (b1OEEPLC_FLAG == 1 && b1OEEMES_FLAG == 0) // 0->1
// Task.Run(() => S2节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
// else if (b1OEEPLC_FLAG == 0 && b1OEEMES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2203, (short)0);
// s2PLCSignal_Old["b1OEEPLC_FLAG"] = s2PLCData["b1OEEPLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2203, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 节拍接口
// #region 心跳
// try
// {
// short states = 0;
// Funs[plcNo].WriteMultipleRegisters(2000, states);
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 心跳
// UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
// stopwatch1.Stop();
// //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
// OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
// }
// else
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
// Funs[plcNo].Connect();
// }
// }
// catch (Exception ex)
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
// Funs[plcNo].ReConnect();
// }
// Thread.Sleep(IntervalReadPLC);
// }
//}
///
/// [S2] FCT(板测)- 进站校验
///
/// PLC编号
/// 工站全称
private void S2进站校验(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string sn = (string)s2PLCData["b1ProductSN_Check"]; // 产品SN(载具码)
sn = sn.Replace("\0", "");
#region 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
// 查询物料码By载具码 并判断是不是假产品
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "b1MES_FLAG_Check";
writeToPLC_Flag1.Adress = 2003;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
return;
}
#endregion 查询载具上的产品信息(查询物料码By载具码,并判断是不是假产品)
string[] cavitySNs = cavityData.Split('.');
string b1Part1SN_Check = ""; // 穴位1物料SN(上位机写入)
string b1Part2SN_Check = ""; // 穴位2物料SN(上位机写入)
short b1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
short b1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
if (cavitySNs != null && cavitySNs.Length >= 2)
{
b1Part1SN_Check = cavitySNs[0];
b1Part2SN_Check = cavitySNs[1];
b1Part1Result_Check = 2;
b1Part2Result_Check = 2;
}
if (b1Part1SN_Check == "假产品")
b1Part1Result_Check = 3;
if (b1Part2SN_Check == "假产品")
b1Part2Result_Check = 3;
// 调用MES进站
stopwatch2.Start();
// 调用MES进站 - 产品1
List item;
int result1 = b1Part1Result_Check;
if (result1 != 3)
{
item = new List();
item.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
});
item.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "1",
});
result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
b1Part1SN_Check, item, out string errorMsg);
}
// 调用MES进站 - 产品2
int result2 = b1Part2Result_Check;
if (result2 != 3)
{
item = new List();
item.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
});
item.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "2",
});
result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
b1Part2SN_Check, item, out string errorMsg);
}
stopwatch2.Stop();
b1Part1Result_Check = result1 == 1 ? (short)1 : (short)2; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
b1Part2Result_Check = result2 == 1 ? (short)1 : (short)2; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
int result = result1;
if (result == 1)
result = result2;
short b1MES_FLAG_Check = (short)result;
//Funs[plcNo].WriteMultipleRegisters(2024, b1Part1SN_Check, 20);
//Funs[plcNo].WriteMultipleRegisters(2044, b1Part2SN_Check, 20);
//Funs[plcNo].WriteMultipleRegisters(2064, b1Part1Result_Check);
//Funs[plcNo].WriteMultipleRegisters(2065, b1Part2Result_Check);
//// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2003, b1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag
writeToPLC_Flag = new WriteToPLC_Flag(); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
writeToPLC_Flag.Name = "b1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = b1MES_FLAG_Check;
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "b1Part1SN_Check",
Adress = 2024,
ValueType = PLCValueType.String,
ValueTypeStrLength = 20,
Value = b1Part1SN_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "b1Part2SN_Check",
Adress = 2044,
ValueType = PLCValueType.String,
ValueTypeStrLength = 20,
Value = b1Part2SN_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "b1Part1Result_Check",
Adress = 2064,
ValueType = PLCValueType.Short,
Value = b1Part1Result_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "b1Part2Result_Check",
Adress = 2065,
ValueType = PLCValueType.Short,
Value = b1Part2Result_Check
});
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2003, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "b1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Check", writeToPLC_Flag);
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_上料进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S2] FCT(板测)- 二穴载具解绑绑定
///
/// PLC编号
/// 工站全称
private void S2二穴载具解绑绑定(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
// 产品换载具
string b1ProductSN_Unbind = (string)s2PLCData["b1ProductSN_Unbind"]; // 原二穴载具SN(需要解绑的)
b1ProductSN_Unbind = b1ProductSN_Unbind.Replace("\0", "");
string b1ProductSN_Bind = (string)s2PLCData["b1ProductSN_Bind"]; // 新二穴载具SN(需要绑定的)
b1ProductSN_Bind = b1ProductSN_Bind.Replace("\0", "");
string b1Part1SN_Bind = (string)s2PLCData["b1Part1SN_Bind"]; // 穴位1物料SN(plc写入)
b1Part1SN_Bind = b1Part1SN_Bind.Replace("\0", "");
string b1Part2SN_Bind = (string)s2PLCData["b1Part2SN_Bind"]; // 穴位2物料SN(plc写入)
b1Part2SN_Bind = b1Part2SN_Bind.Replace("\0", "");
stopwatch2.Start();
#region 查询载具上的产品信息
//string cavityData = string.Empty;
//int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN_Unbind, ref cavityData);
//if (string.IsNullOrEmpty(cavityData))
// cavityData = "";
//if (snResult != 0)
//{
// WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
// writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
// writeToPLC_Flag.Adress = 2077;
// writeToPLC_Flag.Value = (short)6;
// SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
// stopwatch1.Stop();
// AddMessage(LogType.Info, stationNameStr + $"_二穴载具解绑绑定失败!MES边线软件_二穴载具查询返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
// return;
//}
#endregion 查询载具上的产品信息
#region 解绑(边线MES系统)
int snResult = XiaomiMES_RouteCommunication.SNDeleteData(b1ProductSN_Unbind);
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
writeToPLC_Flag1.Adress = 2077;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_二穴载具解绑失败!MES边线软件_二穴载具[{b1ProductSN_Unbind}]解绑返回结果{snResult};总用时" +
stopwatch1.ElapsedMilliseconds + "ms");
return;
}
#endregion 解绑(边线MES系统)
#region 存储绑定数据到 边线MES系统中
string data = string.Concat(b1Part1SN_Bind, ".", b1Part2SN_Bind);
snResult = XiaomiMES_RouteCommunication.SNBindData(b1ProductSN_Bind, data);
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "b1MES_FLAG_Unbind";
writeToPLC_Flag1.Adress = 2077;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_二穴载具绑定失败!MES边线软件_二穴载具[{b1ProductSN_Bind}]绑定[{data}]返回结果{snResult};总用时" +
stopwatch1.ElapsedMilliseconds + "ms");
return;
}
#endregion 存储绑定数据到 边线MES系统中
stopwatch2.Stop();
short b1MES_FLAG_Unbind = 1;
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2077, b1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
writeToPLC_Flag.Adress = 2077;
writeToPLC_Flag.Value = b1MES_FLAG_Unbind;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 二穴载具解绑绑定出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2077, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "b1MES_FLAG_Unbind";
writeToPLC_Flag.Adress = 2077;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG_Unbind", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_二穴载具解绑绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
//// 上次采集到的SN
//private string sn_FCT = string.Empty;
///
/// [S2] FCT(板测)- 出站数据
///
private void S2出站接口(int plcNo, string stationCode, string stationName)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string stationNameStr = stationCode + stationName;
string processItem = stationName; // 测试项目
try
{
stopwatch1.Start();
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
//string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
//string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string b1ProductSN = (string)s2PLCData["b1ProductSN"]; // 产品SN(载具SN)
int b1Part1Result = (int)s2PLCData["b1Part1Result"]; // 产品1结果
int b1Part2Result = (int)s2PLCData["b1Part2Result"]; // 产品2结果
bool pass1 = b1Part1Result == 1;
bool pass2 = b1Part2Result == 1;
#region 根据 载具SN 查 物料SN
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(b1ProductSN, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "b1MES_FLAG";
writeToPLC_Flag1.Adress = 2169;
writeToPLC_Flag1.Value = (short)4;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_上传出站数据失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
"ms");
return;
}
#endregion 根据 载具SN 查 物料SN
string[] cavitySNs = cavityData.Split('.');
string b1ProductSN1 = string.Empty;
string b1ProductSN2 = string.Empty;
if (cavitySNs != null && cavitySNs.Length >= 2)
{
b1ProductSN1 = cavitySNs[0];
b1ProductSN2 = cavitySNs[1];
}
stopwatch2.Start();
// 产品1
int result1 = 0;
if (b1ProductSN1 == "假产品")
result1 = 1;
else
{
List items1 = new List();
items1.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = b1ProductSN.ToString(),
Parameter_unit = ""
});
items1.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "1",
Parameter_unit = ""
});
items1.Add(new TestItem()
{
Parameter_name = "产品结果",
Parameter_value = b1Part1Result == 1 ? "OK" : "NG",
Parameter_unit = ""
});
result1 = SwitctProcessData_old(stationNameStr, items1, equipmentCode, processItem
, workorder_code, mtltmrk, b1ProductSN1, pass1, b1ProductSN, "1");
}
// 产品2
int result2 = 0;
if (b1ProductSN1 == "假产品")
result2 = 1;
else
{
List items2 = new List();
items2.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = b1ProductSN.ToString(),
Parameter_unit = ""
});
items2.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "2",
Parameter_unit = ""
});
items2.Add(new TestItem()
{
Parameter_name = "产品结果",
Parameter_value = b1Part2Result == 1 ? "OK" : "NG",
Parameter_unit = ""
});
result2 = SwitctProcessData_old(stationNameStr, items2, equipmentCode, processItem
, workorder_code, mtltmrk, b1ProductSN2, pass2, b1ProductSN, "2");
}
short result = 0;
List results = new List() { result1, result2 };
if (result1 == 1 && result2 == 1)
result = 1;
else if (results.Contains(3))
result = 3;
else if (results.Contains(2))
result = 2;
else if (results.Contains(4))
result = 4;
else
result = 4;
stopwatch2.Stop();
//Funs[plcNo].WriteMultipleRegisters(2169, result); // 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "b1MES_FLAG";
writeToPLC_Flag.Adress = 2169;
writeToPLC_Flag.Value = result;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
}
catch (Exception ex)
{
stopwatch2.Restart();
// MES_Flag 为4上位机报错
//Funs[plcNo].WriteMultipleRegisters(2169, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "b1MES_FLAG";
writeToPLC_Flag.Adress = 2169;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s2PLCWriteData, "b1MES_FLAG", writeToPLC_Flag);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_[{equipmentCode}]{processItem}出站数据报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站数据;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S2] FCT(板测)- 节拍接口
///
/// PLC编号
/// 工站全称
private void S2节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a2OEEType"]).ToString(); // 节拍类型(plc写入)
string a2OEEPartNo = (string)s1PLCData["a2OEEPartNo"]; // 物料码
a2OEEPartNo = a2OEEPartNo.Replace("\0", "");
string a20EEVehicleCode = (string)s1PLCData["a20EEVehicleCode"]; // 载具SN
a20EEVehicleCode = a20EEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a2OEEPartNo) && string.IsNullOrEmpty(a20EEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a2OEEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a20EEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a20EEVehicleCode}][{a2OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a2OEEPartNo, a20EEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion [S2] FCT(板测)
#endregion PLC2 李晓奇
#region PLC3 刘永村
#region [S3] 值板机
///
/// S3工位的数据- 触发信号上次的值
///
private Dictionary s3PLCSignal_Old = new Dictionary();
///
/// S3工位的数据(含触发信号)
///
private Dictionary s3PLCData = new Dictionary();
///
/// S3工位的数据- 回写点位
///
private Dictionary s3PLCWriteData = new Dictionary();
///
/// [S3] 值板机
///
/// PLC编号
//private void ReadStation_S3(int plcNo)
//{
// // [S1] Tray盘上料装备
// // [S2] FCT
// // [S3] 值板机
// // [S4_1] 载具下线装备 [S4_5] 载具上线装备
// // [S5] Tray盘下料装备
// /// 上位机心跳
// /// 获取设备报警数据与状态信息
// string stationCode = "[S3]";
// string stationName = "值板机";
// string stationNameStr = stationCode + stationName;
// #region 创建字典
// // 触发信号字典 赋值
// s3PLCSignal_Old.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
// s3PLCSignal_Old.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
// s3PLCSignal_Old.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
// s3PLCSignal_Old.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s3PLCSignal_Old.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// // PLC数据字典 赋值
// s3PLCData.Add("c1PLC_FLAG_Check", 0); // PLC_FLAG 进站校验
// s3PLCData.Add("c1MES_FLAG_Check", 0); // MES_FLAG
// s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
// s3PLCData.Add("c1PLC_FLAG_Unbind", 0); // PLC_FLAG 二穴载具解绑
// s3PLCData.Add("c1MES_FLAG_Unbind", 0); // MES_FLAG
// //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
// s3PLCData.Add("c1VehicleCavity_Unbind", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
// s3PLCData.Add("c1PLC_FLAG_Bind", 0); // PLC_FLAG 二穴载具绑定
// s3PLCData.Add("c1MES_FLAG_Bind", 0); // MES_FLAG
// //s3PLCData.Add("c1ProductSN_Check", ""); // 产品SN(二穴载具SN)
// s3PLCData.Add("c1CavityReverse_Bind", 0); // 是否是两个穴位交换
// s3PLCData.Add("c1VehicleCavityFr_Bind", 0); // 来源穴位号(产品取自二穴载具哪个穴位)
// s3PLCData.Add("c1VehicleCavityTo_Bind", 0); // 目标载具穴位号(产品放到二穴载具哪个穴位)
// s3PLCData.Add("c1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s3PLCData.Add("c1MES_FLAG", 0); // MES_FLAG
// s3PLCData.Add("c1ProductSN", ""); // 产品SN(一穴载具SN)
// //s3PLCData.Add("c1ProductSN_Check", ""); // 二穴载具SN(产品取自哪个二穴载具)
// s3PLCData.Add("c1VehicleCavity", 0); // 二穴载具穴位号(产品取自二穴载具哪个穴位)
// s3PLCData.Add("c1Result", 0); // 产品结果
// s3PLCData.Add("c1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s3PLCData.Add("c1OEEMES_FLAG", 0); // MES_FLAG
// s3PLCData.Add("c1OEEProductSN", "");// 产品SN(载具SN)
// s3PLCData.Add("c1OEEType", 0); // 节拍类型(plc写入)
// #endregion 创建字典
// while (IsRun)
// {
// try
// {
// if (!GlobalContext._IsCon_Funs3)
// {
// UpdatePLCMonitor(1, plcNo, 0);
// continue;
// }
// if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
// {
// Stopwatch stopwatch1 = new Stopwatch();
// Stopwatch stopwatch2 = new Stopwatch();
// stopwatch1.Start();
// stopwatch2.Start();
// #region 一次性读取所有数据
// // 一次性读取所有数据
// ModbusClientHelper modbusClientHelper = Funs[plcNo];
// int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
// int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
// int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 36);
// int[] datas = data1.Concat(data2).ToArray();
// datas = datas.Concat(data3).ToArray();
// s3PLCData["c1PLC_FLAG_Check"] = datas[2]; // PLC_FLAG 进站校验
// s3PLCData["c1MES_FLAG_Check"] = datas[3]; // MES_FLAG
// int[] c1ProductSN_CheckData = datas.Skip(4).Take(20).ToArray();
// s3PLCData["c1ProductSN_Check"] = ModbusClient.ConvertRegistersToString(c1ProductSN_CheckData, 0, 40); // 产品SN(二穴载具SN)
// s3PLCData["c1PLC_FLAG_Unbind"] = datas[81]; // PLC_FLAG 二穴载具解绑
// s3PLCData["c1MES_FLAG_Unbind"] = datas[82]; // MES_FLAG
// s3PLCData["c1VehicleCavity_Unbind"] = datas[103]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
// s3PLCData["c1PLC_FLAG_Bind"] = datas[114]; // PLC_FLAG 二穴载具绑定
// s3PLCData["c1MES_FLAG_Bind"] = datas[115]; // MES_FLAG
// s3PLCData["c1CavityReverse_Bind"] = datas[136]; // 是否是两个穴位交换
// s3PLCData["c1VehicleCavityFr_Bind"] = datas[137]; // 来源穴位号(产品取自二穴载具哪个穴位)
// s3PLCData["c1VehicleCavityTo_Bind"] = datas[138]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
// s3PLCData["c1PLC_FLAG"] = datas[149]; // PLC_FLAG 出站接口
// s3PLCData["c1MES_FLAG"] = datas[150]; // MES_FLAG
// int[] c1ProductSNData = datas.Skip(151).Take(20).ToArray();
// s3PLCData["c1ProductSN"] = ModbusClient.ConvertRegistersToString(c1ProductSNData, 0, 40); // 产品SN(一穴载具SN)
// s3PLCData["c1VehicleCavity"] = datas[191]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
// s3PLCData["c1Result"] = datas[192]; // 产品结果
// s3PLCData["c1OEEPLC_FLAG"] = datas[203]; // PLC_FLAG 节拍接口
// s3PLCData["c1OEEMES_FLAG"] = datas[204]; // MES_FLAG
// int[] c1OEEProductSNData = datas.Skip(205).Take(20).ToArray();
// s3PLCData["c1OEEProductSN"] = ModbusClient.ConvertRegistersToString(c1OEEProductSNData, 0, 40); // 产品SN(载具SN)
// s3PLCData["c1OEEType"] = datas[225]; // 节拍类型(plc写入)
// #endregion 一次性读取所有数据
// stopwatch2.Stop();
// #region 回写操作,写后清空flag
// PLCWriteData(Funs[plcNo], ref s3PLCData, ref s3PLCWriteData);
// #endregion 回写操作,写后清空flag
// #region S3进站校验
// try
// {
// int c1PLC_FLAG_Check = (int)s3PLCData["c1PLC_FLAG_Check"];
// int c1MES_FLAG_Check = (int)s3PLCData["c1MES_FLAG_Check"];
// int c1PLC_FLAG_CheckOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Check"];
// if (c1PLC_FLAG_Check != c1PLC_FLAG_CheckOld)
// {
// if (c1PLC_FLAG_Check == 1 && c1MES_FLAG_Check == 0) // 0->1
// Task.Run(() => S3进站校验(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (c1PLC_FLAG_Check == 0 && c1MES_FLAG_Check != 0)
// Funs[plcNo].WriteMultipleRegisters(2003, (short)0);
// s3PLCSignal_Old["c1PLC_FLAG_Check"] = s3PLCData["c1PLC_FLAG_Check"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2003, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上料进站校验出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion S3进站校验
// #region S3二穴载具解绑
// try
// {
// int c1PLC_FLAG_Unbind = (int)s3PLCData["c1PLC_FLAG_Unbind"];
// int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Unbind"];
// int c1PLC_FLAG_UnbindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Unbind"];
// if (c1PLC_FLAG_Unbind != c1PLC_FLAG_UnbindOld)
// {
// if (c1PLC_FLAG_Unbind == 1 && c1MES_FLAG_Bind == 0) // 0->1
// Task.Run(() => S3二穴载具解绑(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (c1PLC_FLAG_Unbind == 0 && c1MES_FLAG_Bind != 0)
// Funs[plcNo].WriteMultipleRegisters(2082, (short)0);
// s3PLCSignal_Old["c1PLC_FLAG_Unbind"] = s3PLCData["c1PLC_FLAG_Unbind"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2083, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具解绑/绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion S3二穴载具解绑
// #region S3二穴载具绑定
// try
// {
// int c1PLC_FLAG_Bind = (int)s3PLCData["c1PLC_FLAG_Bind"];
// int c1MES_FLAG_Bind = (int)s3PLCData["c1MES_FLAG_Bind"];
// int c1PLC_FLAG_BindOld = (int)s3PLCSignal_Old["c1PLC_FLAG_Bind"];
// if (c1PLC_FLAG_Bind != c1PLC_FLAG_BindOld)
// {
// if (c1PLC_FLAG_Bind == 1 && c1MES_FLAG_Bind == 0) // 0->1
// Task.Run(() => S3二穴载具绑定(plcNo, stationNameStr)); // MreTasks[2].Set();
// else if (c1PLC_FLAG_Bind == 0 && c1MES_FLAG_Bind != 0)
// Funs[plcNo].WriteMultipleRegisters(2115, (short)0);
// s3PLCSignal_Old["c1PLC_FLAG_Bind"] = s3PLCData["c1PLC_FLAG_Bind"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2115, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion S3二穴载具绑定
// #region S3出站接口(+一穴载具绑定)
// try
// {
// int c1PLC_FLAG = (int)s3PLCData["c1PLC_FLAG"];
// int c1MES_FLAG = (int)s3PLCData["c1MES_FLAG"];
// int c1PLC_FLAGOld = (int)s3PLCSignal_Old["c1PLC_FLAG"];
// if (c1PLC_FLAG != c1PLC_FLAGOld)
// {
// if (c1PLC_FLAG == 1 && c1MES_FLAG == 0) // 0->1
// Task.Run(() => S3出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
// else if (c1PLC_FLAG == 0 && c1MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2150, (short)0);
// s3PLCSignal_Old["c1PLC_FLAG"] = s3PLCData["c1PLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2150, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion S3出站接口(+一穴载具绑定)
// #region S3节拍接口
// try
// {
// int c1OEEPLC_FLAG = (int)s3PLCData["c1OEEPLC_FLAG"];
// int c1OEEMES_FLAG = (int)s3PLCData["c1OEEMES_FLAG"];
// int c1OEEPLC_FLAGOld = (int)s3PLCSignal_Old["c1OEEPLC_FLAG"];
// if (c1OEEPLC_FLAG != c1OEEPLC_FLAGOld)
// {
// if (c1OEEPLC_FLAG == 1 && c1OEEMES_FLAG == 0) // 0->1
// Task.Run(() => S3节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
// else if (c1OEEPLC_FLAG == 0 && c1OEEMES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2204, (short)0);
// s3PLCSignal_Old["c1OEEPLC_FLAG"] = s3PLCData["c1OEEPLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2204, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion S3节拍接口
// #region 心跳
// try
// {
// short states = 0;
// Funs[plcNo].WriteMultipleRegisters(2000, states);
// }
// catch (Exception ex)
// {
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上位机心跳写入出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion 心跳
// UpdatePLCMonitor(1, plcNo, 1); // 更新PLC状态的UI // 更新PLC状态的UI
// stopwatch1.Stop();
// //if (stopwatch1.ElapsedMilliseconds > 60) // ZS 稳定后取消注释该项
// OnMessage(LogType.Info, $"循环读取PLC数据一次,总用时{stopwatch1.ElapsedMilliseconds}ms[读取用时{stopwatch2.ElapsedMilliseconds}ms]");
// }
// else
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Info, "PLC" + plcNo.ToString() + "_" + stationNameStr + "连接失败!");
// Funs[plcNo].Connect();
// }
// }
// catch (Exception ex)
// {
// UpdatePLCMonitor(1, plcNo, 0); // 更新PLC状态的UI
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr}运行出错!错误信息:" + ex.Message.ToString());
// Funs[plcNo].ReConnect();
// }
// Thread.Sleep(IntervalReadPLC);
// }
//}
///
/// [S3] 值板机- 进站校验
///
/// PLC编号
/// 工站全称
private void S3进站校验(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string sn = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(载具码)
sn = sn.Replace("\0", "");
#region 查询载具上的产品信息
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(sn, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "c1MES_FLAG_Check";
writeToPLC_Flag1.Adress = 2003;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_进站校验失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
return;
}
#endregion 查询载具上的产品信息
string[] cavitySNs = cavityData.Split('.');
string part1Str = ""; // 产品1的SN码
string part2Str = ""; // 产品2的SN码
short c1Part1Result_Check = 1; // 穴位1产品结果(上位机写入);1ok;2ng;3假产品
short c1Part2Result_Check = 1; // 穴位2产品结果(上位机写入);1ok;2ng;3假产品
if (cavitySNs != null && cavitySNs.Length >= 2)
{
part1Str = cavitySNs[0];
part2Str = cavitySNs[1];
c1Part1Result_Check = 2;
c1Part2Result_Check = 2;
}
if (part1Str == "假产品")
c1Part1Result_Check = 3;
if (part2Str == "假产品")
c1Part2Result_Check = 3;
// 调用MES进站
stopwatch2.Start();
// 调用MES进站 - 产品1
List item;
int result1 = c1Part1Result_Check;
if (result1 != 3)
{
item = new List();
item.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
});
item.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "1",
});
result1 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
part1Str, item, out string errorMsg);
}
// 调用MES进站 - 产品2
int result2 = c1Part2Result_Check;
if (result2 != 3)
{
item = new List();
item.Add(new TestItem()
{
Parameter_name = "载具码",
Parameter_value = sn,
});
item.Add(new TestItem()
{
Parameter_name = "载具穴号",
Parameter_value = "2",
});
result2 = SaveStationInData(stationNameStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk,
part2Str, item, out string errorMsg);
}
stopwatch2.Stop();
if (result1 == 2)
c1Part1Result_Check = 2;
if (result2 == 2)
c1Part2Result_Check = 2;
int result = result1;
if (result == 1)
result = result2;
short c1Part1Num_Check = 0; // 穴位1产品返修次数(上位机写入)
short c1Part2Num_Check = 0; // 穴位2产品返修次数(上位机写入)
short c1MES_FLAG_Check = (short)result;
//Funs[plcNo].WriteMultipleRegisters(2024, c1Part1Result_Check);
//Funs[plcNo].WriteMultipleRegisters(2025, c1Part2Result_Check);
//Funs[plcNo].WriteMultipleRegisters(2026, c1Part1Num_Check);
//Funs[plcNo].WriteMultipleRegisters(2027, c1Part2Num_Check);
//// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2003, c1MES_FLAG_Check); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = c1MES_FLAG_Check;
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "c1Part1Result_Check",
Adress = 2024,
ValueType = PLCValueType.Short,
Value = c1Part1Result_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "c1Part2Result_Check",
Adress = 2025,
ValueType = PLCValueType.Short,
Value = c1Part2Result_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "c1Part1Num_Check",
Adress = 2026,
ValueType = PLCValueType.Short,
Value = c1Part1Num_Check
});
writeToPLC_Flag.WriteToPLCDatas.Add(new WriteToPLC_Data()
{
Name = "c1Part2Num_Check",
Adress = 2027,
ValueType = PLCValueType.Short,
Value = c1Part2Num_Check
});
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 进站校验出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2003, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Check";
writeToPLC_Flag.Adress = 2003;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Check", writeToPLC_Flag);
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_进站校验;总用时" + stopwatch1.ElapsedMilliseconds + "ms;调用MES用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S3] 值板机 - 二穴载具解绑
///
/// PLC编号
/// 工站全称
private void S3二穴载具解绑(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
int c1VehicleCavity_Unbind = (int)s3PLCData["c1VehicleCavity_Unbind"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
// 解绑
#region 查询载具上的产品信息
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "c1MES_FLAG_Unbind";
writeToPLC_Flag1.Adress = 2082;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_二穴载具解绑失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
"ms");
return;
}
#endregion 查询载具上的产品信息
string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
#region 解绑
if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
{
// 删除
int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res1}");
}
else
{
string data_new = string.Join(".", cavitySNs);
// 删除再插入
int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{stationNameStr}]-二穴载具解绑SN{c1ProductSN_Check}---{res2},{res3}");
}
#endregion 解绑
short c1MES_FLAG_Unbind = 1;
stopwatch2.Start();
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2082, c1MES_FLAG_Unbind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
writeToPLC_Flag.Adress = 2082;
writeToPLC_Flag.Value = c1MES_FLAG_Unbind;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
stopwatch2.Stop();
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 二穴载具解绑出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2082, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Unbind";
writeToPLC_Flag.Adress = 2082;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Unbind", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_二穴载具解绑;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S3] 值板机 - 二穴载具绑定
///
/// PLC编号
/// 工站全称
private void S3二穴载具绑定(int plcNo, string stationNameStr)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
try
{
stopwatch1.Start();
string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 产品SN(二穴载具SN)
c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
int c1CavityReverse_Bind = (int)s3PLCData["c1CavityReverse_Bind"]; // 是否是两个穴位交换
int c1VehicleCavityFr_Bind = (int)s3PLCData["c1VehicleCavityFr_Bind"]; // 来源穴位号(产品取自二穴载具哪个穴位)
int c1VehicleCavityTo_Bind = (int)s3PLCData["c1VehicleCavityTo_Bind"]; // 目标载具穴位号(产品放到二穴载具哪个穴位)
stopwatch2.Start();
#region 查询载具上的产品信息
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "c1MES_FLAG_Bind";
writeToPLC_Flag1.Adress = 2115;
writeToPLC_Flag1.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_二穴载具绑定失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds +
"ms");
return;
}
#endregion 查询载具上的产品信息
// 产品换载具
string[] cavitySNs = cavityData.Split('.'); // 产品信息【产品1.产品2】
string partSn1 = "";
string partSn2 = "";
if (cavitySNs != null && cavitySNs.Length >= 2)
{
partSn1 = cavitySNs[0];
partSn2 = cavitySNs[1];
}
string data_new = string.Empty;
// 是否是两个穴位交换
if (c1CavityReverse_Bind == 1)
{
// 交换
data_new = string.Concat(partSn2, ".", partSn1);
}
else
{
// 不交换
string sn = string.Copy(cavitySNs[c1VehicleCavityFr_Bind]);
cavitySNs[c1VehicleCavityTo_Bind] = sn;
cavitySNs[c1VehicleCavityFr_Bind] = "";
data_new = string.Join(".", cavitySNs);
}
// 删除再插入
int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
int res2 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
OnMessage(LogType.Debug, $"PLC{plcNo}_[{stationNameStr}]-_二穴载具绑定SN{c1ProductSN_Check}---{res1},{res2}");
stopwatch2.Stop();
short c1MES_FLAG_Bind = 1;
// MES_Flag
//Funs[plcNo].WriteMultipleRegisters(2115, c1MES_FLAG_Bind); // 上位机发送1代表OK可以进站;2代表不需要进站;3代表本站返修料;5客户MES报警;6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
writeToPLC_Flag.Adress = 2115;
writeToPLC_Flag.Value = c1MES_FLAG_Bind;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 二穴载具绑定出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//Funs[plcNo].WriteMultipleRegisters(2115, (short)6); // 6代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG_Bind";
writeToPLC_Flag.Adress = 2115;
writeToPLC_Flag.Value = (short)6;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG_Bind", writeToPLC_Flag);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_二穴载具绑定;总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
//// 上次采集到的SN
//private string sn_值板机 = string.Empty;
///
/// [S3] 值板机 - 出站接口
///
/// PLC编号
private void S3出站接口(int plcNo, string stationCode, string stationName)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string equipmentCode = GlobalContext.LineCode + "-" + stationCode; // 设备编号
string stationNameStr = stationCode + stationName;
string processItem = stationName; // 测试项目
try
{
stopwatch1.Start();
string workorder_code = GlobalContext.WorkOrderCode; // 工单号
//string batch_num = GlobalContext.BatchNumber; // 批次号
string mtltmrk = GlobalContext.Mtltmrk; // 产品型号
//string plcDate_YMD = DateTime.Now.ToString("yyyyMMdd");
string sn = (string)s3PLCData["c1ProductSN"]; // 产品SN(一穴载具SN)
sn = sn.Replace("\0", "");
string c1ProductSN_Check = (string)s3PLCData["c1ProductSN_Check"]; // 二穴载具SN(产品取自哪个二穴载具)
c1ProductSN_Check = c1ProductSN_Check.Replace("\0", "");
int c1VehicleCavity = (int)s3PLCData["c1VehicleCavity"]; // 二穴载具穴位号(产品取自二穴载具哪个穴位)
int c1Result = (int)s3PLCData["c1Result"]; // 产品结果
bool pass = c1Result == 1;
// 查sn
#region 查询载具上的产品信息
string cavityData = string.Empty;
int snResult = XiaomiMES_RouteCommunication.SNQueryData(c1ProductSN_Check, ref cavityData);
if (string.IsNullOrEmpty(cavityData))
cavityData = "";
if (snResult != 0)
{
WriteToPLC_Flag writeToPLC_Flag1 = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag1.Name = "c1MES_FLAG";
writeToPLC_Flag1.Adress = 2150;
writeToPLC_Flag1.Value = (short)4;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag1);
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_出站接口失败!MES边线软件返回结果{snResult};总用时" + stopwatch1.ElapsedMilliseconds + "ms");
return;
}
#endregion 查询载具上的产品信息
string[] cavitySNs = cavityData.Split('.');
string productSN = "";
if (cavitySNs != null && cavitySNs.Length >= 2)
{
productSN = cavitySNs[c1VehicleCavity];
cavitySNs[c1VehicleCavity] = "";
}
stopwatch2.Start();
List items = new List();
items.Add(new TestItem()
{
Parameter_name = "二穴载具码",
Parameter_value = c1ProductSN_Check,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "二穴载具穴号",
Parameter_value = c1VehicleCavity.ToString(),
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "一穴载具码",
Parameter_value = sn,
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "一穴载具穴号",
Parameter_value = "1",
Parameter_unit = ""
});
items.Add(new TestItem()
{
Parameter_name = "产品结果",
Parameter_value = c1Result == 1 ? "OK" : "NG",
Parameter_unit = ""
});
int result1 = SwitctProcessData_old(stationNameStr, items, equipmentCode, processItem
, workorder_code, mtltmrk, productSN, pass, sn, "1");
short result = (short)result1;
stopwatch2.Stop();
#region 存储绑定数据到 边线MES系统中
if (result == 1)
{
string data = string.Concat(productSN);
int resultMesR = XiaomiMES_RouteCommunication.SNBindData(sn, data);
if (resultMesR != 0)
{
result = 4;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_[{equipmentCode}]{processItem}过站失败!MES边线程序返回:{resultMesR}");
}
}
#endregion 存储绑定数据到 边线MES系统中
#region 产品从 来源载具(二穴载具)中删除
if (cavitySNs.All(a => string.IsNullOrEmpty(a)))
{
// 删除
int res1 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res1}");
}
else
{
string data_new = string.Join(".", cavitySNs);
// 删除再插入
int res2 = XiaomiMES_RouteCommunication.SNDeleteData(c1ProductSN_Check);
int res3 = XiaomiMES_RouteCommunication.SNBindData(c1ProductSN_Check, data_new);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{equipmentCode}]{processItem}-出站解绑SN{c1ProductSN_Check}---{res2},{res3}");
}
#endregion 产品从 来源载具(二穴载具)中删除
// MES_Flag 为MES报错
// 上位机发送1代表OK;2代表上传客户MES失败;3代表上位机保存数据失败;4代表上位机报警;
//Funs[plcNo].WriteMultipleRegisters(2150, result); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG";
writeToPLC_Flag.Adress = 2150;
writeToPLC_Flag.Value = result;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
OnMessage(LogType.Debug,
$"PLC{plcNo}_[{equipmentCode}]{processItem}-Write" + (result == 1 ? "成功!" : "失败!"));
}
catch (Exception ex)
{
stopwatch2.Restart();
// MES_Flag 为4上位机报错
//Funs[plcNo].WriteMultipleRegisters(2150, (short)4); // 4代表上位机报警
WriteToPLC_Flag writeToPLC_Flag = new WriteToPLC_Flag(); // MES_Flag
writeToPLC_Flag.Name = "c1MES_FLAG";
writeToPLC_Flag.Adress = 2150;
writeToPLC_Flag.Value = (short)4;
SxPLCWriteData_Add(ref s3PLCWriteData, "c1MES_FLAG", writeToPLC_Flag);
stopwatch2.Stop();
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_[{equipmentCode}]{processItem}上传出站接口报错!错误信息:" + ex.Message.ToString() + ";异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + "_出站接口;总用时" + stopwatch1.ElapsedMilliseconds + "ms;上传接口用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
///
/// [S3] 值板机- 节拍接口
///
/// PLC编号
/// 工站全称
private void S3节拍接口(int plcNo, string stationNameStr, string tagMesCommName, IoT_DataSet_t iot_data)
{
Stopwatch stopwatch1 = new Stopwatch();
Stopwatch stopwatch2 = new Stopwatch();
string resultStr = string.Empty;
try
{
stopwatch1.Start();
string oEEType = ((int)s1PLCData["a3OEEType"]).ToString(); // 节拍类型(plc写入)
string a3OEEPartNo = (string)s1PLCData["a3OEEPartNo"]; // 物料码
a3OEEPartNo = a3OEEPartNo.Replace("\0", "");
string a3OEEVehicleCode = (string)s1PLCData["a3OEEVehicleCode"]; // 载具SN
a3OEEVehicleCode = a3OEEVehicleCode.Replace("\0", "");
bool actionBool = Enum.TryParse(oEEType, out XiaomiDeviceOEE deviceOEE);
if (!actionBool)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- 设备上传了未识别的节拍类型【{oEEType}】请检查;总用时" + stopwatch1.ElapsedMilliseconds +
"ms;写入用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
//作业开始后要有物料和载具信息
if (string.IsNullOrEmpty(a3OEEPartNo) && string.IsNullOrEmpty(a3OEEVehicleCode) &&
Convert.ToInt32(oEEType) > 2)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码与载具SN不可都为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEPartNo))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!物料码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
else if (Convert.ToInt32(oEEType) > 2 && string.IsNullOrEmpty(a3OEEVehicleCode))
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Info,
stationNameStr + $"_[{a3OEEVehicleCode}][{a3OEEPartNo}]上传节拍失败!载具码不可为空;总用时" +
stopwatch1.ElapsedMilliseconds + "ms;调用Iot用时" + stopwatch2.ElapsedMilliseconds + "ms");
return;
}
short _result = 0;
// 上传OEE
(short, string) result = SaveOEEData(plcNo, stationNameStr, deviceOEE, a3OEEPartNo, a3OEEVehicleCode);
_result = result.Item1;
resultStr = result.Item2;
if (_result == 1)
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 1; //OK
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
OnMessage(LogType.Info, $"PLC{plcNo}_{stationNameStr} 节拍{iot_data.BeatAction}上传IOT成功!上传结果:" + resultStr);
stopwatch2.Stop();
}
else
{
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + resultStr);
}
}
catch (Exception ex)
{
string str = ex.StackTrace;
AddMessage_Station(stationNameStr, LogType.Error,
$"PLC{plcNo}_{stationNameStr} 节拍接口出错!错误信息:" + ex.Message + "异常位置:" +
str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// MES_Flag
stopwatch2.Start();
//写入PLC
iot_data.beatReturn = 2; //NG
WriteResultToPlc(plcNo, stationNameStr, tagMesCommName, 1, iot_data);
stopwatch2.Stop();
}
stopwatch1.Stop();
AddMessage(LogType.Info,
stationNameStr + $"_节拍接口-- {resultStr};总用时" + stopwatch1.ElapsedMilliseconds + "ms;写入用时" +
stopwatch2.ElapsedMilliseconds + "ms");
}
#endregion [S3] 值板机
#endregion PLC3 刘永村
#region PLC4 刘果段
#region [S4] 取放桁架
///
/// S4工位的数据- 触发信号上次的值
///
private Dictionary s4PLCSignal_Old = new Dictionary();
///
/// S4工位的数据(含触发信号)
///
private Dictionary s4PLCData = new Dictionary();
///
/// S4工位的数据- 回写点位
///
private Dictionary s4PLCWriteData = new Dictionary();
///
/// [S4] 取放桁架
///
/// PLC编号
//private void ReadStation_S4(int plcNo)
//{
// // [S1] Tray盘上料装备
// // [S2] FCT
// // [S3] 值板机
// // [S4_1] 载具下线装备 [S4_5] 载具上线装备
// // [S5] Tray盘下料装备
// /// 上位机心跳
// /// 获取设备报警数据与状态信息
// string stationCode = "[S4_1]";
// string stationName = "载具下线装备";
// string stationNameStr = stationCode + stationName;
// string stationCode2 = "[S4_2]";
// string stationName2 = "桁架";
// string stationNameStr2 = stationCode2 + stationName2;
// string stationCode3 = "[S4_3]";
// string stationName3 = "提升机1";
// string stationNameStr3 = stationCode3 + stationName3;
// string stationCode4 = "[S4_4]";
// string stationName4 = "提升机2";
// string stationNameStr4 = stationCode4 + stationName4;
// string stationCode5 = "[S4_5]";
// string stationName5 = "载具上线装备";
// string stationNameStr5 = stationCode5 + stationName5;
// #region 创建字典
// // 触发信号字典 赋值
// s4PLCSignal_Old.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
// s4PLCSignal_Old.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
// s4PLCSignal_Old.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s4PLCSignal_Old.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s4PLCSignal_Old.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
// s4PLCSignal_Old.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
// s4PLCSignal_Old.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
// s4PLCSignal_Old.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
// s4PLCSignal_Old.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
// s4PLCSignal_Old.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
// s4PLCSignal_Old.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// // PLC数据字典 赋值
// // 载具下线装备(弹夹上线)
// s4PLCData.Add("d1BulletclipScanCode", 0); // 扫码信号 弹夹扫码
// s4PLCData.Add("d1BulletclipCode", ""); // 扫到的码
// s4PLCData.Add("d1VehicleScanCode", 0); // 扫码信号 载具扫码
// s4PLCData.Add("d1VehicleCode", ""); // 扫到的码
// s4PLCData.Add("d1PLC_FLAG", 0); // PLC_FLAG 出站接口
// s4PLCData.Add("d1MES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d1ProductSN", ""); // 产品SN(弹夹码)
// s4PLCData.Add("d1VehicleCode1", ""); // 载具1码(弹夹穴位1)
// s4PLCData.Add("d1VehicleCode2", ""); // 载具2码(弹夹穴位2)
// s4PLCData.Add("d1VehicleCode3", ""); // 载具3码(弹夹穴位3)
// s4PLCData.Add("d1VehicleCode4", ""); // 载具4码(弹夹穴位4)
// s4PLCData.Add("d1VehicleCode5", ""); // 载具5码(弹夹穴位5)
// s4PLCData.Add("d1VehicleCode6", ""); // 载具6码(弹夹穴位6)
// s4PLCData.Add("d1VehicleCode7", ""); // 载具7码(弹夹穴位7)
// s4PLCData.Add("d1VehicleCode8", ""); // 载具8码(弹夹穴位8)
// s4PLCData.Add("d1VehicleCode9", ""); // 载具9码(弹夹穴位9)
// s4PLCData.Add("d1VehicleCode10", ""); // 载具10码(弹夹穴位10)
// s4PLCData.Add("d1Result", 0); // 产品结果
// s4PLCData.Add("d1OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s4PLCData.Add("d1OEEMES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d1OEEProductSN", "");// 产品SN(载具SN)
// s4PLCData.Add("d1OEEType", 0); // 节拍类型(plc写入)
// s4PLCData.Add("d2BulletclipScanCode", 0); // 扫码信号 查询标机中弹夹的状态
// s4PLCData.Add("d2BulletclipStates", 0); // 弹夹状态
// s4PLCData.Add("d2BulletclipCode", ""); // 扫到的码
// // 真空标机(提升机)
// s4PLCData.Add("d3PLC_FLAG", 0); // PLC_FLAG 真空标机1出站接口
// s4PLCData.Add("d3MES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d3Type", 0); // 进站还是出站
// s4PLCData.Add("d3ProductSN", ""); // 产品SN(弹夹码)
// s4PLCData.Add("d3Result", 0); // 产品结果
// s4PLCData.Add("d4PLC_FLAG", 0); // PLC_FLAG 真空标机2出站接口
// s4PLCData.Add("d4MES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d4Type", 0); // 进站还是出站
// s4PLCData.Add("d4ProductSN", ""); // 产品SN(弹夹码)
// s4PLCData.Add("d4Result", 0); // 产品结果
// // 载具上线装备(弹夹下线)
// s4PLCData.Add("d5BulletclipScanCode", 0); // 扫码信号 弹夹扫码
// s4PLCData.Add("d5BulletclipCode", ""); // 扫到的码
// s4PLCData.Add("d5VehicleScanCode", 0); // 扫码信号 载具扫码
// s4PLCData.Add("d5VehicleCode", ""); // 扫到的码
// s4PLCData.Add("d5PLC_FLAG", 0); // PLC_FLAG 出站接口
// s4PLCData.Add("d5MES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d5ProductSN", ""); // 产品SN(弹夹码)
// s4PLCData.Add("d5VehicleCode1", ""); // 载具1码(弹夹穴位1)
// s4PLCData.Add("d5VehicleCode2", ""); // 载具2码(弹夹穴位2)
// s4PLCData.Add("d5VehicleCode3", ""); // 载具3码(弹夹穴位3)
// s4PLCData.Add("d5VehicleCode4", ""); // 载具4码(弹夹穴位4)
// s4PLCData.Add("d5VehicleCode5", ""); // 载具5码(弹夹穴位5)
// s4PLCData.Add("d5VehicleCode6", ""); // 载具6码(弹夹穴位6)
// s4PLCData.Add("d5VehicleCode7", ""); // 载具7码(弹夹穴位7)
// s4PLCData.Add("d5VehicleCode8", ""); // 载具8码(弹夹穴位8)
// s4PLCData.Add("d5VehicleCode9", ""); // 载具9码(弹夹穴位9)
// s4PLCData.Add("d5VehicleCode10", ""); // 载具10码(弹夹穴位10)
// s4PLCData.Add("d5Result", 0); // 产品结果
// s4PLCData.Add("d5OEEPLC_FLAG", 0); // PLC_FLAG 节拍接口
// s4PLCData.Add("d5OEEMES_FLAG", 0); // MES_FLAG
// s4PLCData.Add("d5OEEProductSN", "");// 产品SN(载具SN)
// s4PLCData.Add("d5OEEType", 0); // 节拍类型(plc写入)
// #endregion 创建字典
// while (IsRun)
// {
// try
// {
// if (!GlobalContext._IsCon_Funs4)
// {
// UpdatePLCMonitor(1, plcNo, 0);
// continue;
// }
// if (Funs[plcNo].IsConnected) // 检查PLC是否已连接上
// {
// Stopwatch stopwatch1 = new Stopwatch();
// Stopwatch stopwatch2 = new Stopwatch();
// stopwatch1.Start();
// stopwatch2.Start();
// #region 一次性读取所有数据
// // 载具下线装备(弹夹上线)
// int[] data1 = Funs[plcNo].ReadHoldingRegisters(2000, 100);
// int[] data2 = Funs[plcNo].ReadHoldingRegisters(2100, 100);
// int[] data3 = Funs[plcNo].ReadHoldingRegisters(2200, 100);
// int[] data4 = Funs[plcNo].ReadHoldingRegisters(2300, 100);
// int[] data5 = Funs[plcNo].ReadHoldingRegisters(2400, 100);
// int[] data6 = Funs[plcNo].ReadHoldingRegisters(2500, 100);
// int[] data7 = Funs[plcNo].ReadHoldingRegisters(2600, 100);
// int[] data8 = Funs[plcNo].ReadHoldingRegisters(2700, 100);
// int[] data9 = Funs[plcNo].ReadHoldingRegisters(2800, 100);
// int[] data10 = Funs[plcNo].ReadHoldingRegisters(2900, 56);
// int[] datas = data1.Concat(data2).ToArray();
// datas = datas.Concat(data3).ToArray();
// datas = datas.Concat(data4).ToArray();
// datas = datas.Concat(data5).ToArray();
// datas = datas.Concat(data6).ToArray();
// datas = datas.Concat(data7).ToArray();
// datas = datas.Concat(data8).ToArray();
// datas = datas.Concat(data9).ToArray();
// datas = datas.Concat(data10).ToArray();
// // 载具下线装备(弹夹上线)
// s4PLCData["d1BulletclipScanCode"] = datas[2]; // 扫码信号 弹夹扫码
// int[] d1BulletclipCodeData = datas.Skip(3).Take(20).ToArray();
// s4PLCData["d1BulletclipCode"] = ModbusClient.ConvertRegistersToString(d1BulletclipCodeData, 0, 40);
// s4PLCData["d1VehicleScanCode"] = datas[33]; // 扫码信号 载具扫码
// int[] d1VehicleCodeData = datas.Skip(34).Take(20).ToArray();
// s4PLCData["d1VehicleCode"] = ModbusClient.ConvertRegistersToString(d1VehicleCodeData, 0, 40);
// s4PLCData["d1PLC_FLAG"] = datas[64]; // PLC_FLAG 出站接口
// s4PLCData["d1MES_FLAG"] = datas[65];
// int[] d1ProductSNData = datas.Skip(66).Take(20).ToArray();
// s4PLCData["d1ProductSN"] = ModbusClient.ConvertRegistersToString(d1ProductSNData, 0, 40); // 产品SN(物料码)
// int[] d1VehicleCode1Data = datas.Skip(86).Take(20).ToArray();
// s4PLCData["d1VehicleCode1"] = ModbusClient.ConvertRegistersToString(d1VehicleCode1Data, 0, 40);
// int[] d1VehicleCode2Data = datas.Skip(106).Take(20).ToArray();
// s4PLCData["d1VehicleCode2"] = ModbusClient.ConvertRegistersToString(d1VehicleCode2Data, 0, 40);
// int[] d1VehicleCode3Data = datas.Skip(126).Take(20).ToArray();
// s4PLCData["d1VehicleCode3"] = ModbusClient.ConvertRegistersToString(d1VehicleCode3Data, 0, 40);
// int[] d1VehicleCode4Data = datas.Skip(146).Take(20).ToArray();
// s4PLCData["d1VehicleCode4"] = ModbusClient.ConvertRegistersToString(d1VehicleCode4Data, 0, 40);
// int[] d1VehicleCode5Data = datas.Skip(166).Take(20).ToArray();
// s4PLCData["d1VehicleCode5"] = ModbusClient.ConvertRegistersToString(d1VehicleCode5Data, 0, 40);
// int[] d1VehicleCode6Data = datas.Skip(186).Take(20).ToArray();
// s4PLCData["d1VehicleCode6"] = ModbusClient.ConvertRegistersToString(d1VehicleCode6Data, 0, 40);
// int[] d1VehicleCode7Data = datas.Skip(206).Take(20).ToArray();
// s4PLCData["d1VehicleCode7"] = ModbusClient.ConvertRegistersToString(d1VehicleCode7Data, 0, 40);
// int[] d1VehicleCode8Data = datas.Skip(226).Take(20).ToArray();
// s4PLCData["d1VehicleCode8"] = ModbusClient.ConvertRegistersToString(d1VehicleCode8Data, 0, 40);
// int[] d1VehicleCode9Data = datas.Skip(246).Take(20).ToArray();
// s4PLCData["d1VehicleCode9"] = ModbusClient.ConvertRegistersToString(d1VehicleCode9Data, 0, 40);
// int[] d1VehicleCode10Data = datas.Skip(266).Take(20).ToArray();
// s4PLCData["d1VehicleCode10"] = ModbusClient.ConvertRegistersToString(d1VehicleCode10Data, 0, 40);
// int[] d1VehicleCode11Data = datas.Skip(286).Take(20).ToArray();
// s4PLCData["d1VehicleCode11"] = ModbusClient.ConvertRegistersToString(d1VehicleCode11Data, 0, 40);
// int[] d1VehicleCode12Data = datas.Skip(306).Take(20).ToArray();
// s4PLCData["d1VehicleCode12"] = ModbusClient.ConvertRegistersToString(d1VehicleCode12Data, 0, 40);
// int[] d1VehicleCode13Data = datas.Skip(326).Take(20).ToArray();
// s4PLCData["d1VehicleCode13"] = ModbusClient.ConvertRegistersToString(d1VehicleCode13Data, 0, 40);
// int[] d1VehicleCode14Data = datas.Skip(346).Take(20).ToArray();
// s4PLCData["d1VehicleCode14"] = ModbusClient.ConvertRegistersToString(d1VehicleCode14Data, 0, 40);
// int[] d1VehicleCode15Data = datas.Skip(366).Take(20).ToArray();
// s4PLCData["d1VehicleCode15"] = ModbusClient.ConvertRegistersToString(d1VehicleCode15Data, 0, 40);
// s4PLCData["d1Result"] = datas[386];
// s4PLCData["d1OEEPLC_FLAG"] = datas[397]; // PLC_FLAG 节拍接口
// s4PLCData["d1OEEMES_FLAG"] = datas[398];
// int[] d1OEEProductSNData = datas.Skip(399).Take(20).ToArray();
// s4PLCData["d1OEEProductSN"] = ModbusClient.ConvertRegistersToString(d1OEEProductSNData, 0, 40);
// s4PLCData["d1OEEType"] = datas[419];
// // 桁架(查询标机中弹夹的状态)
// s4PLCData["d2BulletclipScanCode"] = datas[430];
// s4PLCData["d2BulletclipStates"] = datas[431];
// int[] d2BulletclipCodeData = datas.Skip(432).Take(20).ToArray();
// s4PLCData["d2BulletclipCode"] = ModbusClient.ConvertRegistersToString(d2BulletclipCodeData, 0, 40);
// // 真空标机
// s4PLCData["d3PLC_FLAG"] = datas[462]; // 真空标机1 出站接口
// s4PLCData["d3MES_FLAG"] = datas[463];
// int[] d3ProductSNData = datas.Skip(464).Take(20).ToArray();
// s4PLCData["d3ProductSN"] = ModbusClient.ConvertRegistersToString(d3ProductSNData, 0, 40);
// s4PLCData["d3Result"] = datas[484];
// s4PLCData["d3Type"] = datas[485];
// s4PLCData["d4PLC_FLAG"] = datas[495]; // 真空标机2 出站接口
// s4PLCData["d4MES_FLAG"] = datas[496];
// int[] d4ProductSNData = datas.Skip(497).Take(20).ToArray();
// s4PLCData["d4ProductSN"] = ModbusClient.ConvertRegistersToString(d4ProductSNData, 0, 40);
// s4PLCData["d4Result"] = datas[517];
// s4PLCData["d4Type"] = datas[518];
// // 载具上线装备(弹夹下线)
// s4PLCData["d5BulletclipScanCode"] = datas[528]; // 扫码信号 弹夹扫码
// int[] d5BulletclipCodeData = datas.Skip(529).Take(20).ToArray();
// s4PLCData["d5BulletclipCode"] = ModbusClient.ConvertRegistersToString(d5BulletclipCodeData, 0, 40);
// s4PLCData["d5VehicleScanCode"] = datas[559]; // 扫码信号 载具扫码
// int[] d5VehicleCodeData = datas.Skip(560).Take(20).ToArray();
// s4PLCData["d5VehicleCode"] = ModbusClient.ConvertRegistersToString(d5VehicleCodeData, 0, 40);
// s4PLCData["d5PLC_FLAG"] = datas[590]; // PLC_FLAG 出站接口
// s4PLCData["d5MES_FLAG"] = datas[591];
// int[] d5ProductSNData = datas.Skip(592).Take(20).ToArray();
// s4PLCData["d5ProductSN"] = ModbusClient.ConvertRegistersToString(d5ProductSNData, 0, 40); // 产品SN(物料码)
// int[] d5VehicleCode1Data = datas.Skip(612).Take(20).ToArray();
// s4PLCData["d5VehicleCode1"] = ModbusClient.ConvertRegistersToString(d5VehicleCode1Data, 0, 40);
// int[] d5VehicleCode2Data = datas.Skip(632).Take(20).ToArray();
// s4PLCData["d5VehicleCode2"] = ModbusClient.ConvertRegistersToString(d5VehicleCode2Data, 0, 40);
// int[] d5VehicleCode3Data = datas.Skip(652).Take(20).ToArray();
// s4PLCData["d5VehicleCode3"] = ModbusClient.ConvertRegistersToString(d5VehicleCode3Data, 0, 40);
// int[] d5VehicleCode4Data = datas.Skip(672).Take(20).ToArray();
// s4PLCData["d5VehicleCode4"] = ModbusClient.ConvertRegistersToString(d5VehicleCode4Data, 0, 40);
// int[] d5VehicleCode5Data = datas.Skip(692).Take(20).ToArray();
// s4PLCData["d5VehicleCode5"] = ModbusClient.ConvertRegistersToString(d5VehicleCode5Data, 0, 40);
// int[] d5VehicleCode6Data = datas.Skip(712).Take(20).ToArray();
// s4PLCData["d5VehicleCode6"] = ModbusClient.ConvertRegistersToString(d5VehicleCode6Data, 0, 40);
// int[] d5VehicleCode7Data = datas.Skip(732).Take(20).ToArray();
// s4PLCData["d5VehicleCode7"] = ModbusClient.ConvertRegistersToString(d5VehicleCode7Data, 0, 40);
// int[] d5VehicleCode8Data = datas.Skip(752).Take(20).ToArray();
// s4PLCData["d5VehicleCode8"] = ModbusClient.ConvertRegistersToString(d5VehicleCode8Data, 0, 40);
// int[] d5VehicleCode9Data = datas.Skip(772).Take(20).ToArray();
// s4PLCData["d5VehicleCode9"] = ModbusClient.ConvertRegistersToString(d5VehicleCode9Data, 0, 40);
// int[] d5VehicleCode10Data = datas.Skip(792).Take(20).ToArray();
// s4PLCData["d5VehicleCode10"] = ModbusClient.ConvertRegistersToString(d5VehicleCode10Data, 0, 40);
// int[] d5VehicleCode11Data = datas.Skip(812).Take(20).ToArray();
// s4PLCData["d5VehicleCode11"] = ModbusClient.ConvertRegistersToString(d5VehicleCode11Data, 0, 40);
// int[] d5VehicleCode12Data = datas.Skip(832).Take(20).ToArray();
// s4PLCData["d5VehicleCode12"] = ModbusClient.ConvertRegistersToString(d5VehicleCode12Data, 0, 40);
// int[] d5VehicleCode13Data = datas.Skip(852).Take(20).ToArray();
// s4PLCData["d5VehicleCode13"] = ModbusClient.ConvertRegistersToString(d5VehicleCode13Data, 0, 40);
// int[] d5VehicleCode14Data = datas.Skip(872).Take(20).ToArray();
// s4PLCData["d5VehicleCode14"] = ModbusClient.ConvertRegistersToString(d5VehicleCode14Data, 0, 40);
// int[] d5VehicleCode15Data = datas.Skip(892).Take(20).ToArray();
// s4PLCData["d5VehicleCode15"] = ModbusClient.ConvertRegistersToString(d5VehicleCode15Data, 0, 40);
// s4PLCData["d5Result"] = datas[912];
// s4PLCData["d5OEEPLC_FLAG"] = datas[923]; // PLC_FLAG 节拍接口
// s4PLCData["d5OEEMES_FLAG"] = datas[924];
// int[] d5OEEProductSNData = datas.Skip(925).Take(20).ToArray();
// s4PLCData["d5OEEProductSN"] = ModbusClient.ConvertRegistersToString(d5OEEProductSNData, 0, 40);
// s4PLCData["d5OEEType"] = datas[945];
// #endregion 一次性读取所有数据
// stopwatch2.Stop();
// #region 回写操作,写后清空flag
// PLCWriteData(Funs[plcNo], ref s4PLCData, ref s4PLCWriteData);
// #endregion 回写操作,写后清空flag
// // N801A-S4_1 弹夹扫码
// #region N801A-S4_1 弹夹扫码
// try
// {
// int d1BulletclipScanCode = (int)s4PLCData["d1BulletclipScanCode"];
// int d1BulletclipScanCodeOld = (int)s4PLCSignal_Old["d1BulletclipScanCode"];
// if (d1BulletclipScanCode != d1BulletclipScanCodeOld)
// {
// if (d1BulletclipScanCode == 1) // 0->1
// Task.Run(() => S4_1弹夹扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
// s4PLCSignal_Old["d1BulletclipScanCode"] = s4PLCData["d1BulletclipScanCode"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2002, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_1 弹夹扫码
// // N801A-S4_1 载具扫码
// #region N801A-S4_1 载具扫码
// try
// {
// int d1VehicleScanCode = (int)s4PLCData["d1VehicleScanCode"];
// int d1VehicleScanCodeOld = (int)s4PLCSignal_Old["d1VehicleScanCode"];
// if (d1VehicleScanCode != d1VehicleScanCodeOld)
// {
// if (d1VehicleScanCode == 1) // 0->1
// Task.Run(() => S4_1载具扫码(plcNo, stationNameStr)); // MreTasks[1].Set();
// s4PLCSignal_Old["d1VehicleScanCode"] = s4PLCData["d1VehicleScanCode"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2033, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_1 载具扫码
// // N801A-S4_1 出站接口
// #region N801A-S4_1 出站接口
// try
// {
// int d1PLC_FLAG = (int)s4PLCData["d1PLC_FLAG"];
// int d1MES_FLAG = (int)s4PLCData["d1MES_FLAG"];
// int d1PLC_FLAGOld = (int)s4PLCSignal_Old["d1PLC_FLAG"];
// if (d1PLC_FLAG != d1PLC_FLAGOld)
// {
// if (d1PLC_FLAG == 1 && d1MES_FLAG == 0) // 0->1
// Task.Run(() => S4_1出站接口(plcNo, stationCode, stationName)); // MreTasks[3].Set();
// else if (d1PLC_FLAG == 0 && d1MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2065, (short)0);
// s4PLCSignal_Old["d1PLC_FLAG"] = s4PLCData["d1PLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2065, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_1 出站接口
// // N801A-S4_1 节拍接口
// #region N801A-S4_1 节拍接口
// try
// {
// int d1OEEPLC_FLAG = (int)s4PLCData["d1OEEPLC_FLAG"];
// int d1OEEMES_FLAG = (int)s4PLCData["d1OEEMES_FLAG"];
// int d1OEEPLC_FLAGOld = (int)s4PLCSignal_Old["d1OEEPLC_FLAG"];
// if (d1OEEPLC_FLAG != d1OEEPLC_FLAGOld)
// {
// if (d1OEEPLC_FLAG == 1 && d1OEEMES_FLAG == 0) // 0->1
// Task.Run(() => S4_1节拍接口(plcNo, stationNameStr)); // MreTasks[4].Set();
// else if (d1OEEPLC_FLAG == 0 && d1OEEMES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2398, (short)0);
// s4PLCSignal_Old["d1OEEPLC_FLAG"] = s4PLCData["d1OEEPLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2398, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr, LogType.Error, $"PLC{plcNo}_{stationNameStr} 上传节拍接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_1 节拍接口
// // N801A-S4_2 桁架(查询标机中弹夹的状态) 数据
// #region N801A-S4_2 桁架(查询标机中弹夹的状态)
// try
// {
// int d2BulletclipScanCode = (int)s4PLCData["d2BulletclipScanCode"];
// int d2BulletclipScanCodeOld = (int)s4PLCSignal_Old["d2BulletclipScanCode"];
// if (d2BulletclipScanCode != d2BulletclipScanCodeOld)
// {
// if (d2BulletclipScanCode == 1) // 0->1
// Task.Run(() => S4_2桁架(plcNo, stationNameStr2)); // MreTasks[1].Set();
// s4PLCSignal_Old["d2BulletclipScanCode"] = s4PLCData["d2BulletclipScanCode"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2430, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr2, LogType.Error, $"PLC{plcNo}_{stationNameStr2} 桁架出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_2 桁架(查询标机中弹夹的状态)
// // N801A-S4_3 真空标机1 数据
// #region N801A-S4_3 真空标机1
// try
// {
// int d3PLC_FLAG = (int)s4PLCData["d3PLC_FLAG"];
// int d3MES_FLAG = (int)s4PLCData["d3MES_FLAG"];
// int d3PLC_FLAGOld = (int)s4PLCSignal_Old["d3PLC_FLAG"];
// if (d3PLC_FLAG != d3PLC_FLAGOld)
// {
// if (d3PLC_FLAG == 1 && d3MES_FLAG == 0) // 0->1
// {
// int stationType = (int)s4PLCData["d3Type"];
// if (stationType == 1)
// {
// // S4_3进站接口
// Task.Run(() => S4_3进站接口(plcNo, stationNameStr3)); // MreTasks[3].Set();
// }
// else if (stationType == 2)
// {
// // S4_3出站接口
// Task.Run(() => S4_3出站接口(plcNo, stationCode3, stationName3)); // MreTasks[3].Set();
// }
// }
// else if (d3PLC_FLAG == 0 && d3MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2463, (short)0);
// s4PLCSignal_Old["d3PLC_FLAG"] = s4PLCData["d3PLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2463, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr3, LogType.Error, $"PLC{plcNo}_{stationNameStr3} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_3 真空标机1
// // N801A-S4_4 真空标机2 数据
// #region N801A-S4_4 真空标机2
// try
// {
// int d4PLC_FLAG = (int)s4PLCData["d4PLC_FLAG"];
// int d4MES_FLAG = (int)s4PLCData["d4MES_FLAG"];
// int d4PLC_FLAGOld = (int)s4PLCSignal_Old["d4PLC_FLAG"];
// if (d4PLC_FLAG != d4PLC_FLAGOld)
// {
// if (d4PLC_FLAG == 1 && d4MES_FLAG == 0) // 0->1
// {
// int stationType = (int)s4PLCData["d4Type"];
// if (stationType == 1)
// {
// // S4_4进站接口
// Task.Run(() => S4_4进站接口(plcNo, stationNameStr4)); // MreTasks[3].Set();
// }
// else if (stationType == 2)
// {
// // S4_4出站接口
// Task.Run(() => S4_4出站接口(plcNo, stationCode4, stationName4)); // MreTasks[3].Set();
// }
// }
// else if (d4PLC_FLAG == 0 && d4MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters(2496, (short)0);
// s4PLCSignal_Old["d4PLC_FLAG"] = s4PLCData["d4PLC_FLAG"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2496, (short)4); // 4代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr4, LogType.Error, $"PLC{plcNo}_{stationNameStr4} 上传标机出站接口出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_4 真空标机2
// // N801A-S4_5 弹夹扫码 数据
// #region N801A-S4_5 弹夹扫码
// try
// {
// int d5BulletclipScanCode = (int)s4PLCData["d5BulletclipScanCode"];
// int d5BulletclipScanCodeOld = (int)s4PLCSignal_Old["d5BulletclipScanCode"];
// if (d5BulletclipScanCode != d5BulletclipScanCodeOld)
// {
// if (d5BulletclipScanCode == 1) // 0->1
// Task.Run(() => S4_5弹夹扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
// s4PLCSignal_Old["d5BulletclipScanCode"] = s4PLCData["d5BulletclipScanCode"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2528, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 弹夹扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_5 弹夹扫码
// // N801A-S4_5 载具扫码 数据
// #region N801A-S4_5 载具扫码
// try
// {
// int d5VehicleScanCode = (int)s4PLCData["d5VehicleScanCode"];
// int d5VehicleScanCodeOld = (int)s4PLCSignal_Old["d5VehicleScanCode"];
// if (d5VehicleScanCode != d5VehicleScanCodeOld)
// {
// if (d5VehicleScanCode == 1) // 0->1
// Task.Run(() => S4_5载具扫码(plcNo, stationNameStr5)); // MreTasks[1].Set();
// s4PLCSignal_Old["d5VehicleScanCode"] = s4PLCData["d5VehicleScanCode"];
// }
// }
// catch (Exception ex)
// {
// Funs[plcNo].WriteMultipleRegisters(2559, (short)6); // 6代表上位机报警
// string str = ex.StackTrace;
// AddMessage_Station(stationNameStr5, LogType.Error, $"PLC{plcNo}_{stationNameStr5} 载具扫码出错!错误信息:" + ex.Message + "异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
// }
// #endregion N801A-S4_5 载具扫码
// // N801A-S4_5 出站接口(扫完所有码后立即上传) 数据
// #region N801A-S4_5 出站接口
// try
// {
// int d5PLC_FLAG = (int)s4PLCData["d5PLC_FLAG"];
// int d5MES_FLAG = (int)s4PLCData["d5MES_FLAG"];
// int d5PLC_FLAGOld = (int)s4PLCSignal_Old["d5PLC_FLAG"];
// if (d5PLC_FLAG != d5PLC_FLAGOld)
// {
// if (d5PLC_FLAG == 1 && d5MES_FLAG == 0) // 0->1
// Task.Run(() => S4_5出站接口(plcNo, stationCode5, stationName5)); // MreTasks[3].Set();
// else if (d5PLC_FLAG == 0 && d5MES_FLAG != 0)
// Funs[plcNo].WriteMultipleRegisters