//光谱仪信息
        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
            }
        }
Beispiel #2
0
        /// <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 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
            }
        }
Beispiel #4
0
        /// <summary>
        /// 颜色参数设置子界面快捷键事件
        /// </summary>
        /// <param name="selectchannelNo"></param>
        private void TabControlSelectedIndex0Event(int selectchannelNo)
        {
            int SelectChannelNo = selectchannelNo;

            if (SelectChannelNo > 0 && SelectChannelNo <= ChannelNum)
            {
                try
                {
                    m_CurrentChannelIndex = SelectChannelNo - 1;
                    if (GlobalDataInterface.nVer == 1)
                    {
                        m_CurrentIPM_ID = m_ChanelIDList[m_CurrentChannelIndex];
                    }
                    else if (GlobalDataInterface.nVer == 0)
                    {
                        m_CurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex]));
                    }
                    //m_CurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex]));

                    if (GlobalDataInterface.global_IsTestMode)
                    {
                        GlobalDataInterface.TransmitParam(m_CurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE, null);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("QualityParamSetForm中函数TabControlSelectedIndex1Event出错" + ex + "\n" + ex.StackTrace);
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo("QualityParamSetForm中函数TabControlSelectedIndex1Event出错" + ex + "\n" + ex.StackTrace);
#endif
                }
            }
        }
Beispiel #5
0
        private void FlawChannelcontextMenuStrip_MouseEnter(object sender, EventArgs e) //新增采集IPM原图时使用 Add by ChengSk - 20190508
        {
            try
            {
                ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                m_CurrentChannelIndex = this.FlawChannelcontextMenuStrip.Items.IndexOf(menuItem);
                if (GlobalDataInterface.nVer == 1)            //版本号判断 add by xcw 20200604
                {
                    m_CurrentIPM_ID = (m_FlawChanelIDList[m_CurrentFlawChannelIndex]);
                    //m_CurrentIPM_ID = Commonfunction.EncodeIPMChannel(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex]));
                }
                else if (GlobalDataInterface.nVer == 0)
                {
                    m_CurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex]));
                }
                //m_CurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_FlawChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_FlawChanelIDList[m_CurrentChannelIndex]));
            }
            catch (Exception ex)
            {
                Trace.WriteLine("QualityParamSetForm-FlawSeFormt中函数FlawChannelcontextMenuStrip_MouseEnter出错" + ex);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-FlawSeFormt中函数FlawChannelcontextMenuStrip_MouseEnter出错" + ex);
#endif
            }
        }
Beispiel #6
0
        /// <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
            }
        }
Beispiel #7
0
        /// <summary>
        /// 所有下位机命令/数据发送
        /// </summary>
        /// <param name="nCmd"></param> 命令
        /// <param name="Data"></param> 数据
        /// <param name="bChannelInfo"></param> 子系统通道是否有效 stSysConfig.nChannelInfo
        /// <returns></returns>是否执行成功 0成功 不成功返回相应子系统ID
        public int AllSysSyncRequest(int nCmd, byte[] Data, byte[] bChannelInfo)
        {
            List <int> arrayID = new List <int>();
            int        result  = 0;//成功

            if (nCmd != (int)HC_FSM_COMMAND_TYPE.HC_CMD_SYS_CONFIG)
            {
                Commonfunction.GetAllSysID(bChannelInfo, ref arrayID);
            }
            else
            {
                for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM; i++)
                {
                    for (int j = 0; j < ConstPreDefine.MAX_CHANNEL_NUM; j++)
                    {
                        //if (bChannelInfo[i * ConstPreDefine.MAX_CHANNEL_NUM + j] == 1)
                        if (bChannelInfo[i] > j)  //Modify by ChengSk - 20190521
                        {
                            int id = Commonfunction.EncodeSubsys(i);
                            arrayID.Add(id);
                            break;
                        }
                        stSysConfig sys = new stSysConfig(true);
                        sys = (stSysConfig)Commonfunction.BytesToStruct(Data, typeof(stSysConfig));
                        //if (sys.nChannelInfo[i * ConstPreDefine.MAX_CHANNEL_NUM + j] == 1)
                        if (sys.nChannelInfo[i] > j)  //Modify by ChengSk - 20190521
                        {
                            int id = Commonfunction.EncodeSubsys(i);
                            arrayID.Add(id);
                            break;
                        }
                    }
                }
            }
            Trace.WriteLine(string.Format("函数 AllSysSyncRequest arrayID.Count:{0}", arrayID.Count));
#if REALEASE
            GlobalDataInterface.WriteErrorInfo(string.Format("函数 AllSysSyncRequest arrayID.Count:{0}", arrayID.Count));
#endif
            for (int i = 0; i < arrayID.Count; i++)
            {
                int nDestId = arrayID[i];
                if (!SubsysIsConnected(Commonfunction.GetSubsysIndex(nDestId)))
                {
                    Trace.WriteLine(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#endif
                    continue;
                }
                if (!SyncRequest(nDestId, nCmd, Data))
                {
                    result = nDestId;
                }
            }
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// 通道快捷菜单单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BruiseChannelcontextMenuStrip_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                m_CurrentBruiseChannelIndex = this.BruiseChannelcontextMenuStrip.Items.IndexOf(menuItem);
                //m_BruiseCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]), Commonfunction.GetIPMIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]));
                if (GlobalDataInterface.nVer == 1)            //版本号判断 add by xcw 20200604
                {
                    //m_BruiseCurrentIPM_ID = Commonfunction.EncodeIPMChannel(Commonfunction.GetSubsysIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]), Commonfunction.GetIPMIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]));
                    m_BruiseCurrentIPM_ID = m_BruiseChanelIDList[m_CurrentBruiseChannelIndex];
                }

                else if (GlobalDataInterface.nVer == 0)
                {
                    m_BruiseCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]), Commonfunction.GetIPMIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]));
                }
                stCameraNum cameraNum = new stCameraNum(true);

                switch (GlobalDataInterface.globalOut_SysConfig.nSystemInfo) //Modify by ChengSk - 20190520
                {
                case 64:                                                     //NIR2-右
                    cameraNum.cCameraNum = 0;
                    break;

                case 128:     //NIR2-中
                    cameraNum.cCameraNum = 0;
                    break;

                case 256:     //NIR2-左
                    cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                    break;

                case 1:       //彩色-右
                    cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_BruiseChanelIDList[m_CurrentBruiseChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                    break;
                }
                if (GlobalDataInterface.global_IsTestMode)
                {
                    GlobalDataInterface.TransmitParam(m_BruiseCurrentIPM_ID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                    GlobalDataInterface.TransmitParam(m_BruiseCurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE_SPOT, cameraNum);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("QualityParamSetForm-BruiseSetFormt中函数BruiseChannelcontextMenuStrip_Click出错" + ex);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-BruiseSetFormt中函数BruiseChannelcontextMenuStrip_Click出错" + ex);
#endif
            }
        }
Beispiel #9
0
        /// <summary>
        /// Channel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChannelcomboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int tempChannelIndex    = this.ChannelcomboBox.SelectedIndex;
                int tempCurrentIPMIndex = Commonfunction.GetIPMIndex(m_ChannelIDList[tempChannelIndex]);
                int tempCurrentSysIndex = Commonfunction.GetSubsysIndex(m_ChannelIDList[tempChannelIndex]);

                if (GlobalDataInterface.global_IsTestMode)
                {
                    //if (GlobalDataInterface.nVer == 1)            //版本号判断 add by xcw 20200604
                    //{
                    //    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPMChannel(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                    //    //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                    //    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPMChannel(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                    //}

                    //else if (GlobalDataInterface.nVer == 0)
                    //{
                    //    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                    //    //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                    //    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                    //}
                    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                    //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                    GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null);
                }
                m_CurrentChannelIndex = this.ChannelcomboBox.SelectedIndex;
                m_CurrentIPMIndex     = Commonfunction.GetIPMIndex(m_ChannelIDList[m_CurrentChannelIndex]);
                m_CurrentSysIndex     = Commonfunction.GetSubsysIndex(m_ChannelIDList[m_CurrentChannelIndex]);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("FruitParamForm中函数ChannelcomboBox_SelectedIndexChanged出错" + ex);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("FruitParamForm中函数ChannelcomboBox_SelectedIndexChanged出错" + ex);
#endif
            }
        }
Beispiel #10
0
        /// <summary>
        /// 通道快捷菜单单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FlawChannelcontextMenuStrip_Click(object sender, EventArgs e)
        {
            try
            {
                stCameraNum       cameraNum = new stCameraNum(true);
                ToolStripMenuItem menuItem  = (ToolStripMenuItem)sender;

                switch (menuItem.Text)
                {
                case "Color Camera":
                    cameraNum.cCameraNum = 0;
                    m_cameraIndex        = 0;
                    break;

                case "NIR-F Camera":
                    cameraNum.cCameraNum = 1;
                    m_cameraIndex        = 1;
                    break;

                case "NIR-B Camera":
                    cameraNum.cCameraNum = 2;
                    m_cameraIndex        = 2;
                    break;

                default: break;
                }
                //string chanel = menuItem.OwnerItem.Text;
                m_CurrentFlawChannelIndex = this.FlawChannelcontextMenuStrip.Items.IndexOf(menuItem.OwnerItem);
                //m_CurrentFlawChannelIndex = this.FlawChannelcontextMenuStrip.Items.IndexOf(menuItem);

                if (GlobalDataInterface.nVer == 1)            //版本号判断 add by xcw 20200604
                {
                    m_FlawCurrentIPM_ID = (m_FlawChanelIDList[m_CurrentFlawChannelIndex]);
                }

                else if (GlobalDataInterface.nVer == 0)
                {
                    m_FlawCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_FlawChanelIDList[m_CurrentFlawChannelIndex]), Commonfunction.GetIPMIndex(m_FlawChanelIDList[m_CurrentFlawChannelIndex]));
                }
                // stCameraNum cameraNum = new stCameraNum(true);
                //// cameraNum.bChannelIndex = (byte)Commonfunction.ChanelInIPMIndex(m_FlawChanelIDList[m_CurrentFlawChannelIndex]);
                // switch (GlobalDataInterface.globalOut_SysConfig.nSystemInfo)
                // {
                //     case 1:
                //         cameraNum.cCameraNum = 0;
                //         break;
                //     case 2:
                //         cameraNum.cCameraNum = 0;
                //         break;
                //     case 4:
                //         cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_FlawChanelIDList[m_CurrentFlawChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                //         break;
                //     case 8:
                //         cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_FlawChanelIDList[m_CurrentFlawChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                //         break;
                // }
                if (GlobalDataInterface.global_IsTestMode)
                {
                    m_CurrentIPM_ID = m_FlawCurrentIPM_ID;
                    //GlobalDataInterface.TransmitParam(m_FlawCurrentIPM_ID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                    GlobalDataInterface.TransmitParam(m_CurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE, null); //新增 Add by ChengSk - 20190508
                    Thread.Sleep(500);                                                                                       //add by xcw 20200909
                    GlobalDataInterface.TransmitParam(m_FlawCurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE_SPOT, null);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("QualityParamSetForm-FlawSeFormt中函数FlawChannelcontextMenuStrip_Click出错" + ex);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-FlawSeFormt中函数FlawChannelcontextMenuStrip_Click出错" + ex);
#endif
            }
        }
        /// <summary>
        /// 一对一发送命令/数据
        /// </summary>
        /// <param name="nDestId"></param>命令/数据目的ID
        /// <param name="nCmd"></param>命令
        /// <param name="rData"></param>数据
        /// <returns></returns>
        public bool SyncRequest(int nDestId, int nCmd, byte[] Data)
        {
            bool   boRC = false;//运行正常与否标志位
            Socket socket;

            if (nCmd != (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_OFF &&
                nCmd != (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON &&
                !SubsysIsConnected(Commonfunction.GetSubsysIndex(nDestId)))
            {
                Trace.WriteLine(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#if REALEASE
                GlobalDataInterface.WriteErrorInfo(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#endif
                return(false);
            }
            //C++: AfxGetApp()->BeginWaitCursor();

            string strIP     = "";
            int    nSubsysId = Commonfunction.GetSubSysID(nDestId);
            int    nPortNum  = ConstPreDefine.FSM_PORT_NUM;

            if (nCmd >= 0x2000 && nCmd < 0x3000) //判断为HC->IPM的发送命令
            {
                nPortNum  = ConstPreDefine.IPM_PORT_NUM;
                nSubsysId = Commonfunction.GetIPMID(nDestId);
            }

            string strTemp = ConstPreDefine.LC_IP_ADDR_TEMPLATE;
            strIP = strTemp + nSubsysId;//得到发送的IP地址


            try
            {
                Lock(1000);                //资源加锁

                socket = CreateSocket();   //创建socket
                socket.SendBufferSize = 0; //网络发送缓冲区为0
                if (nCmd == (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON)
                {
                    boRC = ConnectoServer(socket, strIP, nPortNum, true, true);                                                                                                                                                                       //初始连接
                }
                else if ((nCmd >= (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_OFF && nCmd <= (int)HC_FSM_COMMAND_TYPE.HC_CMD_CUPSTATERESET) || (nCmd > (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON && nCmd <= (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADE_INFO)) //所有子系统发送
                {
                    boRC = ConnectoServer(socket, strIP, nPortNum, false, true);                                                                                                                                                                      //运行状态下连接
                }
                else
                {
                    boRC = ConnectoServer(socket, strIP, nPortNum, false, false);//运行状态下连接
                }
                if (!boRC)
                {
                    Trace.WriteLine("网络连接失败!");
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("网络连接失败!"));
#endif
                    UnLock();
                    socket.Close();
                    return(boRC);
                }

                SendCMD cmd = new SendCMD();

                cmd.SYNC    = 0x434e5953;
                cmd.nSrcId  = ConstPreDefine.HC_ID; //发送源ID
                cmd.nDestId = nDestId;              //发送目的ID
                cmd.nCmd    = nCmd;

                int    nStructLen = 4 * sizeof(int);
                byte[] bytes      = new byte[nStructLen];
                bytes = Commonfunction.StructToBytes(cmd); //将结构体转化为byte数组

                boRC = Send(socket, bytes);                //发送命令头
                if (!boRC)
                {
                    Trace.WriteLine("网络发送命令头错误!");
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("网络发送命令头错误!"));
#endif
                    goto leave;
                }

                int A = BitConverter.ToInt32(bytes, 12);

                if (Data != null)
                {
                    boRC = Send(socket, Data);//发送数据
                    if (!boRC)
                    {
                        Trace.WriteLine("网络发送数据错误!");
#if REALEASE
                        GlobalDataInterface.WriteErrorInfo(string.Format("网络发送数据错误!"));
#endif
                        goto leave;
                    }
                }


leave:
                DestroySocket(socket, boRC);
                UnLock();
                //AfxGetApp()->EndWaitCursor();
                if (boRC)
                {
                    Trace.WriteLine(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
#endif
                }
                else
                {
                    if (nCmd == (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON)
                    {
                        m_IsConnected[Commonfunction.GetSubsysIndex(nDestId)] = false;
                    }
                    Trace.WriteLine(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
#endif
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("失败:函数SyncRequest" + e);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("失败:函数SyncRequest" + e);
#endif
                return(false);
            }

            return(boRC);
        }
Beispiel #12
0
        /// <summary>
        /// 腐烂参数设置子界面快捷键事件
        /// </summary>
        /// <param name="selectchannelNo"></param>
        private void TabControlSelectedIndex4Event(int selectchannelNo)
        {
            int SelectChannelNo = selectchannelNo;

            if (SelectChannelNo > 0 && SelectChannelNo <= ChannelNum)
            {
                try
                {
                    m_CurrentRotChannelIndex = SelectChannelNo - 1;
                    //m_RotCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]), Commonfunction.GetIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]));
                    if (GlobalDataInterface.nVer == 1)            //版本号判断 add by xcw 20200604
                    {
                        m_RotCurrentIPM_ID = m_RotChanelIDList[m_CurrentRotChannelIndex];

                        //m_RotCurrentIPM_ID = Commonfunction.EncodeIPMChannel(Commonfunction.GetSubsysIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]), Commonfunction.GetIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]));
                    }
                    else if (GlobalDataInterface.nVer == 0)
                    {
                        m_RotCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]), Commonfunction.GetIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]));
                    }
                    stCameraNum cameraNum = new stCameraNum(true);
                    // cameraNum.bChannelIndex = (byte)Commonfunction.ChanelInIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]);
                    //switch (GlobalDataInterface.globalOut_SysConfig.nSystemInfo)
                    //{
                    //    case 1:
                    //        cameraNum.cCameraNum = 0;
                    //        break;
                    //    case 2:
                    //        cameraNum.cCameraNum = 0;
                    //        break;
                    //    case 4:
                    //        cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                    //        break;
                    //    case 8:
                    //        cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                    //        break;
                    //}
                    switch (GlobalDataInterface.globalOut_SysConfig.nSystemInfo) //Modify by ChengSk - 20190520
                    {
                    case 64:                                                     //NIR2-右
                        cameraNum.cCameraNum = 0;
                        break;

                    case 128:     //NIR2-中
                        cameraNum.cCameraNum = 0;
                        break;

                    case 256:     //NIR2-左
                        cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                        break;

                    case 1:       //彩色-右
                        cameraNum.cCameraNum = (byte)(Commonfunction.ChanelInIPMIndex(m_RotChanelIDList[m_CurrentRotChannelIndex]) * ConstPreDefine.CHANNEL_NUM);
                        break;
                    }
                    if (GlobalDataInterface.global_IsTestMode)
                    {
                        GlobalDataInterface.TransmitParam(m_RotCurrentIPM_ID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null);
                        GlobalDataInterface.TransmitParam(m_RotCurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE_SPOT, cameraNum);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("QualityParamSetForm中函数TabControlSelectedIndex4Event出错" + ex + "\n" + ex.StackTrace);
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo("QualityParamSetForm中函数TabControlSelectedIndex4Event出错" + ex + "\n" + ex.StackTrace);
#endif
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 一对一发送命令/数据
        /// </summary>
        /// <param name="nDestId"></param>命令/数据目的ID
        /// <param name="nCmd"></param>命令
        /// <param name="rData"></param>数据
        /// <returns></returns>
        public bool SyncRequest(int nDestId, int nCmd, byte[] Data)
        {
            bool   boRC = false;//运行正常与否标志位
            Socket socket;

            if (nCmd != (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_OFF &&
                nCmd != (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON &&
                !SubsysIsConnected(Commonfunction.GetSubsysIndex(nDestId)))
            {
                Trace.WriteLine(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#if REALEASE
                GlobalDataInterface.WriteErrorInfo(string.Format("当前子系统不可用,函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
#endif
                return(false);
            }
            //C++: AfxGetApp()->BeginWaitCursor();

            string strIP     = "";
            int    nSubsysId = Commonfunction.GetSubSysID(nDestId);
            int    nPortNum  = ConstPreDefine.FSM_PORT_NUM;

            if (nCmd >= 0x2000 && nCmd < 0x3000) //判断为HC->IPM的发送命令
            {
                nPortNum  = ConstPreDefine.IPM_PORT_NUM;
                nSubsysId = Commonfunction.GetIPMID(nDestId);
            }
            string strTemp = ConstPreDefine.LC_IP_ADDR_TEMPLATE;
            strIP = strTemp + nSubsysId;          //得到发送的IP地址
            //if (nCmd >= 0x7100 && nCmd <= 0x7101) //判断为HC->SIM的发送命令
            if (nCmd >= 0x7000 && nCmd <= 0x7102) //判断为HC->SIM的发送命令
            {
                nPortNum = ConstPreDefine.SIM_PORT_NUM;
                strIP    = ConstPreDefine.SIM_IP_ADDR;//得到发送的IP地址
            }

            try
            {
                Lock(1000);//资源加锁


                socket = CreateSocket();              //创建socket
                socket.SendBufferSize = 0;            //网络发送缓冲区为0
                socket.SendTimeout    = nTrySendTime; //设置发送超时时间
                socket.NoDelay        = false;

                //if (nCmd == (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON)
                //    boRC = ConnectoServer(socket, strIP, nPortNum, true);//初始连接
                //else
                //boRC = ConnectoServer(socket, strIP, nPortNum, false);//运行状态下连接
                boRC = ConnectoServer(socket, strIP, nPortNum, true);//2015-5-14 运行过程中会存在网线断了的情况


                if (!boRC)
                {
                    Trace.WriteLine("网络连接失败!");
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("网络连接失败!"));
#endif
                    UnLock();

                    socket.Close();
                    socket = null;
                    Trace.WriteLine("Socket关闭");
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo("Socket关闭");
#endif
                    return(boRC);
                }
                //byte[] ABC = new byte[1];
                //ABC[0] = 100;
                //if (nCmd == (int)HC_IPM_COMMAND_TYPE.HC_CMD_CONTINUOUS_SAMPLE_ON)
                //{
                //    QueryPerformanceFrequency(ref freq);
                //    QueryPerformanceCounter(ref count);
                //    Trace.WriteLine("发送连续采集前同步信息开始");
                //    boRC = Send(socket, ABC);//发送同步信息
                //    Trace.WriteLine("发送连续采集前同步信息结束");
                //}
                SendCMD cmd = new SendCMD();

                cmd.SYNC    = 0x434e5953;
                cmd.nSrcId  = ConstPreDefine.HC_ID; //发送源ID
                cmd.nDestId = nDestId;              //发送目的ID
                cmd.nCmd    = nCmd;

                int    nStructLen = 4 * sizeof(int);
                byte[] bytes      = new byte[nStructLen];
                bytes = Commonfunction.StructToBytes(cmd);//将结构体转化为byte数组
                //if (nCmd == (int)HC_IPM_COMMAND_TYPE.HC_CMD_CONTINUOUS_SAMPLE_ON)
                //    Trace.WriteLine("发送连续采集命令头开始");
                boRC = Send(socket, bytes);//发送命令头
                //if (nCmd == (int)HC_IPM_COMMAND_TYPE.HC_CMD_CONTINUOUS_SAMPLE_ON)
                //{
                //    //socket.RE
                //    Trace.WriteLine("发送连续采集命令头结束");
                //}
                ////测试获取图像命令发送时间
                //QueryPerformanceCounter(ref count1);
                //count = count1 - count;
                //result = (double)(count) / (double)freq;
                //Trace.WriteLine("发送连续采集同步信息+命令头时间:" + result);
                if (!boRC)
                {
                    Trace.WriteLine("网络发送命令头错误!");
#if REALEASE
                    GlobalDataInterface.WriteErrorInfo(string.Format("网络发送命令头错误!"));
#endif
                    goto leave;
                }

                int A = BitConverter.ToInt32(bytes, 12);

                if (Data != null)
                {
                    boRC = Send(socket, Data);//发送数据

                    if (!boRC)
                    {
                        Trace.WriteLine("网络发送数据错误!");
#if REALEASE
                        GlobalDataInterface.WriteErrorInfo(string.Format("网络发送数据错误!"));
#endif
                        goto leave;
                    }
                }


leave:
                DestroySocket(socket, boRC);
                UnLock();
                //AfxGetApp()->EndWaitCursor();
                if (boRC)
                {
                    if (Data != null)
                    {
                        Trace.WriteLine(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
//#if REALEASE
//                        GlobalDataInterface.WriteErrorInfo(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2}", nDestId, nCmd, Data.Length));
//#endif
                    }
                    else
                    {
                        Trace.WriteLine(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
//#if REALEASE
//                        GlobalDataInterface.WriteErrorInfo(string.Format("成功:函数SyncRequest nDestId:{0},nCmd={1}", nDestId, nCmd));
//#endif   //delete by xcw 20201207
                    }
                }
                else
                {
                    if (nCmd == (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON)
                    {
                        m_IsConnected[Commonfunction.GetSubsysIndex(nDestId)] = false;
                    }
                    if (Data != null)
                    {
                        Trace.WriteLine(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2},当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), nDestId, nCmd, Data.Length));
#if REALEASE
                        GlobalDataInterface.WriteErrorInfo(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},数据长度={2},当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), nDestId, nCmd, Data.Length));
#endif
                    }
                    else
                    {
                        Trace.WriteLine(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), nDestId, nCmd));
#if REALEASE
                        GlobalDataInterface.WriteErrorInfo(string.Format("失败:函数SyncRequest nDestId:{0},nCmd={1},当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), nDestId, nCmd));
#endif   //add by xcw 20201207
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("失败:函数SyncRequest" + e);
#if REALEASE
                GlobalDataInterface.WriteErrorInfo("失败:函数SyncRequest" + e);
#endif
                return(false);
            }

            return(boRC);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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
            }
        }
Beispiel #16
0
        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
            }
        }
Beispiel #17
0
        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
            }
        }