Beispiel #1
0
        internal void Open()
        {
            if (IsOpen)
            {
                return;
            }
            //devIndexes.Clear();
            trigTables.Clear();
            trigLiners.Clear();
            trigModes.Clear();
            //trigEnables.Clear();
            int err, i, j;

            //int devCount = HTM.GetDeviceNum();
            //for (i = 0; i < devCount; i++)
            //{
            //    HTM.DEVICE_INFO devInfo;
            //    if (0 == HTM.GetDeviceInfo(i, out devInfo))
            //        if (devInfo.devType == (byte)HTM.DeviceType.POSTRIG || devInfo.devType == (int)HTM.DeviceType.HTDHVD)
            //        {
            //            devIndexes.Add(i);
            //        }
            //}
            //if (devIndexes.Count == 0)
            //    return;


            for (i = 0; i < TrigChannels; i++)
            {
                trigTables.Add(new double[2] {
                    0, 0
                });
                if (trigType == TriggerType.PosTrig) //目前只有位置触发板卡支持点表模式
                {
                    for (j = 0; j < 2; j++)
                    {
                        err = HTM.SetPtTrigPos(devIndexes[i], j, trigTables[i][j]);
                        if (err != 0)
                        {
                            throw new Exception(string.Format("HtmCompareTrigger.Open() failed By HTM.SetPtTrigPos(devIndexes = {0},ptIndex = {1},0) return Errorcode = {2}", devIndexes[i], j, err));
                        }
                    }
                    for (j = 0; j < 2; j++)
                    {
                        err = HTM.SetPtTrigEnable(devIndexes[i], j, 0);
                        if (0 != err)
                        {
                            throw new Exception(string.Format("HtmCompareTrigger.Open() failed By HTM.SetPtTrigEnable(devIndexes = {0},j = {1},0) return Errorcode = {2}", devIndexes[i], j, err));
                        }
                    }
                }

                HTM.TRIG_LINEAR tl = new HTM.TRIG_LINEAR()
                {
                    startPos = 0, endPos = 0, interval = 1
                };
                err = HTM.SetLinTrigPos(devIndexes[i], ref tl);
                //if (0 != err)
                // throw new Exception(string.Format("HtmCompareTrigger.Open() failed By HTM.SetLinTrigPos(devIndexes = {0},TRIG_LINEAR =\"0,0,0\") return Errorcode = {1}", devIndexes[i], err));


                err = HTM.SetLinTrigEnable(devIndexes[i], 0);
                //if (0 != err)
                // throw new Exception(string.Format("HtmCompareTrigger.Open() failed By HTM.SetLinTrigEnable(devIndexes = {0},0) return Errorcode = {1}", devIndexes[i], err));


                trigModes.Add(JFCompareTrigMode.disable);

                trigLiners.Add(new JFCompareTrigLinerParam()
                {
                    start = 0, interval = 0, repeats = 0
                });
                //trigEnables.Add(false);
            }
            IsOpen = true;
        }
Beispiel #2
0
        public int SetTrigMode(int encChn, JFCompareTrigMode mode)
        {
            if (!IsOpen)
            {
                return((int)ErrorDef.NotOpen);
            }
            if (encChn < 0 || encChn >= EncoderChannels)
            {
                throw new ArgumentOutOfRangeException("SetTrigMode(encChn ,...) fialed By:encChn = " + encChn + " is outof range:0~" + (EncoderChannels - 1));
            }
            int err = 0;

            if (mode == trigModes[encChn])
            {
                return((int)ErrorDef.Success);
            }

            int ret = (int)ErrorDef.ParamError;

            switch (mode)
            {
            case JFCompareTrigMode.disable:
                err = HTM.SetLinTrigEnable(devIndexes[devIndexes[encChn]], 0);
                if (err != 0)
                {
                    return((int)ErrorDef.InvokeFailed);
                }
                if (trigType == TriggerType.PosTrig)
                {
                    for (int i = 0; i < trigTables[encChn].Length; i++)     //HTM点表触发只支持2个点
                    {
                        err = HTM.SetPtTrigEnable(devIndexes[encChn], i, 0);
                        if (err != 0)
                        {
                            return((int)ErrorDef.InvokeFailed);
                        }
                    }
                }
                ret = (int)ErrorDef.Success;
                trigModes[encChn] = mode;
                break;

            case JFCompareTrigMode.liner:
                err = HTM.SetLinTrigEnable(devIndexes[encChn], 1);
                if (err != 0)
                {
                    ret = (int)ErrorDef.InvokeFailed;
                    break;
                }
                if (trigType == TriggerType.PosTrig)
                {
                    for (int i = 0; i < trigTables[encChn].Length; i++)     //HTM点表触发只支持2个点
                    {
                        err = HTM.SetPtTrigEnable(devIndexes[encChn], i, 0);
                        if (err != 0)
                        {
                            return((int)ErrorDef.InvokeFailed);
                        }
                    }
                }
                ret = (int)ErrorDef.Success;
                trigModes[encChn] = mode;
                break;

            case JFCompareTrigMode.table:
                err = HTM.SetLinTrigEnable(devIndexes[encChn], 0);     //先禁用线性触发
                if (err != 0)
                {
                    return((int)ErrorDef.InvokeFailed);
                }
                //if (trigType == TriggerType.PosTrig)
                {
                    for (int i = 0; i < trigTables[encChn].Length; i++)     //HTM点表触发只支持2个点
                    {
                        err = HTM.SetPtTrigEnable(devIndexes[encChn], i, 1);
                        if (err != 0)
                        {
                            return((int)ErrorDef.InvokeFailed);
                        }
                    }
                }
                ret = (int)ErrorDef.Success;
                trigModes[encChn] = mode;
                break;

            default:
                break;
            }

            return(ret);
        }