增加COM设置及界面
This commit is contained in:
1 parent
16586d67aa
commit
f1e0412c01
16 files changed
+1513
-831
No files matched your search
+216
-94
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
@@ -17,6 +18,7 @@ using HslCommunication.LogNet;
|
||||
using WindowsFormsApp1.db;
|
||||
using WindowsFormsApp1.form;
|
||||
using WindowsFormsApp1.mod;
|
||||
using WindowsFormsApp1.mod.database;
|
||||
using WindowsFormsApp1.mod.server;
|
||||
using WindowsFormsApp1.server;
|
||||
using static SQLite.SQLite3;
|
||||
@@ -27,6 +29,22 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
private Thread thread_plc1;
|
||||
private Thread thread_plc2;
|
||||
private SerialPort ScanPort;
|
||||
/*
|
||||
*
|
||||
* COM1 -- COM口名称
|
||||
* 9600 波特率
|
||||
* 校验位 Parity.None == 无
|
||||
* 数据位 :8
|
||||
*
|
||||
* 测试称重
|
||||
* 解除注释
|
||||
* //port.DataReceived += new SerialDataReceivedEventHandler(port_Receive);
|
||||
* //port.Open();
|
||||
* //port.WriteLine("SI");
|
||||
*
|
||||
*/
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -41,6 +59,10 @@ namespace WindowsFormsApp1
|
||||
|
||||
Formrecover();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
线别.Text = "线别:" + Init.t_Line.linename;
|
||||
段别.Text = "段别:" + Init.t_Line.linemode;
|
||||
机台编号.Text = "机台编号:" + Init.t_Line.linecode;
|
||||
@@ -63,6 +85,7 @@ namespace WindowsFormsApp1
|
||||
continue;
|
||||
}
|
||||
|
||||
#region PLC链接及读取
|
||||
SiemensHelp siemensHelp = Plc.plchelp;
|
||||
|
||||
var openresult = siemensHelp.OpenConn();
|
||||
@@ -102,7 +125,74 @@ namespace WindowsFormsApp1
|
||||
PLC链接状态.Text = "PLC链接状态:OK";
|
||||
PLC链接状态.BackColor = SystemColors.Control;
|
||||
PLC通讯时间.Text = "PLC通讯时间:" + Plc_Time.ToString("MM-dd HH:mm:ss");
|
||||
#endregion
|
||||
|
||||
ApiClient apiClient = new ApiClient();
|
||||
otherdata otherdata = new otherdata();
|
||||
|
||||
#region 机台状态及报警
|
||||
//机台状态
|
||||
机台状态.Text = "机台状态:" + Enum.GetName(typeof(plcstatus), Init.Plcstatus);
|
||||
int oldstatus = Init.Plcstatus;
|
||||
DateTime oldPlcstatus_LastTime = Init.Plcstatus_LastTime;
|
||||
//状态+报警
|
||||
if (oldstatus != PlcData.Read_Status || (Plc_Time - oldPlcstatus_LastTime).TotalSeconds > 5)
|
||||
{
|
||||
//反馈状态
|
||||
otherdata.Plc_Status = PlcData.Read_Status;
|
||||
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Status", statusresult.Mesresult, statusresult.Requesttime);
|
||||
}
|
||||
else
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:NG";
|
||||
MES链接状态.BackColor = Color.Red;
|
||||
LogExecute.logNet.WriteError($"MES通讯异常!");
|
||||
}
|
||||
}
|
||||
//机台报警
|
||||
if (PlcData.Read_Status == (short)plcstatus.停机)
|
||||
{
|
||||
机台状态.BackColor = Color.Red;
|
||||
if (oldstatus != (short)plcstatus.停机)
|
||||
{
|
||||
//反馈报警
|
||||
List<string> list = new List<string>();
|
||||
///////////////////////////////测试用
|
||||
list.Add("M03CVSO-01");
|
||||
otherdata.Plc_ErrorMsgs = list;
|
||||
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Alarm", statusresult.Mesresult, statusresult.Requesttime);
|
||||
}
|
||||
else
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:NG";
|
||||
MES链接状态.BackColor = Color.Red;
|
||||
LogExecute.logNet.WriteError($"MES通讯异常!");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
机台状态.BackColor = SystemColors.Control;
|
||||
}
|
||||
#endregion
|
||||
#region 判断及查找流程
|
||||
if (PlcData.Read_Trigger == 0 && PlcData.Write_Status == 0)
|
||||
{
|
||||
continue;
|
||||
@@ -123,64 +213,6 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ApiClient apiClient = new ApiClient();
|
||||
otherdata otherdata = new otherdata();
|
||||
otherdata.JS_SN = "12345";
|
||||
|
||||
|
||||
|
||||
|
||||
//状态+报警
|
||||
if (Init.Plcstatus != PlcData.Read_Status || (Plc_Time - Init.Plcstatus_LastTime).TotalSeconds > 15)
|
||||
{
|
||||
//反馈状态
|
||||
var statusresult = apiClient.CallFunctionByName("Status", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Status", statusresult.Mesresult, statusresult.Requesttime);
|
||||
}
|
||||
else
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:NG";
|
||||
MES链接状态.BackColor = Color.Red;
|
||||
LogExecute.logNet.WriteError($"MES通讯异常!");
|
||||
}
|
||||
}
|
||||
if (Init.Plcstatus == (short)plcstatus.运行 && PlcData.Read_Status == (short)plcstatus.停机)
|
||||
{
|
||||
机台状态.BackColor = Color.Red;
|
||||
//反馈报警
|
||||
var statusresult = apiClient.CallFunctionByName("Alarm", PlcData, otherdata);
|
||||
if (statusresult.Success)
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:OK";
|
||||
MES链接状态.BackColor = SystemColors.Control;
|
||||
MES通讯时间.Text = "MES通讯时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
MES_MsgfORM("Alarm", statusresult.Mesresult, statusresult.Requesttime);
|
||||
}
|
||||
else
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:NG";
|
||||
MES链接状态.BackColor = Color.Red;
|
||||
LogExecute.logNet.WriteError($"MES通讯异常!");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
机台状态.BackColor = SystemColors.Control;
|
||||
}
|
||||
|
||||
Init.Plcstatus = PlcData.Read_Status;
|
||||
Init.Plcstatus_LastTime = DateTime.Now;
|
||||
机台状态.Text = Enum.GetName(typeof(plcstatus), Init.Plcstatus);
|
||||
|
||||
|
||||
|
||||
|
||||
var nowflow = Init.t_Flows.FirstOrDefault(a => a.hopestatus == PlcData.Read_Trigger);
|
||||
if (nowflow == null)
|
||||
{
|
||||
@@ -193,12 +225,21 @@ namespace WindowsFormsApp1
|
||||
LogExecute.logNet.WriteError($"未找到当前期望接口ID {nowflow.hopeinterfaceid},对应的接口!");
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
if(nowinterface.code == "SN_CheckIN")
|
||||
{
|
||||
请扫描LOT号.Enabled = true;
|
||||
ScanPort.Read();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var result = apiClient.CallFunctionByName(nowinterface.code,PlcData, otherdata);
|
||||
if (result.Success)
|
||||
{
|
||||
@@ -284,6 +325,42 @@ namespace WindowsFormsApp1
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SQLiteHelper<t_serialport> sQLiteHelper_serialport = new db.SQLiteHelper<t_serialport>();
|
||||
var serialport_result = sQLiteHelper_serialport.QueryAll();
|
||||
if (!serialport_result.Success)
|
||||
{
|
||||
MessageBox.Show("无法初始化COM口信息,无法开始处理!");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var scanport = serialport_result.Data.FirstOrDefault(a=>a.name == "Scan");
|
||||
if (scanport != null)
|
||||
{
|
||||
if (scanport.enable)
|
||||
{
|
||||
Enum.TryParse(scanport.parity, out Parity parity);
|
||||
ScanPort = new SerialPort(scanport.portName, scanport.baudRate, parity, scanport.dataBits);
|
||||
if (!ScanPort.IsOpen)
|
||||
{
|
||||
//port?.Open();
|
||||
底部注释1.Text = "扫码枪COM-Ready";
|
||||
底部注释1.Visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show("无法开启扫码枪,无法开始处理!" + ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Init.t_Plc1 = plc_result.Data;
|
||||
Init.t_Plc1.plchelp = new SiemensHelp(Init.t_Plc1.plcip, Init.t_Plc1.timeout);
|
||||
Init.t_Plc2 = plc_result2.Data;
|
||||
@@ -335,6 +412,9 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
Init.isrunning2 = false;
|
||||
|
||||
ScanPort?.Close();
|
||||
|
||||
|
||||
Thread.Sleep(500);
|
||||
开始处理.Text = "开始处理";
|
||||
开始处理.BackColor = Color.Green;
|
||||
@@ -391,6 +471,12 @@ namespace WindowsFormsApp1
|
||||
USER_Manage uSER_Manage = new USER_Manage();
|
||||
uSER_Manage.ShowDialog();
|
||||
}
|
||||
|
||||
private void 扫码枪配置ToolStripMenuItem1_Click(object sender, EventArgs e)
|
||||
{
|
||||
SerialPort_Manage serialPort_Manage = new SerialPort_Manage();
|
||||
serialPort_Manage.ShowDialog();
|
||||
}
|
||||
#endregion
|
||||
#region 页面-布局、日志等
|
||||
private void LogNet_BeforeSaveToFile(object sender, HslEventArgs e)
|
||||
@@ -439,8 +525,6 @@ namespace WindowsFormsApp1
|
||||
{
|
||||
当前时间.Text = "当前时间:" + DateTime.Now.ToString("MM-dd HH:mm:ss");
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Formrecover()
|
||||
{
|
||||
MES链接状态.Text = "MES链接状态:None";
|
||||
@@ -487,9 +571,9 @@ namespace WindowsFormsApp1
|
||||
|
||||
}
|
||||
|
||||
public void MES_MsgfORM(string name,mesresult result,DateTime dateTime)
|
||||
public void MES_MsgfORM(string name, mesresult result, DateTime dateTime)
|
||||
{
|
||||
if (事件1.Text.Contains("事件"))
|
||||
if (事件1.Text == name)
|
||||
{
|
||||
事件1.Visible = true;
|
||||
事件1结果.Visible = true;
|
||||
@@ -498,7 +582,7 @@ namespace WindowsFormsApp1
|
||||
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件1结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件2.Text.Contains("事件"))
|
||||
else if (事件2.Text == name)
|
||||
{
|
||||
事件2.Visible = true;
|
||||
事件2结果.Visible = true;
|
||||
@@ -507,7 +591,7 @@ namespace WindowsFormsApp1
|
||||
事件2时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件2结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件3.Text.Contains("事件"))
|
||||
else if (事件3.Text == name)
|
||||
{
|
||||
事件3.Visible = true;
|
||||
事件3结果.Visible = true;
|
||||
@@ -516,7 +600,7 @@ namespace WindowsFormsApp1
|
||||
事件3时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件3结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件4.Text.Contains("事件"))
|
||||
else if (事件4.Text == name)
|
||||
{
|
||||
事件4.Visible = true;
|
||||
事件4结果.Visible = true;
|
||||
@@ -527,37 +611,75 @@ namespace WindowsFormsApp1
|
||||
}
|
||||
else
|
||||
{
|
||||
事件1.Visible = true;
|
||||
事件1结果.Visible = true;
|
||||
事件1时间.Visible = true;
|
||||
事件1.Text = name;
|
||||
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件1结果.Text = result.ToString();
|
||||
if (事件1.Text.Contains("事件"))
|
||||
{
|
||||
事件1.Visible = true;
|
||||
事件1结果.Visible = true;
|
||||
事件1时间.Visible = true;
|
||||
事件1.Text = name;
|
||||
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件1结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件2.Text.Contains("事件"))
|
||||
{
|
||||
事件2.Visible = true;
|
||||
事件2结果.Visible = true;
|
||||
事件2时间.Visible = true;
|
||||
事件2.Text = name;
|
||||
事件2时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件2结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件3.Text.Contains("事件"))
|
||||
{
|
||||
事件3.Visible = true;
|
||||
事件3结果.Visible = true;
|
||||
事件3时间.Visible = true;
|
||||
事件3.Text = name;
|
||||
事件3时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件3结果.Text = result.ToString();
|
||||
}
|
||||
else if (事件4.Text.Contains("事件"))
|
||||
{
|
||||
事件4.Visible = true;
|
||||
事件4结果.Visible = true;
|
||||
事件4时间.Visible = true;
|
||||
事件4.Text = name;
|
||||
事件4时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件4结果.Text = result.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
事件1.Visible = true;
|
||||
事件1结果.Visible = true;
|
||||
事件1时间.Visible = true;
|
||||
事件1.Text = name;
|
||||
事件1时间.Text = dateTime.ToString("MM-dd HH:mm:ss");
|
||||
事件1结果.Text = result.ToString();
|
||||
|
||||
事件2.Visible = false;
|
||||
事件2结果.Visible = false;
|
||||
事件2时间.Visible = false;
|
||||
事件2.Text = "事件2";
|
||||
事件2时间.Text = "事件2时间";
|
||||
事件2结果.Text = "OK";
|
||||
事件2.Visible = false;
|
||||
事件2结果.Visible = false;
|
||||
事件2时间.Visible = false;
|
||||
事件2.Text = "事件2";
|
||||
事件2时间.Text = "事件2时间";
|
||||
事件2结果.Text = "OK";
|
||||
|
||||
事件3.Visible = false;
|
||||
事件3结果.Visible = false;
|
||||
事件3时间.Visible = false;
|
||||
事件3.Text = "事件3";
|
||||
事件3时间.Text = "事件3时间";
|
||||
事件3结果.Text = "OK";
|
||||
|
||||
事件4.Visible = false;
|
||||
事件4结果.Visible = false;
|
||||
事件4时间.Visible = false;
|
||||
事件4.Text = "事件4";
|
||||
事件4时间.Text = "事件4时间";
|
||||
事件4结果.Text = "OK";
|
||||
事件3.Visible = false;
|
||||
事件3结果.Visible = false;
|
||||
事件3时间.Visible = false;
|
||||
事件3.Text = "事件3";
|
||||
事件3时间.Text = "事件3时间";
|
||||
事件3结果.Text = "OK";
|
||||
|
||||
事件4.Visible = false;
|
||||
事件4结果.Visible = false;
|
||||
事件4时间.Visible = false;
|
||||
事件4.Text = "事件4";
|
||||
事件4时间.Text = "事件4时间";
|
||||
事件4结果.Text = "OK";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user