/// <summary> /// 关闭工站/设备,释放各种资源 /// </summary> public void Close() { string errInfo = ""; ///关闭工站 IJFMainStation mainStation = StationMgr.MainStation; if (null != mainStation) { mainStation.Stop(out errInfo); } string[] stationNames = StationMgr.AllStationNames(); if (null != stationNames && stationNames.Length > 0) { foreach (string stationName in stationNames) { IJFStation station = StationMgr.GetStation(stationName); station.Stop(); } } ///关闭所有设备 string[] deviceIDs = InitorManager.GetIDs(typeof(IJFDevice)); if (null != deviceIDs && deviceIDs.Length > 0) { foreach (string devID in deviceIDs) { IJFDevice dev = InitorManager.GetInitor(devID) as IJFDevice; dev.CloseDevice(); } } ///释放其他对象 ///添加代码 ... }
/// <summary> /// 打开/关闭设备 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItemOpenCloseDev_Click(object sender, EventArgs e) { DevNodeInfo nodeInfo = tvDevs.SelectedNode.Tag as DevNodeInfo; IJFDevice dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice; if (dev.IsDeviceOpen) { int nRet = dev.CloseDevice(); if (nRet != 0) { MessageBox.Show("关闭设备失败!错误信息 :" + dev.GetErrorInfo(nRet)); } else { MessageBox.Show("设备已关闭"); } } else { int nRet = dev.OpenDevice(); if (nRet != 0) { MessageBox.Show("打开设备失败!错误信息 :" + dev.GetErrorInfo(nRet)); } else { MessageBox.Show("设备已打开!"); } } }
public bool Action() { _startPfCnt = JFFunctions.PerformanceCounter(); if (!IsInitOK) { _endPfCnt = JFFunctions.PerformanceCounter(); _actionErrorInfo = "初始化未完成"; return(false); } IJFDevice dev = JFHubCenter.Instance.InitorManager.GetInitor(_devID) as IJFDevice; if (null == dev) { _endPfCnt = JFFunctions.PerformanceCounter(); _actionErrorInfo = "设备不存在,DevID = " + _devID; return(false); } int errCode = 0; if (_isOpen) { errCode = dev.OpenDevice(); } else { errCode = dev.CloseDevice(); } _endPfCnt = JFFunctions.PerformanceCounter(); if (0 != errCode) { _actionErrorInfo = (_isOpen ? "打开" : "关闭") + "设备失败:" + dev.GetErrorInfo(errCode); return(false); } _actionErrorInfo = "Success"; return(true); }