Example #1
0
        public short ADCmp2Data(short cardId, short chn, short axisxId, short axisyId, int[] x, int[] y, short outType, ushort startLevel, ushort pulseWidthH, ushort pulseWidthL, short threshold)
        {
            // chn = chn++;
            short rtn = -1;

            //设置二维比较模式
            mc.TPosCompareMode mode = new mc.TPosCompareMode()
            {
                mode          = mc.COMPARE_MODE_2D,
                compareSource = mc.RES_PROFILE,
                sourceX       = axisxId,
                sourceY       = axisyId,
                outputMode    = mc.COMPARE_OUT_PULSE,
                pulseWidthH   = pulseWidthH,
                pulseWidthL   = pulseWidthL,
                startLevel    = 0,
                threshold     = 300
            };

            rtn = mc.API_SetPosCompareMode(1, ref mode, 1);
            if (rtn != 0)
            {
                return(rtn);
            }
            mc.API_PosCompareClear(1, 1); //清除位置比较缓存区 channel为通道号
            //压入数据
            short count1 = (short)x.Length;

            mc.TPosCompareData[] data = new mc.TPosCompareData[count1];

            for (int i = 0; i < count1; i++)
            {
                data[i].posX      = -x[i];
                data[i].posY      = -y[i];
                data[i].segmentID = (ushort)i;
                data[i].triValue  = 1;
            }
            rtn = mc.API_SetPosCompareData(1, ref data[0], count1, 1);
            if (rtn != 0)
            {
                return(rtn);
            }
            //启动比较
            rtn = mc.API_PosCompareStart(1, 1);
            return(0);
        }
Example #2
0
 /// <summary>
 /// 设置二维比较输出数据
 /// </summary>
 /// <param name="cardId">卡号</param>
 /// <param name="chn">0,1</param>
 /// <param name="count">比较点数</param>
 /// <param name="x">数据x</param>
 /// <param name="y">数据y</param>
 /// <param name="fifo">0,1</param>
 /// <returns></returns>
 public short Cmp2dData(short cardId, short chn, short count, int[] x, int[] y, short fifo)
 {
     if (x == null || y == null || x.Length == 0 || y.Length == 0 || x.Length != y.Length ||
         x.Length < count || y.Length < count)
     {
         return(-10);
     }
     mc.TPosCompareData[] data = new mc.TPosCompareData[2048];
     for (int i = 0; i < count; i++)
     {
         data[i].posX      = -x[i];
         data[i].posY      = -y[i];
         data[i].segmentID = (ushort)i;
         data[i].triValue  = 1;
     }
     return(mc.API_SetPosCompareData(1, ref data[0], count, cardId));
 }
Example #3
0
        public short CmpData(short cardId, short axisId, short source, short pulseType, short startLevel, short time, ref int[] buf1, short count1, ref int[] buf2, short count2)
        {
            //清空缓冲区
            short rtn = mc.API_PosCompareClear(1, cardId);

            if (rtn != 0)
            {
                return(rtn);
            }
            //设置一维比较模式
            mc.TPosCompareMode mode = new mc.TPosCompareMode()
            {
                mode          = mc.COMPARE_MODE_1D,
                compareSource = mc.RES_ENCODER,
                sourceX       = axisId,
                sourceY       = mc.RES_NONE,
                outputMode    = pulseType,
                pulseWidthH   = (ushort)time,
                pulseWidthL   = 100,
                startLevel    = (ushort)startLevel,
                threshold     = 10
            };
            rtn = mc.API_SetPosCompareMode(1, ref mode, cardId);
            if (rtn != 0)
            {
                return(rtn);
            }
            //压入数据,只压入X
            mc.TPosCompareData[] data = new mc.TPosCompareData[2048];
            for (int i = 0; i < count1; i++)
            {
                data[i].posX     = -buf1[i];
                data[i].posY     = 0;
                data[i].triValue = 1;
            }
            rtn = mc.API_SetPosCompareData(1, ref data[0], count1, cardId);
            if (rtn != 0)
            {
                return(rtn);
            }
            //启动比较
            return(mc.API_PosCompareStart(1, cardId));
        }