protected void Init() { InitResources(); InitShortcutManager(); //InitMenuBar(); InitToolBars(); InitStatusBar(); InitContextMenus(); InitTrayIcon(); this._wm = new WinGui.Utility.WindowManage(this, this.panelGround); this.Text = CardApplication.applicationName; #region 数据采集卡初始化 short m_dev = D2KDASK.D2K_Register_Card(D2KDASK.DAQ_2205, 0); if (m_dev < 0) { _statusInfo.Text = "Select Device First!"; MessageBox.Show("Select Device First!"); } else { short ret = D2KDASK.D2K_DIO_PortConfig(0, D2KDASK.Channel_P1A, D2KDASK.OUTPUT_PORT); if (ret < 0) { _statusInfo.Text = "D2K_DIO_PortConfig error!"; MessageBox.Show("D2K_DIO_PortConfig error!"); D2KDASK.D2K_Release_Card(0); } D2KDASK.D2K_DO_WritePort(0, D2KDASK.Channel_P1A, Convert.ToUInt32(Defs.StateVector, 2)); } #endregion string Commu = System.Configuration.ConfigurationSettings.AppSettings["CommunicationString1"]; string[] para = Commu.Split(';'); string[] com = para[0].Split('='); string can1 = com[1].Trim(); string[] baud = para[1].Split('='); string baud1 = baud[1].Trim(); com = para[2].Split('='); ReadTimeOutValue_can1 = com[1].Trim(); com = para[3].Split('='); WriteTimeOutValue_can1 = com[1].Trim(); Commu = System.Configuration.ConfigurationSettings.AppSettings["CommunicationString2"]; para = Commu.Split(';'); com = para[0].Split('='); string can2 = com[1].Trim(); baud = para[1].Split('='); string baud2 = baud[1].Trim(); com = para[2].Split('='); ReadTimeOutValue_can2 = com[1].Trim(); com = para[3].Split('='); WriteTimeOutValue_can2 = com[1].Trim(); #region can 总线配置 bool syncflag = false; uint nWriteCount = 10; uint nReadCount = 10; int nRet1 = Defs.Device1.acCanOpen(can1, syncflag, nReadCount, nWriteCount); int nRet2 = Defs.Device2.acCanOpen(can2, syncflag, nReadCount, nWriteCount); if (nRet1 < 0 && nRet2 < 0) { _statusInfo.Text = "Failed to open the CAN1 and CAN2 port, please check the CAN1 and CAN2 port name!"; MessageBox.Show("Failed to open the CAN1 and CAN2 port, please check the CAN1 and CAN2 port name!"); } #endregion int nRet; #region can1 配置 if (nRet1 >= 0) { nRet = Defs.Device1.acEnterResetMode(); if (nRet < 0) { _statusInfo.Text = "Failed to stop opertion1!"; MessageBox.Show("Failed to stop opertion1!"); Defs.Device1.acCanClose(); } else { nRet = Defs.Device1.acSetBaud(Convert.ToUInt32(baud1)); if (nRet < 0) { _statusInfo.Text = "Failed to set baud 1!"; MessageBox.Show("Failed to set baud 1!"); Defs.Device1.acCanClose(); } else { nRet = Defs.Device1.acSetTimeOut(Convert.ToUInt32(ReadTimeOutValue_can1), Convert.ToUInt32(WriteTimeOutValue_can1)); if (nRet < 0) { _statusInfo.Text = "Failed to set Timeout 1!"; MessageBox.Show("Failed to set Timeout 1!"); Defs.Device1.acCanClose(); } else { nRet = Defs.Device1.acEnterWorkMode(); if (nRet < 0) { _statusInfo.Text = "Failed to restart operation!"; MessageBox.Show("Failed to restart operation!"); Defs.Device1.acCanClose(); } } } } } #endregion #region can2 配置 if (nRet2 >= 0) { nRet = Defs.Device2.acEnterResetMode(); if (nRet < 0) { _statusInfo.Text = "Failed to stop opertion2!"; MessageBox.Show("Failed to stop opertion2!"); Defs.Device2.acCanClose(); } else { nRet = Defs.Device2.acSetBaud(Convert.ToUInt32(baud2)); if (nRet < 0) { _statusInfo.Text = "Failed to set baud 2!"; MessageBox.Show("Failed to set baud 2!"); Defs.Device2.acCanClose(); } else { nRet = Defs.Device2.acSetTimeOut(Convert.ToUInt32(ReadTimeOutValue_can2), Convert.ToUInt32(WriteTimeOutValue_can2)); if (nRet < 0) { _statusInfo.Text = "Failed to set Timeout 2!"; MessageBox.Show("Failed to set Timeout 2!"); Defs.Device2.acCanClose(); } else { nRet = Defs.Device2.acEnterWorkMode(); if (nRet < 0) { _statusInfo.Text = "Failed to restart operation!"; MessageBox.Show("Failed to restart operation!"); Defs.Device2.acCanClose(); } } } } } #endregion }