/// <summary> /// 关闭设备 /// </summary> public int CloseDevice() { lock (asynLocker) { if (!IsDeviceOpen) { return((int)ErrorDef.Success); } lock (HtmDllManager.AsynLocker) { HTM.SetLightTrigSrc((int)devIndex, 0);//关闭所有通道 for (int i = 0; i < TrigChannelCount; i++) { channelEnables[i] = false; } HTM.SetLightTrigTime((int)devIndex, 0); HtmDllManager.OpendDevCount--; if (HtmDllManager.OpendDevCount == 0) { HTM.Discard(); } } IsDeviceOpen = false; return((int)ErrorDef.Success); } }
/// <summary>设置通道触发时长</summary> public int SetTrigChannelDuration(int channel, int duration) { if (channel < 0 || channel >= TrigChannelCount) { throw new ArgumentOutOfRangeException("GetTrigChannelDuration(channel ,...) failed By:channel = " + channel + " is out of range 0~" + (TrigChannelCount - 1)); } if (duration < 0) { return((int)ErrorDef.ParamError); } lock (asynLocker) { if (!IsDeviceOpen) { return((int)ErrorDef.NotOpen); } int opt = HTM.SetLightTrigTime((int)devIndex, duration); if (0 == opt) { trigDuration = duration; return((int)ErrorDef.Success); } return((int)ErrorDef.InvokeFailed); } }
/// <summary>设置所有通道触发时长</summary> public int SetTrigDuration(int duration) { if (duration < 0) { return((int)ErrorDef.ParamError); } lock (asynLocker) { if (!IsDeviceOpen) { return((int)ErrorDef.NotOpen); } int opt = HTM.SetLightTrigTime((int)devIndex, duration); if (0 == opt) { trigDuration = duration; return((int)ErrorDef.Success); } return((int)ErrorDef.InvokeFailed); } }
/// <summary> /// 打开设备 /// </summary> public int OpenDevice() { lock (asynLocker) { if (!IsInitOK) { return((int)ErrorDef.InitFailedWhenOpen); } if (IsDeviceOpen) { return((int)ErrorDef.Success); } HTM.INIT_PARA initParam = new HTM.INIT_PARA(); initParam.para_file = config_file; initParam.use_aps_card = (byte)(Array.IndexOf(yesnoRange, use_aps_card) == 0?1:0); initParam.use_htnet_card = (byte)(Array.IndexOf(yesnoRange, use_htnet_card) == 0 ? 1 : 0); initParam.offline_mode = (byte)(Array.IndexOf(openModeRange, offline_mode)); initParam.max_axis_num = (ushort)max_axis_num; initParam.max_io_num = (ushort)max_io_num; initParam.max_dev_num = (ushort)max_dev_num; initParam.max_module_num = (ushort)max_module_num; initParam.language = 0; int nErr = 0; lock (HtmDllManager.AsynLocker) { if (HtmDllManager.OpendDevCount == 0) { HTM.Discard(); nErr = HTM.Init(ref initParam); if (nErr < 0) { return((int)ErrorDef.InvokeFailed); } } HtmDllManager.OpendDevCount++;//HtmDllManager.LightTrigOpend++; IsDeviceOpen = true; } nErr = HTM.SetLightTrigSrc((int)devIndex, 0); //关闭所有通道 if (0 != nErr) { throw new Exception("Turn off all channels failed when open HtmLightTrig devIndex = " + devIndex); } for (int i = 0; i < TrigChannelCount; i++) { srcChannels[i] = 0; channelEnables[i] = false; } nErr = HTM.SetLightTrigTime((int)devIndex, 0); if (0 != nErr) { throw new Exception("SetLightTrigTime(devIndex, 0) failed when open HtmLightTrig devIndex = " + devIndex); } trigDuration = 0; IsDeviceOpen = true; return((int)ErrorDef.Success); } }