private void timer1_Tick_1(object sender, EventArgs e) { //MessageBox.Show(serialPort_B_Str); if ((serialPort_B_Str == "AAA") && (serialPort_A_Str == "BBB")) { timer1.Stop(); TestOut.Text = "PASS"; TestOut.BackColor = Color.Green; richTextBox_A.AppendText("串口测试OK,可以直接拔掉..." + "\n"); richTextBox_B.AppendText("串口测试OK,可以直接拔掉..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口测试OK,可以直接拔掉" + "\n"); Stop_Button(); serialPort_B_Str = string.Empty; serialPort_A_Str = string.Empty; } else { timer1.Stop(); TestOut.Text = "FAIL"; TestOut.BackColor = Color.Red; richTextBox_A.AppendText("串口测试NG,请检测串口回路..." + "\n"); richTextBox_B.AppendText("串口测试NG,请检测串口回路..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口测试NG,请检测串口回路..." + "\n"); Stop_Button(); } }
private void btnXA_Click(object sender, EventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击 <A板查询电压> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <A板查询电压> 按钮..."); sendPLC("XA"); int plcread = 0; readPLC("D100", ref plcread); double mbV = 0; if (Param.AD_Module_Type == Param.AD_Module.FX2N_4AD.ToString()) { mbV = 10.0 / 2000.0 * plcread; if (mbV >= 10) { mbV = 0; //溢出 } } if (Param.AD_Module_Type == Param.AD_Module.FX3U_4AD.ToString()) { mbV = 10.0 / 4000.0 * plcread; if (mbV >= 10) { mbV = 0; //溢出 } } TB_MB_A_Voltage.Text = mbV.ToString(); }
/// <summary> /// 从FICT PLC 接收数据 /// </summary> /// <param name="outdata"></param> /// <param name="msgflag">是否显示結果</param> private void receivePLC(ref string outdata, bool msgflag) { int iA = -1; int iB = -1; if (readPLC(FICT_PLC_Read_AddressA, ref iA) && readPLC(FICT_PLC_Read_AddressB, ref iB)) { try { outdata = Other.Chr(iA) + Other.Chr(iB); } catch (Exception) { } if (msgflag) { SubFunction.updateMessage(lstCommandList, "FICT->PC:" + outdata); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "FICT->PC:" + outdata); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "FICT->PC:" + outdata); } } else { SubFunction.updateMessage(lstCommandList, "FICT->PC:" + outdata + " Fail"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "FICT->PC:" + outdata + " Fail"); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "FICT->PC:" + outdata + " Fail"); } }
private void btnTB_Click(object sender, EventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击 <B板检测电压> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <B板检测电压> 按钮..."); sendPLC("TB"); string plcvalue = string.Empty; receivePLC(ref plcvalue, true); int plcread = 0; readPLC("D101", ref plcread); double mbV = 0; if (Param.AD_Module_Type == Param.AD_Module.FX2N_4AD.ToString()) { mbV = 10.0 / 2000.0 * plcread; if (mbV >= 10) { mbV = 0; //溢出 } } if (Param.AD_Module_Type == Param.AD_Module.FX3U_4AD.ToString()) { mbV = 10.0 / 4000.0 * plcread; if (mbV >= 10) { mbV = 0; //溢出 } } TB_MB_B_Voltage.Text = mbV.ToString(); }
private void serialPort_B_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (serialPort_B.BytesToRead == 0) { return; } Delay(50); string temp_B = string.Empty; serialPort_B_Str = serialPort_B.ReadExisting().Trim(); temp_B = serialPort_B_Str; string spString = serialPort_B_Str; serialPort_B.DiscardInBuffer();//清空buffer this.Invoke((EventHandler)(delegate { richTextBox_B.AppendText("串口调试:串口B已接收到:" + serialPort_B_Str + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:串口B已接收到:" + serialPort_B_Str); })); if (TestOut.Text == "PASS") { serialPort_B_Str = string.Empty; } }
/// <summary> /// 从Robot PLC中读取指定寄存器的值 /// </summary> /// <param name="readaddress">寄存器的地址</param> /// <param name="readdata">读出的值</param> /// <returns></returns> public bool readPLC(string readaddress, ref int readdata) { int iReturn = -1; //执行返回的值 try { iReturn = axActPLC.GetDevice(readaddress, out readdata); } catch (Exception e) { SubFunction.updateMessage(lstCommandList, "Read " + readaddress + " Fail."); SubFunction.updateMessage(lstCommandList, e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Read " + readaddress + " Fail," + e.Message); return(false); } if (iReturn == 0) { return(true); } else { SubFunction.updateMessage(lstCommandList, "Read " + readaddress + " Fail,errorcode = " + iReturn); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Read " + readaddress + " Fail,errorcode = " + iReturn); return(true); } }
private void FICTDebug_FormClosing(object sender, FormClosingEventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击窗口右上角 <关闭> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击窗口右上角 <关闭> 按钮..."); closePLC(); this.btnOPEN.Enabled = true; this.btnCLOSE.Enabled = false; this.comboPLC.Enabled = true; }
private void SerialPortDebug_FormClosing(object sender, FormClosingEventArgs e) { SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击窗口右上角 <关闭> 按钮..."); richTextBox_A.AppendText("串口调试:准备关闭串口A..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备关闭串口A...."); closeSerialPort(serialPort_A); richTextBox_B.AppendText("串口调试:准备关闭串口B..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备关闭串口B...."); closeSerialPort(serialPort_B); }
private void btnCLOSE_Click(object sender, EventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击 <关闭> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <关闭> 按钮..."); closePLC(); this.btnOPEN.Enabled = true; this.btnCLOSE.Enabled = false; this.comboPLC.Enabled = true; // timerScanFICT.Stop(); }
/// <summary> /// 连接Robot PLC /// </summary> /// <param name="portname">Robot PLC IP</param> /// <returns></returns> private bool openPLC(string portname) { try { int iReturnCode = -1;//定義返回值 int iMaxRetry = 3; //设置PLC属性 axActPLC.ActCpuType = 520; // axActPLC.ActHostAddress = portname; axActPLC.ActPortNumber = Convert.ToInt16(portname.Replace("COM", string.Empty)); //axActPLC.ActSourceStationNumber = 5556; axActPLC.ActUnitType = 0x000F; axActPLC.ActProtocolType = 0x0004; axActPLC.ActCpuType = 0x0208; Stopwatch sw = new Stopwatch(); TimeSpan ts = new TimeSpan(); for (int i = 1; i <= iMaxRetry; i++) { sw.Start(); SubFunction.updateMessage(lstCommandList, "第" + i + "次连接PLC"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "第" + i + "次连接PLC"); Application.DoEvents(); try { iReturnCode = axActPLC.Open(); } catch (Exception ex) { SubFunction.updateMessage(lstCommandList, "第" + i + "次连接PLC NG,Message:" + ex.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "第" + i + "次连接PLC NG,Message:" + ex.Message); } sw.Stop(); ts = sw.Elapsed; if (iReturnCode == 0) { SubFunction.updateMessage(lstCommandList, "第" + i + "次连接Robot PLC,Used time(s):" + ts.Seconds); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "第" + i + "次连接PLC OK,Used time(s):" + ts.Seconds); return(true); } } // sw.Stop(); SubFunction.updateMessage(lstCommandList, "第" + iMaxRetry + "次连接PLC NG,,已达到最大retry数,Errorcode=" + iReturnCode + ",Used time(s):" + ts.Seconds); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "第" + iMaxRetry + "次连接PLC NG,已达到最大retry数,Errorcode=" + iReturnCode + ",Used time(s):" + ts.Seconds); return(false); } catch (Exception exx) { SubFunction.updateMessage(lstCommandList, "连接PLC出错,Error:" + exx.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "连接PLC出错,Error:" + exx.Message); return(false); } }
/// <summary> /// 发送数据到串口 /// </summary> /// <param name="spport">串口控件</param> /// <param name="strdata">发送的数据</param> private void sendData(SerialPort spport, string strdata) { try { spport.Write(strdata); //MessageBox.Show("发送成功"); } catch (Exception e) { //SubFunction.updateMessage(lstStatusCommand, "Send " + spport.PortName + " " + strdata + "fail"); //SubFunction.updateMessage(lstStatusCommand, e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Send " + spport.PortName + " " + strdata + "fail," + e.Message); } }
private void Stop_Button() { this.CB_SerialPort_A.Enabled = true; this.CB_SerialPort_B.Enabled = true; this.Btn_Stop.Enabled = false; this.Btn_Test.Enabled = true; this.Btn_Refresh.Enabled = true; richTextBox_A.AppendText("串口调试:准备关闭串口A..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备关闭串口A...."); closeSerialPort(serialPort_A); richTextBox_B.AppendText("串口调试:准备关闭串口B..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备关闭串口B...."); closeSerialPort(serialPort_B); }
private void btnOPEN_Click(object sender, EventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击 <开始> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <开始> 按钮......"); if (!openPLC(Param.PLC)) { return; } this.btnCLOSE.Enabled = true; this.comboPLC.Enabled = false; this.btnOPEN.Enabled = false; this.btnFresh.Enabled = false; // timerScanFICT.Start(); }
/// <summary> /// 发送数据到串口 /// </summary> /// <param name="spport">串口控件</param> /// <param name="strdata">发送的数据</param> private void sendData(SerialPort spport, string strdata) { try { spport.Write(strdata); SubFunction.updateMessage(lstCommandList, "机台调试:向 <" + spport.PortName + "> 发送 '" + strdata + "' 成功..."); //Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:向 <" + spport.PortName + "> 发送 '" + strdata + "' 成功...\r\n"); //Message:" + e.Message + "\r\n"); } catch (Exception e) { SubFunction.updateMessage(lstCommandList, "机台调试:向 <" + spport.PortName + "> 发送 '" + strdata + "' 失败..."); SubFunction.updateMessage(lstCommandList, e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:向 <" + spport.PortName + "> 发送 ' " + strdata + "' 失败...," + e.Message); } }
/// <summary> /// 断开Robot PLC /// </summary> /// <returns></returns> private bool closePLC() { try { axActPLC.Close(); SubFunction.updateMessage(lstCommandList, "clsoe PLC"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "close PLC"); } catch (Exception e) { SubFunction.updateMessage(lstCommandList, "clsoe PLC error," + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "close PLC," + e.Message); return(false); } return(true); }
/// <summary> /// 向FICT PLC 发送命令 /// </summary> /// <param name="commandStr">发送的命令</param> private void sendPLC(string commandStr) { string sA = commandStr.Substring(0, 1); string sB = commandStr.Substring(1, 1); if (writePLC(FICT_PLC_Write_AddressA, Other.Asc(sA)) && writePLC(FICT_PLC_Write_AddressB, Other.Asc(sB))) { SubFunction.updateMessage(lstCommandList, "PC->PLC:" + commandStr); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "PC->PLC:" + commandStr); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "PC->PLC:" + commandStr); } else { SubFunction.updateMessage(lstCommandList, "PC->PLC:" + commandStr + " Fail"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "PC->PLC:" + commandStr + " Fail"); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "PC->PLC:" + commandStr); } }
/// <summary> /// close serial port /// </summary> /// <param name="sp">OK=true,NG=false</param> /// <returns></returns> private bool closeSerialPort(SerialPort sp) { if (sp.IsOpen) { try { sp.Close(); } catch (Exception e) { //MessageBox.Show("Can't close SerialPort=" + sp.PortName.ToString() + ",Message:" + e.Message); //SubFunction.updateMessage(lstStatusCommand, "Can't close SerialPort=" + sp.PortName.ToString() + ",Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Can't close SerialPort=" + sp.PortName.ToString() + ",Message:" + e.Message + "\r\n"); return(false); } } return(true); }
/// <summary> /// 向PLC指定的寄存器写值 /// </summary> /// <param name="devicename"></param> /// <param name="writedata"></param> private bool writePLC(string devicename, int writedata) { int iReturn = -1;//寄存器操作返回的值 //先读要写入的寄存器的值,若值等于要写入的值,则不用写 int dataread = -1; if (!readPLC(devicename, ref dataread)) { return(false); } if (dataread == writedata) { return(true); //值已相等 } //int retry = 0; //while (retry <= 1) //{ try { iReturn = axActPLC.SetDevice(devicename, writedata); } catch (Exception e) { SubFunction.updateMessage(lstCommandList, "Write " + devicename + " Fail"); SubFunction.updateMessage(lstCommandList, e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Write " + devicename + " Fail," + e.Message); return(false); } if (iReturn != 0) { SubFunction.updateMessage(lstCommandList, "Write " + devicename + " Fail,errorcode = " + iReturn); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Write " + devicename + " Fail,errorcode = " + iReturn); return(false); } else { return(true); } //} }
private void Btn_Test_Click(object sender, EventArgs e) { TestOut.Text = string.Empty; Delay(50); richTextBox_A.Clear(); richTextBox_B.Clear(); this.CB_SerialPort_A.Enabled = false; this.CB_SerialPort_B.Enabled = false; this.Btn_Stop.Enabled = true; this.Btn_Test.Enabled = false; this.Btn_Refresh.Enabled = false; richTextBox_A.AppendText("串口调试:准备打开串口A..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备打开串口A...."); if (!string.IsNullOrEmpty(CB_SerialPort_A.Text)) { if (!openSerialPort(serialPort_A, CB_SerialPort_A.Text)) { return; } } richTextBox_B.AppendText("串口调试:准备打开串口B..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试:准备打开串口B...."); if (!string.IsNullOrEmpty(CB_SerialPort_B.Text)) { if (!openSerialPort(serialPort_B, CB_SerialPort_B.Text)) { return; } } sendData(serialPort_A, "AAA"); richTextBox_A.AppendText("串口调试:向B串口发送<AAA>字符串..." + "\n"); sendData(serialPort_B, "BBB"); richTextBox_B.AppendText("串口调试:向A串口发送<BBB>字符串..." + "\n"); timer1.Start(); }
private void btnReCordDB_Use_Click(object sender, EventArgs e) { if (Param.Record_DataBase_Use) { DialogResult MsgBoxResult;//设置对话框返回值 string MEG = string.Empty; MEG = "你是否确定要关闭记录数据库?" + "\n"; MEG += "\n"; MEG += "注意,关闭后:" + "\n" + "1.不能自动获取中控电脑IP地址。" + "\n"; MEG += "2.不能向数据库写入TestLog。" + "\n"; MEG += "3.远程无法监控本机台运行状况。" + "\n"; MEG += "\n"; MEG += "是点击“Yes”,否点击“NO”" + "\n"; MsgBoxResult = MessageBox.Show(MEG, "小心操作!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.Yes) { Param.Record_DataBase_Use = false; IniFile.IniWriteValue("DB_Set", "Record_DataBase_Use", "0", @Param.IniFilePath); checkSwitchStatus(Param.Record_DataBase_Use, this.btnReCordDB_Use); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "设置窗口:执行关闭记录数据库动作..."); } if (MsgBoxResult == DialogResult.No) { SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "取消关闭记录数据库动作..."); } return; } if (!Param.Record_DataBase_Use) { Param.Record_DataBase_Use = true; IniFile.IniWriteValue("DB_Set", "Record_DataBase_Use", "1", @Param.IniFilePath); checkSwitchStatus(Param.Record_DataBase_Use, this.btnReCordDB_Use); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "开启记录数据库..."); return; } }
/// <summary> /// 打开串口 /// </summary> /// <param name="sp">控件</param> /// <param name="portname">串口名称</param> /// <returns>OK=true,NG=false</returns> private bool openSerialPort(SerialPort sp, string portname) { // bool result = true; if (!sp.IsOpen) { try { sp.PortName = portname; sp.Open(); SubFunction.updateMessage(lstCommandList, "机台调试:打开串口 <" + portname + "> 成功..."); //Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:打开串口 <" + portname + "> 成功...\r\n"); //Message:" + e.Message + "\r\n"); } catch (Exception e) { MessageBox.Show("机台调试:不能打开串口 <" + portname + ">,Message:" + e.Message); SubFunction.updateMessage(lstCommandList, "机台调试:不能打开串口 <" + portname + "> ,Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:不能打开串口 <" + portname + "> ,Message:" + e.Message + "\r\n"); return(false); } } return(true); }
private void btnWeb_UseSwitch_Click(object sender, EventArgs e) { if (Param.Web_Use) { DialogResult MsgBoxResult;//设置对话框返回值 string MEG = string.Empty; MEG = "你是否确定要关闭SFCS?" + "\n"; MEG += "\n"; MEG += "注意,关闭后:" + "\n" + "1.不能获取双板另一面条码。" + "\n"; MEG += "2.不能获取条码Model,UPN,MO,Mac等信息。" + "\n"; MEG += "3.不能上抛MB测试结果及机台信息(相当于无效测试)。" + "\n"; MEG += "\n"; MEG += "是点击“Yes”,否点击“NO”" + "\n"; MsgBoxResult = MessageBox.Show(MEG, "小心操作!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.Yes) { Param.Web_Use = false; IniFile.IniWriteValue("SFCS_Set", "Web_Use", "0", @Param.IniFilePath); checkSwitchStatus(Param.Web_Use, this.btnWeb_UseSwitch); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "设置窗口:执行关闭SFCS动作..."); } if (MsgBoxResult == DialogResult.No) { SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "取消关闭SFCS动作..."); } return; } if (!Param.Web_Use) { Param.Web_Use = true; IniFile.IniWriteValue("SFCS_Set", "Web_Use", "1", @Param.IniFilePath); checkSwitchStatus(Param.Web_Use, this.btnWeb_UseSwitch); return; } }
/// <summary> /// 打开串口 /// </summary> /// <param name="sp">控件</param> /// <param name="portname">串口名称</param> /// <returns>OK=true,NG=false</returns> private bool openSerialPort(SerialPort sp, string portname) { // bool result = true; if (!sp.IsOpen) { try { sp.PortName = portname; sp.Open(); //SubFunction.updateMessage(lstStatusCommand, "Open SerialPort=" + portname + " success.");//Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Open SerialPort=" + portname + " success.\r\n");//Message:" + e.Message + "\r\n"); } catch (Exception e) { MessageBox.Show("Can't open SerialPort=" + portname + ",Message:" + e.Message); //SubFunction.updateMessage(lstStatusCommand, "Can't open SerialPort=" + portname + ",Message:" + e.Message); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "Can't open SerialPort=" + portname + ",Message:" + e.Message + "\r\n"); Stop_Button(); return(false); } } return(true); }
/// <summary> /// 从配置档中读取数据 /// </summary> /// <param name="inifilepath"></param> public static void loadConfigData(string inifilepath) { try { //sysconfig Param.SysVersion = IniFile.IniReadValue("SysConfig", "SysVersion", @inifilepath); //配置档升级 Int32 ini_Version = Convert.ToInt32(Param.SysVersion.ToString().Replace(".", "")); //将版本号转换成整数 Int32 Soft_Version = Convert.ToInt32(Application.ProductVersion.ToString().Replace(".", "")); if (ini_Version > Soft_Version) { saveLog(Param.logType.SYSLOG.ToString(), "配置档版本高于软件版本..."); MessageBox.Show("配置档版本高于软件版本:"); } if (ini_Version > Soft_Version) { saveLog(Param.logType.SYSLOG.ToString(), "配置档版本与软件版本匹配..."); } if (ini_Version < Soft_Version) { saveLog(Param.logType.SYSLOG.ToString(), "配置档版本低于软件版本..."); DialogResult MsgBoxResult;//设置对话框返回值 string MEG = string.Empty; MEG += "配置档版本:" + Param.SysVersion.ToString() + "\n"; MEG += "软件版本:" + Application.ProductVersion.ToString() + "\n"; MEG += "因版本不匹配,你是否确定要更新配置档版本?" + "\n"; MEG += "\n"; MEG += "注意:" + "\n" + "1.不更新,仅变更配置档版本号,可能引发参数调用错误" + "\n"; MEG += "2.更新后,可能有必要修改部分参数!!!" + "\n"; MEG += "\n"; MEG += "是点击“Yes”,否点击“NO”" + "\n"; MsgBoxResult = MessageBox.Show(MEG, "小心操作!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (MsgBoxResult == DialogResult.Yes) { File.Delete(@inifilepath);//删除配置档 if (!File.Exists(Param.IniFilePath)) { SubFunction.creatInI(Param.IniFilePath); } SubFunction.loadConfigData(Param.IniFilePath); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "完成配置档更新..."); } if (MsgBoxResult == DialogResult.No) { IniFile.IniWriteValue("SysConfig", "SysVersion", Application.ProductVersion, @inifilepath); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "取消配置档更新,仅更新配置档版本号..."); //Application.Exit(); } } Param.FICTStage = IniFile.IniReadValue("SysConfig", "FICTStage", @inifilepath); Param.FixtrueID = IniFile.IniReadValue("SysConfig", "FixtureID", @inifilepath); Param.PCBLine = IniFile.IniReadValue("SysConfig", "PCBLine", @inifilepath); Param.TestingType = IniFile.IniReadValue("SysConfig", "TestingType", @inifilepath); Param.MBType = IniFile.IniReadValue("SysConfig", "MBType", @inifilepath); Param.RobotModule = IniFile.IniReadValue("SysConfig", "RobotModule", @inifilepath); Param.BarcodeType = IniFile.IniReadValue("SysConfig", "BarcodeType", @inifilepath); Param.MaxErrorCount = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "MaxErrorCount", @inifilepath)); Param.MaxRetestCount = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "MaxRetestCount", @inifilepath)); changeString2Bool(IniFile.IniReadValue("SysConfig", "LeftInsert", @inifilepath), ref Param.LeftInsert); changeString2Bool(IniFile.IniReadValue("SysConfig", "RightInsert", @inifilepath), ref Param.RightInsert); changeString2Bool(IniFile.IniReadValue("SysConfig", "RTC_Use", @inifilepath), ref Param.RTC_Use); //MessageBox.Show(IniFile.IniReadValue("SysConfig", "DetectDelay", @inifilepath)); Param.DetectDelay = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "DetectDelay", @inifilepath)); Param.ShutDown = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "ShutDown", @inifilepath)); changeString2Bool(IniFile.IniReadValue("SysConfig", "LeftInsertRe", @inifilepath), ref Param.LeftInsertRe); changeString2Bool(IniFile.IniReadValue("SysConfig", "RightInsertRe", @inifilepath), ref Param.RightInserRe); changeString2Bool(IniFile.IniReadValue("SysConfig", "UseCommand", @inifilepath), ref Param.UseCommand); //IniFile.IniWriteValue("SysConfig", "InsertDelay", "5", @inifilepath); //IniFile.IniWriteValue("SysConfig", "ST_Flag", "0", @inifilepath); if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "InsertDelay", @inifilepath))) { Param.InsertDelay = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "InsertDelay", @inifilepath)); } if (string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "NG_Stop", @inifilepath))) { changeString2Bool(IniFile.IniReadValue("SysConfig", "NG_Stop", @inifilepath), ref Param.NG_Stop); } if (string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "ST_Flag", @inifilepath))) { changeString2Bool(IniFile.IniReadValue("SysConfig", "ST_Flag", @inifilepath), ref Param.ST_Flag); } if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "AD_Module_Type", @inifilepath).Trim())) { Param.AD_Module_Type = IniFile.IniReadValue("SysConfig", "AD_Module_Type", @inifilepath).ToUpper(); } if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "MB_A_Re", @inifilepath))) { changeString2Bool(IniFile.IniReadValue("SysConfig", "MB_A_Re", @inifilepath), ref Param.MB_A_Re); } if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "MB_B_Re", @inifilepath))) { changeString2Bool(IniFile.IniReadValue("SysConfig", "MB_B_Re", @inifilepath), ref Param.MB_B_Re); } //sfcs_set changeString2Bool(IniFile.IniReadValue("SFCS_Set", "CheckRouter", @inifilepath), ref Param.CheckRouter); changeString2Bool(IniFile.IniReadValue("SFCS_Set", "Web_Use", @inifilepath), ref Param.Web_Use); Param.Web_Site = IniFile.IniReadValue("SFCS_Set", "Web_Site", @inifilepath); changeString2Bool(IniFile.IniReadValue("SFCS_Set", "OKBBBStatus", @inifilepath), ref Param.OKBBBStatus); changeString2Bool(IniFile.IniReadValue("SFCS_Set", "NGBBBStatus", @inifilepath), ref Param.NGBBBStatus); Param.SFC_Stage = IniFile.IniReadValue("SFCS_Set", "SFC_Stage", @inifilepath); Param.OPID = IniFile.IniReadValue("SFCS_Set", "OPID", @inifilepath); changeString2Bool(IniFile.IniReadValue("SFCS_Set", "Arms_Use", @inifilepath), ref Param.Arms_Use); Param.Arms_Version = IniFile.IniReadValue("SFCS_Set", "Arms_Version", @inifilepath); Param.Arms_Path = IniFile.IniReadValue("SFCS_Set", "Arms_Path", @inifilepath); Param.Net_Server = IniFile.IniReadValue("SFCS_Set", "Net_Server", @inifilepath); Param.Net_ID = IniFile.IniReadValue("SFCS_Set", "Net_ID", @inifilepath); Param.Net_Password = IniFile.IniReadValue("SFCS_Set", "Net_Password", @inifilepath); //db_set changeString2Bool(IniFile.IniReadValue("DB_Set", "Center_DataBase_Use", @inifilepath), ref Param.Center_DataBase_Use); Param.CenterIP_DataBase_IP = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_IP", @inifilepath); Param.CenterIP_DataBase_DB = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_DB", @inifilepath); Param.CenterIP_DataBase_Table = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Table", @inifilepath); Param.CenterIP_DataBase_Account = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Account", @inifilepath); Param.CenterIP_DataBase_Password = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Password", @inifilepath); changeString2Bool(IniFile.IniReadValue("DB_Set", "Record_DataBase_Use", @inifilepath), ref Param.Record_DataBase_Use); Param.RecordIP_DataBase_IP = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_IP", @inifilepath); Param.RecordIP_DataBase_DB = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_DB", @inifilepath); Param.RecordIP_DataBase_TestInfo_Table = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_TestInfo_Table", @inifilepath); Param.RecordIP_DataBase_Station_Table = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Station_Table", @inifilepath); Param.RecordIP_DataBase_Account = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Account", @inifilepath); Param.RecordIP_DataBase_Password = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Password", @inifilepath); //comport changeString2Bool(IniFile.IniReadValue("ComPort_Set", "Scanner_Use", @inifilepath), ref Param.Scanner_Use); Param.Scanner = IniFile.IniReadValue("ComPort_Set", "Scanner", @inifilepath); changeString2Bool(IniFile.IniReadValue("ComPort_Set", "DUT_A_Use", @inifilepath), ref Param.DUT_A_Use); Param.DUT_A = IniFile.IniReadValue("ComPort_Set", "DUT_A", @inifilepath); changeString2Bool(IniFile.IniReadValue("ComPort_Set", "DUT_B_Use", @inifilepath), ref Param.DUT_B_Use); Param.DUT_B = IniFile.IniReadValue("ComPort_Set", "DUT_B", @inifilepath); changeString2Bool(IniFile.IniReadValue("ComPort_Set", "PLC_Use", @inifilepath), ref Param.PLC_Use); Param.PLC = IniFile.IniReadValue("ComPort_Set", "PLC", @inifilepath); //timeout Param.Wait_MB_TimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Wait_MB_TimeOut", @inifilepath)); Param.In_Time_TimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "In_Time_TimeOut", @inifilepath)); Param.PowerONTimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "PowerONTimeOut", @inifilepath)); Param.TestOKTimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "TestOKTimeOut", @inifilepath)); Param.Out_Time_TimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Out_Time_TimeOut", @inifilepath)); Param.Test_PeriodCycle_TimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Test_PeriodCycle_TimeOut", @inifilepath)); //连接字符串 Param.Center_DB_ConnStr = "server=" + Param.CenterIP_DataBase_IP + ";user id=" + Param.CenterIP_DataBase_Account + ";password="******";persistsecurityinfo=True;database=" + Param.CenterIP_DataBase_DB; Param.Record_DB_ConnStr = "server=" + Param.RecordIP_DataBase_IP + ";user id=" + Param.RecordIP_DataBase_Account + ";password="******";persistsecurityinfo=True;database=" + Param.RecordIP_DataBase_DB; } catch (Exception ex) { saveLog(Param.logType.SYSLOG.ToString(), "配置档读取出错,请检查配置档,error:" + ex.Message); MessageBox.Show("配置档读取出错,,请检查配置档,error:" + ex.Message); } }
private void btnFresh_Click(object sender, EventArgs e) { getSerialPort(comboPLC); SubFunction.updateMessage(lstCommandList, "机台调试:点击 <刷新> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <刷新> 按钮...\r\n"); }
private void CheckPort(ComboBox PortName, Message m) { if (m.Msg == WM_DEVICE_CHANGE) // 捕获USB设备的拔出消息WM_DEVICECHANGE { string portName = Marshal.PtrToStringUni((IntPtr)(m.LParam.ToInt32() + Marshal.SizeOf(typeof(DEV_BROADCAST_PORT_Fixed)))); switch (m.WParam.ToInt32()) { case DBT_DEVICE_REMOVE_COMPLETE: // USB拔出 DEV_BROADCAST_HDR dbhdr0 = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HDR)); if (dbhdr0.dbch_devicetype == DBT_DEVTYP_PORT) { try { // comboPortName.Items.Remove(portName); if (Btn_Test.Enabled) { getSerialPort(PortName); } else { //sp = new System.Media.SoundPlayer(global::SpotTestTester.Properties.Resources.ng); //sp.Play(); richTextBox_A.AppendText("串口调试: " + "串口编号" + portName + "已经离线" + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试: " + "串口编号" + portName + "已经离线"); //SubFunction.updateMessage(lstStatusCommand, "偵测到串口丟失,請重新设置后點擊开始,若无法啟动,點擊Restart再點擊Start。"); //closePort(spPLC); //closePort(spSN); //pressStopButton(); } } catch (Exception ex) { //sp = new System.Media.SoundPlayer(global::SpotTestTester.Properties.Resources.ng); //sp.Play(); richTextBox_A.AppendText("串口调试: " + "Error," + ex.Message + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试: " + "Error," + ex.Message); } Console.WriteLine("Port '" + portName + "' leaved."); } break; case DBT_DEVICEARRIVAL: // USB插入获取对应串口名称 DEV_BROADCAST_HDR dbhdr = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_HDR)); if (dbhdr.dbch_devicetype == DBT_DEVTYP_PORT) { getSerialPort(CB_SerialPort_A); getSerialPort(CB_SerialPort_B); //getSerialPort(CB_SerialPort_A); //getSerialPort(CB_SerialPort_B); //MessageBox.Show(CB_SerialPort_A.Text); //getSerialPort(comboDUTPort_B); //getSerialPort(comboFICTPort); richTextBox_A.AppendText("串口调试: 串口已检测到《" + portName + "》..." + "\n"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "串口调试: 串口已检测到《" + portName + "》..."); Console.WriteLine("Port '" + portName + "' arrived."); } break; } } base.WndProc(ref m); }
private void btnS1_Click(object sender, EventArgs e) { SubFunction.updateMessage(lstCommandList, "机台调试:点击 <A板关机> 按钮..."); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "机台调试:点击 <A板关机> 按钮..."); sendPLC("S1"); }