public void UpdateModuleStatus() { if (InvokeRequired) { Invoke(new Action(UpdateModuleStatus)); return; } if (null == _module) { cbMode.Text = ""; cbMode.Enabled = false; ucLight.Enabled = false; ucTrig.Enabled = false; btOpenClose.Enabled = false; cbMode.Enabled = false; return; } btOpenClose.Enabled = true; if (_module.IsDeviceOpen) { btOpenClose.Text = "关闭设备"; } else { btOpenClose.Text = "打开设备"; } cbMode.Enabled = true; ucLight.Enabled = true; ucTrig.Enabled = true; JFLightWithTrigWorkMode mode; int err = _module.GetWorkMode(out mode); if (err != 0) { cbMode.Text = _module.GetErrorInfo(err); } else { if (mode == JFLightWithTrigWorkMode.TurnOnOff) { cbMode.Text = "开关模式"; } else if (mode == JFLightWithTrigWorkMode.Trigger) { cbMode.Text = "触发模式"; } } ucLight.UpdateModuleStatus(); ucTrig.UpdateModuleStatus(); }
protected override bool ActionGenuine(out string errorInfo) { string chnID = GetMethodInputValue("光源通道ID") as string; int intensity = (int)GetMethodInputValue("光照强度"); if (string.IsNullOrEmpty(chnID)) { errorInfo = "输入参数项:\"光源通道ID\" 为空字串"; return(false); } if (!JFHubCenter.Instance.MDCellNameMgr.ContainLightChannelName(chnID)) { errorInfo = "输入参数项:\"光源通道ID\" = " + chnID + " 在设备名称表中不存在"; return(false); } if (intensity < 0) { errorInfo = "输入参数项:\"光照强度\" = " + intensity + " 为无效值(参数值必须>=0)"; return(false); } bool isAutoSwitchMode = (bool)GetInitParamValue("自动切换到开关模式"); bool isAutoEnable = (bool)GetInitParamValue("自动使能"); IJFInitializable dev = null; JFDevCellInfo ci = null; string errInfo = null; if (!JFCMFunction.CheckDevCellName(JFCMFunction.LightCtrl, chnID, out dev, out ci, out errInfo)) { errorInfo = errInfo; return(false); } int errCode = 0; IJFDevice_LightController devLight = dev as IJFDevice_LightController; if (typeof(IJFDevice_LightControllerWithTrig).IsAssignableFrom(devLight.GetType())) //如果当前设备带有触发功能 { IJFDevice_LightControllerWithTrig devLT = devLight as IJFDevice_LightControllerWithTrig; JFLightWithTrigWorkMode wm; errCode = devLT.GetWorkMode(out wm); if (errCode != 0) { errorInfo = "获取光源控制器工作模式失败:" + devLT.GetErrorInfo(errCode); return(false); } if (wm == JFLightWithTrigWorkMode.Trigger) //当前处于触发模式 { if (!isAutoSwitchMode) { errorInfo = "控制器当前为触发模式"; return(false); } errCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.TurnOnOff); if (errCode != 0) { errorInfo = "控制器切换工作模式失败:" + devLT.GetErrorInfo(errCode); return(false); } } } bool isLightChnEnabled = false; errCode = devLight.GetLightChannelEnable(ci.ChannelIndex, out isLightChnEnabled); if (0 != errCode) { errorInfo = "获取通道使能状态失败:" + devLight.GetErrorInfo(errCode); return(false); } if (!isLightChnEnabled) { if (!isAutoEnable) { errorInfo = "光源通道未使能"; return(false); } errCode = devLight.SetLightChannelEnable(ci.ChannelIndex, true); if (errCode != 0) { errorInfo = "光源通道使能失败:" + devLight.GetErrorInfo(errCode); return(false); } } errCode = devLight.SetLightIntensity(ci.ChannelIndex, intensity); if (errCode != 0) { errorInfo = "设置光照强度失败:" + devLight.GetErrorInfo(errCode); return(false); } errorInfo = "Success"; return(true); }
///// <summary> ///// 使通道可用(如伺服上电,光源/触发可用) ///// 建议在 打开设备->检查通道可用性 之后调用 ///// </summary> ///// <param name="errorInfo"></param> ///// <returns></returns> public bool EnabledChannel(out string errorInfo) { errorInfo = "Unknown-Error"; bool isOK = false; if (!CheckAvalid(out errorInfo)) { return(false); } int errorCode = 0; IJFDevice dev = Device(); switch (CellType) { case JFDevCellType.DI: isOK = true; errorInfo = "Success"; break; case JFDevCellType.DO: errorInfo = "Success"; isOK = true; break; case JFDevCellType.Axis: { IJFDevice_MotionDaq devMD = Device() as IJFDevice_MotionDaq; JFDevCellInfo ci = CellInfo(); IJFModule_Motion mm = devMD.GetMc(ci.ModuleIndex); errorCode = mm.ServoOn(ci.ChannelIndex); if (errorCode != 0) { errorInfo = mm.GetErrorInfo(errorCode); } else { isOK = true; errorInfo = "Success"; } } break; case JFDevCellType.AI: errorInfo = "Success"; isOK = true; break; case JFDevCellType.AO: errorInfo = "Success"; isOK = true; break; case JFDevCellType.CmpTrig: errorInfo = "Success"; isOK = true; break; case JFDevCellType.Light: dev = Device(); if (dev is IJFDevice_LightControllerWithTrig) //光源控制器 { IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig; errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.TurnOnOff); //切换为开关模式 if (errorCode != 0) { errorInfo = "切换为开关模式失败:" + devLT.GetErrorInfo(errorCode); break; } } IJFDevice_LightController devl = dev as IJFDevice_LightController; errorCode = devl.SetLightChannelEnable(CellInfo().ChannelIndex, true); if (errorCode != 0) { errorInfo = "通道使能失败:" + devl.GetErrorInfo(errorCode); break; } isOK = true; errorInfo = "Success"; break; case JFDevCellType.Trig: dev = Device(); if (dev is IJFDevice_LightControllerWithTrig) //光源控制器 { IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig; errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.Trigger); //切换为触发模式 if (errorCode != 0) { errorInfo = "切换为触发模式失败:" + devLT.GetErrorInfo(errorCode); break; } } IJFDevice_TrigController devt = dev as IJFDevice_TrigController; errorCode = devt.SetTrigChannelEnable(CellInfo().ChannelIndex, true); if (errorCode != 0) { errorInfo = "通道使能失败:" + devt.GetErrorInfo(errorCode); break; } isOK = true; errorInfo = "Success"; break; default: errorInfo = "未定义的通道类型"; break; } return(isOK); }
protected override bool ActionGenuine(out string errorInfo) { string chnID = GetInitParamValue("触发通道ID") as string; bool isAutoSwitchWorkMode = (bool)GetInitParamValue("自动切换到触发模式"); bool isAutoEnable = (bool)GetInitParamValue("自动使能"); int intensity = (int)GetInitParamValue("触发强度"); bool ignoreIntensity = (bool)GetInitParamValue("忽略不支持强度设置"); int duration = (int)GetInitParamValue("触发时长"); bool ignoreDuration = (bool)GetInitParamValue("忽略不支持时长设置"); int[] srcChannels = GetInitParamValue("输入源通道") as int[]; bool ignoreSrcChannels = (bool)GetInitParamValue("忽略不支持源通道设置"); IJFInitializable initor = null; JFDevCellInfo ci = null; if (!JFCMFunction.CheckDevCellName(JFCMFunction.LightTrig, chnID, out initor, out ci, out errorInfo)) { return(false); } int errCode = 0; IJFDevice_TrigController dev = initor as IJFDevice_TrigController; if (typeof(IJFDevice_LightControllerWithTrig).IsAssignableFrom(dev.GetType())) //当前设备同时也是开关式光源控制器 { IJFDevice_LightControllerWithTrig lightCtrlWithT = dev as IJFDevice_LightControllerWithTrig; JFLightWithTrigWorkMode wm; errCode = lightCtrlWithT.GetWorkMode(out wm); if (errCode != 0) { errorInfo = "获取工作模式失败:" + lightCtrlWithT.GetErrorInfo(errCode); return(false); } if (wm == JFLightWithTrigWorkMode.TurnOnOff) //当前处于开关模式 { if (!isAutoSwitchWorkMode) { errorInfo = "当前工作模式为开关光源模式"; return(false); } errCode = lightCtrlWithT.SetWorkMode(JFLightWithTrigWorkMode.Trigger); if (errCode != 0) { errorInfo = "未能将光源控制器切换为触发模式:" + lightCtrlWithT.GetErrorInfo(errCode); return(false); } } } bool isChnEnabled = false; errCode = dev.GetTrigChannelEnable(ci.ChannelIndex, out isChnEnabled); if (0 != errCode) { errorInfo = "获取通道使能状态失败:" + dev.GetErrorInfo(errCode); return(false); } if (!isChnEnabled) { if (!isAutoEnable) { errorInfo = "触发通道当前未使能"; return(false); } errCode = dev.SetTrigChannelEnable(ci.ChannelIndex, true); if (errCode != 0) { errorInfo = "使能触发通道失败:" + dev.GetErrorInfo(errCode); return(false); } } if (null != srcChannels && srcChannels.Length != 0) //需要绑定输入源通道 { int mask = 0; //输入通道掩码 foreach (int srcChn in srcChannels) { mask += 1 << mask; } errCode = dev.SetTrigChannelSrc(ci.ChannelIndex, mask); if (errCode != 0 && !ignoreSrcChannels) { errorInfo = "绑定触发源通道失败:" + dev.GetErrorInfo(errCode); return(false); } } errCode = dev.SetTrigChannelIntensity(ci.ChannelIndex, intensity); if (errCode != 0 && !ignoreIntensity) { errorInfo = "设置触发强度:" + intensity + " 失败:" + dev.GetErrorInfo(errCode); return(false); } errCode = dev.SetTrigChannelDuration(ci.ChannelIndex, duration); if (errCode != 0 && !ignoreDuration) { errorInfo = "设置触发时长:" + duration + " 失败:" + dev.GetErrorInfo(errCode); return(false); } errorInfo = "Success"; return(true); }