void DOButtonClicked(object sender, EventArgs eventArgs) { LampButton doBt = sender as LampButton; string doName = doBt.Text; JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName); if (ci == null) //名称在配置中不存在 { ShowTips("DO操作失败:名称 \"" + doName + "\" 不存在"); return; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { ShowTips(string.Format("DO: \"{0}\" 操作失败:所属设备 \"{1}\" 在系统中不存在", doName, ci.DeviceID)); return; } if (!dev.IsDeviceOpen) { ShowTips(string.Format("DO \"{0}\" 操作失败:所属设备 \"{1}\" 未打开(关闭状态)", doName, ci.DeviceID)); return; } if (dev.DioCount <= ci.ModuleIndex) { ShowTips(string.Format("DO \"{0}\" 操作失败:所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", doName, ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0 ? 0 : dev.DioCount - 1)); return; } IJFModule_DIO md = dev.GetDio(ci.ModuleIndex); if (md.DOCount <= ci.ChannelIndex) { ShowTips(string.Format("DO \"{0}\" 操作失败:通道序号:{1} 超出范围0~{2}", doName, ci.ChannelIndex, md.DOCount == 0 ? 0 : md.DOCount - 1)); return; } bool isON = false; int errCode = md.GetDO(ci.ChannelIndex, out isON); if (0 != errCode) { ShowTips(string.Format("DO \"{0}\" 操作失败:未能获取当前状态,信息:{1}", doName, md.GetErrorInfo(errCode))); return; } errCode = md.SetDO(ci.ChannelIndex, !isON); if (0 != errCode) { ShowTips(string.Format("DO \"{0}\" {1}操作失败:未能,信息:{2}", doName, isON?"关闭":"打开", md.GetErrorInfo(errCode))); return; } }
public void UpdateChannelsInfo(string devID, int moduleIndex) { pnDi.Controls.Clear(); pnDo.Controls.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; IJFModule_DIO md = null; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq; if (dev != null && dev.DioCount > moduleIndex) { md = dev.GetDio(moduleIndex); } int diCount = mgr.GetDiChannelCount(devID, moduleIndex); for (int i = 0; i < diCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnDi.Controls.Add(lbIndex); UcDioChn ucDi = new UcDioChn(); pnDi.Controls.Add(ucDi); ucDi.Location = new Point(32, 2 + i * 33); ucDi.Width = pnDi.Width - 34; ucDi.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucDi.SetDioInfo(md, i, false, mgr.GetDiName(devID, moduleIndex, i)); } int doCount = mgr.GetDoChannelCount(devID, moduleIndex); for (int i = 0; i < doCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnDo.Controls.Add(lbIndex); UcDioChn ucDo = new UcDioChn(); pnDo.Controls.Add(ucDo); ucDo.Location = new Point(32, 2 + i * 33); ucDo.Width = pnDi.Width - 34; ucDo.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucDo.SetDioInfo(md, i, true, mgr.GetDoName(devID, moduleIndex, i)); } }
/// <summary> /// 根据工站的DIO确定控件数量 /// </summary> public void AdjustStationUI() { //rchTips.Text = ""; if (_station == null) { diNamesInView.Clear(); doNamesInView.Clear(); panelDIs.Controls.Clear(); panelDOs.Controls.Clear(); ShowTips("工站未设置"); btOpenAllDev.Enabled = false; return; } btOpenAllDev.Enabled = true; string[] doNamesInStation = _station.DONames; //当前 string[] diNamesInStation = _station.DINames; bool isNeedReAdjustDo = false; // 需要重新规划控件(IO数量/名称/排列发生变化) do { if (doNamesInStation == null || 0 == doNamesInStation.Length) { if (doNamesInView.Count != 0) { isNeedReAdjustDo = true; break; } } else { if (doNamesInView.Count != doNamesInStation.Length) { isNeedReAdjustDo = true; break; } for (int i = 0; i < doNamesInView.Count; i++) { if (doNamesInView[i] != doNamesInStation[i]) { isNeedReAdjustDo = true; break; } } } } while (false); if (isNeedReAdjustDo) { doNamesInView.Clear(); panelDOs.Controls.Clear(); if (null != doNamesInStation) { doNamesInView.AddRange(doNamesInStation); } for (int i = 0; i < doNamesInView.Count; i++) { LampButton lampDo = new LampButton(); lampDo.Size = new Size(_ioButtonWidth, _ioButtonHeight); lampDo.Text = doNamesInView[i]; lampDo.Click += new EventHandler(DOButtonClicked); panelDOs.Controls.Add(lampDo); } } bool isNeedReAdjustDi = false; do { if (diNamesInStation == null || 0 == diNamesInStation.Length) { if (diNamesInView.Count != 0) { isNeedReAdjustDi = true; break; } } else { if (diNamesInView.Count != diNamesInStation.Length) { isNeedReAdjustDi = true; break; } for (int i = 0; i < diNamesInView.Count; i++) { if (diNamesInView[i] != diNamesInStation[i]) { isNeedReAdjustDi = true; break; } } } } while (false); if (isNeedReAdjustDi) { diNamesInView.Clear(); panelDIs.Controls.Clear(); if (null != diNamesInStation) { diNamesInView.AddRange(diNamesInStation); } for (int i = 0; i < diNamesInView.Count; i++) { LampButton lampDi = new LampButton(); lampDi.Enabled = false; lampDi.Size = new Size(_ioButtonWidth, _ioButtonHeight); lampDi.Text = diNamesInView[i]; panelDIs.Controls.Add(lampDi); } } ////更新按钮提示信息 toolTips.RemoveAll(); for (int i = 0; i < doNamesInView.Count; i++) { LampButton lampDo = panelDOs.Controls[i] as LampButton; JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doNamesInView[i]); do { if (ci == null) //名称在配置中不存在 { lampDo.LampColor = LampButton.LColor.Gray; lampDo.ForeColor = Color.Red; lampDo.Enabled = false; toolTips.SetToolTip(lampDo, "名称在命名配置表中不存在"); ShowTips(string.Format("DO: \"{0}\" 在命名配置表中不存在", doNamesInView[i])); break; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { lampDo.LampColor = LampButton.LColor.Gray; lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; lampDo.Enabled = false; toolTips.SetToolTip(lampDo, "未发现所属设备:" + ci.DeviceID); ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 在系统中不存在", doNamesInView[i], ci.DeviceID)); break; } if (!dev.IsDeviceOpen) { lampDo.LampColor = LampButton.LColor.Gray; lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; lampDo.Enabled = false; ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 未打开(关闭状态)", doNamesInView[i], ci.DeviceID)); toolTips.SetToolTip(lampDo, "设备未打开"); break; } if (dev.DioCount <= ci.ModuleIndex) { lampDo.LampColor = LampButton.LColor.Gray; lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; lampDo.Enabled = false; toolTips.SetToolTip(lampDo, "所属模块序号超限"); ShowTips(string.Format("DO: \"{0}\" 所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", doNamesInView[i], ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0?0: dev.DioCount - 1)); break; } IJFModule_DIO md = dev.GetDio(ci.ModuleIndex); if (md.DOCount <= ci.ChannelIndex) { lampDo.LampColor = LampButton.LColor.Gray; lampDo.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; lampDo.Enabled = false; toolTips.SetToolTip(lampDo, "通道序号超限"); ShowTips(string.Format("DO: \"{0}\" 通道序号:{1} 超出范围0~{2}", doNamesInView[i], ci.ChannelIndex, md.DOCount == 0 ? 0 : md.DOCount - 1)); break; } lampDo.Enabled = true; lampDo.ForeColor = Color.Black; } while (false); } for (int i = 0; i < diNamesInView.Count; i++) { LampButton lampDi = panelDIs.Controls[i] as LampButton; JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diNamesInView[i]); do { if (ci == null) //名称在配置中不存在 { lampDi.LampColor = LampButton.LColor.Gray; lampDi.ForeColor = Color.Red; toolTips.SetToolTip(lampDi, "名称在命名配置表中不存在"); ShowTips(string.Format("DI: \"{0}\" 在命名配置表中不存在", diNamesInView[i])); break; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { lampDi.LampColor = LampButton.LColor.Gray; lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; toolTips.SetToolTip(lampDi, "未发现所属设备:" + ci.DeviceID); ShowTips(string.Format("DI: \"{0}\" 所属设备 \"{1}\" 在系统中不存在", diNamesInView[i], ci.DeviceID)); break; } if (!dev.IsDeviceOpen) { lampDi.LampColor = LampButton.LColor.Gray; lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; ShowTips(string.Format("DOI: \"{0}\" 所属设备 \"{1}\" 未打开(关闭状态)", diNamesInView[i], ci.DeviceID)); toolTips.SetToolTip(lampDi, "设备未打开"); break; } if (dev.DioCount <= ci.ModuleIndex) { lampDi.LampColor = LampButton.LColor.Gray; lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; toolTips.SetToolTip(lampDi, "所属模块序号超限"); ShowTips(string.Format("DI: \"{0}\" 所属设备 \"{1}\" 所属模块Index = {2} 超出范围0~{3}", diNamesInView[i], ci.DeviceID, ci.ModuleIndex, dev.DioCount == 0 ? 0 : dev.DioCount - 1)); break; } IJFModule_DIO md = dev.GetDio(ci.ModuleIndex); if (md.DICount <= ci.ChannelIndex) { lampDi.LampColor = LampButton.LColor.Gray; lampDi.ForeColor = Color.Red;//ucdo.IONameTextColor = Color.Red; toolTips.SetToolTip(lampDi, "通道序号超限"); ShowTips(string.Format("DI: \"{0}\" 通道序号:{1} 超出范围0~{2}", diNamesInView[i], ci.ChannelIndex, md.DICount == 0 ? 0 : md.DOCount - 1)); break; } //lampDo.Enabled = true; lampDi.ForeColor = Color.Black; } while (false); } }
/// <summary> /// 将工站IO状态更新到界面上 /// </summary> void UpdateStationUI() { if (_station == null) { return; } for (int i = 0; i < doNamesInView.Count; i++) { string doName = doNamesInView[i]; LampButton lmpdo = panelDOs.Controls[i] as LampButton; JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDoCellInfo(doName); do { if (ci == null) //名称在配置中不存在 { lmpdo.LampColor = LampButton.LColor.Gray; break; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { lmpdo.LampColor = LampButton.LColor.Gray; break; } if (!dev.IsDeviceOpen) { lmpdo.LampColor = LampButton.LColor.Gray; break; } if (dev.DioCount <= ci.ModuleIndex) { lmpdo.LampColor = LampButton.LColor.Gray; break; } IJFModule_DIO md = dev.GetDio(ci.ModuleIndex); if (md.DOCount <= ci.ChannelIndex) { lmpdo.LampColor = LampButton.LColor.Gray; break; } bool isOn = false; int errCode = md.GetDO(ci.ChannelIndex, out isOn); if (0 == errCode) { lmpdo.ForeColor = Color.Black; lmpdo.LampColor = isOn ? LampButton.LColor.Green : LampButton.LColor.Gray; } else { lmpdo.LampColor = LampButton.LColor.Gray; lmpdo.ForeColor = Color.Orange;//ucdo.IONameTextColor = Color.Red; } } while (false); } for (int i = 0; i < diNamesInView.Count; i++) { string diName = diNamesInView[i]; LampButton lmpdi = panelDIs.Controls[i] as LampButton; JFDevCellInfo ci = JFHubCenter.Instance.MDCellNameMgr.GetDiCellInfo(diName); do { if (ci == null) //名称在配置中不存在 { lmpdi.LampColor = LampButton.LColor.Gray; break; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { lmpdi.LampColor = LampButton.LColor.Gray; break; } if (!dev.IsDeviceOpen) { lmpdi.LampColor = LampButton.LColor.Gray; break; } if (dev.DioCount <= ci.ModuleIndex) { lmpdi.LampColor = LampButton.LColor.Gray; break; } IJFModule_DIO md = dev.GetDio(ci.ModuleIndex); if (md.DICount <= ci.ChannelIndex) { lmpdi.LampColor = LampButton.LColor.Gray; break; } bool isOn = false; int errCode = md.GetDI(ci.ChannelIndex, out isOn); if (0 == errCode) { lmpdi.ForeColor = Color.Black; lmpdi.LampColor = isOn ? LampButton.LColor.Green : LampButton.LColor.Gray; } else { lmpdi.LampColor = LampButton.LColor.Gray; lmpdi.ForeColor = Color.Orange;//ucdo.IONameTextColor = Color.Red; } } while (false); } }
protected override bool ActionGenuine(out string errorInfo) { _isRunning = true; string diName = GetMethodInputValue(PN_DIID) as string; if (!JFHubCenter.Instance.MDCellNameMgr.ContainDiName(diName)) { errorInfo = "参数项:\"DI通道名称\" = " + diName + " 在设备名称表中不存在"; return(false); } bool isDIEnable = (bool)GetMethodInputValue(PN_WaitDIStatus); int timeoutMilSeconds = (int)GetMethodInputValue(PN_TimeoutMilliSeconds); int cycleMilliSeconds = (int)GetInitParamValue(PN_CycleMilliSeconds); JFDevChannel diChn = new JFDevChannel(JFDevCellType.DI, diName); string avalidInfo; if (!diChn.CheckAvalid(out avalidInfo)) { errorInfo = avalidInfo; return(false); } _dev = diChn.Device() as IJFDevice_MotionDaq; _ci = diChn.CellInfo(); _dio = _dev.GetDio(_ci.ModuleIndex); DateTime startTime = DateTime.Now; while (true) { if (0 == _workCmd) //正常工作 { // DI状态检查 bool isON = false; int errCode = _dio.GetDI(_ci.ChannelIndex, out isON); if (errCode != 0) { errorInfo = "获取DI状态失败!" + _dio.GetErrorInfo(errCode); _workCmd = 0; _isRunning = false; SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout); return(false); } if (isDIEnable == isON) { errorInfo = "Success"; _workCmd = 0; _isRunning = false; SetOutputParamValue(ON_Result, JFWorkCmdResult.Success); return(true); } if (timeoutMilSeconds >= 0) { TimeSpan ts = DateTime.Now - startTime; if (ts.TotalMilliseconds >= timeoutMilSeconds) { errorInfo = "超时未等到DI:\" " + diName + "\"状态为" + isDIEnable.ToString(); _workCmd = 0; _isRunning = false; SetOutputParamValue(ON_Result, JFWorkCmdResult.Timeout); return(true); } } Thread.Sleep(cycleMilliSeconds); } else if (1 == _workCmd)//当前为暂停状态 { Thread.Sleep(cycleMilliSeconds); continue; } else//指令退出 { errorInfo = "收到退出指令"; _workCmd = 0; _isRunning = false; SetOutputParamValue(ON_Result, JFWorkCmdResult.ActionError); return(false); } } }
void AdjustUI() { if (InvokeRequired) { Invoke(new Action(AdjustUI)); return; } while (tabControlCF1.TabCount > 1) { tabControlCF1.TabPages.RemoveAt(tabControlCF1.TabCount - 1); } gbInitParams.Controls.Clear(); if (null == _dev) { lbModel.Text = "空"; lbID.Text = "空"; lbOpend.Text = "空"; btOpenClose.Enabled = false; btOpenClose.Text = "空设备"; return; } else //更新设备信息 { lbModel.Text = _dev.DeviceModel; lbID.Text = _id; //UpdateDevice(); int locY = 20; int locX = 5; Label lbDevInit = new Label(); lbDevInit.Text = _dev.IsInitOK?"初始化完成":"初始化失败"; lbDevInit.Location = new Point(locX, locY); gbInitParams.Controls.Add(lbDevInit); locY += 28; for (int i = 0; i < _dev.InitParamNames.Length; i++) { UcJFParamEdit ucParam = new UcJFParamEdit(); ucParam.SetParamDesribe(_dev.GetInitParamDescribe(_dev.InitParamNames[i])); ucParam.SetParamValue(_dev.GetInitParamValue(_dev.InitParamNames[i])); ucParam.Enabled = false; ucParam.Location = new Point(locX, locY); gbInitParams.Controls.Add(ucParam); ucParam.Width = gbInitParams.Width - 20; locY = ucParam.Bottom + 2; } if (_dev.DioCount > 0) { ///fmDios = new FormDios(); for (int i = 0; i < _dev.DioCount; i++) { fmDios.AddModule(_dev.GetDio(i), "模块_" + i.ToString()); } TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。 tabPage.Text = "DIO模块"; tabPage.Name = "DioModules"; tabPage.BackColor = fmDios.BackColor; tabControlCF1.TabPages.Add(tabPage); //添加tabPage选项卡到tab控件 fmDios.TopLevel = false; fmDios.FormBorderStyle = FormBorderStyle.None; fmDios.Dock = DockStyle.Fill; fmDios.Parent = tabPage; fmDios.Visible = true; tabPage.Controls.Add(fmDios); //tabPage选项卡添加一个窗体对象 } if (_dev.McCount > 0) { //fmMotions = new FormMotions(); for (int i = 0; i < _dev.McCount; i++) { fmMotions.AddModule(_dev.GetMc(i), "模块_" + i.ToString()); } TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。 tabPage.Text = "Motion模块"; tabPage.Name = "MotionModules"; tabPage.BackColor = fmMotions.BackColor; tabControlCF1.TabPages.Add(tabPage); //添加tabPage选项卡到tab控件 fmMotions.TopLevel = false; fmMotions.FormBorderStyle = FormBorderStyle.None; fmMotions.Dock = DockStyle.Fill; fmMotions.Parent = tabPage; fmMotions.Visible = true; tabPage.Controls.Add(fmMotions); //tabPage选项卡添加一个窗体对象 } if (_dev.CompareTriggerCount > 0) { for (int i = 0; i < _dev.CompareTriggerCount; i++) { fmCmprTrigs.AddModule(_dev.GetCompareTrigger(i), "模块_" + i.ToString()); } TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。 tabPage.Text = "CmprTrig模块"; tabPage.Name = "CmprTrigModule"; tabPage.BackColor = fmCmprTrigs.BackColor; tabControlCF1.TabPages.Add(tabPage); //添加tabPage选项卡到tab控件 fmCmprTrigs.TopLevel = false; fmCmprTrigs.FormBorderStyle = FormBorderStyle.None; fmCmprTrigs.Dock = DockStyle.Fill; fmCmprTrigs.Parent = tabPage; fmCmprTrigs.Visible = true; tabPage.Controls.Add(fmCmprTrigs); //tabPage选项卡添加一个窗体对象 } if (_dev.AioCount > 0) { for (int i = 0; i < _dev.AioCount; i++) { fmAios.AddModule(_dev.GetAio(i), "模块_" + i.ToString()); } TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。 tabPage.Text = "AIO模块"; tabPage.Name = "AioModules"; tabPage.BackColor = fmAios.BackColor; tabControlCF1.TabPages.Add(tabPage); //添加tabPage选项卡到tab控件 fmAios.TopLevel = false; fmAios.FormBorderStyle = FormBorderStyle.None; fmAios.Dock = DockStyle.Fill; fmAios.Parent = tabPage; fmAios.Visible = true; tabPage.Controls.Add(fmAios); //tabPage选项卡添加一个窗体对象 } } tabControlCF1.SelectedIndex = 0; UpdateModuleStatus(); }
/// <summary> /// 检查设备通道是否存在并且可用 /// </summary> /// <param name="category"></param> /// <param name="cellName"></param> /// <param name="initor"></param> /// <param name="cellInfo"></param> /// <param name="errorInfo"></param> /// <returns></returns> public static bool CheckDevCellName(string category, string cellName, out IJFInitializable initor, out JFDevCellInfo ci, out string errorInfo) { initor = null; ci = null; errorInfo = null; if (string.IsNullOrEmpty(cellName)) { errorInfo = "参数项\"cellName\"为空"; return(false); } JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; JFInitorManager initorMgr = JFHubCenter.Instance.InitorManager; JFDevCellInfo cellInfo = null; if (category == DO) //获取数字量输出通道信息 { cellInfo = nameMgr.GetDoCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在DO:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.DioCount) { errorInfo = "DO:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount; return(false); } if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DOCount) { errorInfo = "DO:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DO通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == DI) //获取数字量输入 { cellInfo = nameMgr.GetDiCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在DI:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.DioCount) { errorInfo = "DI:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount; return(false); } if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DICount) { errorInfo = "DI:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DI通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == AI) { } else if (category == AO) { } else if (category == Axis) { cellInfo = nameMgr.GetAxisCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在Axis:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.McCount) { errorInfo = "Axis:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备轴模块数量: " + md.McCount; return(false); } if (cellInfo.ChannelIndex >= md.GetMc(cellInfo.ModuleIndex).AxisCount) { errorInfo = "Axis:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块轴通道数量: " + md.GetMc(cellInfo.ModuleIndex).AxisCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == CmpTrig) { cellInfo = nameMgr.GetCmpTrigCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在CmpTrig:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.CompareTriggerCount) { errorInfo = "CmpTrig:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备比较触发模块数量: " + md.CompareTriggerCount; return(false); } if (cellInfo.ChannelIndex >= md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels) { errorInfo = "CmpTrig:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块比较触发通道数量: " + md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == LightCtrl) { cellInfo = nameMgr.GetLightCtrlChannelInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在LightCtrl:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_LightController).IsAssignableFrom(dev.GetType())) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_LightController "; return(false); } IJFDevice_LightController md = dev as IJFDevice_LightController; if (!md.IsInitOK) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ChannelIndex >= md.LightChannelCount) { errorInfo = "LightCtrl:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备光源通道数量: " + md.LightChannelCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == LightTrig) { cellInfo = nameMgr.GetTrigCtrlChannelInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在LightTrig:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_TrigController).IsAssignableFrom(dev.GetType())) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_TrigController "; return(false); } IJFDevice_TrigController md = dev as IJFDevice_TrigController; if (!md.IsInitOK) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ChannelIndex >= md.TrigChannelCount) { errorInfo = "LightTrig:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备触发通道数量: " + md.TrigChannelCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == Cmr) { IJFInitializable dev = initorMgr.GetInitor(cellName); if (null == dev) { errorInfo = "Camera:\"" + cellName + "\" 在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_Camera).IsAssignableFrom(dev.GetType())) { errorInfo = "Camera:\"" + cellName + "\" 设备类型不是IJFDevice_Camera "; return(false); } initor = dev; errorInfo = "Success"; return(true); } else { errorInfo = "不支持的参数项\"category\" = " + category; } return(false); }
protected bool JFWaitDi(string diName, out string errorInfo, bool isTurnOn, int delaytime = -1) { if (!JFHubCenter.Instance.MDCellNameMgr.ContainDiName(diName)) { errorInfo = "参数项:\"DI通道名称\" = " + diName + " 在设备名称表中不存在"; return(false); } JFDevChannel diChn = new JFDevChannel(JFDevCellType.DI, diName); string avalidInfo; if (!diChn.CheckAvalid(out avalidInfo)) { errorInfo = avalidInfo; return(false); } IJFDevice_MotionDaq _dev = null; IJFModule_DIO _dio = null; JFDevCellInfo _ci = null; _dev = diChn.Device() as IJFDevice_MotionDaq; _ci = diChn.CellInfo(); _dio = _dev.GetDio(_ci.ModuleIndex); DateTime startTime = DateTime.Now; while (true) { if (0 == _workCmd) //正常工作 { // DI状态检查 bool isON = false; int errCode = _dio.GetDI(_ci.ChannelIndex, out isON); if (errCode != 0) { errorInfo = "获取DI状态失败!" + _dio.GetErrorInfo(errCode); _workCmd = 0; _isRunning = false; return(false); } if (isTurnOn == isON) { errorInfo = "Success"; _workCmd = 0; _isRunning = false; return(true); } if (delaytime >= 0) { TimeSpan ts = DateTime.Now - startTime; if (ts.TotalMilliseconds >= delaytime) { errorInfo = "超时未等到DI:\" " + diName + "\"状态为" + isTurnOn.ToString(); _workCmd = 0; _isRunning = false; return(false); } } Thread.Sleep(10); } else if (1 == _workCmd)//当前为暂停状态 { Thread.Sleep(10); continue; } else//指令退出 { errorInfo = "收到退出指令"; _workCmd = 0; _isRunning = false; return(false); } } }