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); }
/// <summary> /// 设置二维比较输出参数 /// </summary> /// <param name="cardId">卡号</param> /// <param name="chn">0,1</param> /// <param name="axisxId">x轴</param> /// <param name="axisyId">y轴</param> /// <param name="src">比较源,0:规划,1:编码器</param> /// <param name="outType">输出方式,0:脉冲,1:电平</param> /// <param name="startLevel">起始电平方式0:位置比较输出引脚电平复位,1:位置比较输出引脚电平取反</param> /// <param name="pulseWidth">脉冲方式脉冲时间,单位微秒</param> /// <param name="maxerr">比较范围最大误差</param> /// <param name="threshold">最优算法阈值</param> /// <returns></returns> public short Cmp2dSetPrm(short cardId, short chn, short axisxId, short axisyId, short src, short outType, short startLevel, short pulseWidth, short maxerr, short threshold) { chn = ++chn; 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 = (ushort)pulseWidth, pulseWidthL = (ushort)pulseWidth, startLevel = (ushort)startLevel, threshold = threshold }; return(mc.API_SetPosCompareMode(chn, ref mode, cardId)); }
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)); }