/// <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); } }
public int OpenDevice() { if (!IsInitOK) { return((int)ErrorDef.InitFailedWhenOpenCard); } 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; lock (HtmDllManager.AsynLocker) { if (0 != HTM.Init(ref initParam)) { HTM.Discard(); int nErr = 0;// HTM.Init(ref initParam); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); nErr = HTM.Init(ref initParam); if (0 == nErr) { break; } } if (nErr < 0) { return((int)ErrorDef.InvokeFailed); } } HtmDllManager.OpendDevCount++; IsDeviceOpen = true; } if (HasAxis()) { McCount = 1; mc.Open(); } else { McCount = 0; } if (HasDio()) { DioCount = 1; dio.Open(); } else { DioCount = 0; } if (HasAio()) { AioCount = 1; aio.Open(); } else { AioCount = 0; } //if (HasCompareTrigger()) //{ // cmpTrig.Open(); // CompareTriggerCount = 1; //} //else // CompareTriggerCount = 0; GenCompareTrigs(); return((int)ErrorDef.Success); }