Attribute VB_Name = "NMC_Lib_Ext"


'/******************************************************************
'
' Moudle Name  :   mtn_lib20_ext.bas
' Abstract     :   GaoChuan Motion 2.0 external user header
' Note :     1.结构体定义中所有的‘reservedxxx’的成员都是保留参数，为保持兼容性，请设置为0
'          2.无特别说明，所有API返回RTN_CMD_SUCCESS（即0值）表示执行成功，其他则表示错误代码
'          3.所有的API参数中，无特别说明，axisHandle表示操作轴的句柄，devHandle表示目标控制器的句柄，crdHandle表示目标坐标系组句柄
' Modification History :
'/******************************************************************


'------------------------------------------------------------------------------------------------------------
'
'           指令分组索引
'
'------------------------------------------------------------------------------------------------------------
'  1.设备高级配置等
'  2.单轴配置读取
'  3.单轴高级指令
'  4.缓冲区高级指令
'  5.硬件捕获及不常用指令
'  6.平台相关指令
'  7.数据采集模块(高级指令)
'  8.激光
'  9.龙门
'  10.通讯扩展等其他
'  11.手轮
'  12.PT
'  13.线性距离位置比较
'  14.二维位置点比较
'  15.多维位置比较输出
'  16.坐标系输出转换
'  17.结构体初始化函数及常见习惯指令
'  18.闭环
'  19.高级BufIo输出配置及控制
'  20.模拟量控制
'  21.scara
'  22.坐标系干涉保护指令
'  23.不常用指令
'  24.自动状态返回
'  25 : 点位自动收发
'  26 : 高速一维位置比较

'------------------------------------------------------------------------------------------------------------
'
'  1.设备高级配置等
'
'------------------------------------------------------------------------------------------------------------

' 设置通讯参数
' devHandle : 设备句柄
' waitTimeInUs：等待时间，微秒
' retryTimes： 通讯重试次数
Public Declare Function NMC_SetCommPara Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal waitTimeInUs As Long, ByVal retryTimes As Long) As Integer

' 板卡打开（根据名称）
' idStr: 板卡ID字符串, 可通过指令写入。pDevHandle: 返回设备操作句柄
' 注：ID号用户可写入，掉电不丢失，可用于区分板卡。出厂板卡号ID号为0
Public Declare Function NMC_DevOpenByID Lib "nmc_lib20.dll" (ByRef idStr As String, ByRef pDevHandle As Integer) As Integer

' 板卡打开（根据IP地址）
' pIPv4Array: 板卡IP地址,四个字节,例如：unsinged char ipv4[4] = {192,168,1,110};
' pDevHandle: 返回设备操作句柄
Public Declare Function NMC_DevOpenByIP Lib "nmc_lib20.dll" (ByRef pIPv4Array As String, ByRef pDevHandle As Integer) As Integer


#If 0 Then
' 修改板卡ID号
' idStr: 要写入的板卡ID字符串，最长16字节，以\0结尾
' 注：修改ID号完成后，板卡要掉电重启，新的ID才有效。
Public Declare Function NMC_DevWriteID Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal idStr As String) As Integer

' 读取板卡ID号
' idStr: 存储字符串的数组，数组长度大于16字节
Public Declare Function NMC_DevReadID Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef idStr As Byte) As Integer
#Else
' 修改板卡ID号
' idStr: 要写入的板卡ID字符串，最长16字节，以\0结尾
' 注：修改ID号完成后，板卡要掉电重启，新的ID才有效。
Public Declare Function NMC_DevWriteID Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal idStr As String) As Integer

' 读取板卡ID号
' idStr: 存储字符串的数组，数组长度大于16字节
Public Declare Function NMC_DevReadID Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal idStr As String) As Integer
#End If

' 读取库的版本
' pVersion：接收版本信息
' example(VB):
'          Dim dllVersion(127) As Byte
'          NMC_GetDllVersion(dllVersion)
Public Declare Function NMC_GetDllVersion Lib "nmc_lib20.dll" (ByRef pVersion As Byte) As Integer

' 运动控制器信息结构
Public Type TCardInfo
        strVer As String * 16             ' 控制器版本号
        strOemVer As String * 16          ' OEM版本号(定制控制器才有)，默认为0
        year As Integer                   ' 时间，年月日，时分秒
        month As Integer
        day As Integer
        hour As Integer
        minute As Integer
        second As Integer
        axisNum As Integer                ' 支持的轴数
        encNum As Integer                 ' 支持的编码器数
        diNum As Integer                  ' 数字输入数量
        doNum As Integer                  ' 数字输出数量
        daNum As Integer                  ' 模拟量通道
        adNum As Integer                  ' 模拟量输入通道
        hsioNum As Integer                ' 高速IO通道
        reserved As Integer               ' 保留
        ipv4(3) As Byte                   ' IP地址
        idStr As String * 16              ' 板卡名称，多卡时可用名称打开参考NMC_DevOpenByID
        uid(3) As Long                    ' 唯一序列号
End Type

' 读取当前运动控制器信息
Public Declare Function NMC_GetCardInfo Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pInfo As TCardInfo) As Integer

' 启动指令调试
' enable: 0 关闭调试信息，默认关闭 ,1 打印到文件
' debugOutputFile: 调试输出文件
Public Declare Function NMC_SetCmdDebug Lib "nmc_lib20.dll" (ByVal enable As Integer, ByVal debugOutputFile As String) As Integer

' 获取错误代码信息
' errCode:错误代码
' errDesc:返回的错误代码描述
Public Declare Function NMC_GetErrDesc Lib "nmc_lib20.dll" (ByVal errCode As Integer, ByVal errDesc As String) As Integer

'固件版本
Public Type MtLibVersion
    strVer As String * 16
    strOemVer As String * 16
    strBuild As String * 32
End Type
' 读取当前运动控制器固件的版本等信息
' devHandle : 设备句柄
' pVersion：版本信息
Public Declare Function NMC_GetMtLibVersion Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pVersion As MtLibVersion) As Integer

' 加载配置文件
Public Declare Function NMC_LoadConfigFromFile Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pFilePath As String) As Integer

' 保存为配置文件
Public Declare Function NMC_SaveConfigToFile Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pFilePath As String) As Integer

' 保存基本的配置信息,将这些信息保存到系统参数区,控制器重启或者NMC_DevReset后,系统将使用这些参数
' 保存的参数包括报警、限位、脉冲方式、编码器方式、安全参数、滤波参数
' enable:1表示保存当前配置,并使能自动加载参数功能,0：表示关闭自动加载参数功能
Public Declare Function NMC_SaveMotionConfig Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal enable As Integer) As Integer

' 获取平台版本号
Public Declare Function NMC_GetVersion Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef verArray As String) As Integer

' 获取控制器功能信息 example : char flags[1024];NMC_DevGetMcInfoFlag(g_hDev,flags);
Public Declare Function NMC_DevGetMcInfoFlag Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef flags As String) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  2.单轴配置读写
'
'------------------------------------------------------------------------------------------------------------

' 获取轴规划模式
' pMode：返回轴运动模式
Public Declare Function NMC_MtGetPrfMode Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pMode As Integer) As Integer



' 获取目标运动速度
' vel: 目标速度（最大速度），单位是 脉冲/ms
Public Declare Function NMC_MtGetVel Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pVel As Double) As Integer

' 获取运动目标位置
' pos: 目标位置，单位是 脉冲
Public Declare Function NMC_MtGetPtpTgtPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pPos As Long) As Integer

' 读编码器通道位置
' devHandle : 控制器句柄；encId: 编码器ID,取值范围[0,n]
' pos:返回编码器数值
Public Declare Function NMC_GetEncPos Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal encId As Integer, ByRef pos As Long) As Integer

' 写编码器通道位置
' devHandle : 控制器句柄
' encId: 编码器ID,取值范围[0,n]
' encPos:编码器数值
Public Declare Function NMC_SetEncPos Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal encId As Integer, ByVal encPos As Long) As Integer

' 设置允许的位置误差，当位置误差超过设定值时，电机停止运动，提示位置误差超限
' posErr为0表示不检查
Public Declare Function NMC_MtSetPosErrLmt Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal posErr As Long) As Integer

' 读取允许的位置误差设定值
Public Declare Function NMC_MtGetPosErrLmt Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pPosErr As Long) As Integer

' 读取编码器模式
' encId: 编码器ID,取值范围[0,n]
' encMode:返回编码器模式，参考宏定义
Public Declare Function NMC_GetEncMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal encId As Integer, ByRef encMode As Integer) As Integer

' 读取限位开关输入是否停止运动
' posEn：正向限位触发允许设置，1为允许，0为禁止
' negEn: 负向限位触发允许设置
Public Declare Function NMC_MtGetLmtOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef posSwt As Integer, ByRef negSwt As Integer) As Integer

' 读取限位开关触发电平
' posSwt：正向限位触发电平设置，1为高电平触发，0为低电平触发
' negSwt: 负向限位触发电平设置
Public Declare Function NMC_MtGetLmtSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef posSwt As Integer, ByRef negSwt As Integer) As Integer

' 读取伺服报警开关是否停止运动
' swt：伺服报警开关输入允许设置，1为允许，0为禁止。（默认为高电平触发）
Public Declare Function NMC_MtGetAlarmOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef swt As Integer) As Integer

' 读取伺服报警开关电平
' swt：伺服报警触发电平设置，1为高电平触发，0为低电平触发
Public Declare Function NMC_MtGetAlarmSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef swt As Integer) As Integer

' 读取软件限位是否停止运动
' enable：软件限位触发允许设置，1为允许，0为禁止
Public Declare Function NMC_MtGetSwLmtOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef enable As Integer) As Integer

' 读取软件限位数值
' posLmt：正向软件限位设置值
' negLmt：负向软件限位设置值。单位为脉冲数
Public Declare Function NMC_MtGetSwLmtValue Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef posLmt As Long, ByRef negLmt As Long) As Integer



' 读取脉冲输出模式
' inv, 脉冲输出方向取反， 1：取反，0：不取反
' mode 0：脉冲方向 1：正负脉冲
Public Declare Function NMC_MtGetStepMode Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef inv As Integer, ByRef mode As Integer) As Integer

' 读取轴速度滤波参数
Public Declare Function NMC_MtGetAxisVelFilter Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pFilterCoef As Integer) As Integer



'------------------------------------------------------------------------------------------------------------
'
'  3.单轴高级指令
'
'------------------------------------------------------------------------------------------------------------

' 读取机械坐标的位置
' pos : 返回位置，单位是 脉冲
Public Declare Function NMC_MtGetAxisPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pos As Long) As Integer

' 读当前指令位置（发送到执行器的位置）
' pos : 返回位置，单位是 脉冲
Public Declare Function NMC_MtGetCmdPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pos As Long) As Integer

' 设定机械位置, 轴静止时执行，如果后面是update指令，需要延时一个周期
' axisPos: 设定实际位置值
' 注：只能在轴静止时使用。
Public Declare Function NMC_MtSetAxisPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal axisPos As Long) As Integer

' 设定编码器位置, 轴静止时执行，如果后面是update指令，需要延时一个周期
' encPos: 设定的编码器位置值
' 注：只能在轴静止时使用。
Public Declare Function NMC_MtSetEncPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal encPos As Long) As Integer

' 设置单轴规划高级参数
' axisHandle : 轴句柄
' mapAxisNo：轴号，取值范围[0,n]
' pCrdHandle：坐标系组句柄
Public Declare Function NMC_MtPrfConfig Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal mapAxisNo As Integer, ByVal port As Integer, ByVal startPos As Long) As Integer

' 读取单轴规划高级参数
Public Declare Function NMC_MtGetPrfConfig Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef mapAxisNo As Integer, ByRef port As Integer, ByRef startPos As Long) As Integer

' 设置单轴比例系数，默认为1
' axisHandle : 轴句柄
' inCoe：单轴比例系数，取值范围(0,1]
Public Declare Function NMC_MtSetPrfCoe Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal inCoe As Double) As Integer

' 读取单轴比例系数
' axisHandle : 轴句柄
' pInCoe：单轴比例系数，取值范围(0,1]
Public Declare Function NMC_MtGetPrfCoe Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pInCoe As Double) As Integer

' 设置轴通道编码器的系数，默认为1
' axisHandle : 轴句柄
' encCoe：单轴通道编码器比例系数，取值范围(0,1]
Public Declare Function NMC_MtSetEncCoe Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal encCoe As Double) As Integer

' 读取轴通道编码器的系数
' axisHandle : 轴句柄
' pEncCoe：比例系数，取值范围(0,1]
Public Declare Function NMC_MtGetEncCoe Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef encCoe As Double) As Integer

' 设置轴的到位误差参数
' axisHandle : 轴句柄
' arrivalBand: 到位误差,单位Pulse 取值大于0
' stableTime: 到位保持时间,单位 ms 取值大于0
Public Declare Function NMC_MtSetAxisArrivalPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal arrivalBand As Long, ByVal stableTime As Long) As Integer

' 获取轴的到位误差参数
' axisHandle : 轴句柄
' pArrivalBand:到位误差,单位Pulse
' pStableTime：到位保持时间,单位 ms
Public Declare Function NMC_MtGetAxisArrivalPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pArrivalBand As Long, ByRef pStableTime As Long) As Integer

' 设置螺距误差补偿参数
' num：补偿的段数,取值范围[2,128]
' startPos：补偿起始位置，终止位置为 startPos + cmpLen
' cmpLen:补偿长度
' pCompPos:正向补偿值
' pCompNeg:负向补偿值
Public Declare Function NMC_MtSetLeadScrewCompPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal num As Integer, ByVal startPos As Long, ByVal cmpLen As Long, ByRef pCompPos As Integer, ByRef pCompNeg As Integer) As Integer

' 使能或禁止螺距位置补偿
Public Declare Function NMC_MtEnableLeadScrew Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal enable As Integer) As Integer

' 设置反向间隙补偿
' compValue： 补偿量
' compDelta： 周期补偿量，比如补偿量为100，周期补偿量为10，则反向补偿会在10个规划周期完成100个脉冲的补偿
' compDir：      补偿方向,0:正向补偿，1：负向补偿
Public Declare Function NMC_MtSetBacklash Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal compValue As Long, ByVal compDelta As Double, ByVal compDir As Long) As Integer

' 获取反向间隙补偿
Public Declare Function NMC_MtGetBacklash Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef compValue As Long, ByRef compDelta As Double, ByRef compDir As Long) As Integer

' 设置单轴急停DI
' gpiIndex：通用输入序号,[0,]，设置为-1，则表示取消急停DI
' sense :触发电平,0：低电平,1：高电平
Public Declare Function NMC_MtSetEstopDI Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal gpiIndex As Integer, ByVal sense As Integer) As Integer

' 读取单轴急停DI
' gpiIndex：通用输入序号,[0,]
' sense :触发电平,0：低电平,1：高电平
Public Declare Function NMC_MtGetEstopDI Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef gpiIndex As Integer, ByRef sense As Integer) As Integer

' 高级捕获通道数目
Public Const CAPT_EX_CH_NUM As Integer = 6

' 捕获源
Public Const CAPT_EX_SRC_GPI As Integer = 0   ' 通用输入
Public Const CAPT_EX_SRC_NEGLMT As Integer = 1   ' 负向限位
Public Const CAPT_EX_SRC_POSLMT As Integer = 2   ' 正向限位
Public Const CAPT_EX_SRC_HOME As Integer = 3   ' 原点
Public Const CAPT_EX_SRC_Z As Integer = 4   ' Z向信号
Public Const CAPT_EX_SRC_PRFPOS As Integer = 5   ' 规划位置（当规划位置达到设定值时触发）
Public Const CAPT_EX_SRC_ENCPOS As Integer = 6   ' 编码器位置

Public Type TAdvCaptureParam
         capPosIndex As Integer ' 捕获的位置源序号,0~N：轴1~N+1。（默认0）注：捕获的编码器位置根据用户设置的编码器模式决定

         trigSrc As Integer             ' 触发源,见上面的定义。（默认：CAPT_EX_SRC_GPI）
         trigIndex As Integer   ' 触发源序号。（默认0）
         filter As Integer              ' 滤波时间常数,单位0.1毫秒,取值范围[0,255]
         trigValue As Long      ' 触发值,对于触发源为IO,表示信号触发的有效电平；对于触发源为位置,则表示触发捕获的位置。（默认0）
End Type

' 设置高级捕获参数,并启动捕获
' pParam:参数
' ch：高级捕获通道号,[0~3]
Public Declare Function NMC_MtSetAdvCaptParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pParam As TAdvCaptureParam, ByVal ch As Integer) As Integer

' 清除高级捕获状态,并取消该通道的捕获
' ch：高级捕获通道号,[0~3]
Public Declare Function NMC_MtClrAdvCaptSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer) As Integer

' 读取高级捕获状态
' captSts:捕获状态,bit0表示设置的信号前沿触发到,bit1表示信号的后沿触发到。
' pPosArray : 返回位置,在触发到时,位置为捕获到的位置值。
' pPosArray[0]:信号前沿触发位置,pPosArray[1]:信号后沿触发位置,单位:脉冲
Public Declare Function NMC_MtGetAdvCaptPos Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef captSts As Integer, ByRef pPosArray As Long, ByVal ch As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  4.缓冲区高级指令
'
'------------------------------------------------------------------------------------------------------------

' 坐标系运动扩展参数
Public Type TExtCrdPara
        startVel As Double           ' 起跳速度（默认0）
        T As Double                  ' 前瞻时间常数 (默认1)
        smoothDec As Double          ' 停止减速度（默认accMax）
        abruptDec As Double          ' 急停减速度（默认无穷大）
        lookAheadSwitch As Integer   ' 前瞻启动开关 (默认有前瞻)
        eventTime As Integer         ' 最小匀速时间 单位ms
        reserved(1) As Integer       ' 保留
End Type

' 设置坐标系扩展参数
' extCrdPara:坐标系扩展参数
Public Declare Function NMC_CrdSetExtPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef refExtCrdPara As TExtCrdPara) As Integer

' 读取坐标系扩展参数
' extCrdPara:坐标系扩展参数
Public Declare Function NMC_CrdGetExtPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pExtCrdPara As TExtCrdPara) As Integer

' 设置坐标系运动缓冲区是否启用，默认为启用状态
' enFlag:启用，1：启动，0：不启用
Public Declare Function NMC_EnableCrdSdram Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal enFlag As Integer) As Integer

'圆弧插补参数配置（高级指令）
Public Const MAX_ERR_TABLE_SECTION As Integer = 2
Public Type TArcSecSetting
        minSectionLen As Double                      ' 分解的最小段长,默认1脉冲,范围[1,10000]
        maxArcDiff As Double                         ' 最大圆弧有效性误差，单位脉冲
' 圆弧插补误差配置表
' 注意：MTN通过限制圆弧插补速度，从而保证插补误差。r全部为0，则表示关闭这个功能
        r(MAX_ERR_TABLE_SECTION) As Double           ' 半径
        err(MAX_ERR_TABLE_SECTION + 1) As Double     ' 半径对应的插补误差，半径 [0,r0],对应err0;半径 [r0,r1],对应err1;[r1,+max],对应err2
End Type

' 设置圆弧插补参数（高级指令）
' pSetting : 设置
Public Declare Function NMC_CrdSetArcSecPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pSetting As TArcSecSetting) As Integer

' 读圆弧插补参数（高级指令）
Public Declare Function NMC_CrdGetArcSecPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pSetting As TArcSecSetting) As Integer

' 坐标系运动参数
Public Type TCrdPara
        orgFlag As Integer           ' 是否自定义坐标系原点 , 0 不指定 ，1 指定
        dummy(2) As Integer          ' 保留
        offset(3) As Long            ' 自定义坐标系原点偏置（基于机械原点
        synAccMax As Double          ' 最大合成加速度
        synVelMax As Double          ' 最大合成速度
End Type

' 设置坐标系参数
' crdPara:坐标系参数
Public Declare Function NMC_CrdSetPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef refCrdPara As TCrdPara) As Integer

' 获取坐标系参数
' crdPara:坐标系参数
Public Declare Function NMC_CrdGetPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pCrdPara As TCrdPara) As Integer



' 获取坐标系速度倍率
' pOverRide：坐标系速度倍率
Public Declare Function NMC_CrdGetOverRide Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pOverRide As Double) As Integer

' 坐标系状态字位定义:内部扩展
Public Const BIT_CORD_POSREC As Integer = &H40    ' bit 6 , 伺服位置到达，步进模式时位置到达，伺服模式时实际位置到达误差限
Public Const BIT_CORD_AUXAXIS_BUSY As Integer = &H80    ' bit 7 , 坐标系运动中的关联轴启动前处于运动状态错误
Public Const BIT_CORD_AUXAXIS_ERR As Integer = &H100   ' bit 8 , 插补辅助轴错误
Public Const BIT_CORD_AXIS_ERR As Integer = &H200   ' bit 9 , 插补轴存在报警错误（如限位、驱动报警）
Public Const BIT_CORD_SDRAM_CALC_ERR As Integer = &H400   ' bit 10 , SDRAM缓冲区计算错误

' 读取内部坐标系状态
' pStsWord：返回状态字，定义64bits(二维的long数组)，便于后续扩展状态位
Public Declare Function NMC_CrdGetInnerSts Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pStsWord As Long) As Integer

' 直接修改坐标系偏移
' pOffsetArray:坐标系偏移
' cnt:数组长度
Public Declare Function NMC_CrdModifyOffset Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pOffsetArray As Long, ByVal cnt As Integer) As Integer

' 缓冲区设置急停DI
' axis:轴号,取值范围[0,n)
' gpiIndex:通用输入序号
' sense:触发电平
Public Declare Function NMC_CrdBufSetEstopDI Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axis As Integer, ByVal gpiIndex As Integer, ByVal sense As Integer) As Integer

' 缓冲区数据打包
Public Const BUF_LINE As Integer = 0       '缓冲区直线插补
Public Const BUF_DO      As Integer = 1    '缓冲区DO输出
Public Const BUF_OUT     As Integer = 2    '缓冲区OUT输出
Public Const BUF_DELAY As Integer = 3  '缓冲区延时
Public Const BUF_AXMOVE  As Integer = 4 '缓冲区单轴运动
Public Const BUF_DOEX As Integer = 5   '缓冲区DO输出（根据掩码输出）
Public Const BUF_ARC_R As Integer = 6  '平面圆弧插补：终点位置、半径、方向
Public Const BUF_ARC_C  As Integer = 7 '平面圆弧插补：终点位置、圆心、方向
Public Const BUF_LASER_SETPOWER As Integer = 8           ' 激光：设置能量
Public Const BUF_LASER_ONOFF    As Integer = 9                   ' 激光：缓冲区开关光
Public Const BUF_LASER_SETFOLLOW        As Integer = 10          ' 激光：设置跟随
Public Const BUF_LASER_SETPARAM As Integer = 11          ' 激光：设置参数
Public Const BUF_LINEXYZA               As Integer = 12          ' 缓冲区四轴直线插补
Public Const BUF_SHIO_GATEPULSE As Integer = 13          ' 缓冲区输出Gate脉冲
Public Const BUF_DOBITPULSE             As Integer = 14          ' DoBitPulse功能
Public Const BUF_XYZD8          As Integer = 15                  ' LineXYZD8,数据结构体为：TCrdLineXYZD8Unit
Public Const BUF_SHIOMINFRQ     As Integer = 16                  ' 设置或清除SHIO最小频率
Public Const BUF_SHIOSETPARAM    As Integer = 17         ' 设置SHIO参数
Public Const BUF_SHIOGATEONOFF   As Integer = 18         ' 设置Gate开关
Public Const BUF_WAITENCINPOS    As Integer = 19         ' 等待电机到位
Public Const BUF_WAITDI          As Integer = 20         ' 等待DI

Public Type TCrdBufLine
         segNo As Long       ' 用户自定义段号
         tgPos(3) As Long      ' 目标位置
         endVel As Double     ' 终点速度
         vel As Double        ' 最大速度
         synAcc As Double     ' 插补加速度
         mask As Integer        ' crdAxMask,参与的插补轴,按位表示
         lookaheadDis As Integer '是否使用前瞻
     reserved  As Long    ' 保留
End Type

Public Type TCrdBufLineXYZA
         tgPos(4) As Long     ' 目标位置
         endVel As Double     ' 终点速度
         vel As Double        ' 最大速度
         synAcc As Double     ' 插补加速度
         segNo As Long        ' 用户自定义段号
         mask As Integer        ' crdAxMask,参与的插补轴,按位表示
         lookaheadDis As Integer '是否使用前瞻
End Type

Public Type TCrdBufOut

         segNo As Long      ' 用户自定义段号
         pgroup As Integer    ' Out输出类型
         ch As Integer       ' 通道号,取值范围[0,n]
         outValue As Long       ' 输出
End Type

Public Type TCrdBufDO

         segNo As Long    ' 用户自定义段号
         pgroup As Integer    ' 缓冲区输出DO组
         ch As Integer       ' 位序号,取值范围[0,31]
         value As Long     ' 输出值,取值范围[0,1]
End Type

Public Type TCrdBufDelay

         segNo As Long     ' 用户自定义段号
         scale As Long     ' 延时单位,0表示单位为毫秒,1表示单位为秒
         count As Long     ' 延时时长
End Type

Public Type TCrdBufDOEx

         segNo As Long      ' 用户自定义段号
         pgroup As Long    ' 缓冲区输出DO组
         doMask As Long    ' 输出操作位,bit位为1表示要输出
         value As Long     ' 输出值,bit位指示输出值
End Type

Public Type TCrdBufAxMove

         segNo As Long         ' 用户自定义段号
         axis As Integer                    ' 单轴移动的轴号 [0,n],非坐标系内轴
         soomthCoef As Integer   ' smoothCoef:平滑系数
         blockEn As Integer      ' 是否为阻塞模式 0 不阻塞 ,1 阻塞
         synEn As Integer        ' 是否为同步模式 0 异步 ,1 同步
     gPos As Long           ' 目标位置
         vel As Double          ' 运动速度
         acc As Double        ' 运动加速度
End Type

Public Type TCrdBufArcR

         segNo As Long         ' 用户自定义段号
         tgPos(2) As Long               ' 目标位置
         circleDir As Integer    ' 是否为同步模式 0 异步 ,1 同步
         lookaheadDis As Byte   ' 是否使用前瞻
         panelIndex As Byte     ' 圆弧插补平面：0：XY平面，1：YZ平面，其他：ZX平面
         radius As Double               ' 半径
         endVel As Double      ' 终点速度
         vel As Double         ' 运动速度
         acc As Double         ' 运动加速度
End Type

Public Type TCrdBufArcC

         segNo As Long         ' 用户自定义段号
         tgPos(2) As Long               ' 目标位置
         centerPos(2) As Long   ' 目标位置
         circleDir As Integer    ' 是否为同步模式 0 异步 ,1 同步
         lookaheadDis As Byte   ' 是否使用前瞻
         panelIndex As Byte     ' 圆弧插补平面：0：XY平面，1：YZ平面，其他：ZX平面
         endVel As Double       ' 终点速度
         vel As Double          ' 运动速度
         acc As Double          ' 运动加速度
End Type

Public Type TCrdBufLaserSetParam

         segNo As Long         ' 用户自定义段号
         onDelay As Long     ' 开光延时
         offDelay As Long      ' 关光延时
         minValue As Long      ' 最小输出值
         maxValue As Long      ' 最大输出值
         standbyPower As Long   ' 待机能量
         ch As Integer                  ' 激光控制通道
         reserved As Integer            ' 保留
End Type

Public Type TCrdBufLaserSetFollow

         segNo As Long         ' 用户自定义段号
         followType As Integer     ' 跟随类型
         ch As Integer                  ' 激光通道号
         overRide As Double     ' 跟随倍率
End Type

Public Type TCrdBufLaserOnOff

         segNo As Long        ' 用户自定义段号
         onOff As Integer               ' 开关,0：关光,1：开光
         ch As Integer                  ' 激光通道号
End Type

Public Type TCrdBufLaserSetPower

         segNo As Long        ' 用户自定义段号
         ch As Integer                  ' 激光通道号
         reserved As Integer            ' 保留
         power As Double                ' 能量
End Type

Public Type TCrdBufSHIOGatePulse

         segNo As Long        ' 用户自定义段号
         outCount As Long               ' 输出个数
         gateTime As Double     ' gate输出的脉宽，单位：微秒
         gateFrq As Double      ' gate输出的频率，单位：HZ
         ch As Integer                  ' ch:通道
     reserved(3) As Integer  ' 保留
End Type


Public Type TCrdBufDoBitPulse

         segNo As Long                  ' 用户自定义段号
         highLevelTime As Long  ' 高电平宽度，单位:us
         lowLevelTime As Long   ' 低电平宽度，单位:us
         outCount As Long               ' 输出脉冲个数
         initialLevel As Long   ' 0：先输出低电平，1：先输出高电平
         ch As Integer                  ' ch:通道
         enable As Integer              ' 1:使能,0:关闭
         doType As Integer              ' DO类型,默认CRD_BUFF_DO_GPDO1
         doIndex As Integer             ' DO序号，取值范围[0,n]
End Type

Public Type TCrdBufSHIOMinFrq

         segNo As Long                  ' 用户自定义段号
     minFrq As Long         ' 最小频率，仅当enable=1时有效
         ch As Integer                  ' 通道
         setOrClr As Integer            ' 1:设置,0:清除
End Type

Public Type TCrdBufSHIOSetParam

         segNo As Long                  ' 用户自定义段号
         ch As Integer                  ' 通道
         reserved As Integer            ' 保留
     delay As Double       ' 延时开关光时间
     gateTime As Double    ' gate打开时间，单位:秒
     gateDistance As Double ' 固定模式下的位置间隔，单位pulse
End Type

Public Type TCrdBufSHIOGateOnOff

         segNo As Long                          ' 用户自定义段号
         ch As Integer                  ' 通道
         onOff As Integer               ' 1:打开，0：关闭
End Type

Public Type TCrdBufWaitEncInPosition

         segNo As Long                  ' 用户自定义段号
         axisMask As Long               ' 轴掩码
         overTime As Long               ' 等待超时时间，单位：毫秒
End Type

Public Type TCrdBufWaitDI

         segNo As Long                  ' 用户自定义段号
         index As Integer               ' 通道号,取值范围[0,127],前64通道代表通用DI，后64通道代表扩展IO
         level As Integer               ' 等待值
     waitLastTime As Long  '超时,单位：毫秒
End Type



' 打包插补数据
' pBufData 插补数据结构存储数组
' dataLen 数据长度
' 压入数据时，先压入指令字，然后再压入指令字对应的工作数据，总的数据长度不超过1000个字节
Public Declare Function NMC_CrdBufDataPack Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pBufData As String, ByVal dataLen As Integer) As Integer

'功能：缓冲区探位置停止并后续加位置偏置
' useCaptPos：是否使用捕获位置  1使用,0不使用
' axis:轴序号
' sense:触发电平,0：低电平,1：高电平
' gpiIndex:通用输入序号
Public Declare Function NMC_CrdBufSetStopOffset Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axis As Integer, ByVal gpiIndex As Integer, ByVal sense As Integer, ByVal useCaptPos As Integer) As Integer

'功能：解除缓冲区探位置停止并后续加位置偏置
Public Declare Function NMC_CrdBufClrStopOffset Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axis As Integer) As Integer

' 设置是否计算所有线段长度
Public Declare Function NMC_CrdSetBufLengthFlag Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal flag As Integer) As Integer

' 读取插补线段长度
Public Declare Function NMC_CrdGetBufLength Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pLen As Double) As Integer

Public Declare Function NMC_CrdSetIsShortLine Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal isShortLine As Integer) As Integer

Public Declare Function NMC_CrdSetLookAheadCentriAcc Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal isUsingSetAcc As Integer, ByVal centriAcc As Double) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  5.硬件捕获及不常用指令
'
'------------------------------------------------------------------------------------------------------------

' 编码器硬件捕获模式选择
Public Const CAPT_MODE_Z                 As Integer = 0             ' 编码器Z相捕获
Public Const CAPT_MODE_IO                As Integer = 1             ' IO 捕获
Public Const CAPT_MODE_Z_AND_IO          As Integer = 2             ' IO+Z相 捕获
Public Const CAPT_MODE_Z_AFT_IO          As Integer = 3             ' 先IO触发再Z相触发 捕获

' 编码器硬件捕获IO源选择
Public Const CAPT_IO_SRC_HOME            As Integer = 0             ' 原点输入作为捕获IO
Public Const CAPT_IO_SRC_LMTN            As Integer = 1             ' 负向限位输入作为捕获IO
Public Const CAPT_IO_SRC_LMTP            As Integer = 2             ' 正向限位输入作为捕获IO
Public Const CAPT_IO_SRC_DI0             As Integer = 3             ' 通用数字输入0作为捕获IO
Public Const CAPT_IO_SRC_DI1             As Integer = 4             ' 通用数字输入1作为捕获IO
Public Const CAPT_IO_SRC_DI2             As Integer = 5             ' 通用数字输入2作为捕获IO
Public Const CAPT_IO_SRC_DI3             As Integer = 6             ' 通用数字输入3作为捕获IO
Public Const CAPT_IO_SRC_DI4             As Integer = 7             ' 通用数字输入4作为捕获IO
Public Const CAPT_IO_SRC_DI5             As Integer = 8             ' 通用数字输入5作为捕获IO
Public Const CAPT_IO_SRC_DI6             As Integer = 9             ' 通用数字输入6作为捕获IO
Public Const CAPT_IO_SRC_DI7             As Integer = 10            ' 通用数字输入7作为捕获IO
Public Const CAPT_IO_SRC_DI8             As Integer = 11            ' 通用数字输入8作为捕获IO
Public Const CAPT_IO_SRC_DI9             As Integer = 12            ' 通用数字输入9作为捕获IO
Public Const CAPT_IO_SRC_DI10            As Integer = 13            ' 通用数字输入10作为捕获IO
Public Const CAPT_IO_SRC_DI11            As Integer = 14            ' 通用数字输入11作为捕获IO
Public Const CAPT_IO_SRC_DI12            As Integer = 15            ' 通用数字输入12作为捕获IO

' 设置捕获有效电平
' mode : 模式选择，参考宏定义
' ioSrc：IO输入源选择，参考宏定义
' level: 触发沿。0为下降沿，1为上升沿
Public Declare Function NMC_MtSetCaptSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal mode As Integer, ByVal ioSrc As Integer, ByVal level As Integer) As Integer

' 读取捕获有效电平
' mode : 模式选择，参考宏定义
' ioSrc：IO输入源选择，参考宏定义
' level: 触发沿。0为下降沿，1为上升沿
Public Declare Function NMC_MtGetCaptSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef mode As Integer, ByRef ioSrc As Integer, ByRef level As Integer) As Integer

' 设置启动捕获
' 注：捕获触发标志在轴状态字里。
Public Declare Function NMC_MtSetCapt Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 清除轴的捕获状态
Public Declare Function NMC_MtClrCaptSts Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 读捕获位置
' pos : 返回位置，单位:脉冲
Public Declare Function NMC_MtGetCaptPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pos As Long) As Integer

' 读取脉冲输出滤波
' pCoe系数： 范围0~65535,0不滤波,数值越大滤波效果越明显。默认值为0
Public Declare Function NMC_MtGetStepFilter Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pCoe As Integer) As Integer

' 多轴同时启动
' axisHandle:任意轴
' axisMask：按bit对应相应轴号,bit为1表示启动,bit为0表示不启动
Public Declare Function NMC_MtUpdateMulti Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal axisMask As Long) As Integer

' 多轴同时停止
' axisHandle:任意轴
' axisMask：按bit对应相应轴号,bit为1表示启动,bit为0表示不启动
Public Declare Function NMC_MtStopMulti Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal axisMask As Long) As Integer

' 按位设置通用输入信号取反
' bitIndex:取值范围[0,n],位序号,前64位为本地的通用输入,大于64为扩展Di
' revs:是否取反,1：取反,0：不取反
Public Declare Function NMC_SetDIBitRevs Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByVal revs As Integer) As Integer

' 按位读取通用输入信号取反
' bitIndex:取值范围[0,n],位序号,前64位为本地的通用输入,大于64为扩展Di
' pRevs:是否取反,1：取反,0：不取反
Public Declare Function NMC_GetDIBitRevs Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByRef pRevs As Integer) As Integer

' 按位设置通用输出信号取反
' bitIndex:取值范围[0,n],位序号,前64位为本地的通用输出,大于64为扩展Do
' revs:是否取反,1：取反,0：不取反
Public Declare Function NMC_SetDOBitRevs Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByVal revs As Integer) As Integer

' 按位读取通用输出信号取反
' bitIndex:取值范围[0,n],位序号,前64位为本地的通用输出,大于64为扩展Do
' pRevs:是否取反,1：取反,0：不取反
Public Declare Function NMC_GetDOBitRevs Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByRef pRevs As Integer) As Integer

' DO输出定时脉冲
' bitIndex:取值范围[0,n],位序号,前64位为本地的通用输出,大于64为扩展Do
' value:设置通用数字量输出。1, 输出高电平,0,输出低电平
' reverseTime:持续的电平,单位:毫秒
Public Declare Function NMC_SetDOBitAutoReverse Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByVal value As Integer, ByVal reverseTime As Integer) As Integer

' DIO映射
Public Const DIO_MAP_MAX_NUM As Integer = 8   ' 最多允许的映射关系

' 信号类型定义
Public Const DIO_TYPE_GPI As Integer = 1   ' 通用输入
Public Const DIO_TYPE_HOME As Integer = 2   ' 轴Home信号
Public Const DIO_TYPE_ALM As Integer = 3   ' 驱动器报警信号
Public Const DIO_TYPE_LMTN As Integer = 4   ' 轴负向限位信号
Public Const DIO_TYPE_LMTP As Integer = 5   ' 轴正向限位信号
Public Const DIO_TYPE_GPO As Integer = 6   ' 通用输出信号
Public Const DIO_TYPE_SVON As Integer = 7   ' 伺服使能信号
Public Const DIO_TYPE_SVCLR As Integer = 8   ' 报警清除信号


' DIo映射参数配置
Public Type TDioMappingCfg

           enable As Byte               ' 1：启用，0：禁用
           pinGrp As Byte           ' 映射的信号类型
           pinIndex As Byte         ' 映射的信号序号
           outEnable As Byte        ' 输出允许
           newGrp As Byte           ' 映射到的信号类型
           newIndex As Byte              ' 映射到的信号序号
End Type

' 增加一组映射，映射关系目前最多存在DIO_MAP_MAX_NUM组
Public Declare Function NMC_SetDioMapping Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pDioCfg As TDioMappingCfg) As Integer

' 获取所有的DIO映射数据
' pDioCfg：映射数据数组,目前为DIO_MAP_MAX_NUM组
Public Declare Function NMC_GetAllDioMapping Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pDioCfg As TDioMappingCfg) As Integer

' 清除所有的DIO映射关系
Public Declare Function NMC_ClrAllDioMapping Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


'------------------------------------------------------------------------------------------------------------
'
'  6.平台相关指令
'
'------------------------------------------------------------------------------------------------------------

' 通用可寻址变量宏定义
Public Const VAR_PWM0_CTL    As Integer = 256   ' pwm通道0打开关闭，1表示打开，0表示关闭
Public Const VAR_PWM0_VALUE  As Integer = 257   ' pwm通道0输出值
Public Const VAR_PWM1_CTL    As Integer = 258   ' pwm通道1打开关闭，1表示打开，0表示关闭
Public Const VAR_PWM1_VALUE  As Integer = 259   ' pwm通道1输出值
Public Const VAR_EXT_DAC0    As Integer = 260   ' 扩展的DAC通道0
Public Const VAR_EXT_DAC1    As Integer = 261   ' 扩展的DAC通道1
Public Const VAR_OUT_OPTION  As Integer = 262   ' PWM输出通道选项
Public Const VAR_DAC0        As Integer = 263   ' DAC通道0~7
Public Const VAR_DAC1        As Integer = 264
Public Const VAR_DAC2        As Integer = 265
Public Const VAR_DAC3        As Integer = 266
Public Const VAR_DAC4        As Integer = 267
Public Const VAR_DAC5        As Integer = 268
Public Const VAR_DAC6        As Integer = 269
Public Const VAR_DAC7        As Integer = 270
Public Const VAR_ADC0        As Integer = 271   ' ADC通道0~7
Public Const VAR_ADC1        As Integer = 272
Public Const VAR_ADC2        As Integer = 273
Public Const VAR_ADC3        As Integer = 274
Public Const VAR_ADC4        As Integer = 275
Public Const VAR_ADC5        As Integer = 276
Public Const VAR_ADC6        As Integer = 277
Public Const VAR_ADC7        As Integer = 278

' 设置通用可寻址变量
' varID:变量ID
' value:设置值
Public Declare Function NMC_SetVar8B Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal varID As Long, ByVal value As Double) As Integer

' 读取通用可寻址变量
' varID:变量ID
' pValue:变量当前值
Public Declare Function NMC_GetVar8B Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal varID As Long, ByRef pValue As Double) As Integer

' 通用可寻址系统变量宏定义
Public Const SYS_VAR_SET_STAT_ENABLE   As Integer = 100
Public Const SYS_VAR_GET_CLOCK         As Integer = 101
Public Const SYS_VAR_GET_USERAPP_COUNT As Integer = 107
Public Const SYS_VAR_GET_USERAPP_MIN   As Integer = 108
Public Const SYS_VAR_GET_USERAPP_MAX   As Integer = 109
Public Const SYS_VAR_GET_USERAPP_AVG   As Integer = 110
Public Const SYS_VAR_GET_USERAPP_CURT  As Integer = 111
Public Const SYS_VAR_GET_PRFINT_COUNT  As Integer = 112
Public Const SYS_VAR_GET_PRFINT_MIN    As Integer = 113
Public Const SYS_VAR_GET_PRFINT_MAX    As Integer = 114
Public Const SYS_VAR_GET_PRFINT_AVG    As Integer = 115
Public Const SYS_VAR_GET_PRFINT_CURT   As Integer = 116
Public Const SYS_VAR_GET_MAINLP_COUNT  As Integer = 117
Public Const SYS_VAR_GET_MAINLP_MIN    As Integer = 118
Public Const SYS_VAR_GET_MAINLP_MAX    As Integer = 119
Public Const SYS_VAR_GET_MAINLP_AVG    As Integer = 120
Public Const SYS_VAR_GET_MAINLP_CURT   As Integer = 121

' 设置通用可寻址系统变量
' varID:变量ID
' value:设置值
Public Declare Function NMC_SysSetVar8B Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal varID As Long, ByVal value As Double) As Integer

' 读取通用可寻址系统变量
' varID:变量ID
' pValue:变量当前值
Public Declare Function NMC_SysGetVar8B Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal varID As Long, ByRef pValue As Double) As Integer

'向备份内存写数据
'src: 要写入的数据
'lenth: 要写入的长度,一次最多1440字节，总长度约1500byte
'off: 要写入的地址(偏移量)
'注：1)写入的数据掉电不丢失。
'     2)一次最多写1440字节。总长度约1500byte。
Public Declare Function NMC_BackSramWrite Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef src As Byte, ByVal lenth As Long, ByVal off As Long) As Integer

'从备份内存读数据
'dst: 读出的数据暂存区
'lenth: 要读出的长度,一次最多1440字节，总长度约1500byte
'off: 读数据的地址(偏移量)
Public Declare Function NMC_BackSramRead Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef dst As Byte, ByVal lenth As Long, ByVal off As Long) As Integer

' 控制器时间结构
Public Type TNMCTime
        year As Integer                ' 年，真实年份。取值范围[2000,2099]
        mon As Integer                 ' 月,取值范围[1,12]
        day As Integer                 ' 日,取值范围[1,31]
        hour As Integer                ' 时,取值范围[0,23]
        min As Integer                 ' 分,取值范围[0,59]
        second As Integer              ' 秒,取值范围[0,59]
End Type

' 读时间
' pTime ：返回时间结构，参考 TNMCTime 结构定义
' 注：时间在出厂时根据实际时间设定，用户不可通过指令修改
Public Declare Function NMC_GetTime Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pTime As TNMCTime) As Integer

'写时间
' pTime ：返回时间结构，参考 TNMCTime 结构定义
' 注：时间在出厂时根据实际时间设定，用户不可通过指令修改
Public Declare Function NMC_SetTime Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pTime As TNMCTime, ByVal pPassword As String) As Integer

'修改控制器系统密码，密码用于修改系统时钟等
' pPasswordOld : 控制器系统当前密码，长度最多为15个字符
' pPasswordNew : 新的控制器系统密码，长度最多为15个字符
' 注意：1.初始出厂无密码
'           2.修改密码后，请务必记住新的密码。忘记密码只能返厂复位。
'           3.密码大小写敏感
Public Declare Function NMC_ChangePassword Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal pPasswordOld As String, ByVal pPasswordNew As String) As Integer

' 验证系统密码
' pPassword : 控制器系统当前密码，长度最多为15个字符
' 返回0表示验证通过，其他表示错误
Public Declare Function NMC_VerifyPassword Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal pPassword As String) As Integer

' 清除系统密码及用户密码
' pData:解密数据，长度为8
Public Declare Function NMC_ClrPassword Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal pData As Integer) As Integer

' 读设备唯一序列号
' pUID ：返回设备唯一序列号，为四个Int32的数据
Public Declare Function NMC_GetUID Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pUID As Long) As Integer

' 写用户参数
' add ：参数区的偏移地址(字节地址)；len : 写入长度；pWrData ：要写入的数据；
' 注：1)写入的数据掉电不丢失。
'     2)一次最多写240字节。参数区总长度为2048字节。
'     3)此指令比其它指令操作时间会长。
Public Declare Function NMC_UserParaWr Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal add As Long, ByVal lenth As Long, ByRef pWrData As Byte) As Integer

' 读用户参数
' add ：参数区的偏移地址；len : 读出的长度；pRdData ：读出数据存储的数组
' 注：一次最多读240字节。参数区总长度为2048字节。（参考函数 ： NMC_UserParaWr）
Public Declare Function NMC_UserParaRd Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal add As Long, ByVal lenth As Long, ByRef pWrData As Byte) As Integer

'  写扩展用户参数
'  add ：参数区的偏移地址(字节地址)
'  len : 写入长度,单位：byte
'  pWrData ：要写入的数据；
'  注：1)写入的数据掉电不丢失。
'      2)一次最多写1000字节。参数区总长度为32K字节。
'      3)此指令比其它指令操作时间会长,如果出现通讯错误（返回-1）,则需要将通过NMC_SetCommPara延长指令通讯时间
Public Declare Function NMC_UserParaWrEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal add As Long, ByVal lenth As Long, ByRef pWrData As Byte) As Integer

'  读扩展用户参数
'  add ：参数区的偏移地址(字节地址)
'  len : 写入长度,单位：byte
'  pRdData ：要读取的数据存储
'  注：一次最多读1000字节。参数区总长度为32K字节。（参考函数 ： NMC_UserParaWr）
Public Declare Function NMC_UserParaRdEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal add As Long, ByVal lenth As Long, ByRef pRdData As Byte) As Integer

'  掉电保存：备份数据定义
Public Type TBackGroup1
         crdSegNo As Long                        ' 坐标系运动的段号
         crdPrfPos(3) As Long                    ' 坐标系运动的规划位置
         axPrfPos(8) As Long                     ' 规划位置
         axisPos(8) As Long                      ' 机械位置
         encPos(8) As Long                       ' 编码器的位置
End Type

' 读取当前备份的变量数值（断电自动保存）
' pBackVar : 备份的变量值，参考结构体定义
Public Declare Function NMC_GetBackedVarGroup1 Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pBackVar As TBackGroup1) As Integer

Public Type TBackGroup2
        crdSegNo(2) As Long      '坐标系运动的段号
        crdPrfPos(2, 3) As Long '  坐标系运动的规划位置
        axPrfPos(12) As Long               '  规划位置
        axisPos(12) As Long                '  机械位置
        encPos(12) As Long         '  编码器位置
End Type
'  读取当前备份的变量数值（断电自动保存）
'  pBackVar : 备份的变量值,参考结构体定义
Public Declare Function NMC_GetBackedVarGroup2 Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pBackVar As TBackGroup2) As Integer

' 开始或者关闭变量的自动备份（断电自动保存，默认为关闭状态）
' en:是否开启，1：开启变量的自动备份，0：停止变量的自动备份
Public Declare Function NMC_SetBackedVarOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal en As Integer) As Integer

' 读取当前自动备份的开启状态
' pEn:当前的开启状态
Public Declare Function NMC_GetBackedVarOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pEn As Integer) As Integer

' paraID
Public Const PARA_IP_ADDR         As Integer = 100    ' IP地址，四个字节分别表示四段
Public Const PARA_IP_MSK          As Integer = 101    ' IP mask
Public Const PARA_IP_GW           As Integer = 102    ' Gateway
Public Const PARA_IP_DHCP         As Integer = 103    ' DHCP
Public Const PARA_WRITE_EN        As Integer = 999    ' 参数保存

' 读取系统参数（long 型）
' paraID :　系统参数ID，参见后面定义。pValue : 返回值
' 注：此函数可用于设置板卡上的扩展资源
Public Declare Function NMC_DevGetPara Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal paraID As Long, ByRef pValue As Long) As Integer

' 设置系统参数（long 型）
' paraID :　系统参数ID，参见后面定义。value : 设置值
' 注：此函数可用于读取板卡上的扩展资源
' 注：IP地址等参数写成功后，需要调用NMC_DevSetPara(devHandle,PARA_WRITE_EN,1)才能使得写下去的参数保存
' 注：IP地址等参数写成功后，将在控制器重新启动后生效
Public Declare Function NMC_DevSetPara Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal paraID As Long, ByVal value As Long) As Integer

'  设置用户密码
'  pUserName    : 指定的用户名,目前只支持"USER1"
'  pPasswordOld : 该用户的当前密码,长度最多为15个字符
'  pPasswordNew : 新的该用户的密码,长度最多为15个字符
'  注意：1.初始出厂无密码,一旦设置密码,则必须要登陆后,控制器某些指令才能正常工作（包括启动运动指令,设置DO输出指令）
'       2.修改密码后,请务必记住新的密码。忘记密码只能返厂复位。
'       3.密码大小写敏感
Public Declare Function NMC_UserSetPassword Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pUserName As String, ByRef pPasswordOld As String, ByRef pPasswordNew As String) As Integer

'  用户登陆
'  pUserName    : 指定的用户名,目前只支持"USER1"
'  pPassword    : 该用户的密码
Public Declare Function NMC_UserLogin Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pUserName As String, ByRef pPassword As String) As Integer

'  用户退出登陆
'  pUserName    : 指定的用户名,目前只支持"USER1"
Public Declare Function NMC_UserLogout Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pUserName As String) As Integer

'  设置控制器的规划周期
'  period：单位us       只能为250 500 1000
Public Declare Function NMC_SetProfilePeriod Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal period As Integer) As Integer

'  获取控制器的规划周期
'  period：单位us       只能为250 500 1000
Public Declare Function NMC_GetProfilePeriod Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPeriod As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  7.数据采集模块(高级指令)
'
'------------------------------------------------------------------------------------------------------------

' Collect模块：变量类型
Public Const COLLECT_ADDRESS_PRF_POS        As Integer = (0) ' 规划位置
Public Const COLLECT_ADDRESS_AXIS_POS       As Integer = (1) ' 机械位置
Public Const COLLECT_ADDRESS_ENC_POS        As Integer = (2) ' 编码器位置
Public Const COLLECT_ADDRESS_CMD_POS        As Integer = (3) ' 命令位置
Public Const COLLECT_ADDRESS_AXIS_VEL       As Integer = (4) ' 电机速度
Public Const COLLECT_ADDRESS_CRD_POS        As Integer = (5) ' 坐标系位置
Public Const COLLECT_ADDRESS_CRD_VEL        As Integer = (6) ' 坐标系速度
Public Const COLLECT_ADDRESS_ENC_VEL        As Integer = (7) ' 编码器速度
Public Const COLLECT_ADDRESS_CMD_VEL        As Integer = (8) ' 命令速度
Public Const COLLECT_ADDRESS_CRD_POS1 As Integer = (9) '  坐标系1位置
Public Const COLLECT_ADDRESS_CRD_VEL1 As Integer = (10) '  坐标系1速度
Public Const COLLECT_ADDRESS_LASER_OUTPUT As Integer = (11) '  激光输出（补偿前）
Public Const COLLECT_ADDRESS_LASER_GATE As Integer = (12) '  激光gate信号状态
Public Const COLLECT_ADDRESS_LASER_POWER As Integer = (13) '  激光能量当前输出值
Public Const COLLECT_ADDRESS_DI As Integer = (14) '  数字量输入状态
Public Const COLLECT_ADDRESS_DO As Integer = (15) '  数字量输出状态

' 获取需要采集数据变量的地址
'  index:变量的序号(从0开始)
'  type: 变量的类型
'  pAddr: 返回的数据地址
' pDataLen: 返回的该数据长度
Public Declare Function NMC_GetCollectDataAddr Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal index As Integer, ByVal dataType As Integer, ByRef pAddr As Long, ByRef pDataLen As Integer) As Integer

' 采集模块：采集配置
Public Const COLLECT_LIST_MAX   As Integer = 8   ' 每组最多采集8个数据
Public Type TCollectCfg
         count As Integer                        ' 需要采集的变量个数
         interval As Integer                     ' 采集的间隔时间
         address(COLLECT_LIST_MAX) As Long       ' 变量的地址
         length(COLLECT_LIST_MAX) As Integer     ' 每个变量的长度
End Type

'采集模块：触发模式
Public Const COLLECT_MODE_NONE           As Integer = 0             ' 无条件
Public Const COLLECT_MODE_G_SRC1         As Integer = 1             ' 采集源1数值大于比较值
Public Const COLLECT_MODE_L_SRC1         As Integer = 2             ' 采集源1数值小于比较值
Public Const COLLECT_MODE_DIFF           As Integer = 3             ' 采集源1与采集源2两项差值大于比较值

' 采集模块：触发配置
Public Type TCollectTrig
         mode As Integer                         ' 触发模式，
         source1 As Integer                      ' 触发源1
         source2 As Integer                      ' 触发源2
         startDelay As Integer                   ' 触发启动的延时
         value As Double                         ' 触发比较值
End Type

' 配置采集数据通道,需要配置对应结构体参数
Public Declare Function NMC_ConfigCollect Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pCollect As TCollectCfg, ByRef pTrig As TCollectTrig) As Integer

' 启动或停止数据采集
' en 0停止
Public Declare Function NMC_CollectOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal en As Integer) As Integer

' Collect模块：采集状态
Public Const COLLECT_BUSY                 As Integer = &H1
Public Const COLLECT_OVERRIDE_DATA        As Integer = &H2
Public Const COLLECT_PUSH_DATA_ERR        As Integer = &H4

' 获取采集状态:
' pSts：采集状态，按位表示各自状态
' pDataLen: 采集的数据量
Public Declare Function NMC_GetCollectSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pSts As Integer, ByRef pDataLen As Integer) As Integer

' 获取采数据:
' lenth：采集数据长度（单位：char）
' pData: 采集的数据（均以char为单元存储）
Public Declare Function NMC_GetCollectData Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal lenth As Integer, ByRef pData As Byte) As Integer

' 清除采集状态
Public Declare Function NMC_ClearCollectSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  8.激光
'
'------------------------------------------------------------------------------------------------------------

Public Const MAX_LASER_NUMS As Integer = (2)     ' 最大激光通道

' 激光输出模式
Public Const LASER_DISABLE_MODE          As Integer = (0)      ' 禁用激光功能
Public Const IMMEDIT_OUTPUT_MODE         As Integer = (1)      ' 立即输出模式
Public Const TIME_ARRAY_OUTPUT_MODE As Integer = (2)      ' 波形输出模式
Public Const SHIO_OUTPUT_MODE As Integer = (3)      ' 位置比较输出模式

'设置激光输出的模式。该模式的设定，约束相应指令的功能和操作
'mode: 激光输出模式，参考上述宏定义
Public Declare Function NMC_LaserSetMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal mode As Integer, ByVal ch As Integer) As Integer

' 激光物理信号类型
Public Const LASER_NONE As Integer = (0)         ' 关闭激光输出模式
Public Const LASER_DA As Integer = (1)         ' DA输出
Public Const LASER_PWM_DUTY As Integer = (2)         ' 占空比输出
Public Const LASER_PWM_FRQ As Integer = (3)         ' 频率输出
Public Const LASER_PWM_FRQ_EXT As Integer = (4)         ' 频率输出,脉宽固定

' 激光物理信号输出类型配置
' outputType：输出的类型
' index :输出通道序号,取值范围[0,n]
' optionVal: 当作为占空比输出时,该值为PWM的频率,单位HZ；
'            当为LASER_PWM_FRQ时,该值作为占空比值,（0~100）；
'            当为LASER_PWM_FRQ_EXT时,该值为脉宽,单位为0.5微秒,取值范围(0,~)
' ch :激光通道,取值范围[0,n]
Public Declare Function NMC_LaserSetOutputType Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal outputType As Integer, ByVal index As Integer, ByVal optionVal As Integer, ByVal ch As Integer) As Integer

' 激光物理信号输出类型配置(高精度)
' outputType：输出的类型
' index :输出通道序号,取值范围[0,n]
' optionVal: 当作为占空比输出时,该值为PWM的频率,单位HZ；
'            当为LASER_PWM_FRQ时,该值作为占空比值,单位为百分比；
'            当为LASER_PWM_FRQ_EXT时,该值为脉宽,单位为微秒,取值范围(0,~)
' ch :激光通道,取值范围[0,n]
Public Declare Function NMC_LaserSetOutputTypeEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal outputType As Integer, ByVal index As Integer, ByVal optionVal As Double, ByVal ch As Integer) As Integer

' 功能：设置立即输出激光的能量,
' outVal: 激光能量（设定值意义与NMC_LaserSetOutputType设置的输出类型对应）
' ch：输出通道 (需要根据不同物理信号端口数量进行设定)
Public Declare Function NMC_LaserSetPower Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal outVal As Long, ByVal ch As Integer) As Integer

' 功能：读取当前激光的能量
' pVal: 激光能量值
' ch：通道号
Public Declare Function NMC_LaserGetPower Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pVal As Double, ByVal ch As Integer) As Integer

' 功能：读取当前激光开关状态
' pOnOffState: 激光开关状态，1：激光处于打开状态，0:激光处于关闭状态
' ch：通道号
Public Declare Function NMC_LaserGetOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pOnOffState As Integer, ByVal ch As Integer)

' 功能：设置立即输出激光的能量(高精度)
' chn：输出通道 (需要根据不同物理信号端口数量进行设定)
' outVal: 激光能量（设定值意义与NMC_LaserSetOutputTypeEx设置的输出类型对应）
Public Declare Function NMC_LaserSetPowerEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal outVal As Double, ByVal ch As Integer) As Integer

' 功能：激光立即输出开关
' onOffl: 0或者1表示打开或关闭激光输出
' ch：输出通道 (需要根据不同物理信号端口数量进行设定)
Public Declare Function NMC_LaserOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onOff As Integer, ByVal ch As Integer) As Integer

' 设置激光参数
' onDelay:开光延时,单位us,取值范围[0,65535]
' offDelay:关光延时,单位us,取值范围[0,65535]
' minValue:最小输出值,取值范围[0,32767]
' maxValue:最大输出值,取值范围[0,32767]
' standbyPower:待机能量,为0表示取消待机能量输出功能
' ch:激光控制通道
Public Declare Function NMC_LaserSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onDelay As Long, ByVal offDelay As Long, ByVal minValue As Long, ByVal maxValue As Long, ByVal standbyPower As Long, ByVal ch As Integer) As Integer

' 缓冲区设置激光参数
' onDelay:开光延时,单位us,取值范围[0,65535]
' offDelay:关光延时,单位us,取值范围[0,65535]
' minValue:最小输出值，DA输出时，范围[0,32767],占空比输出时，范围[0,100],频率输出时，范围[0,2000000]
' maxValue:最大输出值，DA输出时，范围[0,32767],占空比输出时，范围[0,100],频率输出时，范围[0,2000000]
' standbyPower:待机能量,为0表示取消待机能量输出功能
' ch:激光控制通道
Public Declare Function NMC_CrdBufLaserSetParam Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segment As Long, ByVal onDelay As Long, ByVal offDelay As Long, ByVal minValue As Long, ByVal maxValue As Long, ByVal standbyPower As Long, ByVal ch As Integer) As Integer

' 读取激光参数
Public Declare Function NMC_LaserGetParam Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pOnDelay As Long, ByRef pOffDelay As Long, ByRef pMinValue As Long, ByRef pMaxValue As Long, ByRef pStandbyPower As Long, ByVal ch As Integer) As Integer

' 设置缓冲区激光能量跟随
' segNo:段号
' overRide:跟随倍率,为0表示取消激光能量跟随
' followType:跟随类型,0：跟随规划速度,1：跟随实际速度
' ch:激光通道号,取值范围[0,n]
Public Declare Function NMC_CrdBufLaserSetFollow Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal overRide As Double, ByVal followType As Integer, ByVal ch As Integer) As Integer

' 设置缓冲区激光能量跟随
' powerFilter:能量输出滤波系数，取值范围[0,32]，0：不开启（默认）
' followAdvMode:能量输出计算方法
' ch:激光通道号,取值范围[0,n]
Public Declare Function NMC_LaserSetFollowParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal powerFilter As Integer, ByVal followAdvMode As Integer, ByVal ch As Integer) As Integer

' 缓冲区激光开关
' segNo:段号
' onOff:开关,0：关光,1：开光
' ch:激光控制通道
Public Declare Function NMC_CrdBufLaserOnOff Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal onOff As Integer, ByVal ch As Integer) As Integer

' 缓冲区设置激光能量,激光能量跟随模式下,调用这条指令无效
' segNo:段号
' power:能量
' ch:激光控制通道
Public Declare Function NMC_CrdBufLaserPower Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal power As Long, ByVal ch As Integer) As Integer

' 激光能量补偿数据表单方向长度最大值
Public Const LASER_CMP_DATA_LEN_MAX As Integer = (10)

' 设置激光能量补偿表
' tableNo： 补偿表号 ：支持20张表
' pXCmpPos：X方向轴的比较位置,长度为xCount
' pYCmpPos: Y方向轴的比较位置,长度为yCount
' xCount： 表X方向的长度,取值范围[2,10]
' yCount： 表Y方向的长度,取值范围[2,10]
' powerMin:     大于该最小能量才补偿
' powerMax:     小于该最大能量才补偿
' pLaserCmpPower：补偿表的值，该参数为2维数组的首地址
' chn:对应的激光通道号
Public Declare Function NMC_SetLaserPowerCmpTable Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal tableNo As Integer, ByRef pXCmpPos As Long, ByRef pYCmpPos As Long, ByVal xCount As Integer, ByVal yCount As Integer, ByVal powerMin As Long, ByVal powerMax As Long, ByRef pLaserCmpPower As Long, ByVal chn As Integer) As Integer

' 启动激光能量补偿
' pAxisNo： pAxisNo[0]表X方向的位置比较轴号 pAxisNo[1]表Y方向的位置比较轴号
' chn：补偿输出给哪路激光通道
Public Declare Function NMC_StartLaserPowerComp Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal pAxisNo As Long, ByRef power As Integer, ByVal chn As Integer) As Integer

' 停止激光能量补偿
Public Declare Function NMC_StopLaserPowerComp Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef power As Integer, ByVal chn As Integer) As Integer

'
Public Const LASER_GROUP As Integer = (12)            ' 最大激光能量组数
Public Const LASET_POINT As Integer = (40)            ' 每组最大点数

Public Type TTimeArrayPara
         pwmEnable As Integer           ' 是否需要输出PWM,0:立即输出一个波形，1：根据位移周期输出
         outputType As Integer          ' 开关信号输出类型：0：gate,1：GPO
         outputCh As Integer                    ' 开关信号输出通道
         stLevelRevs As Integer             ' SHIO输出电平取反,默认为0，不取反
         pwmPeriod As Long                      ' 保留,PWM周期,单位us,不能小于时间数组的总周期
         pwmWidth As Long                       ' 保留,PWM脉宽,单位us,此参数保留,脉宽等于时间数组的总周期
     gateDistance As Long           ' 固定模式下的位置间隔 单位：pulse。
' 默认0,模式2~4 下会进行有效性检查
     minFrqFrq As Long      ' 保留,SHIO输出最低频率，单位HZ
     posSrc As Integer              ' 比较模式,外部编码器还是内部规划值。
' 0：外部编码器（推荐）,1：内部规划值。
' 默认0。
     axisMask As Integer            ' 轴号,按bit 位对应。（一般两个轴）。
' 默认 0。
     minFrqEn As Integer                    ' 保留,是否启用SHIO输出最低频率，默认0，不启用
         reserved2 As Integer       ' 保留
End Type

' 设置时间数组输出参数
' ch : 激光通道
' pPara ： 参数
' 注：1.仅时间数组输出方式下有效
Public Declare Function NMC_LaserSetTimeArrayPara Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TTimeArrayPara, ByVal ch As Integer) As Integer

Public Type TLaserPower
         time(LASET_POINT) As Integer ' 每个点之间的间隔时间,单位微秒
         power(LASET_POINT) As Integer         ' 各点的能量大小
         count As Integer                                       ' 实际压入点数
End Type

' 设置激光的能量,对于立即输出模式,group无效,pLaserPower为指定的单个能量信息
' group : 设置哪一组激光能量
' pLaserPower ： 设置的数据
' 注：1.即波形设置
'     2.该接口对于SHIO模式无效
Public Declare Function NMC_LaserSetTimeArrayPower Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef pLaserPower As TLaserPower) As Integer

' 执行时间序列激光,只在时间序列输出模式下有效
' group : 设置哪一组激光能量
' ch:激光通道
' 注：1.启用时间数组输出后,直到最后一个点,如果最后一个点能量不为0,则维持最后一个能量输出
'    2.如果最后一个点能量为0,且没有PWM输出配合,则自动关闭激光。有PWM配合则需要调用NMC_LaserOnOff或者NMC_CrdBufLaserOnOff关闭激光
Public Declare Function NMC_LaserTimeArrayExe Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByVal ch As Integer) As Integer

' 缓冲区执行时间序列激光,只在时间序列输出模式下有效
' segNo:段号
' group:设置哪一组激光能量
' ch:激光控制通道
' 注：1.启用时间数组输出后,直到最后一个点,如果最后一个点能量不为0,则维持最后一个能量输出
'    2.如果最后一个点能量为0,且没有PWM输出配合,则自动关闭激光。有PWM配合则需要调用NMC_LaserOnOff或者NMC_CrdBufLaserOnOff关闭激光
Public Declare Function NMC_CrdBufLaserTimeArrayExe Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal group As Integer, ByVal ch As Integer) As Integer

Public Type TSHIOPara
         isArray As Integer             ' 是否固定间距还是数组。0：固定间距（仅支持）,默认0
         outMode As Integer             ' 输出模式。默认1
'                                   1：只输出gate 立即开或关,
'                                   2: 根据位移输出gate
'                                   3: 根据位移输出gate,gate 和同部trigger 信号同步
'                                   4: 根据位移输出gate,gate 和信号输入同步
         posSrc As Integer              ' 比较模式,外部编码器还是内部规划值。
'                                     0：外部编码器（推荐）,1：内部规划值。
'                                     默认0。
         axisMask As Integer    ' 轴号,按bit 位对应。（一般两个轴）。
'                                 默认 0。
         delay As Double                ' 延时开关光时间( 暂不用 ),单位：s。默认 0。
         gateTime As Double     ' 设置gate 打开时间,单位：s（内部最小值：1/36us ）,取值范围(0,0.0009)
'                                 默认0。
         gateDistance As Long   ' 固定模式下的位置间隔 单位：pulse。
'                                 默认0,模式2~4 下会进行有效性检查。
     reserved1 As Long          ' 保留参数,应设为0。
         reserved2 As Long      ' 保留参数,应设为0。
         reserved3 As Long      ' 保留参数,应设为0。
         reserved4 As Long      ' 保留参数,应设为0。
         reserved5 As Long      ' 保留参数,应设为0。
End Type

' 配置SHIO功能的参数
Public Declare Function NMC_SHIOConfigPara Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pSHIOPara As TSHIOPara, ByVal ch As Integer) As Integer

' SHIO输出的最小频率功能开
' minFrq:最低频率，单位HZ
Public Declare Function NMC_SHIOEnableMinFrq Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal minFrq As Long, ByVal ch As Integer) As Integer

' SHIO输出的最小频率功能关闭
Public Declare Function NMC_SHIODisableMinFrq Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer) As Integer

' 缓冲区SHIO输出的最小频率功能开
' minFrq:最低频率，单位HZ
Public Declare Function NMC_CrdBufSHIOSetMinFrq Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segment As Long, ByVal minFrq As Long, ByVal ch As Integer) As Integer

' 缓冲区SHIO输出的最小频率功能关闭
Public Declare Function NMC_CrdBufSHIOClrMinFrq Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segment As Long, ByVal ch As Integer) As Integer

' 缓冲区配置SHIO功能的参数
' delay:延时开关光时间( 暂不用 ),单位：s。默认 0。
' gateTime:设置gate 打开时间,单位：s（内部最小值：1/36us ）,取值范围(0,0.0009),默认0。
' gateDistance:固定模式下的位置间隔 单位：pulse。
Public Declare Function NMC_CrdBufSHIOSetParam Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segment As Long, ByVal delay As Double, ByVal gateTime As Double, ByVal gateDistance As Double, ByVal ch As Integer) As Integer

' 切换轴（允许和坐标系不完全一致）
Public Declare Function NMC_SHIOChangeAxisMask Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal axisMask As Integer) As Integer

' 切换轴（允许和坐标系不完全一致）,缓冲区指令
Public Declare Function NMC_CrdBufSHIOChangeAxisMask Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segment As Long, ByVal axisMask As Integer, ByVal ch As Integer) As Integer

' 允许GATE输出
' 注：设置后根据模式输出
Public Declare Function NMC_SHIOGateOn Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


' 禁止GATE输出
' 注：设置后立即禁止输出
Public Declare Function NMC_SHIOGateOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


' 设置Trigger 输出，
' triggerFreq : 设置triger 脉冲频率单位：HZ。
' triggerWidth : 设置triger 脉冲宽度，单位：s（内部最小值：1/36us ）。默认0。
' 注：设置后立即输出
Public Declare Function NMC_SHIOTriggerOn Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal freq As Double, ByVal width As Double) As Integer


' 禁止GATE输出
' 注：设置后马上禁止
Public Declare Function NMC_SHIOTriggerOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


' 允许GATE输出
' 注：设置后根据模式输出
Public Declare Function NMC_BufSHIOGateOn Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long) As Integer


'禁止GATE输出
'注：缓冲区执行到该指令后立即禁止输出
Public Declare Function NMC_BufSHIOGateOff Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long) As Integer

' PWM映射到GATE引脚输出
' pwmCh:pwm 通道号
' gateCh:gate信号通道号
' onOff: 0 -- 不映射，1 -- 映射 （默认为0）
Public Declare Function NMC_SetPwmToGate Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal pwmCh As Integer, ByVal gateCh As Integer, ByVal onOff As Integer) As Integer

' 缓冲区SHIO点动出光，输出一段gate脉冲,注意：必须在激光SHIO控制模式下使用
' gateTime:gate输出的脉宽，单位：微秒
' gateFrq:gate输出的频率，单位：HZ
' outCount:输出个数
' ch:通道
Public Declare Function NMC_CrdBufSHIOGatePulse Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal gateTime As Double, ByVal gateFrq As Double, ByVal outCount As Long, ByVal ch As Integer) As Integer

' SHIO点动出光，输出一段gate脉冲,注意：必须在激光SHIO控制模式下使用
' gateTime:gate输出的脉宽，单位：微秒
' gateFrq:gate输出的频率，单位：HZ
' outCount:输出个数
' ch:通道
Public Declare Function NMC_SHIOGatePulse Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal gateTime As Double, ByVal gateFrq As Double, ByVal outCount As Long, ByVal ch As Integer) As Integer

' 输出一段PWM脉冲,注意：必须在激光SHIO控制模式下使用
' onTime:PWM输出的脉宽，单位：微秒
' pwmFrq:PWM输出的频率，单位：HZ
' outCount:输出个数
' ch:通道
Public Declare Function NMC_PwmPulseOut Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onTime As Double, ByVal pwmFrq As Double, ByVal outCount As Long, ByVal ch As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'  9.龙门
'
'------------------------------------------------------------------------------------------------------------
' 设置龙门主动轴
' axisHandle: 龙门主动轴句柄
' group     : 龙门组号,取值范围[0,n]
Public Declare Function NMC_SetGantryMaster Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer) As Integer


' 设置龙门从动轴
' axisHandle  : 龙门从动轴句柄;
' group       : 龙门组号,取值范围[0,n]
' gantryErrLmt: 龙门保护误差,取值范围(0,...)
Public Declare Function NMC_SetGantrySlave Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal group As Integer, ByVal gantryErrLmt As Long) As Integer


' 龙门功能关闭
' group :       龙门组号,取值范围[0,n]
Public Declare Function NMC_DelGantryGroup Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal group As Integer) As Integer


'------------------------------------------------------------------------------------------------------------
'
'  10.通讯扩展等其他
'
'------------------------------------------------------------------------------------------------------------
' 通讯扩展
' 用户指令传输，只写
Public Declare Function NMC_UserCmdWrite Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef sendBuffer As Byte, ByVal sendLen As Long) As Integer


' 用户指令传输，只读
Public Declare Function NMC_UserCmdRead Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef sendBuffer As Byte, ByVal sendLen As Long, ByRef recBuffer As Byte, ByVal recLen As Long) As Integer


' 批量数据传输，只写
Public Declare Function NMC_DataTransfer Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef sendBuffer As Byte, ByVal sendLen As Long) As Integer


' 禁止用户程序运行
Public Declare Function NMC_SysSetUserApp Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal mode As Byte) As Integer


' 升级
Public Declare Function NMC_SysUpgrade Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


' 升级固件
Public Declare Function NMC_SysUpgradeEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal cmd As Byte, ByRef sendBuffer As Byte, ByVal sendLen As Long, ByRef recBuffer As Byte, ByVal recvedLen As Long) As Integer


' 设置调试信息
'0关闭，1打开
Public Declare Function NMC_SetDebugErrorEn Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal debugErrEn As Integer) As Integer


'读取最后一次的错误代码
'返回值：错误代码
Public Declare Function NMC_GetLastErr Lib "nmc_lib20.dll" () As Integer

'设置指令错误返回值模式
'mode:0-标准模式，将返回详细的错误代码；1--简洁模式，只返回错误代码类别
Public Declare Function NMC_SetErrCodeMode Lib "nmc_lib20.dll" (ByVal mode As Integer) As Integer

' 设置指令通讯看门狗
' timeout:看门狗超时时间,单位毫秒,小于等于0代表关闭看门狗功能
' stopMode:超时停止模式,1:马上停止,0:缓冲区执行完毕后停止
' groupID:超时输出do的组号
' doValue:超时输出do状态
Public Declare Function NMC_SetWatchDog Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal timeout As Long, ByVal stopMode As Integer, ByVal groupID As Integer, ByVal doValue As Long) As Integer

'------------------------------------------------------------------------------------------------------------
'
'       11.手轮
'
'------------------------------------------------------------------------------------------------------------
' 退出手轮
Public Declare Function NMC_ClrHandWheel Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer


' 启动手轮
' axis:轴号，取值范围[0,n]
' ratio:跟随倍率，取值范围(0,..]，数值越大，则同样的输入，跟随轴运动距离越长
' acc:跟随的加速度
' vel:跟随的速度
Public Declare Function NMC_SetHandWheel Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal axis As Integer, ByVal ratio As Double, ByVal acc As Double, ByVal vel As Double) As Integer


' 选择手轮跟随的编码器通道
' index:编码器通道编号，取值范围[0,9]
Public Declare Function NMC_SetHandWheelInput Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal index As Integer) As Integer


' 设置手轮跟随的倍率
' ratio:跟随倍率，取值范围(0,..]
Public Declare Function NMC_SetHandWheelRatio Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ratio As Double) As Integer

'------------------------------------------------------------------------------------------------------------
'
'       12.PT
'
'------------------------------------------------------------------------------------------------------------
' onOff:                1：数据驻存模式   0：数据刷新模式(默认模式)
' loopCount:    循环次数 ：仅数据驻存模式下有效
Public Declare Function NMC_MtPtSetStatic Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal onOff As Integer, ByVal loopCount As Long) As Integer

' onOff:                1：数据驻存模式   0：数据刷新模式(默认模式)
' loopCount:    循环次数 ：仅数据驻存模式下有效
Public Declare Function NMC_MtPtGetStatic Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef onOff As Integer, ByRef loopCount As Long) As Integer

' 查询PT数据剩余空间大小
' pSpace:返回的剩余空间大小
' pUsed: 已使用的空间段数
Public Declare Function NMC_MtPtGetSpace Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pSpace As Integer, ByRef pUsed As Integer) As Integer

' PT数据段类型
Public Const MT_PT_NORMAL As Integer = (0)
Public Const MT_PT_STOP As Integer = (1)
Public Const MT_PT_EVEN As Integer = (2)

' 向Pt运动缓存区中压运动数据段
' count:压入的数据段数
' pPosArray:段运行距离
' pTimeArray:段运行时间
' pTypeArray:段类型,见宏定义
Public Declare Function NMC_MtPtPush Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal count As Integer, ByRef pPosArray As Double, ByRef pTimeArray As Long, ByRef pTypeArray As Integer) As Integer

' 清空PT数据
Public Declare Function NMC_MtPtBufClr Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 启动Pt运动
' otherSynAxCnts： 不包括axisHandle 的其他同步启动轴数量
' pOtherSynAxArray: 其他同步启动轴的序号：0~N
' 注：同步的轴必须属于同一个控制器
Public Declare Function NMC_MtPtStartMtn Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal otherSynAxCnts As Integer, ByRef pOtherSynAxArray As Integer) As Integer

'-------------------------------------------------------------------------------
' 13.线性距离位置比较
'-------------------------------------------------------------------------------

' 精确输出结构体
Public Type TLinearCmpPara
         dimens As Integer
         compMode As Integer
         axMask As Integer
         src As Integer
         gateTime As Double
End Type

' 功能：设置精确位置比较的参数，并清除线性位置比较位置数据
' dimens:比较的维数 1或者2
' axisMask：选比较的轴号,按bit选择:不能超过2个bit同时为1
' src：比较源：1:编码器位置  0：规划位置
' cmpMode：比较的模式：0 按输出数组位置比较,1 线性比较,按interval间距比较
' gateTime:输出的脉冲宽度
' chn：输出通道 目前只支持0
Public Declare Function NMC_LinearCompSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal dimens As Integer, ByVal axisMask As Integer, ByVal src As Integer, ByVal cmpMode As Integer, ByVal gateTime As Double, ByVal chn As Integer) As Integer

' 获取配置参数
Public Declare Function NMC_LinearCompGetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pLinearCmpPara As TLinearCmpPara, ByVal chn As Integer) As Integer

' 功能：设置精确比较位置数据
' pStartPos：起始比较位置，注意：暂时没用
' pPos :比较的位置数组地址。
'                注意：这里为相对距离，第一点为相对于NMC_LinearCompOnOff调用时的位置的距离，第二点为相对第一点的距离
' count：比较的位置个数，最大不能超过250，如果比较数据过多，可以通过多次调用的方式下压数据，缓冲区长度
' chn：输出通道 目前只支持0
Public Declare Function NMC_LinearCompSetData Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pStartPos As Long, ByRef pPos As Long, ByVal count As Long, ByVal chn As Integer) As Integer

' 功能：线性比较输出
' pStartPos：起始比较位置
' interval:线性比较间距（小于32767）
' count: 线性比较次数
Public Declare Function NMC_LinearCompInterval Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pStartPos As Long, ByVal interval As Long, ByVal count As Long, ByVal chn As Integer) As Integer

' 功能：精确位置比较使能
' onOff： 0 停止,1输出
' chn：输出通道 目前只支持0
Public Declare Function NMC_LinearCompOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onOff As Integer, ByVal chn As Integer) As Integer

' 功能：比较的输出状态
' pStatus: 0 未启动比较 1 比较输出中
' pOutCount：输出的个数,对于数组输出模式，输出计数计算请咨询我们
' chn：输出通道 目前只支持0
Public Declare Function NMC_LinearCompStatus Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pStatus As Integer, ByRef pOutCount As Integer, ByVal chn As Integer) As Integer

'-------------------------------------------------------------------------------
'14.二维位置点比较
'-------------------------------------------------------------------------------
Public Const CMP_OUTPUT_CHN_MAX As Integer = (3)

' 二维位置点比较结构体
Public Type TComp2DimensParam
         outputchn(CMP_OUTPUT_CHN_MAX) As Integer               ' 比较输出的通道:-1表示不输出处理
         outputType(CMP_OUTPUT_CHN_MAX) As Integer              ' 输出方式0：脉冲1：电平
         chnType(CMP_OUTPUT_CHN_MAX) As Integer         ' 通道类型：0 GPO, 1  GATE通道
         dir1No As Integer                                                              ' 方向1 的位置源轴号（0~11）
         dir2No As Integer                                                              ' 方向2 的位置源轴号（0~11）
         posSrc As Integer                                                              ' 轴位置类型 ：0规划1：编码器
         stLevel(CMP_OUTPUT_CHN_MAX) As Integer                 ' 电平模式下的起始电平（0或1）
         gateTime(CMP_OUTPUT_CHN_MAX) As Integer                ' 脉冲方式脉冲时间:单位ms
         errZoneAs  As Integer                                                          ' 进入比较点容差半径范围（pulse）
End Type


' 功能：设置2维位置比较的参数
' param: 二维比较参数
' group:组号,0 或者1
' chn:保留,设为0
Public Declare Function NMC_Comp2DimensSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef param As TComp2DimensParam, ByVal chn As Integer) As Integer

' 功能：获取2维位置比较的参数
' param: 二维比较参数
' group:组号,0 或者1
' chn:保留,设为0
Public Declare Function NMC_Comp2DimensGetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef param As TComp2DimensParam, ByVal chn As Integer) As Integer

' 功能：设置二维比较数据
' pArrayPos:比较数组地址
' count:位置点数
' group:组号,0 或者1
' chn:保留,设为0
Public Declare Function NMC_Comp2DimensSetData Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef pArrayPos As Long, ByVal count As Integer, ByVal chn As Integer) As Integer

' 功能：2维位置比较使能
' onOff： 0 停止,1输出
' group:组号,0 或者1
' chn:保留,设为0
Public Declare Function NMC_Comp2DimensOnoff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByVal onOff As Integer, ByVal chn As Integer) As Integer

' 功能：2维位置比较的输出状态
' pStatus: 0 未启动比较 1 比较输出中
' pOutCount：输出的个数
' group:组号,0 或者1
' chn:保留,设为0
Public Declare Function NMC_Comp2DimensStatus Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef pStatus As Integer, ByRef pOutCount As Integer, ByVal chn As Integer) As Integer

'-------------------------------------------------------------------------------
'15.多维位置比较输出通用接口
'-------------------------------------------------------------------------------
' X维位置点比较结构体
Public Type TCompXDimensParam
        dimens As Integer                                     ' 维度
        axMask As Integer                           ' 使用的轴,按位
        src As Integer                                    ' 轴位置类型 ：0规划1：编码器

        outCnts As Integer                                                        ' 输出数量
        outType(CMP_OUTPUT_CHN_MAX) As Integer            ' 输出方式0：脉冲1：电平
        outChnType(CMP_OUTPUT_CHN_MAX) As Integer ' 通道类型：0 GPO, 1  GATE通道
        outIndex(CMP_OUTPUT_CHN_MAX) As Integer     ' GPO：0~63  GATE：0
        outStLevel(CMP_OUTPUT_CHN_MAX) As Integer   ' 电平模式下的起始电平（0或1）
        outGateTime(CMP_OUTPUT_CHN_MAX) As Integer        ' 脉冲模式下的脉冲时间:单位ms
        errZone As Integer                                                        ' 进入比较点容差半径范围（pulse）
End Type

' 功能：设置X维位置比较的参数
' param: X维比较参数
' ch:组号,0~2
Public Declare Function NMC_CompXDimensSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef param As TCompXDimensParam, ByVal chn As Integer) As Integer

' 功能：获取X维位置比较的参数
' param: 二维比较参数
' chn:组号
Public Declare Function NMC_CompXDimensGetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal group As Integer, ByRef param As TCompXDimensParam, ByVal chn As Integer) As Integer

' 功能：设置X维位置比较的输出模式
' outMode: 输出模式 0：同时输出模式 1： 轮循输出模式
' ch:组号,0~N
Public Declare Function NMC_CompXDimensSetCmpOutMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal outMode As Integer, ByVal chn As Integer) As Integer

' 功能：设置X维比较数据
' pArrayPos:比较数组地址,注：若是1维比较,则pPosArray传入一维数组地址,若是2维比较,则pPosArray应传入2维数组地址
' outValue
' count:位置点数,注：若为2维数组比较时,每两个数据为一个点数
' ch:组号,0~N
' 注：按结构体定义的IO,同时输出
Public Declare Function NMC_CompXDimensSetData Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPosArray As Long, ByVal count As Integer, ByVal chn As Integer) As Integer

' 功能：X维位置比较使能
' onOff： 0 停止,1输出
' chn： 组号
Public Declare Function NMC_CompXDimensOnoff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onOff As Integer, ByVal chn As Integer) As Integer

' 功能：X维位置比较的输出状态
' pStatus: 0 未启动比较 1 比较输出中
' pOutCount：输出的个数
' chn：组号
Public Declare Function NMC_CompXDimensStatus Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pStatus As Integer, ByRef pOutCount As Integer, ByVal chn As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'       16.坐标系输出转换（根据机械结构进行转换）
'
'------------------------------------------------------------------------------------------------------------
' 功能：使能旋转转换处理
'       用户数据是按照直角坐标描述,实际加工在一个旋转面上加工,可以用此功能
' rotAxisNo：旋转轴轴号
' angleRadEqual：旋转轴脉冲转弧度系数
' firstAxisInitPos：旋转中心,X轴的位置
' secAxisInitPos：旋转中心,Y轴的位置
Public Declare Function NMC_CrdSetTransRotate Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal rotAxisNo As Integer, ByVal angleRadEqual As Double, ByVal firstAxisInitPos As Long, ByVal secAxisInitPos As Long) As Integer

' 功能：使能极坐标转换处理
'       用户数据是按照直角坐标描述，实际机械机构是一个旋转轴和一个进给轴
'参数： rotAxNo：旋转轴轴号
'               transAxNo：平移轴轴号
'               rotEquiv：旋转轴当量，2PI/电机一圈脉冲数
Public Declare Function NMC_CrdSetTransPolar Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal rotAxNo As Integer, ByVal transAxNo As Integer, ByVal rotEquiv As Double) As Integer

' 功能：运行至设定的极坐标位置并且进行圈数清零处理（利用单轴PTP运行到指定位置）
'参数： xPos:极坐标系下X方向位置
'                   yPos:极坐标系下Y方向位置,比如运动到（5000，5000）的位置，则相当于旋转轴转到45度角，进给轴运动到根号2*5000的位置
'                   rotVel:旋转速度
'                   transVel:进给速度
Public Declare Function NMC_CrdRunToPolarPos Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal xPos As Double, ByVal yPos As Double, ByVal rotVel As Double, ByVal transVel As Double) As Integer

' 功能：运行至设定的极坐标角度位置（利用单轴PTP运行到指定位置）
'参数： theta:旋转轴目标角度
'                               vel:旋转速度
'                               clrRoundFlag:是否清除圈数
Public Declare Function NMC_CrdRunToPolarTheta Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal theta As Double, ByVal vel As Double, ByVal clrRoundFlag As Integer) As Integer

' 功能：销毁极坐标机型（只恢复直角坐标系）
Public Declare Function NMC_CrdDelTransPolar Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' XYZA机型设置接口
' 设置XYZA的映射轴号
' pAxisMapArray[0]~[3]分别对应X、Y、Z和A
Public Declare Function NMC_CrdSetTransXYZA Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pAxisMapArray As Integer) As Integer

' 销毁XYZA机型，回归XYZ结构
Public Declare Function NMC_CrdDelTransXYZA Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 求工具参数
' deltaTheta：从0°往正方向旋转过的角度值
' deltaX：旋转deltaTheta角度后，重新校正到同一点位置后，X轴的相对移动量
' deltaY：旋转deltaTheta角度后，重新校正到同一点位置后，Y轴的相对移动量
' pToolX: 工具的X值
' pToolY: 工具的Y值
Public Declare Function NMC_CrdSetXYZAToolCalc Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal deltaTheta As Double, ByVal deltaX As Long, ByVal deltaY As Long, ByRef pToolX As Long, ByRef pToolY As Long) As Integer

' 设置XYZA机型参数
' pulse2Rad: A轴的每个脉冲对应的弧度值
' toolX：工具的X值
' toolY: 工具的Y值
Public Declare Function NMC_CrdSetXYZAPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal pulse2Rad As Double, ByVal toolX As Long, ByVal toolY As Long) As Integer

' 设置XYZA机型参数
' pPulse2Rad:A轴的每个脉冲对应的弧度值
' pToolX:工具的X值
' pToolY:工具的Y值
Public Declare Function NMC_CrdGetXYZAPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pPulse2Rad As Double, ByRef pToolX As Long, ByRef pToolY As Long) As Integer

'-------------------------------------------------------------------------------
'17.结构体初始化函数
'-------------------------------------------------------------------------------

Public Declare Function NMC_TArcSecSettingStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TArcSecSetting) As Integer
Public Declare Function NMC_TCrdParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TCrdPara) As Integer
Public Declare Function NMC_TCollectCfgStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TCollectCfg) As Integer
Public Declare Function NMC_TCollectTrigStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TCollectTrig) As Integer
Public Declare Function NMC_TTimeArrayParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TTimeArrayPara) As Integer
Public Declare Function NMC_TLaserPowerStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TLaserPower) As Integer
Public Declare Function NMC_TSHIOParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TSHIOPara) As Integer
Public Declare Function NMC_TLinearCmpParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TLinearCmpPara) As Integer
Public Declare Function NMC_TComp2DimensParamStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TComp2DimensParam) As Integer

Public Declare Function NMC_TNMCTimeStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TNMCTime) As Integer

' 清除轴错误状态,同时多个
Public Declare Function NMC_MtClrErrorEx Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal count As Integer) As Integer

' 输出DO,16位
' bitsFlag,0:低16位,1：高16位
Public Declare Function NMC_SetDOGroupEx Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal value As Long, ByVal groupID As Integer, ByVal bitsFlag As Integer) As Integer

'-------------------------------------------------------------------------------
'18.闭环
'-------------------------------------------------------------------------------

' PID参数
Public Type TPidPara
     kp  As Single                                                                                      ' 增益系数
     ki As Single                                                                                       ' 积分系数
     kd As Single                                                                                       ' 微分系数
     kvff As Single                                                                                     ' 速度前馈系数
     integralLimit As Long                                 ' 积分饱和极限
     derivativeLimit As Long                               ' 微分饱和极限
     outLimit As Integer                                     ' 输出饱和极限
End Type

' Dac参数
Public Type TDacMotor
         inverse As Integer                     ' 电压是否取反
         bias As Integer                                ' Dac零漂
         dacLmt As Integer                      ' Dac输出极限值
End Type

' 设置单轴闭环控制的DA参数,轴与DA通道的对应
Public Declare Function NMC_MtSetCloseLoopDac Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pDacPara As TDacMotor) As Integer

' 获取单轴闭环控制的DA参数
Public Declare Function NMC_MtGetCloseLoopDac Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pDacPara As TDacMotor) As Integer

' 设置单轴的控制模式：默认使用对应轴的编码器作为输入反馈,对应序号的DAC作为输出
' 闭环模式下,先调用NMC_SetCloseLoopDac指令
'mode: 0 脉冲控制  1 DA闭环控制，默认为脉冲控制
Public Declare Function NMC_MtSetCtrlMode Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal mode As Integer) As Integer

' 读取单轴的控制模式
Public Declare Function NMC_MtGetCtrlMode Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pMode As Integer) As Integer

'设置对应组号的PID参数
Public Declare Function NMC_MtSetPIDPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal index As Integer, ByRef pPidPara As TPidPara) As Integer

' 获取对应组号的PID参数
Public Declare Function NMC_MtGetPIDPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal index As Integer, ByRef pPidPara As TPidPara) As Integer

' 设置使用哪组PID
Public Declare Function NMC_MtSetPIDIndex Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal index As Integer) As Integer

' 获取正使用的PID组号
Public Declare Function NMC_MtGetPIDIndex Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pIndex As Integer) As Integer

'-------------------------------------------------------------------------------
'19.高级BufIo输出配置及控制
'-------------------------------------------------------------------------------
' BufIo输出最大组数
Public Const MAX_ADV_BUFIO_GROUP As Integer = 2

' 高级BufIo输出参数
Public Type TAdvBufIoParam
' 输出点
         outType As Integer                             ' 输出类型，0：通用输出；1：Gate信号；其他保留
         outGroup As Integer                            ' 输出组，取值范围[0,n]
         outIndex As Integer                            ' 输出序号，取值范围[0,n]
         outSns As Integer                              ' 有效电平,0:低电平有效，1：高电平

' 信号
         pulseMode As Integer           ' 0：电平输出，1：脉冲输出W
         pulseOnTime As Long            ' 有效电平时间（脉冲输出方式下有效），单位：微秒
         pulseOffTime As Long           ' 无效电平时间（脉冲输出方式下有效），单位：微秒

        reservedAs As String * 32       ' 保留
End Type

' 设置BufIo输出参数
Public Declare Function NMC_AdvBufIoSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPrm As TAdvBufIoParam, ByVal ch As Integer) As Integer

' 读取BufIo输出参数
Public Declare Function NMC_AdvBufIoGetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPrm As TAdvBufIoParam, ByVal ch As Integer) As Integer

' 缓冲区设置高级BufIo输出有效（运动一段距离后输出特定状态）
' outLength:距离，单位：脉冲
' value: 脉冲模式下输出脉冲个数，电平方式下无意义。
' ch:输出组，取值范围：[0,MAX_ADV_BUFIO_GROUP)
Public Declare Function NMC_CrdAdvBufIoOnAfterLen Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal outLength As Long, ByVal value As Long, ByVal ch As Integer) As Integer

' 缓冲区设置高级BufIo关闭输出（缓冲区全部运动结束前提前一段距离输出特定状态）
' outLength:距离，单位：脉冲
' ch:输出组，取值范围：[0,MAX_ADV_BUFIO_GROUP)
Public Declare Function NMC_CrdAdvBufIoOffBeforeLen Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal outLength As Long, ByVal ch As Integer) As Integer

' 立即设置高级BufIo输出
' value: 脉冲模式下输出脉冲个数，电平方式下0:关闭，1:打开。
' ch:输出组，取值范围：[0,MAX_ADV_BUFIO_GROUP)
Public Declare Function NMC_AdvBufIoOut Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal value As Long, ByVal ch As Integer) As Integer

' 读取BufIo的输出数量
' pOutCout:输出脉冲个数
' ch:输出组，取值范围：[0,MAX_ADV_BUFIO_GROUP)
Public Declare Function NMC_AdvBufIoGetPulseCnt Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pOutCout As Long, ByVal ch As Integer) As Integer

' DO脉冲输出最大通道数
Public Const MAX_NUM_DOBIT_PULSE As Integer = 4

' DO脉冲输出
' doType:DO类型,0：通用输出；其他保留
' doIndex:DO序号，取值范围[0,n]
' highLevelTime:高电平宽度，单位:us
' lowLevelTime:低电平宽度，单位:us
' outCount:输出脉冲个数
' firstLevel:0：先输出低电平，1：先输出高电平
' ch:输出脉冲通道号,取值范围:[0,MAX_NUM_DOBIT_PULSE-1]
Public Declare Function NMC_DoBitPulseEnable Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal doType As Integer, ByVal doIndex As Integer, ByVal highLevelTime As Long, ByVal lowLevelTime As Long, ByVal outCount As Long, ByVal initialLevel As Integer, ByVal ch As Integer) As Integer

' 关闭DO脉冲输出
Public Declare Function NMC_DoBitPulseDisable Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer) As Integer

' DO脉冲输出 （缓冲区）
Public Declare Function NMC_CrdBufDoBitPulseEnable Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal doType As Integer, ByVal doIndex As Integer, ByVal highLevelTime As Long, ByVal lowLevelTime As Long, ByVal outCount As Long, ByVal initialLevel As Integer, ByVal ch As Integer) As Integer

' 关闭DO脉冲输出（缓冲区）
Public Declare Function NMC_CrdBufDoBitPulseDisable Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal ch As Integer) As Integer

'-------------------------------------------------------------------------------
'20.模拟量控制
'-------------------------------------------------------------------------------

' 设置DAC（模拟量输出）通道的模式
' ch:模拟量通道号,取值范围[0,n]
' mode:模拟量输出范围,0:0~5V, 1:0~10V, 2: 0~10.8V, 3:+/-5V, 4:+/-10V, 5:+/-10.8V,其他无效，默认为4
Public Declare Function NMC_SetDacMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByVal mode As Integer) As Integer

' 读取DAC（模拟量输出）通道的模式
' ch:模拟量通道号,取值范围[0,n]
' pMode:返回的模拟量输出范围设定值
Public Declare Function NMC_GetDacMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal segNo As Long, ByVal ch As Integer, ByRef pMode As Integer) As Integer

' 设置Adc参数
' ch:模拟量通道号,0~7表示轴通道上的AD，256：表示扩展AD
' mode:模拟量范围,0:0~5V, 1:0~10V, 2: 0~10.8V, 3:+/-5V, 4:+/-10V, 5:+/-10.8V,默认为4
' 注意：目前只支持+/-10V
' filterCoe:滤波系数，取值范围[0,64],0表示取消Adc滤波，单位:ms，默认值为0
Public Declare Function NMC_SetAdcMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByVal range As Integer, ByVal filterCoe As Integer) As Integer

' 读取Adc参数
' ch:模拟量通道号,0~7表示轴通道上的AD，256：表示扩展AD
' pMode:模拟量范围
' pFilterCoe:滤波系数
Public Declare Function NMC_GetAdcMode Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByRef pRange As Integer, ByRef pFilterCoe As Integer) As Integer

' 设置DAC（模拟量输出）输出值
' ch:模拟量通道号,取值范围[0,n]
' dacValue:模拟量输出值,取值范围[-32768,32767],对应DAC输出范围
Public Declare Function NMC_SetDac Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByVal dacValue As Integer) As Integer

' 读取DAC（模拟量输出）输出值
' ch:模拟量通道号,取值范围[0,n]
' pDacValue:返回模拟量输出值,取值范围[-32768,32767],对应DAC输出范围
Public Declare Function NMC_GetDac Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByRef pDacValue As Integer) As Integer

' 读取ADC（模拟量输入）值
' ch:模拟量通道号,取值范围[0,n]
' pAdcValue:返回模拟量输入值，取值范围[-32768,32767],对应Adc输入电压范围
Public Declare Function NMC_GetAdc Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal ch As Integer, ByRef pAdcValue As Integer) As Integer

'-------------------------------------------------------------------------------
'21.scara
'-------------------------------------------------------------------------------
' 相关结构体
Public Type TScaraMechPara
    arm1Len As Double         ' 杆1长，单位是用户单位
    arm2Len As Double          ' 杆2长，单位是用户单位
    pitch As Double            ' Z轴的丝杆节距，单位是用户单位
    reserved(16) As Double     ' 保留，设置为0
End Type

Public Type TScaraJiontPara

     encBits As Long           ' 关节的电机一圈的脉冲数
     zeroPulsePos As Long     ' 关节零点位置的脉冲位置
     posLmt As Single           ' 关节的正限位位置：单位 度
     negLmt As Single           ' 关节的负限位位置：单位 度
     ratio As Single            ' 减速比
     maxVel As Single           ' 最大关节速度  ：单位  °/s
     maxAcc As Single           ' 最大关节加速度: 单位 °/s^2
         reserved1 As Single            ' 保留，设置为0
     reserved(8) As Double          ' 保留，设置为0
End Type

' 设置机械参数
Public Declare Function NMC_CrdSetScaraMechPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pScaraMechPara As TScaraMechPara) As Integer

' 读取机械参数
Public Declare Function NMC_CrdGetScaraMechPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pScaraMechPara As TScaraMechPara) As Integer

' 设置关节参数
Public Declare Function NMC_CrdSetScaraJiontPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal jointNo As Integer, ByRef pScaraJiontPara As TScaraJiontPara) As Integer

' 读取关节参数
Public Declare Function NMC_CrdGetScaraJiontPara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal jointNo As Integer, ByRef pScaraJiontPara As TScaraJiontPara) As Integer

' 设置crd类型为scara
' jointNum: 2/3
' jointAxNoArray 数组长度为4，不用的数据设置为0
Public Declare Function NMC_CrdSetTransScara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal jointNum As Integer, ByRef jointAxNoArray As Integer) As Integer

' 销毁scara机型
Public Declare Function NMC_CrdDelTransScara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

Public Type TFlyFollowPara
    masterAxNo As Integer       ' 传输带轴号，0~N
    useEnc As Integer   ' 使用编码器，0：规划，1：编码器
    dirReverse As Integer    ' 传输轴方向取反。0：不取反，1：取反

    followedAxNo As Integer   ' 跟随哪个轴，0:X，1:Y
    posCoe As Double     ' 传输轴当量和跟随轴的当量比例，跟随当量 / 传输轴当量

    reserved2(16) As Long  ' 保留，设置为0
End Type

' 设置crd启用飞行跟随模式
' *pFlyFollowPara 模式参数
Public Declare Function NMC_CrdSetFlyFollow Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pFlyFollowPara As TFlyFollowPara) As Integer

' 销毁飞行跟随
Public Declare Function NMC_CrdDelFlyFollow Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 查询是否在暂停后已经跟随上状态
' sts : 1表示跟随上  0表示没有跟随上
Public Declare Function NMC_CrdGetFlyFollowUpSts Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pSts As Integer) As Integer

' 缓冲区设置飞行跟随功能的启动和关闭
Public Declare Function NMC_CrdBufEnableFlyFollow Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal enable As Integer) As Integer

'-------------------------------------------------------------------------------
'22.坐标系干涉保护指令
'-------------------------------------------------------------------------------
Public Const CRD_INTERF_GROUP_MAX As Integer = (2)

' 启动坐标系的干涉保护
' groupNo: 干涉坐标系组号（目前只有两个坐标系，所以该值为0）
' mode: 0:基本模式，出现干涉，两坐标系均停止  1：激光模式，出现干涉，其中一个停止并离开
Public Declare Function NMC_SetMvProtect Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupNo As Integer, ByVal mode As Integer) As Integer

' 取消坐标系的干涉保护
' groupNo: 干涉坐标系组号（目前只有两个坐标系，所以该值为0）
Public Declare Function NMC_DelMvProtect Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupNo As Integer) As Integer

' 获取坐标系的干涉状态
' groupNo: 干涉坐标系组号（目前只有两个坐标系，所以该值为0）
' pSts: 0 没有启动干涉功能 1  没有出现干涉  2 干涉发生
Public Declare Function NMC_GetMvProtectSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupNo As Integer, ByRef pSts As Integer) As Integer

Public Type TMvProtectPara
    crdNo(2) As Integer            ' 需要干涉保护的两坐标系号
    crdAxNo(2) As Integer  ' 坐标系的干涉轴号,指XYZ中哪一个（X:0  Y:1    Z:2）
    moveDir(2) As Integer    ' 两干涉轴分别往距离减小时的运动方向，1：正向 -1：负向

    orgDis As Long          ' 两坐标系的crdAxNo轴在原点时的距离
    mvProtectDis As Long     ' 干涉的保护距离
    safeWaitPos As Long     ' mode为激光模式时，干涉轴需要停止到的等待位置（mode为0时无效）
    mvToSafeAcc As Double  ' 运动到等待位置的移动加速度
    mvToSafeVel As Double  ' 运动到等待位置的移动速度
    stopCrdNo As Integer           ' mode为激光模式时，需要停止的坐标系号（mode为0时无效）
    reserved(3) As Integer      ' 保留参数
End Type

' 设置坐标系的干涉保护参数
' groupNo:      干涉坐标系组号（目前只有两个坐标系，所以该值为0）
' pCrdInterfProtectPara： 干涉参数
Public Declare Function NMC_SetMvProtectMode01Para Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupNo As Integer, ByRef pMvProtectPara As TMvProtectPara) As Integer

' 获取坐标系的干涉保护参数
' groupNo:      干涉坐标系组号（目前只有两个坐标系，所以该值为0）
' pCrdInterfProtectPara： 干涉参数
Public Declare Function NMC_GetMvProtectMode01Para Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupNo As Integer, ByRef pMvProtectPara As TMvProtectPara) As Integer

'-------------------------------------------------------------------------------
'23.不常用指令
'-------------------------------------------------------------------------------
Public Type TPackedCrdSts3
     crdSts As Integer          ' 坐标系状态
     axSts(3) As Integer        ' 坐标系里各轴状态
     prfPos(3) As Long       ' 用户坐标系下的规划位置
     axisPos(3) As Long        ' 机械坐标系下的规划位置
     encPos(3) As Long          ' 编码器位置
     userSeg As Long           ' 运行的缓冲区段号
     prfVel As Double           ' 运动速度
     gpDi As Long               ' 通用输入0~31
     gpDo As Long              ' 通用输出0~31
     motDi(3) As Integer        ' 限位、原点、报警。请参考专用IO位定义( 搜索 BIT_AXMTIO_LMTN )
     reserved As Integer        ' 保留
     crdFreeSpace As Long        ' 缓冲区剩余空间
     reserved2 As Long
End Type
' 坐标系运动模式下,打包读取控制器状态
Public Declare Function NMC_CrdGetStsPack3 Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pPackSts As TPackedCrdSts3) As Integer

' 坐标系模式下,读取多个轴的机械坐标位置
' cnts: 读取个数,1~N
' pPos：返回坐标数组
Public Declare Function NMC_CrdGetAxisPos Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal cnts As Integer, ByRef pPosArray As Long) As Integer

' 读取规划位置XYZ
' cnts: 读取个数,1~N
' pPosArray：返回坐标数组
Public Declare Function NMC_CrdGetPrfPos Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal cnts As Integer, ByRef pPosArray As Long) As Integer

' 读取编码器位置
' cnts: 读取个数,1~N
' pPos：返回坐标数组。
Public Declare Function NMC_CrdGetEncPos Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal cnts As Integer, ByRef pPosArray As Long) As Integer

' 获取坐标系合成速度
' pVel：坐标系合成速度
Public Declare Function NMC_CrdGetVel Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pVel As Double) As Integer

' 打开坐标系组
' pCrdHandle：返回坐标系组句柄
Public Declare Function NMC_CrdOpen Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pCrdHandle As Integer) As Integer

' 单轴急停
' 注：运动会按设定的急停加速度停止。如果没有设置,则会立即停止。
Public Declare Function NMC_MtEstp Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 读取打包轴状态（8轴）
Public Type TAxisStsPack8
         prfPos(8)  As Long     ' 规划位置
         encPos(8) As Long     ' 实际位置
         prfVel(8) As Single    ' 规划速度
         motionIO(8) As Long   ' 轴专用IO
         sts(8) As Integer ' 轴状态
         gpo As Long ' 通用输出
         gpi As Long            ' 通用输入
End Type
' 打包读取8个轴的状态,从第一个轴开始读取
' axisFirstHandle : 第一个轴句柄
' pPackSts: 打包的状态数据,参考结构体定义
Public Declare Function NMC_MtGetStsPack8 Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByRef pPackSts As TAxisStsPack8) As Integer

' 直线插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' crdAxMask:参与的轴,按位表示
' pTgPosArray：目标位置数组,长度为3
Public Declare Function NMC_CrdLineXYZ Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal crdAxMask As Integer, ByRef pTgPosArray As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' 设置通用输出  (按通道,支持超过32位)
' groupID:DO组，取值范围[0,n],0: 本地DO31~DO0, 1: 本地DO63~DO32，其他指扩展IO模块
' value: 设置通用数字量输出。1, 输出高电平，0，输出低电平
Public Declare Function NMC_SetDO Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupID As Integer, ByVal value As Long) As Integer

' 读取通用输出
' groupID:DO组，取值范围[0,n],0: 本地DO31~DO0, 1: 本地DO63~DO32，其他指扩展IO模块
' value: 设置通用数字量输出。1, 高电平，0，低电平
Public Declare Function NMC_GetDO Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupID As Integer, ByRef value As Long) As Integer

' 读通用输入
' groupID:DI组，取值范围[0,n],0: 本地DI31~DI0, 1: 本地DI63~DI32，其他指扩展IO模块
' inValue: 通用数字量输入值。1, 高电平，0，低电平
Public Declare Function NMC_GetDI Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal groupID As Integer, ByRef inValue As Long) As Integer

' 设置限位开关输入是否停止运动
' posEn：正向限位触发允许设置，1为允许，0为禁止
' negEn: 负向限位触发允许设置
Public Declare Function NMC_MtLmtOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal posSwt As Integer, ByVal negSwt As Integer) As Integer

' 设置限位开关触发电平
' posSwt：正向限位触发电平设置，1为高电平触发，0为低电平触发
' negSwt: 负向限位触发电平设置
Public Declare Function NMC_MtLmtSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal posSwt As Integer, ByVal negSwt As Integer) As Integer

' 设置原点开关触发电平，注意：这里的电平设置不会影响捕获的电平
' sns：原点电平设置,1为高电平触发,0为低电平触发
Public Declare Function NMC_MtHomeSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal sns As Integer, ByVal negSwt As Integer) As Integer

' 读取原点开关触发电平
' pSns：当前的原点电平设置,1为高电平触发,0为低电平触发
Public Declare Function NMC_MtGetHomeSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal sns As Integer, ByRef pSns As Integer) As Integer


' 设置伺服报警开关是否停止运动
' swt：伺服报警开关输入允许设置，1为允许，0为禁止。（默认为高电平触发）
Public Declare Function NMC_MtAlarmOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal swt As Integer) As Integer

' 设置伺服报警开关电平
' swt：伺服报警触发电平设置，1为高电平触发，0为低电平触发
Public Declare Function NMC_MtAlarmSns Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal swt As Integer) As Integer

' 读取打包轴状态（12轴）
Public Type TAxisStsPack12

         prfPos(12) As Long     ' 规划位置
         encPos(12) As Long     ' 实际位置
         prfVel(12) As Single    ' 规划速度
         motionIO(12) As Long   ' 轴专用IO
         sts(12) As Integer       ' 轴状态
         gpo As Long            ' 通用输出
         gpi As Long           ' 通用输入
End Type
' 打包读取12个轴的状态,从第一个轴开始读取
' axisFirstHandle : 第一个轴句柄
' pPackSts: 打包的状态数据,参考结构体定义
Public Declare Function NMC_MtGetStsPack12 Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByRef pPackSts As TAxisStsPack12) As Integer

'------------------------------------------------------------------------
'
'  24.自动状态返回
'
'------------------------------------------------------------------------
Public Const AUTO_RTN_MAX_AXIS As Integer = 12
' 打包返回状态结构
Public Type TAutoRtnPackedSts

    mtSts(12) As Integer          ' 单轴状态
    mtMio(12) As Integer          ' 单轴专用IO
    mtPrfPos(12) As Long       ' 单轴规划位置
    mtEncPos(12) As Long       ' 单轴实际位置
        mtPrfVel(12) As Single       ' 单轴规划速度

    crdSts(2) As Integer          ' 坐标系状态
        crdPrfVel(2) As Single     ' 坐标系运动速度
    crdUserSeg(2) As Long      ' 坐标系运行的缓冲区段号
        crdFreeSpace(2) As Long    ' 坐标系缓冲区剩余空间
    crdUsedSpace(2) As Long    ' 坐标系缓冲区使用空间

    gpi As Long                ' 通用输入
    gpo As Long                ' 通用输出
    reserved(32) As Integer       ' 预留
End Type

' 设置启用自动状态返回
' mode1 : 设置哪些状态主动返回，0：固定时间周期返回（默认）; 1：周期+轴状态变化，坐标系状态变化；
' mode2 : 备用
' cycleInMs: 周期，单位ms。取值5~10000。建议值100ms。
' port: 端口，写0（库里会修改）
' hostTag : 上位机标签，写0（库里会修改）
Public Declare Function NMC_DevAutoRtnSet Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal mode1 As Long, ByVal mode2 As Long, ByVal cycleInMs As Long, ByVal port As Long, ByVal hostTag As Long) As Integer

' 设置禁用自动状态返回
Public Declare Function NMC_DevAutoRtnClr Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer

' 同步，
' 把之前的状态缓冲清除掉。以后读到的是同步指令发送后的状态
' hostTag : 上位机标签，写0
Public Declare Function NMC_DevAutoRtnSyn Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal hostTag As Long) As Integer

' 读状态
' packedSts : 打包状态
Public Declare Function NMC_DevAutoRtnGet Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef packedSts As TAutoRtnPackedSts, ByRef pReady As Integer) As Integer

' 设置PTP位置比较输出
' comparaPos： 目标位置，单位是 脉冲
' upDateVel：比较后的更新速度 pulse/ms
Public Declare Function NMC_MtSetPtpComparePara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal comparaPos As Long, ByVal upDateVel As Double) As Integer

' 获取PTP比较输出状态
Public Declare Function NMC_MtGetPtpCompareSts Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pIsCompareActive As Integer, ByRef pIsCompareOut As Integer) As Integer

'------------------------------------------------------------------------
'
'  Group 25 : 点位自动收发
'
'------------------------------------------------------------------------

' 设置启用点位自动收发
Public Declare Function NMC_DevAsynCommSet Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal delayInMs As Long) As Integer

' 设置关闭点位自动收发
Public Declare Function NMC_DevAsynCommClr Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer

' 自动状态返回
Public Declare Function NMC_DevAsynGetSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef packedSts As TAutoRtnPackedSts, ByRef pReady As Integer) As Integer

' 多轴点位运动
Public Declare Function NMC_DevAsynAbsMoveType1 Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal acc As Single, ByVal dec As Single, ByVal vel As Single, ByVal smooth As Integer, ByVal arrivalBand As Long, ByVal stableTime As Long, ByVal tgtPos As Long) As Integer

' 设置Do
Public Declare Function NMC_DevAsynSetDoBit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIdx As Integer, ByVal setValue As Integer) As Integer

'------------------------------------------------------------------------
'
'  Group 26 : 一维高速位置比较
'
'------------------------------------------------------------------------

Public Const CMP_HS1DIMENS_CHN_MAX As Integer = (4)         ' 最大支持四个通道
Public Const CMP_HS1DIMENS_POS_MAX As Integer = (8)         ' 每个通道最多支持8个位置点

' 一维高速位置比较参数结构
Public Type TCompHs1DimensParam
   dirNo As Integer            ' 编码器源（0~7），对应轴0~7的编码器。
   out1StLevel As Integer     ' out1起始电平（0或1）
   out2StLevel As Integer      ' out2起始电平（0或1）
   reserved As Integer         ' 保留
   out1Width As Long         ' out1脉冲宽度，0~65535,单位us
   out2Width As Long         ' out2脉冲宽度，0~65535,单位us
   out2Delay As Long         ' out2延时，0~65535,单位us
End Type
' 功能：设置高速1维位置比较的参数（比较编码器）
' param: 一维比较参数
' chn：通道号,范围0~3
' 注：1)需要先设置编码器模式，可设置外部编码器或内部计数。
'???? 2)比较输出引脚位置请参考硬件手册。
'???? 3)out1比较位置到后马上输出, out2到位后延时输出。
Public Declare Function NMC_CompHs1DimensSetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef param As TCompHs1DimensParam, ByVal chn As Integer) As Integer

' 功能：读取高速1维位置比较的参数
' param, chn：同上
Public Declare Function NMC_CompHs1DimensGetParam Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef param As TCompHs1DimensParam, ByVal chn As Integer) As Integer

' 功能：设置高速1维比较数据
' pArrayPos:比较数组地址
' count:位置点数
' chn: 同上
Public Declare Function NMC_CompHs1DimensSetData Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pArrayPos As Long, ByVal count As Integer, ByVal chn As Integer) As Integer

' 功能：高速1维位置比较使能
' onOff： 0:停止,1:输出,2:手动输出（必须在空闲状态下,也需要提前设置参数）
' chn: 同上
Public Declare Function NMC_CompHs1DimensOnOff Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal onOff As Integer, ByVal chn As Integer) As Integer

' 功能：高速1维位置比较的状态
' pBusy: 0 未启动比较 1 比较输出中
' pOutCount：输出的个数
' pWaitCnts：等待比较的个数
' pFreeCnts：缓冲区空闲的个数
' chn: 同上
Public Declare Function NMC_CompHs1DimensStatus Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pBusy As Integer, ByRef pOutCount As Integer, ByRef pWaitCnts As Integer, ByRef pFreeCnts As Integer, ByVal chn As Integer) As Integer




