Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>设置通道使能状态</summary>
        public int SetTrigChannelEnable(int channel, bool isEnable)
        {
            if (channel < 0 || channel >= TrigChannelCount)
            {
                throw new ArgumentOutOfRangeException("SetTrigChannelEnable(channel ,...) failed By:channel = " + channel + "  is out of range 0~" + (TrigChannelCount - 1));
            }
            lock (asynLocker)
            {
                if (!IsDeviceOpen)
                {
                    return((int)ErrorDef.NotOpen);
                }
                if (isEnable == channelEnables[channel])
                {
                    return((int)ErrorDef.Success);
                }
                int opt = 0;
                if (isEnable)
                {
                    opt = HTM.SetLightTrigSrc((int)devIndex, (HTM.LightTrigSrc)srcChannels[channel]);
                }
                else
                {
                    opt = HTM.SetLightTrigSrc((int)devIndex, HTM.LightTrigSrc.NONE);
                }
                if (0 != opt)
                {
                    return((int)ErrorDef.InvokeFailed);
                }
                channelEnables[channel] = isEnable;

                return((int)ErrorDef.Success);
            }
        }
Ejemplo n.º 3
0
        public int SetTrigChannelSrc(int trigChannel, int srcMask)
        {
            if (trigChannel < 0 || trigChannel >= TrigChannelCount)
            {
                throw new ArgumentOutOfRangeException("SetTrigChannelSrc(channel ,...) failed By:channel = " + trigChannel + "  is out of range 0~" + (TrigChannelCount - 1));
            }

            int sm = srcMask & 0xf;

            if (IsDeviceOpen && channelEnables[trigChannel])
            {
                int opt = HTM.SetLightTrigSrc((int)devIndex, (HTM.LightTrigSrc)sm);
                if (0 != opt)
                {
                    return((int)ErrorDef.InvokeFailed);
                }
            }

            srcChannels[trigChannel] = srcMask & 0xf;
            return((int)ErrorDef.Success);
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }