/// <summary> /// 确认 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WaveCaptureOKbutton_Click(object sender, EventArgs e) { try { m_EndInterval.CopyTo(m_waveInterval, 0); if (m_waveInterval[0] > m_waveInterval[1]) { byte temp = m_waveInterval[0]; m_waveInterval[0] = m_waveInterval[1]; m_waveInterval[1] = temp; } int WeightSubsysindex = Commonfunction.GetSubsysIndex(m_nChannelID); int WeightSubsysChannelIndex = Commonfunction.GetChannelIndex(m_nChannelID); GlobalDataInterface.globalOut_WeightBaseInfo[WeightSubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + WeightSubsysChannelIndex].waveinterval[0] = m_waveInterval[0]; GlobalDataInterface.globalOut_WeightBaseInfo[WeightSubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + WeightSubsysChannelIndex].waveinterval[1] = m_waveInterval[1]; if (GlobalDataInterface.global_IsTestMode) { GlobalDataInterface.TransmitParam(m_nChannelID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_WEIGHT_INFO, null); GlobalDataInterface.TransmitParam(m_nChannelID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_WAVE_FORM_OFF, null);//开启波形捕捉 } } catch (Exception ex) { Trace.WriteLine("WaveCaptureForm中函数WaveCaptureOKbutton_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("WaveCaptureForm中函数WaveCaptureOKbutton_Click出错" + ex); #endif } }
//光谱仪信息 - 生效(仅当前通道的光谱仪信息生效,其它通道不变) private void ButtonSetSpectrum_Click(object sender, EventArgs e) { try { bool resFlag = SetupParameterCheckProcess2(); if (!resFlag) { return; } if (MessageBox.Show("将光谱信息参数更新到通道" + (m_InnerQualitySelectIndex + 1).ToString() + "设备." + System.Environment.NewLine + System.Environment.NewLine + "是否继续?" , "警告信息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes) { return; } this.LabelWaitCount.Text = "光谱仪信息发送中..."; //将“当前通道”的光谱信息参数下发到设备 SendSpectrumInfoData(m_InnerQualitySelectIndex); int SelId = m_ChanelIDList[m_InnerQualitySelectIndex]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 int dataIndex = m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex; GlobalDataInterface.globalOut_SysDevInfoData[dataIndex].ToCopy(temp_SysDevInfoData[dataIndex]); //局部变量赋值到全局变量 } catch (Exception ex) { Trace.WriteLine("ProjectSetForm-InnerQuality中函数ButtonSetSpectrum_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm-InnerQuality中函数ButtonSetSpectrum_Click出错" + ex); #endif } }
/// <summary> /// 通道出口初始化 /// </summary> private void SetExitlistViewEx() { try { this.ExitlistViewEx.Items.Clear(); int SelId = m_ChanelIDList[0]; m_ExitSubsysindex = Commonfunction.GetSubsysIndex(SelId); m_ExitSubsysChannelIndex = Commonfunction.GetChannelIndex(SelId); ListViewItem lvi; for (int i = 0; i < GlobalDataInterface.globalOut_SysConfig.nExitNum; i++) { lvi = new ListViewItem(m_resourceManager.GetString("Outletlabel.Text") + string.Format(" {0}", i + 1)); //lvi.SubItems.Add(string.Format("{0}", tempExitInfo[m_ExitSubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_ExitSubsysChannelIndex].exits[i].nOffset)); //lvi.SubItems.Add(string.Format("{0}", tempExitInfo[m_ExitSubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_ExitSubsysChannelIndex].exits[i].nDis)); lvi.SubItems.Add(tempGlobalExitInfo[m_ExitSubsysindex].Delay_time[i].ToString()); lvi.SubItems.Add(tempGlobalExitInfo[m_ExitSubsysindex].Hold_time[i].ToString()); //lvi.SubItems.Add(string.Format("{0}", tempExitInfo[m_ExitSubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_ExitSubsysChannelIndex].exits[i].nDriverPin)); //Note by ChengSk - 20180402 this.ExitlistViewEx.Items.Add(lvi); } } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数ChannelExitIntial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数ChannelExitIntial出错" + ex); #endif } }
//光谱仪信息 private void SetFormInfoDisplay() { try { //加载通道零 if (this.ComboBoxChannel.Items.Count == 0) { return; } int SelId = m_ChanelIDList[m_InnerQualitySelectIndex]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 int dataIndex = m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex; this.EditInfoProductID.Text = Commonfunction.ByteArrayToString(temp_SysDevInfoData[dataIndex].ProductID.buf); this.EditInfoProductSerial.Text = Commonfunction.ByteArrayToString(temp_SysDevInfoData[dataIndex].ProductSerial.buf); this.EditInfoSpectoroSerial.Text = System.Text.Encoding.Default.GetString(temp_SysDevInfoData[dataIndex].SpectraSerial.buf); this.EditCcdInfoCoeffA0.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[0]); this.EditCcdInfoCoeffA1.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[1]); this.EditCcdInfoCoeffA2.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[2]); this.EditCcdInfoCoeffA3.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[3]); this.EditCcdInfoCoeffA4.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[4]); this.EditCcdInfoCoeffA5.Text = string.Format("{0:0.0000000E+00}", temp_SysDevInfoData[dataIndex].unitDblAr.DblArray[5]); } catch (Exception ex) { Trace.WriteLine("ProjectSetForm-InnerQuality中函数SetFormInfoDisplay出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm-InnerQuality中函数SetFormInfoDisplay出错" + ex); #endif } }
private bool SetupParameterCheckProcess2() { SetBlackDisplay(); #region 验证光谱信息是否合法 int SelId = m_ChanelIDList[m_InnerQualitySelectIndex]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 string strData = this.EditInfoProductID.Text.Trim(); int len = strData.Length; string qProductID = ""; string qProductSerial = ""; string qSpectrometerSerial = ""; float FL = 0; if ((len < 5) || (len > 23) || string.IsNullOrWhiteSpace(strData)) { this.EditInfoProductID.ForeColor = Color.Red; return(false); } else { this.EditInfoProductID.ForeColor = Color.Black; qProductID = strData; } strData = this.EditInfoProductSerial.Text.Trim(); len = strData.Length; if ((len < 5) || (len > 23) || string.IsNullOrWhiteSpace(strData)) { this.EditInfoProductSerial.ForeColor = Color.Red; return(false); } else { this.EditInfoProductSerial.ForeColor = Color.Black; qProductSerial = strData; } strData = this.EditInfoSpectoroSerial.Text.Trim(); len = strData.Length; if ((len < 5) || (len > 23) || string.IsNullOrWhiteSpace(strData)) { this.EditInfoSpectoroSerial.ForeColor = Color.Red; return(false); } else { this.EditInfoSpectoroSerial.ForeColor = Color.Black; qSpectrometerSerial = strData; } TMsgByte24Format buffProductID = Commonfunction.StringToByteArrayConversion(qProductID); TMsgByte24Format buffProductSerial = Commonfunction.StringToByteArrayConversion(qProductSerial); TMsgByte24Format buffSpectrometerSerial = Commonfunction.StringToByteArrayConversion(qSpectrometerSerial); for (int i = 0; i < 23; i++) { temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].ProductID.buf[i] = buffProductID.buf[i]; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].ProductSerial.buf[i] = buffProductSerial.buf[i]; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].SpectraSerial.buf[i] = buffSpectrometerSerial.buf[i]; } temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].ProductID.buf[23] = 0; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].ProductSerial.buf[23] = 0; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].SpectraSerial.buf[23] = 0; if (float.TryParse(this.EditCcdInfoCoeffA0.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA0.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[0] = FL; } else { this.EditCcdInfoCoeffA0.ForeColor = Color.Red; return(false); } if (float.TryParse(this.EditCcdInfoCoeffA1.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA1.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[1] = FL; } else { this.EditCcdInfoCoeffA1.ForeColor = Color.Red; return(false); } if (float.TryParse(this.EditCcdInfoCoeffA2.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA2.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[2] = FL; } else { this.EditCcdInfoCoeffA2.ForeColor = Color.Red; return(false); } if (float.TryParse(this.EditCcdInfoCoeffA3.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA3.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[3] = FL; } else { this.EditCcdInfoCoeffA3.ForeColor = Color.Red; return(false); } if (float.TryParse(this.EditCcdInfoCoeffA4.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA4.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[4] = FL; } else { this.EditCcdInfoCoeffA4.ForeColor = Color.Red; return(false); } if (float.TryParse(this.EditCcdInfoCoeffA5.Text.Trim(), out FL)) { this.EditCcdInfoCoeffA5.ForeColor = Color.Black; temp_SysDevInfoData[m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex].unitDblAr.DblArray[5] = FL; } else { this.EditCcdInfoCoeffA5.ForeColor = Color.Red; return(false); } #endregion return(true); }
private void SendDevParaThread(object arg) { try { int channelNumber = (int)arg; int index = 0; while (index < channelNumber) { try { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送中..."; })); } else { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送中..."; } //首先关闭当前的连接 if (tcpClient.IsConnected) { tcpClient.Close(); GlobalDataInterface.CommportConnectFlag = false; } else { GlobalDataInterface.CommportConnectFlag = false; } int SelId = m_ChanelIDList[index]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 int dataIndex = m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex; m_TcpChannelIndex = dataIndex; //当前选择的TCP通道索引 string ip = ConstPreDefine.LC_IP_ADDR_TEMPLATE + (dataIndex + 101); #region 网络Ping验证 Ping m_ping = new Ping(); PingReply pingReply = m_ping.Send(ip, 500); if (pingReply.Status != IPStatus.Success) //网络不通 { Thread.Sleep(1000); if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送失败"; })); } else { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送失败"; } Thread.Sleep(1000); index++; continue; } #endregion tcpClient.Connect(new IPEndPoint(IPAddress.Parse(ip), ConstPreDefine.LC_PORT_NUM)); //建立index+1的通道连接 Thread.Sleep(1000); if (GlobalDataInterface.CommportConnectFlag) { GlobalDataInterface.globalOut_SysDevParaData.ToCopy(temp_SysDevParaData); byte[] bytes = Commonfunction.StructToBytes(GlobalDataInterface.globalOut_SysDevParaData); MessageDataSend(ConstPreDefine.SBC_PARA_SET, bytes); //设置基础信息 if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送成功"; })); } else { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送成功"; } } else { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送失败"; })); } else { this.LabelWaitCount.Text = "通道" + (index + 1).ToString() + "基础信息发送失败"; } } Thread.Sleep(500); if (tcpClient.IsConnected) //最后关闭当前的连接(仅在有需要时才打开连接) { tcpClient.Close(); GlobalDataInterface.CommportConnectFlag = false; } else { GlobalDataInterface.CommportConnectFlag = false; } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm中函数OpenTcpThread的while循环出错,index=" + index.ToString() + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm中函数OpenTcpThread的while循环出错,index=" + index.ToString() + ex); #endif } index++; } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm中函数SendDevParaThread出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm中函数SendDevParaThread出错" + ex); #endif } }
private void OpenTcpThread(object arg) { try { int channelNumber = (int)arg; int index = 0; while (index < channelNumber) { try { //首先关闭当前的连接 if (tcpClient.IsConnected) { tcpClient.Close(); GlobalDataInterface.CommportConnectFlag = false; } else { GlobalDataInterface.CommportConnectFlag = false; } int SelId = m_ChanelIDList[index]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 int dataIndex = m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex; m_TcpChannelIndex = dataIndex; //当前选择的TCP通道索引 string ip = ConstPreDefine.LC_IP_ADDR_TEMPLATE + (dataIndex + 101); #region 网络Ping验证 Ping m_ping = new Ping(); PingReply pingReply = m_ping.Send(ip, 500); if (pingReply.Status != IPStatus.Success) { index++; continue; } //网络不通 #endregion tcpClient.Connect(new IPEndPoint(IPAddress.Parse(ip), ConstPreDefine.LC_PORT_NUM)); //建立index+1的通道连接 Thread.Sleep(500); if (GlobalDataInterface.CommportConnectFlag) { MessageDataSend(ConstPreDefine.SBC_INFO_REQ); //请求光谱仪指令 } Thread.Sleep(1000); //最后关闭当前的连接(仅在有需要时才打开连接) if (tcpClient.IsConnected) { tcpClient.Close(); GlobalDataInterface.CommportConnectFlag = false; } else { GlobalDataInterface.CommportConnectFlag = false; } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm中函数OpenTcpThread的while循环出错,index=" + index.ToString() + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm中函数OpenTcpThread的while循环出错,index=" + index.ToString() + ex); #endif } index++; } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm中函数OpenTcpThread出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm中函数OpenTcpThread出错" + ex); #endif } }
private void ReceivedMessageProcess(byte[] receiveMessageData) { try { int msgHead = receiveMessageData[0]; int msgType = receiveMessageData[1]; if (msgHead != ConstPreDefine.STX) { return; } IntPtr pData = IntPtr.Zero; int nLength = 0; switch (msgType) { case ConstPreDefine.SBC_INFO_REP: nLength = Marshal.SizeOf(typeof(TSYS_DEV_INFORMATION)); pData = Marshal.AllocHGlobal(nLength); if (pData != IntPtr.Zero) { int SelId = m_ChanelIDList[m_InnerQualitySelectIndex]; int m_InnerQualitySubsysindex = Commonfunction.GetSubsysIndex(SelId); //子系统索引 int m_InnerQualityChannelIndex = Commonfunction.GetChannelIndex(SelId); //子系统通道 int dataIndex = m_InnerQualitySubsysindex * ConstPreDefine.MAX_CHANNEL_NUM + m_InnerQualityChannelIndex; Marshal.Copy(receiveMessageData, 4, pData, nLength); GlobalDataInterface.globalOut_SysDevInfoData[dataIndex] = (TSYS_DEV_INFORMATION)Marshal.PtrToStructure(pData, typeof(TSYS_DEV_INFORMATION)); Marshal.FreeHGlobal(pData); temp_SysDevInfoData[dataIndex].ToCopy(GlobalDataInterface.globalOut_SysDevInfoData[dataIndex]); if (m_TcpChannelIndex == 0) { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { m_InnerQualitySelectIndex = 0; SetFormInfoDisplay(); //刷新光谱仪的信息 })); } } } if (m_TcpChannelIndex == 0) { MessageDataSend(ConstPreDefine.SBC_PARA_REQ); } //仅获取通道1的基础信息 break; case ConstPreDefine.SBC_PARA_REP: nLength = Marshal.SizeOf(typeof(TSYS_DEV_PARAMETER)); pData = Marshal.AllocHGlobal(nLength); if (pData != IntPtr.Zero) { Marshal.Copy(receiveMessageData, 4, pData, nLength); GlobalDataInterface.globalOut_SysDevParaData = (TSYS_DEV_PARAMETER)Marshal.PtrToStructure(pData, typeof(TSYS_DEV_PARAMETER)); Marshal.FreeHGlobal(pData); temp_SysDevParaData.ToCopy(GlobalDataInterface.globalOut_SysDevParaData); if (m_TcpChannelIndex == 0) { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { SetFormParaDisplay(); //刷新内部品质参数 })); } } } break; default: break; } //stopwatch.Stop(); //Common.FileHelper.logQueue.Enqueue(string.Format("ReceivedMessageProcess函数结束时间{0},耗时:{1}", System.DateTime.Now, stopwatch.Elapsed.TotalMilliseconds)); } catch (Exception ex) { Trace.WriteLine("ProjectSetForm中函数ReceivedMessageProcess出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm中函数ReceivedMessageProcess出错" + ex); #endif } }