private void InitialHal() { m_objComPort = new clsFixture.stComPort(); if (Properties.Settings.Default.PLC_ComNum == "") { MessageBox.Show("Com Number 输入错误!"); return; } m_objComPort.strComPortNumber = Properties.Settings.Default.PLC_ComNum; m_objComPort.iBaundRate = Properties.Settings.Default.PLC_BaudRate; m_objComPort.iDataBit = Properties.Settings.Default.PLC_DataBit; m_objComPort.iStopBit = Properties.Settings.Default.PLC_StopBit; m_objComPort.strParity = Properties.Settings.Default.PLC_Parity; //m_objFixtureAMP204 = new clsFixtureAMP204(); //if (m_objFixtureAMP204.InitialFixture(Properties.Settings.Default.Card204, 0) == false) //{ // MessageBox.Show("APM 204 card initial fail 通信初始化失败!!!"); // ShowLog("APM 204 初始化失败"); // //return; //} //else //{ // ShowLog("APM 204 初始化成功"); //} //m_objFixtureAMP204.ServoOn(true); //m_objFixtureAMP204.HomeXY(); //scanner try { clsScanner.Callback += new clsScanner.OnMessageCallback(ShowLog); m_objScanner = new clsScanner(); } catch (Exception ex) { MessageBox.Show(ex.Message); } m_objFixture8338 = new clsFixture8338(); if (m_objFixture8338.InitialFixture(Properties.Settings.Default.Card8338ID) == false) { MessageBox.Show("card 8338 initial fail 通信初始化失败!!!"); ShowLog("PCIE-8338 初始化失败"); //return; } else { ShowLog("PCIE-8338 初始化成功"); } m_objFixture8338.SickLaserPowerOnOff(true); m_objFixture8338.Scanner = m_objScanner; m_objFixture8338.ServoOn(true); m_objFixture8338.HomeXY(); //frmShowImage objImageShowFromLocal = new frmShowImage(); //pbxLocal = objImageShowFromLocal.PbxShowImage; m_objCameraLocl = new CCBasler(); List <ICameraInfo> listCam = CCBasler.GetDeviceList(); bool findLocalCam = false; foreach (ICameraInfo cam in listCam) { if (cam[CameraInfoKey.FriendlyName].Contains(Properties.Settings.Default.Camera_LocalSN)) { findLocalCam = true; m_objCameraLocl.SetDeviceInfo(cam); m_objCameraLocl.ConnectToDevice(); m_objCameraLocl.SetExposure(Properties.Settings.Default.Camera_LocalExp); break; } } if (findLocalCam == false) { MessageBox.Show("局部相机 通信初始化失败!!!"); ShowLog("未能找到局部相机 ID:" + Properties.Settings.Default.Camera_LocalSN); //return; } //remove plc //m_objFixture = new clsFixture(); //m_objFixture.ComPort = m_objComPort; //if (m_objFixture.InitFixture() == false) //{ // MessageBox.Show("PLC 通信初始化失败!!!"); // ShowLog("PLC 通信失败"); // //return; //} }
private void UpdateDeviceTree() { try { m_listallCameras = CCBasler.GetDeviceList(); foreach (ICameraInfo cameraInfo in m_listallCameras) { bool newitem = true; foreach (RadTreeNode radTreeNode in this.radTreeView_Devices.Nodes) { if (radTreeNode.Name == cameraInfo[CameraInfoKey.FriendlyName] || cameraInfo[CameraInfoKey.FriendlyName].Contains("22546306")) { newitem = false; break; } } if (newitem) { RadTreeNode root = this.radTreeView_Devices.Nodes.Add(cameraInfo[CameraInfoKey.FriendlyName], 0); root.Nodes.Add(CCBasler.ConnectionType._Connect, 2); root.Nodes.Add(CCBasler.ConnectionType._DisConnect, 3); root.Nodes.Add(CCBasler.ConnectionType._OneShot, 3); root.Nodes.Add(CCBasler.ConnectionType._ContinusShot, 3); root.Nodes.Add(CCBasler.ConnectionType._StopContinusShot, 3); root.Nodes.Add(CCBasler.ConnectionType._Configuration, 3); RadTreeNode treeNodeConnect = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._Connect); treeNodeConnect.Enabled = true; RadTreeNode treeNodeDisConnect = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._DisConnect); treeNodeDisConnect.Enabled = false; RadTreeNode treeNodeOneShot = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._OneShot); treeNodeOneShot.Enabled = false; RadTreeNode treeNodeContinusShot = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._ContinusShot); treeNodeContinusShot.Enabled = false; RadTreeNode treeNodeStopContinusShot = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._StopContinusShot); treeNodeStopContinusShot.Enabled = false; RadTreeNode treeNodeConfiguration = radTreeView_Devices.GetNodeByName(CCBasler.ConnectionType._Configuration); treeNodeConfiguration.Enabled = false; CCamerInfo objCCamerInfo = new CCamerInfo(); frmShowImage objImageShowFrom = new frmShowImage(); //objImageShowFrom.Fixture = m_objFixture; //objImageShowFrom.Fixtureapm204 = m_objFixtureAMP204; frmShowImage.Callback += new frmShowImage.OnMessageCallback(ShowLog); objImageShowFrom.Fixture = m_objFixture8338; objImageShowFrom.BaslerLocalCamera = m_objCameraLocl; objCCamerInfo.m_objImageShowFrom = objImageShowFrom; System.Windows.Forms.PictureBox pbx = objImageShowFrom.PbxShowImage; CCBasler objBasler = new CCBasler(ref pbx); objCCamerInfo.m_objBasler = objBasler; objCCamerInfo.m_objCameraInfo = cameraInfo; //add name objCCamerInfo.m_strDisplayName = cameraInfo[CameraInfoKey.FriendlyName]; m_listCCamerInfo.Add(objCCamerInfo); } } // Remove old camera devices that have been disconnected. List <RadTreeNode> lstRadTreeNodeRemove = new List <RadTreeNode>(); List <ICameraInfo> lstCameraInfoRemove = new List <ICameraInfo>(); List <CCamerInfo> lstCameraRemove = new List <CCamerInfo>(); foreach (RadTreeNode radTreeNode in this.radTreeView_Devices.Nodes) { bool exists = false; ICameraInfo tempCamInfo = null; // For each camera in the list, check whether it can be found by enumeration. foreach (ICameraInfo cameraInfo in m_listallCameras) { tempCamInfo = cameraInfo; if (radTreeNode.Name == cameraInfo[CameraInfoKey.FriendlyName]) { exists = true; break; } } // If the camera has not been found, remove it from the list view. if (!exists) { lstRadTreeNodeRemove.Add(radTreeNode); //lstCameraInfoRemove.Add(tempCamInfo); } } if (lstRadTreeNodeRemove.Count > 0) { foreach (RadTreeNode rdTreeNode in lstRadTreeNodeRemove) { this.radTreeView_Devices.Nodes.Remove(rdTreeNode); } } if (lstRadTreeNodeRemove.Count > 0) { foreach (RadTreeNode rdTreeNode in lstRadTreeNodeRemove) { foreach (CCamerInfo cmInfo in m_listCCamerInfo) { if (cmInfo.m_objCameraInfo[CameraInfoKey.FriendlyName] == rdTreeNode.Text) { //获取需要删除的 相机 lstCameraRemove.Add(cmInfo); } } } foreach (CCamerInfo cmInfoForRemove in lstCameraRemove) { cmInfoForRemove.m_objBasler.Stop(); cmInfoForRemove.m_objBasler.DestroyCamera(); cmInfoForRemove.m_objImageShowFrom.Close(); m_listCCamerInfo.Remove(cmInfoForRemove); } } } catch (Exception exception) { ShowException(exception); } this.radTreeView_Devices.Nodes.Refresh(); }