Attribute VB_Name = "NMC_Lib"

     
'   指令返回值定义，Motion 2.0的错误代码请参考c++的头文件mtn_lib20_err.h


'------------------------------------------------------------------------------------------------------------
'
'           指令分组索引
'
'------------------------------------------------------------------------------------------------------------
'  1.控制器连接、关闭
'  2.单轴配置
'  3.单轴控制
'  4.单轴状态读取
'  5.IO控制及外部资源读写
'  6.坐标系配置
'  7.坐标系控制
'  8.坐标系及运动缓冲区状态读取
'  9.缓冲区插补运动和IO控制
'  10.回零



'------------------------------------------------------------------------------------------------------------
'
'          1.控制器连接、关闭
'
'------------------------------------------------------------------------------------------------------------
'通讯模式设置
Public Enum TSearchMode
        USB = 0
        Ethernet
        RS485
End Enum

' 设备信息结构
Public Type TDevInfo
        address As Integer           ' 在上位机系统中的设备序号,
        idStr As String * 16         ' 识别字符串
        description As String * 64   ' 描述符
        ID As Integer                ' 板上的ID
End Type

' 板卡搜寻
Public Declare Function NMC_DevSearch Lib "nmc_lib20.dll" (ByVal mode As TSearchMode, ByRef pDevNo As Integer, ByRef pInfoList As TDevInfo) As Integer

' 板卡打开（根据序号）
' devNo: 设备序号，取值范围[0,n]； pDevHandle: 返回设备操作句柄
Public Declare Function NMC_DevOpen Lib "nmc_lib20.dll" (ByVal devNo As Integer, ByRef pDevHandle As Integer) As Integer

' 板卡关闭
' pDevHandle : 设备句柄指针
Public Declare Function NMC_DevClose Lib "nmc_lib20.dll" (ByRef pDevHandle As Integer) As Integer

' 板卡复位
Public Declare Function NMC_DevReset Lib "nmc_lib20.dll" (ByVal devHandle As Integer) As Integer

' 打开单轴
' devHandle : 设备句柄
' itemNo：轴号，取值范围[0,n]
' pCrdHandle：坐标系组句柄
Public Declare Function NMC_MtOpen Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal itemNo As Integer, ByRef pAxisHandle As Integer) As Integer

' 关闭单轴
' devHandle : 设备句柄指针
Public Declare Function NMC_MtClose Lib "nmc_lib20.dll" (ByRef pAxisHandle As Integer) As Integer

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

' 关闭坐标系组
' pCrdHandle：坐标系组句柄
Public Declare Function NMC_CrdClose Lib "nmc_lib20.dll" (ByRef pCrdHandle As Integer) As Integer


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

' 编码器模式：定义信号源，信号类型，取反，,编码器分频等
' Bit7:0 分频系数，数值为0~255。对应分频数值 1~256
' Bit9:8 信号号源选择
'   00：外部信号输入
'   01: 轴脉冲输入
'   10：自动产生信号（正脉冲）
'   11：自动产生信号（负脉冲）
' Bit11:10 信号类型（外部）
'  00：AB相，90度差
'  01：脉冲+方向
'  10：正脉冲+负脉冲
'  11：保留
' Bit12 输入A、B交换（外部） 0：不交换，1：交换
' Bit13 输入A取反（外部） 0：不取反，1：取反
' Bit14 输入B取反（外部） 0：不取反，1：取反
' Bti15 编码器饱和，0：最大最小值翻转，1：不翻转

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

' 设置软件限位是否停止运动
' posLmt：正向软件限位设置值
' negLmt：负向软件限位设置值。单位为脉冲数
Public Declare Function NMC_MtSwLmtValue Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal posLmt As Long, ByVal negLmt As Long) As Integer


' 设置软件限位数值
' swt：软件限位触发允许设置,1为允许,0为禁止：正向软件限位设置值
Public Declare Function NMC_MtSwLmtOnOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal swt As Integer) As Integer

' 轴运动安全参数
Public Type TSafePara
        estpDec As Double              ' 急停减速度
        maxVel As Double               ' 最大速度
        maxAcc As Double               ' 最大加速度
End Type

' 设置轴安全参数
' TSafePara：包含急停减速度、最大允许速度、最大允许加速度
Public Declare Function NMC_MtSetSafePara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef refPara As TSafePara) As Integer

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

' 设置轴速度滤波参数
' 注：filterCoef系数在0~5之间，值越大，速度越平滑
Public Declare Function NMC_MtSetAxisVelFilter Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal filterCoef As Integer) As Integer

' 硬件限位配置
' posLmtEnable: 正向限位触发允许设置，1为允许，0为禁止
' negLmtEnable: 负向限位触发允许设置，1为允许，0为禁止
' posLmtSns: 正向限位触发电平，1为高电平触发，0为低电平触发
' negLmtSns: 正向限位触发电平，1为高电平触发，0为低电平触发
Public Declare Function NMC_MtSetLmtCfg Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal posLmtEnable As Integer, ByVal negLmtEnable As Integer, ByVal posLmtSns As Integer, ByVal negLmtSns As Integer) As Integer

' 伺服报警配置
'alarmEnable: 伺服报警触发允许设置，1为允许，0为禁止
'alarmSns:     伺服报警触发电平，1为高电平触发，0为低电平触发
Public Declare Function NMC_MtSetAlarmCfg Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal alarmEnable As Integer, ByVal alarmSns As Integer) As Integer

' 设置脉冲输出滤波
' coe系数： 范围0~65535，0不滤波，数值越大滤波效果越明显。
Public Declare Function NMC_MtSetStepFilter Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal coe As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'          3.单轴控制指令
'
'------------------------------------------------------------------------------------------------------------
' 各轴的规划模式
Public Const MT_NONE_PRF_MODE            As Integer = -1            ' 无效
Public Const MT_PTP_PRF_MODE             As Integer = 0             ' 梯形规划
Public Const MT_JOG_PRF_MODE             As Integer = 1             ' 连续速度模式
Public Const MT_CRD_PRF_MODE As Integer = 3             ' 坐标系
Public Const MT_GANTRY_MODE As Integer = 4             ' 龙门跟随模式
Public Const MT_PT_PRF_MODE As Integer = 5                          ' PT模式
Public Const MT_MULTI_LINE_MODE As Integer = 6                          ' 多轴直线插补

' 设置单轴规划模式
' mode：单轴运动模式
Public Declare Function NMC_MtSetPrfMode Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal mode As Integer) As Integer

' 单轴运动参数结构
Public Type TPtpPara
        acc As Double                ' 加速度
        dec As Double                ' 减速度
        startVel As Double           ' 起跳速度
        endVel As Double             ' 终止速度
        smoothCoef As Integer        ' 平滑系数，取值范围[0,199]
        dummy(2) As Integer          ' 保留
End Type

' 设置多个参数, 并更新。
' pAxPara：参数，参考结构定义。
Public Declare Function NMC_MtSetPtpPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef refAxPara As TPtpPara) As Integer

' 单轴JOG运动参数结构
Public Type TJogPara
        acc As Double                ' 加速度
        dec As Double                ' 减速度
        smoothCoef As Double         ' 平滑系数，取值范围[0,199]
End Type

' 获取Ptp参数
' pAxPara：参数
Public Declare Function NMC_MtGetPtpPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pAxPara As TPtpPara) As Integer

' 获取Jog参数
' pAxPara：参数
Public Declare Function NMC_MtGetJogPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pAxPara As TJogPara) As Integer

' 读取轴安全参数
' TSafePara：包含急停减速度、最大允许速度、最大允许加速度
Public Declare Function NMC_MtGetSafePara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pPara As TSafePara) As Integer

' 设置Jog运动参数
' pAxPara：参数，参考结构定义。
Public Declare Function NMC_MtSetJogPara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef refAxPara As TJogPara) As Integer

' 设置目标运动速度,只针对PTP和Jog：PTP模式下只接受正数，Jog模式下正负号标识运动方向
' vel: 目标速度（最大速度），单位是 脉冲/ms
Public Declare Function NMC_MtSetVel Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal vel As Double) As Integer

' 设置目标运动位置，只针对PTP
' pos: 目标位置，单位是 脉冲
Public Declare Function NMC_MtSetPtpTgtPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal pos As Long) As Integer

' 参数更新,只针对PTP和Jog
Public Declare Function NMC_MtUpdate Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 单轴运动停止
' 注：运动会按设定的减速度停止。
Public Declare Function NMC_MtStop Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

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

' 单轴位置系统清零，规划以及编码器
Public Declare Function NMC_MtZeroPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 设置伺服报警清除
' swt: 设置开关有效状态。1, 有效（输出低电平），0，无效（输出高电平）
Public Declare Function NMC_MtSetSvClr Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal swt As Integer) As Integer

' 设置伺服ON, 轴静止时执行，如果后面是update指令，需要延时一个周期
Public Declare Function NMC_MtSetSvOn Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 设置伺服OFF, 轴静止时执行，如果后面是update指令，需要延时一个周期
Public Declare Function NMC_MtSetSvOff Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 清除轴错误状态
Public Declare Function NMC_MtClrError Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 清除轴错误状态，按位清除
' stsMask:对应位为1表明需要清除对应位的错误状态
Public Declare Function NMC_MtClrStsByBits Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal stsMask As Integer) As Integer

' 单轴点位运动,包含NMC_MtSetPrfMode,NMC_MtSetPtpPara,NMC_MtSetVel,NMC_MtSetPtpTgtPos,NMC_MtUpdate
' acc:加速度,dec：减速度,startVel:起跳速度,endVel:终止速度,smoothCoef:平滑系数
' maxVel：最大速度
' tgtPos:目标位置,单位：脉冲
Public Declare Function NMC_MtMovePtpAbs Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal acc As Double, ByVal dec As Double, ByVal startVel As Double, ByVal endVel As Double, ByVal maxVel As Double, ByVal smoothCoef As Integer, ByVal tgtPos As Long) As Integer

' 单轴连续速度运动
' acc:加速度,dec：减速度,smoothCoef:平滑系数
' maxVel：最大速度
' clrStsFlag:是否运动前先清除轴状态，0：不清除，1：清除
Public Declare Function NMC_MtMoveJog Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal acc As Double, ByVal dec As Double, ByVal maxVel As Double, ByVal smoothCoef As Integer, ByVal clrStsFlag As Integer) As Integer

Public Type TMovePtpPack8
     axisMask As Integer                        ' 轴掩码，对应bit为1表示该轴参与运动
     clrStsFlag As Integer                      ' 是否运动前先清除轴状态，0：不清除，1：清除
     reserved(2) As Integer                     ' 保留
     acc(8) As Double                   ' 加速度
     dec(8) As Double                   ' 减加速度
     startVel(8) As Double              ' 起跳速度
     endVel(8) As Double                ' 终止速度
         maxVel(8) As Double            ' 最大速度
         smoothCoef(8) As Double        ' 平滑系数
         tgtPos(8) As Long                      ' 位置，单位:脉冲
End Type
' 单轴点位运动打包(绝对运动)
' axisFirstHandle:数组的第一个轴句柄
' pPackData:打包参数
' 注意：1.如果某轴存在无法运动的错误状态，则所有轴不会启动运动
Public Declare Function NMC_MtMovePtpAbsPack8 Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByRef pPackData As TMovePtpPack8) As Integer

' 单轴点位运动打包(相对运动)
' axisFirstHandle:数组的第一个轴句柄
' pPackData:打包参数
' 注意：1.如果某轴存在无法运动的错误状态，则所有轴不会启动运动
Public Declare Function NMC_MtMovePtpRelPack8 Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByRef pPackData As TMovePtpPack8) As Integer

' 单轴点位运动,相对运动
' acc:加速度,dec：减速度,startVel:起跳速度,endVel:终止速度,smoothCoef:平滑系数
' maxVel：最大速度
' relPos:相对当前位置的移动量,单位：脉冲
Public Declare Function NMC_MtMovePtpRel Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByVal acc As Double, ByVal dec As Double, ByVal startVel As Double, ByVal endVel As Double, ByVal maxVel As Double, ByVal smoothCoef As Integer, ByVal relPos As Long) As Integer

' PTP两段速运动参数
Public Type TPtpTwoStagePrm
     acc As Double         ' 加速度
     dec As Double         '减速度
     startVel As Double     ' 启动速度
     endVel As Double      ' 终点速度
     maxVel As Double      ' 最大速度
     tgtPos As Long        ' 目标位置
     reserved As Integer      ' 保留参数
     smoothCoef As Integer   ' 平滑系数
     inType As Integer       '输入类型：0：通用DI，1：Home信号;
     inIdx As Integer      ' 输入信号通道号
     inTrigLevel As Integer ' 触发电平，0：低电平，1：高电平
     action As Integer       ' 触发后的动作，0：不动作，1：更新目标速度,
' 2.更新目标位置
' 3:更新目标位置（位置为相对触发点的相对位置）
' 4:急停
     prm1 As Double        ' action=1时表示更新的目标速度
     prm2 As Double        ' action=2，3时表示更新的目标位置
     prm3 As Double        ' 保留
     prm4 As Double       ' 保留
End Type

' 两段速PTP运动
Public Declare Function NMC_MtMovePtpAbsTwoStage Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pPrm As TPtpTwoStagePrm) As Integer

'------------------------------------------------------------------------------------------------------------
'
'         4.单轴状态读取
'
'------------------------------------------------------------------------------------------------------------

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

' 读当前轴规划速度
' pVel: 返回速度，单位是 脉冲/ms
Public Declare Function NMC_MtGetPrfVel Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pVel As Double) As Integer

' 单轴打包控制器状态结构
Public Type TAxisStsPack
        cmdPos(4) As Long               ' 规划位置
        encPos(4) As Long               ' 实际位置
        cmdVel(4) As Single             ' 规划速度
        motionIO(4) As Long             ' 轴专用IO
        sts(4) As Integer               ' 轴状态
        gpo As Long                     ' 通用输出
        gpi As Long                     ' 通用输入
End Type

' 打包读取多个轴的状态，从第一个轴开始读取后续四个轴的状态
' axisFirstHandle : 第一个轴句柄
' count:读取状态的轴数量,取值范围：[1,4]
' packSts: 打包的状态数据，参考结构体定义
Public Declare Function NMC_MtGetStsPack Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByVal count As Integer, ByRef packSts As TAxisStsPack) As Integer

' 读取打包轴状态（12轴）
Public Type TAxisStsPack12Ex
    mtSts(12) As Integer           ' 单轴状态，位定义参考NMC_MtGetSts
    mtMio(12) As Integer         ' 单轴专用IO,位定义参考NMC_MtGetMotionIO
    mtMioLog(12) As Integer        ' 单轴专用IO:逻辑电平,位定义参考NMC_MtGetMotionIOLogical
    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         ' 通用输出
    rdLeftLen(2) As Long    ' 坐标系缓冲区剩余段长，单位:脉冲
    crdAllCmdCnt(2) As Long   ' 坐标系缓冲区总共压入的指令数目
    extDi(6) As Long    ' 扩展模块输入，2号站~8号站
    extDo(6) As Long    ' 扩展模块输出，2号站~8号站
    reserved(16)  As Long    ' 预留

End Type
' 打包读取12个轴的状态
' axisFirstHandle : 第一个轴句柄
' pPackSts: 打包的状态数据,参考结构体定义
Public Declare Function NMC_MtGetStsPack12Ex Lib "nmc_lib20.dll" (ByVal axisFirstHandle As Integer, ByRef pPackSts As TAxisStsPack12Ex) As Integer

' 读当前轴编码器通道
' pPos:返回编码器数值
Public Declare Function NMC_MtGetEncPos Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pos As Long) As Integer

' 读编码器速度
' devHandle : 控制器句柄；encId: 编码器ID,取值范围[0,n]
' vel:返回编码器速度
Public Declare Function NMC_GetEncVel Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal encId As Integer, ByRef vel As Double) As Integer

' 轴状态字位定义
Public Const BIT_AXIS_BUSY               As Integer = &H1           ' bit 0  , 运动:1 ，静止 0
Public Const BIT_AXIS_POSREC             As Integer = &H2           ' bit 1  , 伺服位置到达，步进模式时位置到达，伺服模式时实际位置到达误差限
Public Const BIT_AXIS_MVERR              As Integer = &H4           ' bit 2  , 上次运动出错，或当前无法启动运动，需要软件复位
Public Const BIT_AXIS_SVON               As Integer = &H8           ' bit 3  , 伺服允许
Public Const BIT_AXIS_CRD                As Integer = &H10          ' bit 4  , 坐标系模式
Public Const BIT_AXIS_STEP               As Integer = &H20          ' bit 5  , 步进/伺服
Public Const BIT_AXIS_LMTP               As Integer = &H40          ' bit 6  , 正向限位
Public Const BIT_AXIS_LMTN               As Integer = &H80          ' bit 7  , 负面限位
Public Const BIT_AXIS_SOFTPOSLMT         As Integer = &H100         ' bit 8  , 正向软限位触发
Public Const BIT_AXIS_SOFTNEGLMT         As Integer = &H200         ' bit 9  , 负向软限位触发
Public Const BIT_AXIS_ALM                As Integer = &H400         ' bit 10 , 伺服报警，需要软件复位
Public Const BIT_AXIS_POSERR             As Integer = &H800         ' bit 11 , 位置超限，需要软件复位
Public Const BIT_AXIS_ESTP               As Integer = &H1000        ' bit 12 , 急停，需要软件复位
Public Const BIT_AXIS_HWERR              As Integer = &H2000        ' bit 13 , 硬件错误
Public Const BIT_AXIS_CAPTSET            As Integer = &H4000        ' bit 14 , 捕获触发

' 读当前轴状态
' pStsWord: 返回轴状态字。参考位定义
Public Declare Function NMC_MtGetSts Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pStsWord As Integer) As Integer

' 专用IO定义，alm : home : limit+ , limit-
Public Const BIT_AXMTIO_LMTN             As Integer = &H1           ' bit 0  ,负向限位
Public Const BIT_AXMTIO_LMTP             As Integer = &H2           ' bit 1  ,正向限位
Public Const BIT_AXMTIO_HOME             As Integer = &H4           ' bit 2  ,原点
Public Const BIT_AXMTIO_ALARM            As Integer = &H8           ' bit 3  ,驱动报警
Public Const BIT_AXMTIO_ARRIVE As Integer = &H10          ' bit 4 ,电机到位
Public Const BIT_AXMTIO_CAPT As Integer = &H20          ' bit 5 ,捕获源信号

' 读运动控制专用IO
' inValue : 返回专用IO的状态，原点，限位，报警。参考位定义。对应位为0为低电平，1为高电平。
Public Declare Function NMC_MtGetMotionIO Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef inValue As Long) As Integer

' 读运动控制专用IO,逻辑电平
' inValue : 返回专用IO的状态，原点，限位，报警。参考位定义。对应位为0为低电平，1为高电平。
Public Declare Function NMC_MtGetMotionIOLogical Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef inValue As Long) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        5.IO控制及外部资源读写
'
'------------------------------------------------------------------------------------------------------------

'设置通用输出(按通道,支持超过32位),带默认group
'value: 设置通用数字量输出。1, 输出高电平，0，输出低电平
'groupID:DO组，取值范围[0,n],具体需要看控制器是否存在多组数字量输出
Public Declare Function NMC_SetDOGroup Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal value As Long, ByVal groupID As Integer) As Integer

'读通用输入(按通道,支持超过32位) ,带默认group
'pInValue: 通用数字量输入值。1, 高电平，0，低电平
'groupID:DI组，取值范围[0,n],0: 本地DI31~DI0, 1: 本地DI63~DI32，其他指扩展IO模块
Public Declare Function NMC_GetDIGroup Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pInValue As Long, ByVal groupID As Integer) As Integer

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

' 按位设置通用输出
' bitIndex:取值范围[0,n],位序号
' value: 设置通用数字量输出。1, 输出高电平，0，输出低电平
Public Declare Function NMC_SetDOBit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByVal value As Integer) As Integer

' 按位读通用输入
' 读通用输入 Lib "nmc_lib20.dll" (按通道,支持超过32位)
' bitIndex:取值范围[0,n],位序号
' bitValue: 通用数字量输入值。1, 高电平，0，低电平
Public Declare Function NMC_GetDIBit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal bitIndex As Integer, ByRef bitValue As Integer) As Integer

' 设置IO模块有效
' chDevId : 模块地址，2~9
Public Declare Function NMC_SetIOModuleEn Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte) As Integer

' 读IO模块状态
' sts：返回状态，bit2 ~ bit9 对应外部IO扩展模块，1：在线，0：不在线
Public Declare Function NMC_GetIOModuleSts Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef sts As Long) As Integer

' 扩展模块类型定义
Public Const IOMODULE_TYPE_IO64 = 1     ' 32DI32DO模块（包括16DI16DO模块）
Public Const IOMODULE_TYPE_IO32_DA = 2     ' 4AD4DA模块

' 设置扩展IO模块有效(带模块类型)
' chDevId:设备ID
' chDevType:模块类型，见宏定义
Public Declare Function NMC_IOModuleSetEn Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal chDevType As Integer) As Integer

' 读取扩展IO模块类型
' chDevId:设备ID
' pChDevType:返回的模块类型，见宏定义
Public Declare Function NMC_IOModuleGetType Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByRef chDevType As Integer) As Integer

' 扩展IO模块通道写，8位长度
' chDevId：设备站号
' offset:数据偏移
Public Declare Function NMC_IOModuleWr8Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByVal data As Byte) As Integer

' 扩展IO模块通道写，16位长度
Public Declare Function NMC_IOModuleWr16Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByVal data As Integer) As Integer

' 扩展IO模块通道写，32位长度
Public Declare Function NMC_IOModuleWr32Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByVal data As Long) As Integer

' 扩展IO模块通道读输出，8位长度
' chDevId：设备站号
' offset:数据偏移
Public Declare Function NMC_IOModuleRdOut8Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Byte) As Integer

' 扩展IO模块通道读输出，16位长度
Public Declare Function NMC_IOModuleRdOut16Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Integer) As Integer

' 扩展IO模块通道读输出，32位长度
Public Declare Function NMC_IOModuleRdOut32Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Long) As Integer

' 扩展IO模块通道读，8位长度
' chDevId：设备站号
' offset:数据偏移
Public Declare Function NMC_IOModuleRd8Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Byte) As Integer

' 扩展IO模块通道读，16位长度
Public Declare Function NMC_IOModuleRd16Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Integer) As Integer

' 扩展IO模块通道读，32位长度
Public Declare Function NMC_IOModuleRd32Bit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByVal chDevId As Byte, ByVal offset As Byte, ByRef pData As Long) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        6.坐标系配置
'
'------------------------------------------------------------------------------------------------------------

' 坐标系配置
Public Type TCrdConfig
        axCnts As Integer            ' 参与插补的轴数目
        dummy(3) As Integer          ' 保留
        pAxis(4) As Integer          ' X,Y,Z,A轴映射的物理轴，序号取值范围[0,n],不使用设置为-1
        port(4) As Integer           ' X,Y,Z,A轴端口号，请设为0
End Type

' 建立插补坐标系系统(必须)
' refConfig:坐标系配置，参考结构体定义
Public Declare Function NMC_CrdConfig Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef refConfig As TCrdConfig) As Integer

'缓冲区运动安全参数
Public Type TCrdSafePara
        estpDec As Double            ' 急停减速度
        maxVel As Double             ' 最大速度
        maxAcc As Double             ' 最大加速度
End Type

' 设置轴缓冲区运动安全参数
' pPara：包含急停减速度、最大允许速度、最大允许加速度
Public Declare Function NMC_CrdSetSafePara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pPara As TCrdSafePara) As Integer

' 设置轴缓冲区运动偏移
' count:设置偏移的轴数
' pOffsetArray：缓冲区运动偏移，long数组
' 注：会同时修改坐标系内相关轴的运动偏移
Public Declare Function NMC_CrdSetOffset Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal count As Integer, ByRef pOffsetArray As Long) As Integer

' 删除坐标系
Public Declare Function NMC_CrdDelete Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        7.坐标系运行控制
'
'------------------------------------------------------------------------------------------------------------

' 坐标系缓冲运动启动
Public Declare Function NMC_CrdStartMtn Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 立即平滑停止运动
' 注：立即停止运动。并不清空指令缓冲区。需要再次启动才能继续运行缓冲区指令。
Public Declare Function NMC_CrdStopMtn Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 急停
' 并不清空指令缓冲区
Public Declare Function NMC_CrdEstopMtn Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 结束缓冲区运动（等待运动完后才结束区运动，并置空闲标志）
' 注：缓冲区运动结束并不立即停止运动。把指令缓冲区全部执行完后，结束缓冲区运动状态。
Public Declare Function NMC_CrdEndMtn Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 坐标系缓冲运动回到断点
' vel:返回时使用的速度
' acc:返回时使用的加速度
Public Declare Function NMC_CrdGotoBreak Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal acc As Double, ByVal vel As Double) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        8.坐标系及运动缓冲区状态读取
'
'------------------------------------------------------------------------------------------------------------

' 坐标系状态字位定义
Public Const BIT_CORD_BUSY               As Integer = &H1           ' bit 0 , 运动:1 ，静止 0,立即运动下运动停止，完成
Public Const BIT_CORD_MVERR              As Integer = &H2           ' bit 1 , 运动出错，或当前运动指令无法启动，需要软件复位
Public Const BIT_CORD_EMPTY              As Integer = &H4           ' bit 2 , 缓冲区空
Public Const BIT_CORD_FULL               As Integer = &H8           ' bit 3 , 缓冲区满
Public Const BIT_CORD_NODATASTOP         As Integer = &H10          ' bit 4 , 缓冲区空异常停止或者急停
Public Const BIT_CORD_SDRAM_HWERR        As Integer = &H20          ' bit 5 , 插补缓冲区硬件或者其他错误

' 读取坐标系状态
' pStsWord：返回状态字，参考宏定义
Public Declare Function NMC_CrdGetSts Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pStsWord As Integer) As Integer

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

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

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

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

' 打包坐标系状态结构体
Public Type TPackedCrdSts4
        crdSts As Integer              ' 坐标系状态
        axSts(4) As Integer            ' 坐标系里轴X/Y/Z状态
        prfPos(4) As Long              ' 用户坐标系下的规划位置
        axisPos(4) As Long             ' 机械坐标系下的规划位置
        encPos(4) As Long              ' 编码器位置
        userSeg As Long                ' 运行的缓冲区段号
        prfVel As Double               ' 运动速度
        gpDi As Long                   ' 通用输入0~31
        gpDo As Long                   ' 通用输出0~31
        motDi(4) As Integer            ' 限位、原点、报警。请参考专用IO位定义( 搜索 BIT_AXMTIO_LMTN )
        reserved As Integer            ' 保留
        crdFreeSpace As Long           ' 剩余空间
        reserved2 As Long              ' 保留
End Type

' 坐标系运动模式下，打包读取控制器状态
Public Declare Function NMC_CrdGetStsPack4 Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pPackSts As TPackedCrdSts3) As Integer

' 清坐标系运动错误状态，同时清除所包含轴的错误状态
Public Declare Function NMC_CrdClrError Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 读取指令缓冲区空闲长度
' pRes：返回空闲的长度
Public Declare Function NMC_CrdBufGetFree Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pRes As Long) As Integer

' 读取指令缓冲区已用长度
' pLen: 长度。缓冲区中还未执行的指令个数。
Public Declare Function NMC_CrdBufGetUsed Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pLen As Long) As Integer

' 获取插补缓冲区中尚未完成的总位移量
' pLen: 长度
Public Declare Function NMC_CrdGetBufLeftLength Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pLen As Double) As Integer

' 指令缓冲区清空
Public Declare Function NMC_CrdBufClr Lib "nmc_lib20.dll" (ByVal crdHandle As Integer) As Integer

' 设置坐标系剩余位移量，用于控制激光能量跟随后的关闭波形输出
Public Declare Function NMC_CrdSetLeftLenForLaserWaveOff Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal length As Double) As Integer

' 读段号
' pSegNo：返回的当前段号
Public Declare Function NMC_CrdGetUserSegNo Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pSegNo As Long) As Integer

' 读取插补坐标系系统配置信息
' config:返回坐标系配置，参考结构体定义
Public Declare Function NMC_CrdGetConfig Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pConfig As TCrdConfig) As Integer

' 读取总共压了多少条指令
' pCnt:返回的指令数
Public Declare Function NMC_CrdGetBufAllCmdCnt Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByRef pCnt As Long) As Integer

' 开始计算缓冲区执行时间
' 注意:1.如果需要计算执行时间，需要使用上位机前瞻
'     2.开始后，所有的缓冲区指令，都不会压入控制器
Public Declare Function NMC_CrdStartExeTimeCalc Lib "nmc_lib20.dll" () As Integer

' 读取缓冲区指令的执行时间，并停止计算，单位:ms
Public Declare Function NMC_CrdGetExeTime Lib "nmc_lib20.dll" (ByVal pTime As Double) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        9.缓冲区插补运动和IO控制
'
'------------------------------------------------------------------------------------------------------------

' 四轴直线插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' crdAxMask:参与的轴,按位表示
' endVel,vel,synAcc:终点速度，最大速度，插补加速度
' pTgPosArray：目标位置数组
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdLineXYZA 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, ByVal lookaheadDis As Integer) As Integer

' 设置4维插补下，A轴的最大容忍转弯速度，若大于该速度，则需要进行降速处理
Public Declare Function NMC_CrdSetFourthAxisTolTurnVel Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal tolVel As Double) As Integer

' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' crdAxMask:参与的轴,按位表示
' pTgPosArray：目标位置数组,长度为3
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdLineXYZEx 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, ByVal lookaheadDis As Integer) As Integer

' 多轴直线插补（最多支持8轴）
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' crdAxmask:坐标系中参与的轴,按位表示
' extAxMask:其他参与轴,按位表示,不能包括坐标系中
' pTgPosArray：目标位置数组,长度为所有参与运动的轴的数量,
'              索引小的是坐标系内的轴的坐标（按crdAxMask位排列）。索引大的是其它联动轴的坐标（按extAxMask位排列）
' lookaheadDis:是否使用前瞻(仅仅适用与坐标系中的轴的运动),0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdLineXYZD8 Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal crdAxMask As Integer, ByVal extAxMask As Integer, ByRef pTgPosArray As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' 8轴插补打包的直线插补结构
Public Type TCrdLineXYZD8Unit
    segNo As Long            ' 用户自定义段号
    crdAxMask As Integer
    extAxMask As Integer
    tgPos(8) As Long         ' 目标位置
    endVel As Single         ' 终点速度
    vel As Single            ' 最大速度
    acc As Single            ' 插补加速度
    lookaheadDis As Integer          ' 是否使用前瞻
    reserved As Integer   ' 保留
End Type

' 打包的直线插补
' count:打包指令数，取值范围[1,5]
' pCmdArray:指令列表
Public Declare Function NMC_CrdLineXYZD8Pack Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal count As Integer, ByRef pCmdArray As TCrdLineXYZD8Unit) As Integer

' 4轴插补打包的直线插补结构
Public Type TCrdLineXYZD4Unit
    segNo As Long            ' 用户自定义段号
    crdAxMask As Integer
    extAxMask As Integer
    tgPos(4) As Long         ' 目标位置
    vel As Single            ' 最大速度
    endVel As Single         ' 终点速度
    acc As Single            ' 插补加速度
    lookaheadDis As Integer          ' 是否使用前瞻
    reserved As Integer   ' 保留
End Type

' 打包的直线插补
' count:打包指令数，取值范围[1,5]
' pCmdArray:指令列表
Public Declare Function NMC_CrdLineXYZD4Pack Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal count As Integer, ByRef pCmdArray As TCrdLineXYZD4Unit) As Integer

' 打包的4轴直线插补
Public Type TCrdLineXYZUnit
    segNo As Long            ' 用户自定义段号
    tgPos(3) As Long         ' 目标位置
    endVel As Double         ' 终点速度
    vel As Double            ' 最大速度
    synAcc As Double            ' 插补加速度
    mask As Integer            ' 参与的轴,按位表示
    lookaheadDis As Integer          ' 参与的轴，按位表示
    reserved(2) As Integer   ' 保留
End Type

' 打包的直线插补
' count:打包指令数，取值范围[1,5]
' pCmdArray:指令列表
Public Declare Function NMC_CrdLineXYZPack Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal count As Integer, ByRef pCmdArray As TCrdLineXYZUnit) As Integer

' XY平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示XY的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcRadius Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' YZ平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示YZ的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcRadiusYZ Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer


' ZX平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示ZX的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcRadiusZX Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer


' XY平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示XY的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcRadiusEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' YZ平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示YZ的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcRadiusYZEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' ZX平面圆弧插补：终点位置、半径、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' radius:圆弧半径,大于0表示劣弧,小于0表示优弧
' pTgPosArray：目标位置数组（二维数组,分别表示ZX的位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcRadiusZXEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByVal radius As Double, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' XY平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示XY轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示XY轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcCenter Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' YZ平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示YZ轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示YZ轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcCenterYZ Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' ZX平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示ZX轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示ZX轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdArcCenterZX Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' XY平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示XY轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示XY轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcCenterEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' YZ平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示ZX轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示YZ轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcCenterYZEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' ZX平面圆弧插补：终点位置、圆心、方向
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标（二维数组,分别表示ZX轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' pTgPosArray：目标位置（二维数组,分别表示ZX轴的目标位置）
' circleDir:圆弧方向,0表示顺时针方向,1表示逆时针方向
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcCenterZXEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

'  XY平面圆弧插补：起点（当前点）、中点、终点
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pMidPosArray:中间位置点坐标（二维数组,分别表示中间点的XY轴的位置
' pTgPosArray：终点位置坐标（二维数组,分别表示终点的XY轴的位置）
Public Declare Function NMC_CrdArcPPP Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pMidPosArray As Long, ByRef pTgPosArray As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' XY平面圆弧插补：起点（当前点）、中点、终点
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pMidPosArray:中间位置点坐标（二维数组,分别表示中间点的XY轴的位置）
' pTgPosArray：终点位置坐标（二维数组,分别表示终点的XY轴的位置）
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArcPPPEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pMidPosArray As Long, ByRef pTgPosArray As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' 椭圆插补，默认不参与速度前瞻，起始和终止速度为0（注意！椭圆为整圆）
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPos：椭圆圆心点位置（二维数组,分别表示中点的XY轴的位置）。注意！起点位置到圆心位置为长轴的
' abRatio:表示椭圆AB轴的长度比例值 值范围：[0.05,1]
' ellipseDir:椭圆绘画方向,0表示顺时针方向,1表示逆时针方向
Public Declare Function NMC_CrdEllipse Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal abRatio As Double, ByRef pCenterPos As Long, ByVal ellipseDir As Integer, ByVal vel As Double, ByVal synAcc As Double) As Integer

' 螺旋线插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pCenterPosArray:圆心坐标为相对起点的偏移量
' pTgPosArray：目标位置
' rounds：圈数
Public Declare Function NMC_CrdHelixCenter Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal rounds As Double, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' 螺旋线插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pTgPosArray：目标位置（三维数组,分别表示终点的XYZ轴的位置）
' pCenterPosArray:圆心位置（二维数组,分别表示XY轴相对于起点的圆心位置）,注意：圆心坐标为相对于起点的相对位置
' rounds: Z方向圈数
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdHelixCenterEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pTgPosArray As Long, ByRef pCenterPosArray As Long, ByVal circleDir As Integer, ByVal rounds As Double, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' 3D圆弧插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pMidPos：中点位置（三维数组,分别表示中点的XYZ轴的位置）
' pTgPos:终点位置（三维数组,分别表示终点的XYZ轴的位置）
Public Declare Function NMC_CrdArc3D Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pMidPos As Long, ByRef pTgPos As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double) As Integer

' 3D圆弧插补
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pMidPos：中点位置（三维数组,分别表示中点的XYZ轴的位置）
' pTgPos:终点位置（三维数组,分别表示终点的XYZ轴的位置）
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdArc3DEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pMidPos As Long, ByRef pTgPos As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' 3D圆弧插补(整圆)
' segNo:段号；endVel:终点速度;vel:最大速度;synAcc:合成加速度
' pMidPos：中点位置（三维数组,分别表示中点的XYZ轴的位置）
' pTgPos:终点位置（三维数组,分别表示终点的XYZ轴的位置）
' lookaheadDis:是否使用前瞻,0：使用前瞻,则控制器自动计算终点速度,1：禁用前瞻,使用设定的终点速度（endVel）
Public Declare Function NMC_CrdCircle3DEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByRef pMidPos As Long, ByRef pTgPos As Long, ByVal endVel As Double, ByVal vel As Double, ByVal synAcc As Double, ByVal lookaheadDis As Integer) As Integer

' 缓冲区输出DO组定义
Public Const CRD_BUFF_DO_MOTOR_ENABLE    As Integer = 1             ' 电机使能
Public Const CRD_BUFF_DO_MOTOR_CLEAR     As Integer = 2             ' 电机报警清除
Public Const CRD_BUFF_DO_GPDO1           As Integer = 3             ' 通用输出1
Public Const CRD_BUFF_DO_GPDO2 As Integer = 4             ' 通用输出2
Public Const CRD_BUFF_DO_EXTDO1 As Integer = 5             ' 扩展模块1
Public Const CRD_BUFF_DO_EXTDO2 As Integer = 6             ' 扩展模块2
Public Const CRD_BUFF_DO_EXTDO3 As Integer = 7             ' 扩展模块3
Public Const CRD_BUFF_DO_EXTDO4 As Integer = 8             ' 扩展模块4
Public Const CRD_BUFF_DO_EXTDO5 As Integer = 9             ' 扩展模块5
Public Const CRD_BUFF_DO_EXTDO6 As Integer = 10             ' 扩展模块6

' 缓冲区DO
' segNo:段号
' gourp:Do组别,见宏定义
' opBits：操作位
' value：输出值
Public Declare Function NMC_CrdBufDo Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal group As Integer, ByVal opBits As Long, ByVal value As Long) As Integer

' 缓冲区DO
' segNo:段号
' gourp:Do组别,见宏定义
' doMask：位掩码
' doValue：输出值
Public Declare Function NMC_CrdBufDoEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal group As Integer, ByVal doMask As Long, ByVal doValue As Long) As Integer

' 通用输出宏类型
Public Const BUF_OUT_GROUP_DA            As Integer = 0             ' 模拟量输出
Public Const BUF_OUT_GROUP_PWM           As Integer = 1             ' PWM输出

' 缓冲区输出
' segNo:段号
' gourp:组别
' opBits：通道
' value：输出值
Public Declare Function NMC_CrdBufOut Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal group As Integer, ByVal ch As Integer, ByVal value As Long) As Integer

' 缓冲区DI等待
' index:通道号
' diValue：等待值
' waitLastTime：超时
Public Declare Function NMC_CrdBufWaitDI Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal index As Integer, ByVal diValue As Integer, ByVal waitLastTime As Long) As Integer

' 功能:缓冲区等待电机运动到位
' segNo:段号
' axisMask:需要等待到位的轴掩码（按位对应轴号,不能超出控制器的最大轴数）
' overTime:等待到位超时的时间，单位：ms
Public Declare Function NMC_CrdBufWaitEncInPosition Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axisMask As Long, ByVal overTime As Long) As Integer

' 功能:缓冲区等待特定位置，满足条件才执行下一条指令
' segNo:段号
' axisNo:需要等待到位的轴号
' condition:到位条件，0：小于等于设定位置  1：大于等于设定位置
' pos:设定位置
' posSrc:等待规划还是编码器，0：编码器 1：内部规划
' overTime:等待到位超时的时间，单位：ms
Public Declare Function NMC_CrdBufWaitPos Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axisNo As Integer, ByVal condition As Integer, ByVal pos As Long, ByVal posSrc As Integer, ByVal overTime As Long) As Integer

'缓冲区延时单位
Public Const CRD_BUFF_DELAY_SCALE_MS     As Integer = 0             ' 毫秒
Public Const CRD_BUFF_DELAY_SCALE_SECAND As Integer = 1             ' 秒

' 缓冲区延时
' segNo:段号
' ascale:延时单位 0表示单位为毫秒，1表示单位为秒
' count：延时时长
Public Declare Function NMC_CrdBufDelay Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal ascale As Integer, ByVal count As Long) As Integer

' 缓冲区单轴移动
' segNo:段号
' axMask:参与的轴
' pTgPos：目标位置
' blockEn:是否为阻塞模式
' synEn：是否为同步模式
Public Declare Function NMC_CrdBufAxMove Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axMask As Integer, ByVal pTgPos As Long, ByVal blockEn As Integer, ByVal synEn As Integer) As Integer

' 缓冲区单轴移动(带参数)
' segNo:段号
' axisMask:参与的轴
' pTgPos：目标位置
' vel:速度
' acc:加速度
' blockEn:是否为阻塞模式
' synEn：是否为同步模式,如果synEn和blockEn同时为1,则同步优先
Public Declare Function NMC_CrdBufAxMoveEx Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axMask As Integer, ByVal pTgPos As Long, ByVal vel As Double, ByVal acc As Double, ByVal blockEn As Integer, ByVal synEn As Integer) As Integer

' 缓冲区单轴移动(相对位移移动)
' segNo:段号
' axisMask:参与的轴
' pRelPos：相对移动位置
' blockEn:是否为阻塞模式
' synEn：是否为同步模式,如果synEn和blockEn同时为1,则同步优先
Public Declare Function NMC_CrdBufAxMoveRel Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axMask As Integer, ByVal pRelPos As Long, ByVal blockEn As Integer, ByVal synEn As Integer) As Integer


' 缓冲区单轴移动参数设置
' segNo:段号
' axis：轴号，[0,n]
' vel:运动速度
' acc:运动加速度
' smoothCoef:平滑系数
Public Declare Function NMC_CrdBufSetPtpMovePara Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axis As Integer, ByVal vel As Double, ByVal acc As Double, ByVal soomthCoef As Integer) As Integer

' 缓冲区跟随
' segNo:段号
' onOff:开关
Public Declare Function NMC_CrdBufValueFollow Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal onOff As Integer) As Integer

' 缓冲区设置加工幅面范围，超出范围则停止运动
' crdAxMask:是否激活幅面限制    按位进行判断 ，bit0~2，分别对应XYZ轴 1：开启，0 关闭
' pXMax: pXMax[0]为X的最小行程边界      pXMax[1]为X的最大行程边界  pXMax[2]为X发生干涉时等待的参考位置
' pYMax和pZMax 同pXMax说明
Public Declare Function NMC_CrdBufSetScaleLimit Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal crdAxMask As Integer, ByVal pXMax As Long, ByVal pYMax As Long, ByVal pZMax As Long) As Integer

' 设置跟随运动前的运动补偿量
' axis:轴号  0~N
'relDistance：相对补偿位移量
'vel：补偿速度
Public Declare Function NMC_CrdBufBeforeAxSyncMove Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal segNo As Long, ByVal axis As Integer, ByVal relDistance As Long, ByVal vel As Double) As Integer

' 设置坐标系速度倍率
' overRide：坐标系速度倍率
Public Declare Function NMC_CrdSetOverRide Lib "nmc_lib20.dll" (ByVal crdHandle As Integer, ByVal overRide As Double) As Integer

'------------------------------------------------------------------------------------------------------------
'
'        10.回零
'
'------------------------------------------------------------------------------------------------------------

' 回零类型定义
Public Enum THomeMode
        HM_MODE1 = 0      ' 单原点
        HM_MODE2          ' 单限位
        HM_MODE3          ' 单Z相
        HM_MODE4          ' 原点 + Z相
        HM_MODE5          ' 原点 + -Z相
        HM_MODE6          ' 限位+ -Z相
End Enum

' 回零参数设置
Public Type THomeSetting
        mode As Integer               ' 模式，HM_MODE1 ~ HM_MODE6 （必须）
        dir As Integer                ' 搜寻零点方向（必须）, 0:负向，1：正向，其它值无意义
        offset As Long                ' 原点偏移（必须）
        scan1stVel As Double          ' 基本搜寻速度（必须）
        scan2ndVel As Double          ' 低速（两次搜寻时需要）
                                      ' 当usePreSetPtpPara=0时，回零运动的减加速度默认等于acc,起跳速度、终点速度、平滑系数默认为0
        acc As Double                 ' 加速度
        reScanEn As Byte              ' 是否两次搜寻零点（可选，不用时设为0）
        homeEdge As Byte              ' 原点，触发沿（默认下降沿）
        lmtEdge As Byte               ' 限位，触发沿（默认下降沿）
        zEdge As Byte                 ' 限位，触发沿（默认下降沿）
        iniRetPos As Long             ' 起始反向运动距离（可选，不用时设为0）
        retSwOffset As Long           ' 反向运动时离开开关距离（可选，不用时设为0）
        safeLen As Long               ' 安全距离，回零时最远搜寻距离（可选，不用时设为0，不限制距离）
        usePreSetPtpPara As Byte      ' 为1表示用户需要在启动回零前，自己设置回零运动（点到点）的参数
        reserved0 As Byte             ' 保留
        reserved1 As Byte             ' 保留
        reserved2 As Byte             ' 保留
        reserved3 As Long             ' 保留
End Type

' 读取回零参数
' pHomePara: 回零参数结构，参考结构定义
Public Declare Function NMC_MtGetHomePara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pHomePara As THomeSetting) As Integer
' 设置回零参数
' pHomePara: 回零参数结构，参考结构定义
Public Declare Function NMC_MtSetHomePara Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef refHomePara As THomeSetting) As Integer

' 回零状态字位定义
Public Const BIT_AXHOME_BUSY             As Integer = &H1           ' bit 0  , 忙
Public Const BIT_AXHOME_OK               As Integer = &H2           ' bit 1  , 成功
Public Const BIT_AXHOME_FAIL             As Integer = &H4           ' bit 2  , 失败
Public Const BIT_AXHOME_ERR_MV           As Integer = &H8           ' bit 3  , 错误：运动参数出错导致不动
Public Const BIT_AXHOME_ERR_SWT          As Integer = &H10          ' bit 4  , 错误：搜寻过程中开关没触发
 
 ' 读回零状态
' pStsWord: 返回状态字。参数宏定义,高8位为错误代码
Public Declare Function NMC_MtGetHomeSts Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef pStsWord As Integer) As Integer

' 启动回零
Public Declare Function NMC_MtHome Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 尝试性回零（测试回零误差，不清位置）
Public Declare Function NMC_MtTryHome Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 终止回零
Public Declare Function NMC_MtHomeStop Lib "nmc_lib20.dll" (ByVal axisHandle As Integer) As Integer

' 读新回零位置和历史回零位置的差值
' cmdPos: 位置偏差
' 注：回零成功时才有意义
Public Declare Function NMC_MtGetHomeError Lib "nmc_lib20.dll" (ByVal axisHandle As Integer, ByRef cmdPos As Long) As Integer




Public Declare Function NMC_TSafeParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TSafePara) As Integer
Public Declare Function NMC_TCrdConfigStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TCrdConfig) As Integer
Public Declare Function NMC_TCrdSafeParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TCrdSafePara) As Integer
Public Declare Function NMC_THomeSettingStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As THomeSetting) As Integer
Public Declare Function NMC_TPtpParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TPtpPara) As Integer
Public Declare Function NMC_TJogParaStructInit Lib "nmc_lib20.dll" (ByVal devHandle As Integer, ByRef pPara As TJogPara) As Integer

