From 41ae92878883c18977380ec14a3026a519a8b11a Mon Sep 17 00:00:00 2001 From: lhiven Date: Tue, 12 Nov 2024 16:21:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9B=B7=E8=B5=9B=E5=8D=A1?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Framework/TcpClientHelper.cs | 16 + Rs.Motion/Invoke/Leisai/LTDMC.cs | 1269 ++++++++++++++++++++++ Rs.Motion/IoManager.cs | 88 +- Rs.Motion/Leisai/LeisaiAxis.cs | 1438 +++++++++++++++++++++++++ Rs.Motion/Leisai/LeisaiCard.cs | 119 ++ Rs.Motion/Leisai/LeisaiCardManager.cs | 151 +++ Rs.Motion/Leisai/LeisaiIO.cs | 14 + Rs.Motion/Leisai/LeisaiIOCard.cs | 49 + Rs.Motion/Rs.Motion.csproj | 6 + Rs.MotionPlat.sln | 6 + 10 files changed, 3155 insertions(+), 1 deletion(-) create mode 100644 Rs.Motion/Invoke/Leisai/LTDMC.cs create mode 100644 Rs.Motion/Leisai/LeisaiAxis.cs create mode 100644 Rs.Motion/Leisai/LeisaiCard.cs create mode 100644 Rs.Motion/Leisai/LeisaiCardManager.cs create mode 100644 Rs.Motion/Leisai/LeisaiIO.cs create mode 100644 Rs.Motion/Leisai/LeisaiIOCard.cs diff --git a/Rs.Framework/TcpClientHelper.cs b/Rs.Framework/TcpClientHelper.cs index 056d0f4..a9b8652 100644 --- a/Rs.Framework/TcpClientHelper.cs +++ b/Rs.Framework/TcpClientHelper.cs @@ -149,10 +149,19 @@ namespace Rs.Framework try { int len = m_Socket.Send(sendData); + //if(len <= 0) + //{ + // m_IsConnected = false; + // m_Socket.Close(); + // m_Socket.Dispose(); + // Connect(m_HostName, m_Port); + // OnDisconnected?.Invoke(m_Socket); + //} return len; } catch (Exception) { + m_IsConnected = false; m_Socket.Close(); m_Socket.Dispose(); Connect(m_HostName, m_Port); @@ -161,5 +170,12 @@ namespace Rs.Framework } return -1; } + + public void DisConnect() + { + m_Socket.Close(); + m_Socket.Dispose(); + m_IsConnected = false; + } } } diff --git a/Rs.Motion/Invoke/Leisai/LTDMC.cs b/Rs.Motion/Invoke/Leisai/LTDMC.cs new file mode 100644 index 0000000..24dbb72 --- /dev/null +++ b/Rs.Motion/Invoke/Leisai/LTDMC.cs @@ -0,0 +1,1269 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + + +namespace csLTDMC //命名空间根据应用程序修改 +{ + public partial class LTDMC + { + //--------------------- 板卡初始和配置函数 ---------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_init(); + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_reset(); + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_close", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_close(); + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_init_onecard", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_init_onecard(ushort CardNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_close_onecard", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_close_onecard(ushort CardNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_board_reset_onecard", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_board_reset_onecard(ushort CardNo); + + [DllImport("LTDMC.dll")] + public static extern short dmc_soft_reset(ushort CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_cool_reset(ushort CardNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_original_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_original_reset(ushort CardNo); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_CardInfList", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_CardInfList(ref UInt16 CardNum, UInt32[] CardTypeList, UInt16[] CardIdList); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_card_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_card_version(UInt16 CardNo, ref UInt32 CardVersion); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_card_soft_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_card_soft_version(UInt16 CardNo, ref UInt32 FirmID, ref UInt32 SubFirmID); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_card_lib_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_card_lib_version(ref UInt32 LibVer); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_release_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_release_version(ushort ConnectNo, byte[] ReleaseVersion);//读取发布版本号 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_total_axes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_total_axes(UInt16 CardNo, ref UInt32 TotalAxis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_total_ionum", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_total_ionum(ushort CardNo, ref ushort TotalIn, ref ushort TotalOut); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_total_adcnum", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_total_adcnum(ushort CardNo, ref ushort TotalIn, ref ushort TotalOut); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_total_liners", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_total_liners(UInt16 CardNo, ref UInt32 TotalLiner); + + // 轴IO映射配置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_AxisIoMap", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_AxisIoMap(UInt16 CardNo, UInt16 Axis, UInt16 IoType, UInt16 MapIoType, UInt16 MapIoIndex, UInt32 Filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_AxisIoMap", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_AxisIoMap(UInt16 CardNo, UInt16 Axis, UInt16 IoType, ref UInt16 MapIoType, ref UInt16 MapIoIndex, ref UInt32 Filter); + //以上函数以毫秒为单位可继续使用,新函数将时间统一到秒为单位 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_axis_io_map", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_axis_io_map(UInt16 CardNo, UInt16 Axis, UInt16 IoType, UInt16 MapIoType, UInt16 MapIoIndex, double Filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_axis_io_map", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_axis_io_map(UInt16 CardNo, UInt16 Axis, UInt16 IoType, ref UInt16 MapIoType, ref UInt16 MapIoIndex, ref double Filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_special_input_filter", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_special_input_filter(UInt16 CardNo, double Filter); //设置所有专用IO滤波时间 + + // 虚拟IO映射 用于读取滤波后的IO口电平状态 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_io_map_virtual", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_io_map_virtual(UInt16 CardNo, UInt16 bitno, UInt16 MapIoType, UInt16 MapIoIndex, double Filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_io_map_virtual", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_io_map_virtual(UInt16 CardNo, UInt16 bitno, ref UInt16 MapIoType, ref UInt16 MapIoIndex, ref double Filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_inbit_virtual", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_inbit_virtual(UInt16 CardNo, UInt16 bitno); + + //下载参数文件 + [DllImport("LTDMC.dll", EntryPoint = "dmc_download_configfile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_download_configfile(UInt16 CardNo, String FileName); + //下载固件文件 + [DllImport("LTDMC.dll", EntryPoint = "dmc_download_firmware", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_download_firmware(UInt16 CardNo, String FileName); + + //----------------------限位异常设置------------------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_softlimit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_softlimit(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 source_sel, UInt16 SL_action, Int32 N_limit, Int32 P_limit); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_softlimit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_softlimit(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 source_sel, ref UInt16 SL_action, ref Int32 N_limit, ref Int32 P_limit); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_el_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_el_mode(UInt16 CardNo, UInt16 axis, UInt16 el_enable, UInt16 el_logic, UInt16 el_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_el_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_el_mode(UInt16 CardNo, UInt16 axis, ref UInt16 el_enable, ref UInt16 el_logic, ref UInt16 el_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_emg_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_emg_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 emg_logic); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_emg_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_emg_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enbale, ref UInt16 emg_logic); + //外部减速停止信号及减速停止时间设置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_dstp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_dstp_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 logic, UInt32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_dstp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_dstp_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 logic, ref UInt32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_dstp_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_dstp_time(UInt16 CardNo, UInt16 axis, UInt32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_dstp_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_dstp_time(UInt16 CardNo, UInt16 axis, ref UInt32 time); + //以上函数以毫秒为单位可继续使用,新函数将时间统一到秒为单位 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_io_dstp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_io_dstp_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 logic); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_io_dstp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_io_dstp_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 logic); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_dec_stop_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_dec_stop_time(UInt16 CardNo, UInt16 axis, double stop_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_dec_stop_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_dec_stop_time(UInt16 CardNo, UInt16 axis, ref double stop_time); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_vector_dec_stop_time(UInt16 CardNo, UInt16 Crd, double stop_time); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_vector_dec_stop_time(UInt16 CardNo, UInt16 Crd, ref double stop_time); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_dec_stop_dist(UInt16 CardNo, UInt16 axis, Int32 dist); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_dec_stop_dist(UInt16 CardNo, UInt16 axis, ref Int32 dist); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_io_dstp_bitno(UInt16 CardNo, UInt16 axis, UInt16 bitno, double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_io_dstp_bitno(UInt16 CardNo, UInt16 axis, ref UInt16 bitno, ref double filter); + + //---------------------------速度设置---------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_profile(UInt16 CardNo, UInt16 axis, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double stop_vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_profile(UInt16 CardNo, UInt16 axis, ref double Min_Vel, ref double Max_Vel, ref double Tacc, ref double Tdec, ref double stop_vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_acc_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_acc_profile(UInt16 CardNo, UInt16 axis, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double stop_vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_acc_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_acc_profile(UInt16 CardNo, UInt16 axis, ref double Min_Vel, ref double Max_Vel, ref double Tacc, ref double Tdec, ref double stop_vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_s_profile(UInt16 CardNo, UInt16 axis, UInt16 s_mode, double s_para); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_s_profile(UInt16 CardNo, UInt16 axis, UInt16 s_mode, ref double s_para); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_vector_profile_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_vector_profile_multicoor(UInt16 CardNo, UInt16 Crd, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double Stop_Vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_vector_profile_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_vector_profile_multicoor(UInt16 CardNo, UInt16 Crd, ref double Min_Vel, ref double Max_Vel, ref double Taccdec, ref double Tdec, ref double Stop_Vel); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_vector_s_profile_multicoor(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, double s_para); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_vector_s_profile_multicoor(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, ref double s_para); + + //---------------------运动模块脉冲模式------------------ + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_pulse_outmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_pulse_outmode(UInt16 CardNo, UInt16 axis, UInt16 outmode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_pulse_outmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_pulse_outmode(UInt16 CardNo, UInt16 axis, ref UInt16 outmode); + + //-----------------------点位运动----------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_pmove", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_pmove(UInt16 CardNo, UInt16 axis, Int32 Dist, UInt16 posi_mode); + [DllImport("LTDMC.dll")] + public static extern short dmc_pmove_extern(UInt16 CardNo, UInt16 axis, double dist, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double stop_Vel, double s_para, UInt16 posi_mode); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_reset_target_position", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_reset_target_position(UInt16 CardNo, UInt16 axis, Int32 dist, UInt16 posi_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_change_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_change_speed(UInt16 CardNo, UInt16 axis, double Curr_Vel, double Taccdec); + [DllImport("LTDMC.dll", EntryPoint = "dmc_update_target_position", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_update_target_position(UInt16 CardNo, UInt16 axis, Int32 dist, UInt16 posi_mode); + //----------------------PVT运动--------------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_PvtTable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_PvtTable(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, Int32[] pPos, double[] pVel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_PtsTable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_PtsTable(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, Int32[] pPos, double[] pPercent); + [DllImport("LTDMC.dll", EntryPoint = "dmc_PvtsTable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_PvtsTable(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, Int32[] pPos, double velBegin, double velEnd); + [DllImport("LTDMC.dll", EntryPoint = "dmc_PttTable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_PttTable(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, int[] pPos); + [DllImport("LTDMC.dll", EntryPoint = "dmc_PvtMove", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_PvtMove(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList); + + [DllImport("LTDMC.dll")] + public static extern short dmc_PttTable_add(UInt16 CardNo, UInt16 iaxis, UInt16 count, double[] pTime, long[] pPos); + [DllImport("LTDMC.dll")] + public static extern short dmc_PtsTable_add(UInt16 CardNo, UInt16 iaxis, UInt16 count, double[] pTime, long[] pPos, double[] pPercent); + [DllImport("LTDMC.dll")] + public static extern short dmc_pvt_get_remain_space(UInt16 CardNo, UInt16 iaxis); + [DllImport("LTDMC.dll")] + public static extern short dmc_pvt_table_unit(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, double[] pPos, double[] pVel); + [DllImport("LTDMC.dll")] + public static extern short dmc_pts_table_unit(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, double[] pPos, double[] pPercent); + [DllImport("LTDMC.dll")] + public static extern short dmc_pvts_table_unit(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, double[] pPos, double velBegin, double velEnd); + [DllImport("LTDMC.dll")] + public static extern short dmc_ptt_table_unit(UInt16 CardNo, UInt16 iaxis, UInt32 count, double[] pTime, double[] pPos); + [DllImport("LTDMC.dll")] + public static extern short dmc_pvt_move(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList); + + [DllImport("LTDMC.dll")] + public static extern short dmc_SetGearProfile(UInt16 CardNo, UInt16 axis, UInt16 MasterType, UInt16 MasterIndex, Int32 MasterEven, Int32 SlaveEven, UInt32 MasterSlope); + [DllImport("LTDMC.dll")] + public static extern short dmc_GetGearProfile(UInt16 CardNo, UInt16 axis, ref UInt16 MasterType, ref UInt16 MasterIndex, ref UInt32 MasterEven, ref UInt32 SlaveEven, ref UInt32 MasterSlope); + [DllImport("LTDMC.dll")] + public static extern short dmc_GearMove(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList); + + //---------------------JOG运动-------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_vmove", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_vmove(UInt16 CardNo, UInt16 axis, UInt16 dir); + //直线插补 + [DllImport("LTDMC.dll", EntryPoint = "dmc_line_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_line_multicoor(UInt16 CardNo, UInt16 crd, UInt16 axisNum, UInt16[] axisList, Int32[] DistList, UInt16 posi_mode); + //平面圆弧 + [DllImport("LTDMC.dll", EntryPoint = "dmc_arc_move_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_arc_move_multicoor(UInt16 CardNo, UInt16 crd, UInt16[] AxisList, Int32[] Target_Pos, Int32[] Cen_Pos, UInt16 Arc_Dir, UInt16 posi_mode); + + //--------------------回零运动--------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_home_pin_logic", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_home_pin_logic(UInt16 CardNo, UInt16 axis, UInt16 org_logic, double filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_home_pin_logic", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_home_pin_logic(UInt16 CardNo, UInt16 axis, ref UInt16 org_logic, ref double filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_homemode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_homemode(UInt16 CardNo, UInt16 axis, UInt16 home_dir, double vel, UInt16 mode, UInt16 EZ_count); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_homemode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_homemode(UInt16 CardNo, UInt16 axis, ref UInt16 home_dir, ref double vel, ref UInt16 home_mode, ref UInt16 EZ_count); + [DllImport("LTDMC.dll", EntryPoint = "dmc_home_move", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_home_move(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_home_profile_unit(ushort CardNo, ushort axis, double Low_Vel, double High_Vel, double Tacc, double Tdec); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_home_profile_unit(ushort CardNo, ushort axis, ref double Low_Vel, ref double High_Vel, ref double Tacc, ref double Tdec); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_home_result(UInt16 CardNo, UInt16 axis, ref UInt16 state); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_home_position_unit(UInt16 CardNo, UInt16 axis, UInt16 enable, double position); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_home_position_unit(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref double position); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_el_home(UInt16 CardNo, UInt16 axis, UInt16 mode); + + // 回原点减速信号配置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_sd_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_sd_mode(UInt16 CardNo, UInt16 axis, UInt16 sd_logic, UInt16 sd_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_sd_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_sd_mode(UInt16 CardNo, UInt16 axis, ref UInt16 sd_logic, ref UInt16 sd_mode); + //--------------------3800,3600,5800,5600专用 原点锁存------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_homelatch_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_homelatch_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 logic, UInt16 source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_homelatch_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_homelatch_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 logic, ref UInt16 source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_homelatch_flag", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_homelatch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_reset_homelatch_flag", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_reset_homelatch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_homelatch_value", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_homelatch_value(UInt16 CardNo, UInt16 axis); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_ezlatch_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 logic, UInt16 source); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_ezlatch_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 logic, ref UInt16 source); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_ezlatch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_reset_ezlatch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_ezlatch_value(UInt16 CardNo, UInt16 axis); + + //--------------------手轮运动--------------------- + //3800,3600,5800,5600专用 手轮通道选择 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_handwheel_channel", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_handwheel_channel(UInt16 CardNo, UInt16 index); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_handwheel_channel", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_handwheel_channel(UInt16 CardNo, ref UInt16 index); + //一个手轮信号控制单个轴运动 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_handwheel_inmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_handwheel_inmode(UInt16 CardNo, UInt16 axis, UInt16 inmode, Int32 multi, double vh); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_handwheel_inmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_handwheel_inmode(UInt16 CardNo, UInt16 axis, ref UInt16 inmode, ref Int32 multi, ref double vh); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_handwheel_inmode_decimals", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_handwheel_inmode_decimals(UInt16 CardNo, UInt16 axis, UInt16 inmode, double multi, double vh); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_handwheel_inmode_decimals", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_handwheel_inmode_decimals(UInt16 CardNo, UInt16 axis, ref UInt16 inmode, ref double multi, ref double vh); + + //3800,3600,5800,5600专用 一个手轮信号控制多个轴运动 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_handwheel_inmode_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_handwheel_inmode_extern(UInt16 CardNo, UInt16 inmode, UInt16 AxisNum, UInt16[] AxisList, Int32[] multi); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_handwheel_inmode_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_handwheel_inmode_extern(UInt16 CardNo, ref UInt16 inmode, ref UInt16 AxisNum, UInt16[] AxisList, Int32[] multi); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_handwheel_inmode_extern_decimals(UInt16 CardNo, UInt16 inmode, UInt16 AxisNum, UInt16[] AxisList, double[] multi); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_handwheel_inmode_extern_decimals(UInt16 CardNo, ref UInt16 inmode, ref UInt16 AxisNum, UInt16[] AxisList, double[] multi); + //启动手轮运动 + [DllImport("LTDMC.dll", EntryPoint = "dmc_handwheel_move", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_handwheel_move(UInt16 CardNo, UInt16 axis); + // + [DllImport("LTDMC.dll")] + public static extern short dmc_set_handwheel_encoder(ushort CardNo, ushort channel, int pos); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_handwheel_encoder(ushort CardNo, ushort channel, ref int pos); + + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_set_axislist(UInt16 CardNo, UInt16 AxisSelIndex, UInt16 AxisNum, UInt16[] AxisList); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_get_axislist(UInt16 CardNo, UInt16 AxisSelIndex, ref UInt16 AxisNum, UInt16[] AxisList); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_set_ratiolist(UInt16 CardNo, UInt16 AxisSelIndex, UInt16 StartRatioIndex, UInt16 RatioSelNum, double[] RatioList); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_get_ratiolist(UInt16 CardNo, UInt16 AxisSelIndex, UInt16 StartRatioIndex, UInt16 RatioSelNum, double[] RatioList); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_set_mode(UInt16 CardNo, UInt16 InMode, UInt16 IfHardEnable); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_get_mode(UInt16 CardNo, ref UInt16 InMode, ref UInt16 IfHardEnable); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_set_index(UInt16 CardNo, UInt16 AxisSelIndex, UInt16 RatioSelIndex); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_get_index(UInt16 CardNo, ref UInt16 AxisSelIndex, ref UInt16 RatioSelIndex); + [DllImport("LTDMC.dll")] + public static extern short dmc_handwheel_stop(UInt16 CardNo); + + //---------------------编码器--------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_counter_inmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_counter_inmode(UInt16 CardNo, UInt16 axis, UInt16 mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_counter_inmode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_counter_inmode(UInt16 CardNo, UInt16 axis, ref UInt16 mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_encoder", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_encoder(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_encoder", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_encoder(UInt16 CardNo, UInt16 axis, Int32 encoder_value); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_ez_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_ez_mode(UInt16 CardNo, UInt16 axis, UInt16 ez_logic, UInt16 ez_mode, double filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_ez_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_ez_mode(UInt16 CardNo, UInt16 axis, ref UInt16 ez_logic, ref UInt16 ez_mode, ref double filter); + //---------------------辅助编码器--------------------- + [DllImport("LTDMC.dll")] + public static extern short dmc_set_extra_encoder_mode(ushort CardNo, ushort channel, ushort inmode, ushort multi); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_extra_encoder_mode(ushort CardNo, ushort channel, ref ushort inmode, ref ushort multi); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_extra_encoder(ushort CardNo, ushort channel, int pos); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_extra_encoder(ushort CardNo, ushort channel, ref int pos); + + //-------------------------高速锁存(旧)------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_ltc_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_ltc_mode(UInt16 CardNo, UInt16 axis, UInt16 ltc_logic, UInt16 ltc_mode, Double filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_ltc_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_ltc_mode(UInt16 CardNo, UInt16 axis, ref UInt16 ltc_logic, ref UInt16 ltc_mode, ref Double filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_latch_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_latch_mode(UInt16 CardNo, UInt16 axis, UInt16 all_enable, UInt16 latch_source, UInt16 triger_chunnel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_latch_mode(UInt16 CardNo, UInt16 axis, ref UInt16 all_enable, ref UInt16 latch_source, ref UInt16 triger_chunnel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_value", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_latch_value(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_latch_value_unit(UInt16 CardNo, UInt16 axis, ref double pos_by_mm); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_flag", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_latch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_reset_latch_flag", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_reset_latch_flag(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_value_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_latch_value_extern(UInt16 CardNo, UInt16 axis, UInt16 Index); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_flag_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_latch_flag_extern(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_SetLtcOutMode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_SetLtcOutMode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 bitno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_GetLtcOutMode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_GetLtcOutMode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 bitno); + //LTC端口触发延时急停时间 单位us + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_latch_stop_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_latch_stop_time(UInt16 CardNo, UInt16 axis, Int32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_latch_stop_time", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_latch_stop_time(UInt16 CardNo, UInt16 axis, ref Int32 time); + //----------------------高速锁存(新)--------------------------- + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_set_mode(ushort CardNo, ushort latch, ushort ltc_mode, ushort ltc_logic, double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_get_mode(ushort CardNo, ushort latch, ref ushort ltc_mode, ref ushort ltc_logic, ref double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_set_source(ushort CardNo, ushort latch, ushort axis, ushort ltc_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_get_source(ushort CardNo, ushort latch, ushort axis, ref ushort ltc_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_reset(ushort CardNo, ushort latch); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_get_number(ushort CardNo, ushort latch, ushort axis, ref int number); + [DllImport("LTDMC.dll")] + public static extern short dmc_ltc_get_value_unit(ushort CardNo, ushort latch, ushort axis, ref double value); + //-----------------------软锁存--------------------------------- + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_set_mode(ushort ConnectNo, ushort latch, ushort ltc_enable, ushort ltc_mode, ushort ltc_inbit, ushort ltc_logic, double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_get_mode(ushort ConnectNo, ushort latch, ref ushort ltc_enable, ref ushort ltc_mode, ref ushort ltc_inbit, ref ushort ltc_logic, ref double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_set_source(ushort ConnectNo, ushort latch, ushort axis, ushort ltc_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_get_source(ushort ConnectNo, ushort latch, ushort axis, ref ushort ltc_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_reset(ushort ConnectNo, ushort latch); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_get_number(ushort ConnectNo, ushort latch, ushort axis, ref int number); + [DllImport("LTDMC.dll")] + public static extern short dmc_softltc_get_value_unit(ushort ConnectNo, ushort latch, ushort axis, ref double value); + + //----------------------单轴低速位置比较----------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_set_config", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_set_config(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 cmp_source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_config", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_config(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 cmp_source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_clear_points", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_clear_points(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_add_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_add_point(UInt16 CardNo, UInt16 axis, int pos, UInt16 dir, UInt16 action, UInt32 actpara); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_current_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_current_point(UInt16 CardNo, UInt16 axis, ref Int32 pos); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_points_runned", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_points_runned(UInt16 CardNo, UInt16 axis, ref Int32 pointNum); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_points_remained", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_points_remained(UInt16 CardNo, UInt16 axis, ref Int32 pointNum); + + //-------------------二维低速位置比较----------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_set_config_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_set_config_extern(UInt16 CardNo, UInt16 enable, UInt16 cmp_source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_config_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_config_extern(UInt16 CardNo, ref UInt16 enable, ref UInt16 cmp_source); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_clear_points_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_clear_points_extern(UInt16 CardNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_add_point_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_add_point_extern(UInt16 CardNo, UInt16[] axis, Int32[] pos, UInt16[] dir, UInt16 action, UInt32 actpara); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_current_point_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_current_point_extern(UInt16 CardNo, Int32[] pos); + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_add_point_extern_unit(UInt16 CardNo, UInt16[] axis, double[] pos, UInt16[] dir, UInt16 action, UInt32 actpara); + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_get_current_point_extern_unit(UInt16 CardNo, double[] pos); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_points_runned_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_points_runned_extern(UInt16 CardNo, ref Int32 pointNum); + [DllImport("LTDMC.dll", EntryPoint = "dmc_compare_get_points_remained_extern", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_compare_get_points_remained_extern(UInt16 CardNo, ref Int32 pointNum); + + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_set_config_multi(UInt16 CardNo, UInt16 queue, UInt16 enable, UInt16 axis, UInt16 cmp_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_get_config_multi(UInt16 CardNo, UInt16 queue, ref UInt16 enable, ref UInt16 axis, ref UInt16 cmp_source); + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_add_point_multi(UInt16 CardNo, UInt16 cmp, Int32 pos, UInt16 dir, UInt16 action, UInt32 actpara, double times); + + //----------- 单轴高速位置比较----------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_set_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_set_mode(UInt16 CardNo, UInt16 hcmp, UInt16 cmp_enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_get_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_get_mode(UInt16 CardNo, UInt16 hcmp, ref UInt16 cmp_enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_set_config", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_set_config(UInt16 CardNo, UInt16 hcmp, UInt16 axis, UInt16 cmp_source, UInt16 cmp_logic, Int32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_get_config", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_get_config(UInt16 CardNo, UInt16 hcmp, ref UInt16 axis, ref UInt16 cmp_source, ref UInt16 cmp_logic, ref Int32 time); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_set_config_extern(UInt16 CardNo, UInt16 hcmp, UInt16 axis, UInt16 cmp_source, UInt16 cmp_logic, UInt16 cmp_mode, Int32 dist, Int32 time); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_get_config_extern(UInt16 CardNo, UInt16 hcmp, ref UInt16 axis, ref UInt16 cmp_source, ref UInt16 cmp_logic, ref UInt16 cmp_mode, ref Int32 dist, ref Int32 time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_add_point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_add_point(UInt16 CardNo, UInt16 hcmp, Int32 cmp_pos); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_set_liner", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_set_liner(UInt16 CardNo, UInt16 hcmp, Int32 Increment, Int32 Count); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_get_liner", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_get_liner(UInt16 CardNo, UInt16 hcmp, ref Int32 Increment, ref Int32 Count); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_get_current_state", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_get_current_state(UInt16 CardNo, UInt16 hcmp, ref Int32 remained_points, ref Int32 current_point, ref Int32 runned_points); + [DllImport("LTDMC.dll", EntryPoint = "dmc_hcmp_clear_points", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_hcmp_clear_points(UInt16 CardNo, UInt16 hcmp); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_cmp_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_cmp_pin(UInt16 CardNo, UInt16 hcmp); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_cmp_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_cmp_pin(UInt16 CardNo, UInt16 hcmp, UInt16 on_off); + + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_set_enable(UInt16 CardNo, UInt16 hcmp, UInt16 cmp_enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_get_enable(UInt16 CardNo, UInt16 hcmp, ref UInt16 cmp_enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_set_config(UInt16 CardNo, UInt16 hcmp, UInt16 cmp_mode, UInt16 x_axis, UInt16 x_cmp_source, UInt16 y_axis, UInt16 y_cmp_source, Int32 error, UInt16 cmp_logic, Int32 time, UInt16 pwm_enable, double duty, Int32 freq, UInt16 port_sel, UInt16 pwm_number); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_get_config(UInt16 CardNo, UInt16 hcmp, ref UInt16 cmp_mode, ref UInt16 x_axis, ref UInt16 x_cmp_source, ref UInt16 y_axis, ref UInt16 y_cmp_source, ref Int32 error, ref UInt16 cmp_logic, ref Int32 time, ref UInt16 pwm_enable, ref double duty, ref Int32 freq, ref UInt16 port_sel, ref UInt16 pwm_number); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_add_point(UInt16 CardNo, UInt16 hcmp, Int32 x_cmp_pos, Int32 y_cmp_pos); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_get_current_state(UInt16 CardNo, UInt16 hcmp, ref Int32 remained_points, ref Int32 x_current_point, ref Int32 y_current_point, ref Int32 runned_points, ref UInt16 current_state); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_clear_points(UInt16 CardNo, UInt16 hcmp); + [DllImport("LTDMC.dll")] + public static extern short dmc_hcmp_2d_force_output(UInt16 CardNo, UInt16 hcmp, UInt16 enable); + + //------------------------通用IO----------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_inbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_inbit(UInt16 CardNo, UInt16 bitno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_outbit(UInt16 CardNo, UInt16 bitno, UInt16 on_off); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_outbit(UInt16 CardNo, UInt16 bitno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_inport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern UInt32 dmc_read_inport(UInt16 CardNo, UInt16 portno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern UInt32 dmc_read_outport(UInt16 CardNo, UInt16 portno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_outport(UInt16 CardNo, UInt16 portno, UInt32 outport_val); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_outport_16X", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_outport_16X(UInt16 CardNo, UInt16 portno, UInt32 outport_val); + //3800,3600,5800,5600专用 IO辅助功能 + [DllImport("LTDMC.dll", EntryPoint = "dmc_IO_TurnOutDelay", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_IO_TurnOutDelay(UInt16 CardNo, UInt16 bitno, UInt32 DelayTime); + [DllImport("LTDMC.dll", EntryPoint = "dmc_SetIoCountMode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_SetIoCountMode(UInt16 CardNo, UInt16 bitno, UInt16 mode, UInt32 filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_GetIoCountMode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_GetIoCountMode(UInt16 CardNo, UInt16 bitno, ref UInt16 mode, ref UInt32 filter); + [DllImport("LTDMC.dll", EntryPoint = "dmc_SetIoCountValue", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_SetIoCountValue(UInt16 CardNo, UInt16 bitno, UInt32 CountValue); + [DllImport("LTDMC.dll", EntryPoint = "dmc_GetIoCountValue", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_GetIoCountValue(UInt16 CardNo, UInt16 bitno, ref UInt32 CountValue); + //以上函数以毫秒为单位可继续使用,新函数将时间统一到秒为单位 + [DllImport("LTDMC.dll", EntryPoint = "dmc_reverse_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_reverse_outbit(UInt16 CardNo, UInt16 bitno, double reverse_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_io_count_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_io_count_mode(UInt16 CardNo, UInt16 bitno, UInt16 mode, double filter_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_io_count_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_io_count_mode(UInt16 CardNo, UInt16 bitno, ref UInt16 mode, ref double filter_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_io_count_value", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_io_count_value(UInt16 CardNo, UInt16 bitno, UInt32 CountValue); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_io_count_value", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_io_count_value(UInt16 CardNo, UInt16 bitno, ref UInt32 CountValue); + + //-----------------------专用IO------------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_inp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_inp_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 inp_logic); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_inp_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_inp_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 inp_logic); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_rdy_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 rdy_logic); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_rdy_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 rdy_logic); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_erc_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_erc_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 erc_logic, UInt16 erc_width, UInt16 erc_off_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_erc_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_erc_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 erc_logic, ref UInt16 erc_width, ref UInt16 erc_off_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_alm_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_alm_mode(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 alm_logic, UInt16 alm_action); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_alm_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_alm_mode(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 alm_logic, ref UInt16 alm_action); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_sevon_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_sevon_pin(UInt16 CardNo, UInt16 axis, UInt16 on_off); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_sevon_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_sevon_pin(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_erc_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_erc_pin(UInt16 CardNo, UInt16 axis, UInt16 sel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_erc_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_erc_pin(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_rdy_pin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_rdy_pin(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_write_sevrst_pin(UInt16 CardNo, UInt16 axis, UInt16 on_off); + [DllImport("LTDMC.dll")] + public static extern short dmc_read_sevrst_pin(UInt16 CardNo, UInt16 axis); + //--------------------运动状态---------------------- + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_current_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern double dmc_read_current_speed(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_position", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_position(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_position", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_position(UInt16 CardNo, UInt16 axis, Int32 current_position); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_target_position", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_get_target_position(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_check_done", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_check_done(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_check_done_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_check_done_multicoor(UInt16 CardNo, UInt16 crd); + [DllImport("LTDMC.dll", EntryPoint = "dmc_axis_io_status", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern UInt32 dmc_axis_io_status(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_stop(UInt16 CardNo, UInt16 axis, UInt16 stop_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_stop_multicoor", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_stop_multicoor(UInt16 CardNo, UInt16 crd, UInt16 stop_mode); + [DllImport("LTDMC.dll", EntryPoint = "dmc_emg_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_emg_stop(UInt16 CardNo); + //检测轴到位状态 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_factor_error", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_factor_error(UInt16 CardNo, UInt16 axis, double factor, Int32 error); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_factor_error", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_factor_error(UInt16 CardNo, UInt16 axis, ref double factor, ref Int32 error); + [DllImport("LTDMC.dll", EntryPoint = "dmc_check_success_pulse", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_check_success_pulse(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll", EntryPoint = "dmc_check_success_encoder", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_check_success_encoder(UInt16 CardNo, UInt16 axis); + //3800,3600,5800,5600专用 主卡与接线盒通讯状态 + [DllImport("LTDMC.dll", EntryPoint = "dmc_LinkState", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_LinkState(UInt16 CardNo, ref UInt16 State); + + //3800,3600,5800,5600专用 CAN-IO扩展 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_can_state", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_can_state(UInt16 CardNo, UInt16 NodeNum, UInt16 state, UInt16 Baud); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_can_state", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_can_state(UInt16 CardNo, ref UInt16 NodeNum, ref UInt16 state); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_can_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_can_outbit(UInt16 CardNo, UInt16 Node, UInt16 bitno, UInt16 on_off); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_can_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_can_outbit(UInt16 CardNo, UInt16 Node, UInt16 bitno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_can_inbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_can_inbit(UInt16 CardNo, UInt16 Node, UInt16 bitno); + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_can_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_can_outport(UInt16 CardNo, UInt16 Node, UInt16 PortNo, UInt32 outport_val); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_can_outport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern UInt32 dmc_read_can_outport(UInt16 CardNo, UInt16 Node, UInt16 PortNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_can_inport", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern UInt32 dmc_read_can_inport(UInt16 CardNo, UInt16 Node, UInt16 PortNo); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_can_errcode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_can_errcode(UInt16 CardNo, ref UInt16 Errcode); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_can_errcode_extern(UInt16 CardNo, ref UInt16 Errcode, ref UInt16 msg_losed, ref UInt16 emg_msg_num, ref UInt16 lostHeartB, ref UInt16 EmgMsg); + //CAN-ADDA + [DllImport("LTDMC.dll")] + public static extern short nmc_set_da_output(ushort CardNo, ushort NoteID, ushort channel, double Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_da_output(ushort CardNo, ushort NoteID, ushort channel, ref double Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_ad_input(ushort CardNo, ushort NoteID, ushort channel, ref double Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_ad_mode(ushort CardNo, ushort NoteID, ushort channel, ushort mode, uint buffer_nums); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_ad_mode(ushort CardNo, ushort NoteID, ushort channel, ref ushort mode, uint buffer_nums); + [DllImport("LTDMC.dll")] + public static extern short nmc_write_to_flash(ushort CardNo, ushort PortNum, ushort NodeNum); + + [DllImport("LTDMC.dll")] + public static extern short nmc_set_connect_state(UInt16 CardNo, UInt16 NodeNum, UInt16 state, UInt16 baud); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_connect_state(UInt16 CardNo, ref UInt16 NodeNum, ref UInt16 state); + + //密码管理 + [DllImport("LTDMC.dll", EntryPoint = "dmc_write_sn", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_write_sn(UInt16 CardNo, string new_sn); + [DllImport("LTDMC.dll", EntryPoint = "dmc_check_sn", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_check_sn(UInt16 CardNo, string check_sn); + + //函数库打印输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_debug_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_debug_mode(UInt16 mode, string FileName); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_debug_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_debug_mode(ref UInt16 mode, IntPtr FileName); + + //DMC5000系列专用,基于脉冲当量的高级运动,连续插补等功能 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_axis_run_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_axis_run_mode(UInt16 CardNo, UInt16 axis, ref UInt16 run_mode); //轴运动模式 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_trace", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_trace(UInt16 CardNo, UInt16 axis, UInt16 enable); //trace功能 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_trace", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_trace(UInt16 CardNo, UInt16 axis, ref UInt16 enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_trace_data", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_trace_data(UInt16 CardNo, UInt16 axis, UInt16 data_option, ref Int32 ReceiveSize, double[] time, double[] data, ref Int32 remain_num); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_equiv", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_equiv(UInt16 CardNo, UInt16 axis, ref double equiv); //脉冲当量 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_equiv", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_equiv(UInt16 CardNo, UInt16 axis, double equiv); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_backlash_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_backlash_unit(UInt16 CardNo, UInt16 axis, double backlash); //反向间隙 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_backlash_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_backlash_unit(UInt16 CardNo, UInt16 axis, ref double backlash); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_position_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_position_unit(UInt16 CardNo, UInt16 axis, double pos); //当前指令位置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_position_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_position_unit(UInt16 CardNo, UInt16 axis, ref double pos); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_encoder_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_encoder_unit(UInt16 CardNo, UInt16 axis, double pos); //当前反馈位置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_encoder_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_encoder_unit(UInt16 CardNo, UInt16 axis, ref double pos); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_pmove_unit(UInt16 CardNo, UInt16 axis, double Dist, UInt16 posi_mode); //定长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_t_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_t_pmove_unit(UInt16 CardNo, UInt16 axis, double Dist, UInt16 posi_mode); //对称T型定长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_ex_t_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_ex_t_pmove_unit(UInt16 CardNo, UInt16 axis, double Dist, UInt16 posi_mode); //非对称T型定长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_s_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_s_pmove_unit(UInt16 CardNo, UInt16 axis, double Dist, UInt16 posi_mode); //对称S型定长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_ex_s_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_ex_s_pmove_unit(UInt16 CardNo, UInt16 axis, double Dist, UInt16 posi_mode); //非对称S型定长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_line_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_line_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, UInt16 posi_mode); //单段直线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_arc_move_center_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_arc_move_center_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Cen_Pos, UInt16 Arc_Dir, Int32 Circle, UInt16 posi_mode); //圆心终点式圆弧/螺旋线/渐开线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_arc_move_radius_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_arc_move_radius_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double Arc_Radius, UInt16 Arc_Dir, Int32 Circle, UInt16 posi_mode); //半径终点式圆弧/螺旋线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_arc_move_3points_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_arc_move_3points_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Mid_Pos, Int32 Circle, UInt16 posi_mode); //三点式圆弧/螺旋线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_read_current_speed_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_read_current_speed_unit(UInt16 CardNo, UInt16 Axis, ref double current_speed); //轴当前运行速度 + + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_vector_profile_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_vector_profile_unit(UInt16 CardNo, UInt16 Crd, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double Stop_Vel); //单段插补速度参数 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_vector_profile_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_vector_profile_unit(UInt16 CardNo, UInt16 Crd, ref double Min_Vel, ref double Max_Vel, ref double Tacc, ref double Tdec, ref double Stop_Vel); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_profile_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_profile_unit(UInt16 CardNo, UInt16 Axis, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double Stop_Vel); //单轴速度参数 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_profile_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_profile_unit(UInt16 CardNo, UInt16 Axis, ref double Min_Vel, ref double Max_Vel, ref double Tacc, ref double Tdec, ref double Stop_Vel); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_profile_unit_acc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_profile_unit_acc(UInt16 CardNo, UInt16 Axis, double Min_Vel, double Max_Vel, double Tacc, double Tdec, double Stop_Vel); //单轴速度参数 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_profile_unit_acc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_profile_unit_acc(UInt16 CardNo, UInt16 Axis, ref double Min_Vel, ref double Max_Vel, ref double Tacc, ref double Tdec, ref double Stop_Vel); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_reset_target_position_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_reset_target_position_unit(UInt16 CardNo, UInt16 Axis, double New_Pos); //在线变位 + [DllImport("LTDMC.dll", EntryPoint = "dmc_update_target_position_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_update_target_position_unit(UInt16 CardNo, UInt16 Axis, double New_Pos); //强行变位 + [DllImport("LTDMC.dll", EntryPoint = "dmc_change_speed_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_change_speed_unit(UInt16 CardNo, UInt16 Axis, double New_Vel, double Taccdec); //在线变速 + + //连续插补 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_open_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_open_list(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList); //打开连续缓存区 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_close_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_close_list(UInt16 CardNo, UInt16 Crd); //关闭连续缓存区 + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_reset_list(UInt16 CardNo, UInt16 Crd); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_stop_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_stop_list(UInt16 CardNo, UInt16 Crd, UInt16 stop_mode); //连续插补中停止 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_pause_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_pause_list(UInt16 CardNo, UInt16 Crd); //连续插补中暂停 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_start_list", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_start_list(UInt16 CardNo, UInt16 Crd); //开始连续插补 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_remain_space", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_conti_remain_space(UInt16 CardNo, UInt16 Crd); //查连续插补剩余缓存数 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_read_current_mark", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern Int32 dmc_conti_read_current_mark(UInt16 CardNo, UInt16 Crd); //读取当前连续插补段的标号 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_blend", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_blend(UInt16 CardNo, UInt16 Crd, UInt16 enable); //blend拐角过度模式 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_blend", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_blend(UInt16 CardNo, UInt16 Crd, ref UInt16 enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_lookahead_end_vel_zero", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_lookahead_end_vel_zero(UInt16 CardNo, UInt16 Crd, UInt16 enable); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_profile_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_profile_unit(UInt16 CardNo, UInt16 Crd, double Min_Vel, double Max_vel, double Tacc, double Tdec, double Stop_Vel); //设置连续插补速度 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_s_profile(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, double s_para); //设置连续插补平滑时间 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_s_profile(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, ref double s_para); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_pause_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_pause_output(UInt16 CardNo, UInt16 Crd, UInt16 action, Int32 mask, Int32 state); //暂停时IO输出 action 0, 不工作;1, 暂停时输出io_state; 2 暂停时输出io_state, 继续运行时首先恢复原来的io; 3,在2的基础上,停止时也生效。 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_pause_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_pause_output(UInt16 CardNo, UInt16 Crd, ref UInt16 action, ref Int32 mask, ref Int32 state); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_override", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_override(UInt16 CardNo, UInt16 Crd, double Percent); //设置每段速度比例 缓冲区指令 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_change_speed_ratio", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_change_speed_ratio(UInt16 CardNo, UInt16 Crd, double Percent); //连续插补动态变速 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_run_state", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_run_state(UInt16 CardNo, UInt16 Crd); //读取连续插补状态:0-运行,1-暂停,2-正常停止,3-异常停止 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_check_done", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_check_done(UInt16 CardNo, UInt16 Crd); //检测连续插补运动状态:0-运行,1-停止 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_wait_input", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_wait_input(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double TimeOut, Int32 mark); //设置连续插补等待输入 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_delay_outbit_to_start", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_delay_outbit_to_start(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double delay_value, UInt16 delay_mode, double ReverseTime); //相对于轨迹段起点IO滞后输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_delay_outbit_to_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_delay_outbit_to_stop(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double delay_time, double ReverseTime); //相对于轨迹段终点IO滞后输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_ahead_outbit_to_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_ahead_outbit_to_stop(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double ahead_value, UInt16 ahead_mode, double ReverseTime); //相对轨迹段终点IO提前输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_accurate_outbit_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_accurate_outbit_unit(UInt16 CardNo, UInt16 Crd, UInt16 cmp_no, UInt16 on_off, UInt16 map_axis, double abs_pos, UInt16 pos_source, double ReverseTime); //确定位置精确输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_write_outbit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_write_outbit(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double ReverseTime); //缓冲区立即IO输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_delay", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_delay(UInt16 CardNo, UInt16 Crd, double delay_time, Int32 mark); //添加延时指令 + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_reverse_outbit(UInt16 CardNo, UInt16 Crd, UInt16 bitno, double reverse_time); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_delay_outbit(UInt16 CardNo, UInt16 Crd, UInt16 bitno, UInt16 on_off, double delay_time); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_pmove_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_pmove_unit(UInt16 CardNo, UInt16 Crd, UInt16 Axis, double dist, UInt16 posi_mode, UInt16 mode, Int32 mark); //连续插补中控制指定外轴运动 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_line_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_line_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, UInt16 posi_mode, Int32 mark); //连续插补直线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_arc_move_center_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_arc_move_center_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Cen_Pos, UInt16 Arc_Dir, Int32 Circle, UInt16 posi_mode, Int32 mark); //圆心终点式圆弧/螺旋线/渐开线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_arc_move_radius_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_arc_move_radius_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double Arc_Radius, UInt16 Arc_Dir, Int32 Circle, UInt16 posi_mode, Int32 mark); //半径终点式圆弧/螺旋线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_arc_move_3points_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_arc_move_3points_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Mid_Pos, Int32 Circle, UInt16 posi_mode, Int32 mark); //三点式圆弧/螺旋线 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_clear_io_action", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_clear_io_action(UInt16 CardNo, UInt16 Crd, UInt32 IoMask); //清除段内未执行完的IO动作 + + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_stop_reason", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_stop_reason(UInt16 CardNo, UInt16 axis, ref Int32 StopReason); //读取轴停止原因 + [DllImport("LTDMC.dll", EntryPoint = "dmc_clear_stop_reason", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_clear_stop_reason(UInt16 CardNo, UInt16 axis); //清除轴停止原因 + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_involute_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_involute_mode(UInt16 CardNo, UInt16 Crd, UInt16 mode); //设置螺旋线是否封闭 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_involute_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_involute_mode(UInt16 CardNo, UInt16 Crd, ref UInt16 mode); //读取螺旋线是否封闭设置 + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_rectangle_move_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_rectangle_move_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] TargetPos, double[] MaskPos, Int32 Count, UInt16 rect_mode, UInt16 posi_mode, Int32 mark); //矩形区域插补,连续插补指令 + [DllImport("LTDMC.dll", EntryPoint = "dmc_calculate_arclength_center", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_calculate_arclength_center(double[] start_pos, double[] target_pos, double[] cen_pos, UInt16 arc_dir, double circle, ref double ArcLength); //计算圆心圆弧弧长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_calculate_arclength_3point", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_calculate_arclength_3point(double[] start_pos, double[] mid_pos, double[] target_pos, double circle, ref double ArcLength); //计算三点圆弧弧长 + [DllImport("LTDMC.dll", EntryPoint = "dmc_calculate_arclength_radius", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_calculate_arclength_radius(double[] start_pos, double[] target_pos, double arc_radius, UInt16 arc_dir, double circle, ref double ArcLength); //计算半径圆弧弧长 + + [DllImport("LTDMC.dll", EntryPoint = "dmc_rectangle_move_unit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_rectangle_move_unit(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] TargetPos, double[] MaskPos, Int32 Count, UInt16 rect_mode, UInt16 posi_mode); //矩形区域插补,单段插补指令 + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_gear_follow_profile(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt16 master_axis, double ratio);//双Z轴 + [DllImport("LTDMC.dll")] + public static extern short dmc_get_gear_follow_profile(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt16 master_axis, ref double ratio); + + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_line_unit_extern(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Cen_Pos, UInt16 posi_mode, Int32 mark); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_arc_move_center_unit_extern(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Target_Pos, double[] Cen_Pos, double Arc_Radius, UInt16 posi_mode, Int32 mark); + + //DA输出 + + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_da_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_da_enable(UInt16 CardNo, UInt16 enable);//开启DA输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_da_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_da_enable(UInt16 CardNo, ref UInt16 enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_da_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_da_output(UInt16 CardNo, UInt16 channel, double Vout);//设置DA输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_da_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_da_output(UInt16 CardNo, UInt16 channel, ref double Vout); + //DA跟随 + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_set_da_output(UInt16 CardNo, UInt16 Crd, UInt16 channel, double Vout); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_da_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_da_enable(ushort CardNo, ushort Crd, ushort enable, ushort channel, int mark); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_encoder_da_follow_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_encoder_da_follow_enable(ushort CardNo, ushort axis, ushort enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_encoder_da_follow_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_encoder_da_follow_enable(ushort CardNo, ushort axis, ref ushort enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_da_follow_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_da_follow_speed(ushort CardNo, ushort Crd, ushort da_no, double MaxVel, double MaxValue, double acc_offset, double dec_offset, double acc_dist, double dec_dist); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_da_follow_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_da_follow_speed(ushort CardNo, ushort Crd, ushort da_no, ref double MaxVel, ref double MaxValue, ref double acc_offset, ref double dec_offset, ref double acc_dist, ref double dec_dist); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_encoder_da_follow_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_encoder_da_follow_enable(ushort CardNo, ushort Crd, ushort axis, ushort enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_encoder_da_follow_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_encoder_da_follow_enable(ushort CardNo, ushort Crd, ushort axis, ref ushort enable); + //AD输入 + [DllImport("LTDMC.dll")] + public static extern short dmc_get_ad_input(ushort CardNo, ushort channel, ref double Vout); + + //设置插补运动速度曲线的平滑时间 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_vector_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_vector_s_profile(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, double s_para); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_vector_s_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_vector_s_profile(UInt16 CardNo, UInt16 Crd, UInt16 s_mode, ref double s_para); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_lookahead_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_lookahead_mode(UInt16 CardNo, UInt16 Crd, UInt16 enable, Int32 LookaheadSegments, double PathError, double LookaheadAcc); + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_lookahead_mode", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_lookahead_mode(UInt16 CardNo, UInt16 Crd, ref UInt16 enable, ref Int32 LookaheadSegments, ref double PathError, ref double LookaheadAcc); + //PWM输出 + [DllImport("LTDMC.dll")] + public static extern short dmc_set_pwm_pin(UInt16 CardNo, UInt16 portno, UInt16 ON_OFF, double dfreqency, double dduty); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_pwm_pin(UInt16 CardNo, UInt16 portno, ref UInt16 ON_OFF, ref double dfreqency, ref double dduty); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_pwm_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_pwm_enable(UInt16 CardNo, UInt16 enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_pwm_enable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_pwm_enable(UInt16 CardNo, ref UInt16 enable); + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_pwm_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_pwm_output(UInt16 CardNo, UInt16 pwm_no, double fDuty, double fFre); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_pwm_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_pwm_output(UInt16 CardNo, UInt16 pwm_no, ref double fDuty, ref double fFre); + + //连续插补PWM输出 + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_pwm_onoff_duty", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_pwm_onoff_duty(UInt16 CardNo, UInt16 PwmNo, double fOnDuty, double fOffDuty); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_pwm_onoff_duty", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_pwm_onoff_duty(UInt16 CardNo, UInt16 PwmNo, ref double fOnDuty, ref double fOffDuty); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_pwm_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_pwm_output(UInt16 CardNo, UInt16 Crd, UInt16 pwm_no, double fDuty, double fFre); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_pwm_enable_extern(UInt16 CardNo, UInt16 channel, UInt16 enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_pwm_enable_extern(UInt16 CardNo, UInt16 channel, ref UInt16 enable); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_set_pwm_follow_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_set_pwm_follow_speed(UInt16 CardNo, UInt16 Crd, UInt16 pwm_no, UInt16 mode, double MaxVel, double MaxValue, double OutValue); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_get_pwm_follow_speed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_get_pwm_follow_speed(UInt16 CardNo, UInt16 Crd, UInt16 pwm_no, ref UInt16 mode, ref double MaxVel, ref double MaxValue, ref double OutValue); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_delay_pwm_to_start", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_delay_pwm_to_start(UInt16 CardNo, UInt16 Crd, UInt16 pwmno, UInt16 on_off, double delay_value, UInt16 delay_mode, double ReverseTime); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_ahead_pwm_to_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_ahead_pwm_to_stop(UInt16 CardNo, UInt16 Crd, UInt16 pwmno, UInt16 on_off, double ahead_value, UInt16 ahead_mode, double ReverseTime); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_conti_write_pwm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_conti_write_pwm(UInt16 CardNo, UInt16 Crd, UInt16 pwmno, UInt16 on_off, double ReverseTime); + + [DllImport("LTDMC.dll", EntryPoint = "dmc_set_arc_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_set_arc_limit(UInt16 CardNo, UInt16 Crd, UInt16 Enable, double MaxCenAcc, double MaxArcError); + [DllImport("LTDMC.dll", EntryPoint = "dmc_get_arc_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_get_arc_limit(UInt16 CardNo, UInt16 Crd, ref UInt16 Enable, ref double MaxCenAcc, ref double MaxArcError); + //trace + [DllImport("LTDMC.dll")] + public static extern short dmc_trace_start(ushort CardNo, ushort AxisNum, ushort[] AxisList); + [DllImport("LTDMC.dll")] + public static extern short dmc_trace_stop(ushort CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_IoFilter(UInt16 CardNo, UInt16 bitno, double filter); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_IoFilter(UInt16 CardNo, UInt16 bitno, ref double filter); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_lsc_index_value(UInt16 CardNo, UInt16 axis, UInt16 IndexID, Int32 IndexValue); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_lsc_index_value(UInt16 CardNo, UInt16 axis, UInt16 IndexID, ref Int32 IndexValue); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_lsc_config(UInt16 CardNo, UInt16 axis, UInt16 Origin, UInt32 Interal, UInt32 NegIndex, UInt32 PosIndex, double Ratio); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_lsc_config(UInt16 CardNo, UInt16 axis, ref UInt16 Origin, ref UInt32 Interal, ref UInt32 NegIndex, ref UInt32 PosIndex, ref double Ratio); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_watchdog(UInt16 CardNo, UInt16 enable, UInt32 time); + [DllImport("LTDMC.dll")] + public static extern short dmc_call_watchdog(UInt16 CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_read_diagnoseData(UInt16 CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_set_cmd_end(UInt16 CardNo, UInt16 Crd, UInt16 enable); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_zone_limit_config(UInt16 CardNo, UInt16[] axis, UInt16[] Source, Int32 x_pos_p, Int32 x_pos_n, Int32 y_pos_p, Int32 y_pos_n, UInt16 action_para); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_zone_limit_config(UInt16 CardNo, UInt16[] axis, UInt16[] Source, ref Int32 x_pos_p, ref Int32 x_pos_n, ref Int32 y_pos_p, ref Int32 y_pos_n, ref UInt16 action_para); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_zone_limit_enable(UInt16 CardNo, UInt16 enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_interlock_config(UInt16 CardNo, UInt16[] axis, UInt16[] Source, Int32 delta_pos, UInt16 action_para); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_interlock_config(UInt16 CardNo, UInt16[] axis, UInt16[] Source, ref Int32 delta_pos, ref UInt16 action_para); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_interlock_enable(UInt16 CardNo, UInt16 enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_grant_error_protect(UInt16 CardNo, UInt16 axis, UInt16 enable, UInt32 dstp_error, UInt32 emg_error); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_grant_error_protect(UInt16 CardNo, UInt16 axis, ref UInt16 enable, ref UInt32 dstp_error, ref UInt32 emg_error); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_camerablow_config(UInt16 CardNo, UInt16 camerablow_en, Int32 cameraPos, UInt16 piece_num, Int32 piece_distance, UInt16 axis_sel, Int32 latch_distance_min); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_camerablow_config(UInt16 CardNo, ref UInt16 camerablow_en, ref Int32 cameraPos, ref UInt16 piece_num, ref Int32 piece_distance, ref UInt16 axis_sel, ref Int32 latch_distance_min); + [DllImport("LTDMC.dll")] + public static extern short dmc_clear_camerablow_errorcode(UInt16 CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_camerablow_errorcode(UInt16 CardNo, ref UInt16 errorcode); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_io_limit_config(UInt16 CardNo, UInt16 portno, UInt16 enable, UInt16 axis_sel, UInt16 el_mode, UInt16 el_logic); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_io_limit_config(UInt16 CardNo, UInt16 portno, ref UInt16 enable, ref UInt16 axis_sel, ref UInt16 el_mode, ref UInt16 el_logic); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_handwheel_filter(UInt16 CardNo, UInt16 axis, double filter_factor); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_handwheel_filter(UInt16 CardNo, UInt16 axis, ref double filter_factor); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_get_interp_map(UInt16 CardNo, UInt16 Crd, ref UInt16 AxisNum, UInt16[] AxisList, double[] pPosList); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_get_crd_errcode(UInt16 CardNo, UInt16 Crd, ref UInt16 errcode); + + [DllImport("LTDMC.dll")] + public static extern short dmc_line_unit_follow(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] Dist, UInt16 posi_mode); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_line_unit_follow(UInt16 CardNo, UInt16 Crd, UInt16 AxisNum, UInt16[] AxisList, double[] pPosList, UInt16 posi_mode, Int32 mark); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_set_da_action(UInt16 CardNo, UInt16 Crd, UInt16 mode, UInt16 portno, double dvalue); + + [DllImport("LTDMC.dll")] + public static extern short dmc_read_encoder_speed(UInt16 CardNo, UInt16 Axis, ref double current_speed); + [DllImport("LTDMC.dll")] + public static extern short dmc_axis_follow_line_enable(UInt16 CardNo, UInt16 Crd, UInt16 enable_flag); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_interp_compensation(UInt16 CardNo, UInt16 axis, double dvalue, double time); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_interp_compensation(UInt16 CardNo, UInt16 axis, ref double dvalue, ref double time); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_io_exactstop(UInt16 CardNo, UInt16 axis, UInt16 ioNum, UInt16[] ioList, UInt16 enable, UInt16 valid_logic, UInt16 action); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_distance_to_start(UInt16 CardNo, UInt16 Crd, ref double distance_x, ref double distance_y, Int32 imark); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_start_distance_flag(UInt16 CardNo, UInt16 Crd, UInt16 flag); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_home_soft_limit(UInt16 CardNo, UInt16 Axis, Int32 N_limit, Int32 P_limit); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_home_soft_limit(UInt16 CardNo, UInt16 Axis, ref Int32 N_limit, ref Int32 P_limit); + [DllImport("LTDMC.dll")] + public static extern short dmc_conti_gear_unit(UInt16 CardNo, UInt16 Crd, UInt16 axis, double dist, UInt16 follow_mode, Int32 imark); + //轨迹拟合使能设置 + [DllImport("LTDMC.dll")] + public static extern short dmc_set_path_fitting_enable(UInt16 CardNo, UInt16 Crd, UInt16 enable); + //螺距补偿功能(新) + [DllImport("LTDMC.dll")] + public static extern short dmc_enable_leadscrew_comp(UInt16 CardNo, UInt16 axis, UInt16 enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_leadscrew_comp_config(UInt16 CardNo, UInt16 axis, UInt16 n, Int32 startpos, Int32 lenpos, Int32[] pCompPos, Int32[] pCompNeg); + //指定轴做定长位移运动 按固定曲线运动 + [DllImport("LTDMC.dll")] + public static extern short dmc_t_pmove_extern(UInt16 CardNo, UInt16 axis, double MidPos, double TargetPos, double Min_Vel, double Max_Vel, double stop_Vel, double acc, double dec, UInt16 posi_mode); + [DllImport("LTDMC.dll")] + public static extern short dmc_set_pulse_encoder_count_error(UInt16 CardNo, UInt16 axis, UInt16 error); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_pulse_encoder_count_error(UInt16 CardNo, UInt16 axis, ref UInt16 error); + [DllImport("LTDMC.dll")] + public static extern short dmc_check_pulse_encoder_count_error(UInt16 CardNo, UInt16 axis, ref Int32 pulse_position, ref Int32 enc_position); + [DllImport("LTDMC.dll")] + public static extern short dmc_update_target_position_extern(UInt16 CardNo, UInt16 axis, double mid_pos, double aim_pos, double vel, UInt16 posi_mode); + + //新物件分拣功能 + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_close(UInt16 CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_start(UInt16 CardNo); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_init_config(UInt16 CardNo, UInt16 cameraCount, Int32[] pCameraPos, UInt16[] pCamIONo, UInt32 cameraTime, UInt16 cameraTrigLevel, UInt16 blowCount, Int32[] pBlowPos, UInt16[] pBlowIONo, UInt32 blowTime, UInt16 blowTrigLevel, UInt16 axis, UInt16 dir, UInt16 checkMode); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_camera_trig_count(UInt16 CardNo, UInt16 cameraNum, UInt32 cameraTrigCnt); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_camera_trig_count(UInt16 CardNo, UInt16 cameraNum, ref UInt32 pCameraTrigCnt, UInt16 count); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_blow_trig_count(UInt16 CardNo, UInt16 blowNum, UInt32 blowTrigCnt); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_blow_trig_count(UInt16 CardNo, UInt16 blowNum, ref UInt32 pBlowTrigCnt, UInt16 count); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_camera_config(UInt16 CardNo, UInt16 index, ref Int32 pos, ref UInt32 trigTime, ref UInt16 ioNo, ref UInt16 trigLevel); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_blow_config(UInt16 CardNo, UInt16 index, ref Int32 pos, ref UInt32 trigTime, ref UInt16 ioNo, ref UInt16 trigLevel); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_blow_status(UInt16 CardNo, ref Int32 trigCntAll, ref UInt16 trigMore, ref UInt16 trigLess); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_trig_blow(UInt16 CardNo, UInt16 blowNum); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_blow_enable(UInt16 CardNo, UInt16 blowNum, UInt16 enable); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_piece_config(UInt16 CardNo, UInt32 maxWidth, UInt32 minWidth, UInt32 minDistance, UInt32 minTimeIntervel); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_get_piece_status(UInt16 CardNo, ref UInt32 pieceFind, ref UInt32 piecePassCam, ref UInt32 dist2next, ref UInt32 pieceWidth); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_cam_trig_phase(UInt16 CardNo, UInt16 blowNo, double coef); + [DllImport("LTDMC.dll")] + public static extern short dmc_sorting_set_blow_trig_phase(UInt16 CardNo, UInt16 blowNo, double coef); + + [DllImport("LTDMC.dll")] + public static extern short dmc_set_sevon_enable(UInt16 CardNo, UInt16 axis, UInt16 on_off); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_sevon_enable(UInt16 CardNo, UInt16 axis); + [DllImport("LTDMC.dll")] + public static extern short dmc_compare_add_point_cycle(UInt16 CardNo, UInt16 cmp, Int32 pos, UInt16 dir, UInt32 bitno, UInt32 cycle, UInt16 level);//添加比较点 + + //通用文件下载 + [DllImport("LTDMC.dll", EntryPoint = "dmc_download_file", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_download_file(ushort CardNo, string pfilename, byte[] pfilenameinControl, ushort filetype); + [DllImport("LTDMC.dll", EntryPoint = "dmc_download_memfile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_download_memfile(ushort CardNo, byte[] pbuffer, uint buffsize, byte[] pfilenameinControl, ushort filetype); + [DllImport("LTDMC.dll", EntryPoint = "dmc_upload_file", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_upload_file(ushort CardNo, string pfilename, byte[] pfilenameinControl, ushort filetype); + [DllImport("LTDMC.dll", EntryPoint = "dmc_upload_memfile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short dmc_upload_memfile(ushort CardNo, byte[] pbuffer, uint buffsize, byte[] pfilenameinControl, ref uint puifilesize, ushort filetype); + [DllImport("LTDMC.dll")] + public static extern short dmc_get_progress(ushort CardNo, ref float process); + + //总线参数 + [DllImport("LTDMC.dll", EntryPoint = "nmc_download_configfile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_download_configfile(UInt16 CardNo, UInt16 PortNum, String FileName);//总线ENI配置文件 + [DllImport("LTDMC.dll", EntryPoint = "nmc_download_mapfile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_download_mapfile(UInt16 CardNo, String FileName); + [DllImport("LTDMC.dll")] + public static extern short nmc_upload_configfile(UInt16 CardNo, UInt16 PortNum, String FileName); + [DllImport("LTDMC.dll", EntryPoint = "nmc_set_manager_para", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_set_manager_para(UInt16 CardNo, UInt16 PortNum, Int32 baudrate, UInt16 ManagerID); + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_manager_para", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_manager_para(UInt16 CardNo, UInt16 PortNum, ref UInt32 baudrate, ref UInt16 ManagerID); + [DllImport("LTDMC.dll", EntryPoint = "nmc_set_manager_od", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_set_manager_od(UInt16 CardNo, UInt16 PortNum, UInt16 index, UInt16 subindex, UInt16 valuelength, UInt32 value); + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_manager_od", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_manager_od(UInt16 CardNo, UInt16 PortNum, UInt16 index, UInt16 subindex, UInt16 valuelength, ref UInt32 value); + + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_total_axes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_total_axes(ushort CardNo, ref uint TotalAxis); + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_total_ionum", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_total_ionum(UInt16 CardNo, ref UInt16 TotalIn, ref UInt16 TotalOut); + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_LostHeartbeat_Nodes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_LostHeartbeat_Nodes(UInt16 CardNo, UInt16 PortNum, UInt16[] NodeID, ref UInt16 NodeNum); + [DllImport("LTDMC.dll", EntryPoint = "nmc_get_EmergeneyMessege_Nodes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_get_EmergeneyMessege_Nodes(UInt16 CardNo, UInt16 PortNum, UInt32[] NodeMsg, ref UInt16 MsgNum); + [DllImport("LTDMC.dll", EntryPoint = "nmc_SendNmtCommand", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_SendNmtCommand(UInt16 CardNo, UInt16 PortNum, UInt16 NodeID, UInt16 NmtCommand); + [DllImport("LTDMC.dll", EntryPoint = "nmc_syn_move", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern short nmc_syn_move(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList, Int32[] Position, UInt16[] PosiMode); + // + [DllImport("LTDMC.dll")] + public static extern short nmc_syn_move_unit(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList, double[] Position, UInt16[] PosiMode); + [DllImport("LTDMC.dll")] + public static extern short nmc_sync_pmove_unit(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList, double[] Dist, UInt16[] PosiMode); + [DllImport("LTDMC.dll")] + public static extern short nmc_sync_vmove_unit(UInt16 CardNo, UInt16 AxisNum, UInt16[] AxisList, UInt16[] Dir); + + [DllImport("LTDMC.dll")] + public static extern short nmc_set_master_para(UInt16 CardNo, UInt16 PortNum, UInt16 Baudrate, UInt32 NodeCnt, UInt16 MasterId); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_master_para(UInt16 CardNo, UInt16 PortNum, ref UInt16 Baudrate, ref UInt32 NodeCnt, ref UInt16 MasterId); + + [DllImport("LTDMC.dll")] + public static extern short nmc_get_total_adcnum(ushort CardNo, ref ushort TotalIn, ref ushort TotalOut); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_controller_workmode(ushort CardNo, ushort controller_mode); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_controller_workmode(ushort CardNo, ref ushort controller_mode); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_cycletime(ushort CardNo, ushort FieldbusType, int CycleTime); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_cycletime(ushort CardNo, ushort FieldbusType, ref int CycleTime); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_node_od(ushort CardNo, ushort PortNum, ushort nodenum, ushort index, ushort subindex, ushort valuelength, ref int value); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_node_od(ushort CardNo, ushort PortNum, ushort nodenum, ushort index, ushort subindex, ushort valuelength, int value); + [DllImport("LTDMC.dll")] + public static extern short nmc_reset_to_factory(ushort CardNo, ushort PortNum, ushort NodeNum); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_alarm_clear(ushort CardNo, ushort PortNum, ushort nodenum); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_slave_nodes(ushort CardNo, ushort PortNum, ushort BaudRate, ref ushort NodeId, ref ushort NodeNum); + [DllImport("LTDMC.dll")] + public static extern short nmc_write_outbit(ushort CardNo, ushort NodeID, ushort IoBit, ushort IoValue); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_outbit(ushort CardNo, ushort NodeID, ushort IoBit, ref ushort IoValue); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_inbit(ushort CardNo, ushort NodeID, ushort IoBit, ref ushort IoValue); + [DllImport("LTDMC.dll")] + public static extern short nmc_write_outport(ushort CardNo, ushort NodeID, ushort PortNo, int IoValue); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_outport(ushort CardNo, ushort NodeID, ushort PortNo, ref int IoValue); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_inport(ushort CardNo, ushort NodeID, ushort PortNo, ref int IoValue); + + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_state_machine(ushort CardNo, ushort axis, ref ushort Axis_StateMachine); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_statusword(ushort CardNo, ushort axis, ref int statusword); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_setting_contrlmode(ushort CardNo, ushort axis, ref int contrlmode); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_contrlword(ushort CardNo, ushort axis, ref int contrlword); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_type(ushort CardNo, ushort axis, ref ushort Axis_Type); + + [DllImport("LTDMC.dll")] + public static extern short nmc_get_consume_time_fieldbus(ushort CardNo, ushort Fieldbustype, ref uint Average_time, ref uint Max_time, ref UInt64 Cycles); + [DllImport("LTDMC.dll")] + public static extern short nmc_clear_consume_time_fieldbus(ushort CardNo, ushort Fieldbustype); + + [DllImport("LTDMC.dll")] + public static extern short nmc_set_axis_enable(ushort CardNo, ushort axis); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_axis_disable(ushort CardNo, ushort axis); + + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_node_address(ushort CardNo, ushort axis, ref ushort SlaveAddr, ref ushort Sub_SlaveAddr); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_total_slaves(ushort CardNo, ushort PortNum, ref ushort TotalSlaves); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_home_profile(ushort CardNo, ushort axis, ushort home_mode, double Low_Vel, double High_Vel, double Tacc, double Tdec, double offsetpos); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_home_profile(ushort CardNo, ushort axis, ref ushort home_mode, ref double Low_Vel, ref double High_Vel, ref double Tacc, ref double Tdec, ref double offsetpos); + [DllImport("LTDMC.dll")] + public static extern short nmc_home_move(ushort CardNo, ushort axis); + // + [DllImport("LTDMC.dll")] + public static extern short nmc_start_scan_ethercat(ushort CardNo, ushort AddressID); + [DllImport("LTDMC.dll")] + public static extern short nmc_stop_scan_ethercat(ushort CardNo, ushort AddressID); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_axis_run_mode(ushort CardNo, ushort axis, ushort run_mode); + // + [DllImport("LTDMC.dll")] + public static extern short nmc_clear_alarm_fieldbus(ushort CardNo, ushort PortNum); + [DllImport("LTDMC.dll")] + public static extern short nmc_stop_etc(ushort CardNo, ref ushort ETCState); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_contrlmode(ushort CardNo, ushort Axis, ref int Contrlmode); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_io_in(ushort CardNo, ushort axis); + + [DllImport("LTDMC.dll")] + public static extern short nmc_set_axis_io_out(UInt16 CardNo, UInt16 axis, UInt32 iostate); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_io_out(UInt16 CardNo, UInt16 axis); + + [DllImport("LTDMC.dll")] + public static extern short nmc_get_errcode(ushort CardNo, ushort channel, ref ushort errcode); + [DllImport("LTDMC.dll")] + public static extern short nmc_clear_errcode(ushort CardNo, ushort channel); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_axis_errcode(ushort CardNo, ushort axis, ref ushort Errcode); + [DllImport("LTDMC.dll")] + public static extern short nmc_clear_axis_errcode(ushort CardNo, ushort axis); + + //RTEX卡添加函数 + [DllImport("LTDMC.dll")] + public static extern short nmc_start_connect(UInt16 CardNo, UInt16 chan, ref UInt16 info, ref UInt16 len); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_vendor_info(UInt16 CardNo, UInt16 axis, Byte[] info, ref UInt16 len); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_slave_type_info(UInt16 CardNo, UInt16 axis, Byte[] info, ref UInt16 len); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_slave_name_info(UInt16 CardNo, UInt16 axis, Byte[] info, ref UInt16 len); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_slave_version_info(UInt16 CardNo, UInt16 axis, Byte[] info, ref UInt16 len); + + [DllImport("LTDMC.dll")] + public static extern short nmc_write_parameter(UInt16 CardNo, UInt16 axis, UInt16 index, UInt16 subindex, UInt32 para_data); + /************************************************************** + *功能说明:RTEX驱动器写EEPROM操作 + **************************************************************/ + [DllImport("LTDMC.dll")] + public static extern short nmc_write_slave_eeprom(UInt16 CardNo, UInt16 axis); + + [DllImport("LTDMC.dll")] + public static extern short nmc_read_parameter(UInt16 CardNo, UInt16 axis, UInt16 index, UInt16 subindex, ref UInt32 para_data); + /************************************************************** + * *index:rtex驱动器的参数分类 + * *subindex:rtex驱动器在index类别下的参数编号 + * *para_data:读出的参数值 + * **************************************************************/ + [DllImport("LTDMC.dll")] + public static extern short nmc_read_parameter_attributes(UInt16 CardNo, UInt16 axis, UInt16 index, UInt16 subindex, ref UInt32 para_data); + [DllImport("LTDMC.dll")] + public static extern short nmc_set_cmdcycletime(UInt16 CardNo, UInt16 PortNum, UInt32 cmdtime); + //设置RTEX总线周期比(us) + [DllImport("LTDMC.dll")] + public static extern short nmc_get_cmdcycletime(UInt16 CardNo, UInt16 PortNum, ref UInt32 cmdtime); + [DllImport("LTDMC.dll")] + public static extern short nmc_config_atuo_log(UInt16 CardNo, UInt16 ifenable, UInt16 dir, UInt16 byte_index, UInt16 mask, UInt16 condition, UInt32 counter); + + //扩展PDO + [DllImport("LTDMC.dll")] + public static extern short nmc_write_rxpdo_extra(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, Int32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_rxpdo_extra(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, ref Int32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_txpdo_extra(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, ref Int32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_write_rxpdo_extra_uint(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, UInt32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_rxpdo_extra_uint(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, ref UInt32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_read_txpdo_extra_uint(UInt16 CardNo, UInt16 PortNum, UInt16 address, UInt16 DataLen, ref UInt32 Value); + [DllImport("LTDMC.dll")] + public static extern short nmc_get_log_state(UInt16 CardNo, UInt16 chan, ref UInt32 state); + [DllImport("LTDMC.dll")] + public static extern short nmc_driver_reset(UInt16 CardNo, UInt16 axis); + } +} diff --git a/Rs.Motion/IoManager.cs b/Rs.Motion/IoManager.cs index 1a835ea..bf37526 100644 --- a/Rs.Motion/IoManager.cs +++ b/Rs.Motion/IoManager.cs @@ -1,13 +1,16 @@ -锘縰sing GTN; +锘縰sing csLTDMC; +using GTN; using gts; using Rs.DataAccess; using Rs.Framework; using Rs.Motion.Base; using Rs.Motion.GugaoEcat; using Rs.Motion.GugaoPulse; +using Rs.Motion.Leisai; using Rs.Motion.Ztm; using System; using System.Collections.Generic; +using System.ComponentModel.Design; using System.Data; using System.IO; using System.Linq; @@ -62,6 +65,19 @@ namespace Rs.Motion ushort.Parse(dr["OutNum"].ToString()), int.Parse(dr["SlaveID"].ToString() )); + case "LeisaiPulse": + case "LeisaiPulseEx": + return LeisaiCardManager.Instance.AddIoCard( + int.Parse(dr["CardID"].ToString()), + dr["CardName"].ToString(), + + dr["vender"].ToString(), + false, + ushort.Parse(dr["InNum"].ToString()), + ushort.Parse(dr["OutNum"].ToString()), + int.Parse(dr["SlaveID"].ToString() + )); + default:return null; } } @@ -224,6 +240,36 @@ namespace Rs.Motion } } + else if (io.Card.Vender == "LeisaiPulse") + { + LeisaiIO eio = (LeisaiIO)io; + apiResult = LTDMC.dmc_read_inbit((ushort)io.CardID, eio.Index); + if (eio.IsReverse) + { + return (short)((~apiResult) & 0x01); + } + else + { + return (short)apiResult; + } + } + else if (io.Card.Vender == "LeisaiPulseEx") + { + LeisaiIO eio = (LeisaiIO)io; + ushort value = 0; + apiResult = LTDMC.nmc_read_inbit((ushort)io.CardID, eio.SlaveNo, eio.Index,ref value); + if(apiResult==0) + { + if (eio.IsReverse) + { + return (short)((~value) & 0x01); + } + else + { + return (short)value; + } + } + } } return -1; } @@ -321,6 +367,36 @@ namespace Rs.Motion } } } + else if (io.Card.Vender == "LeisaiPulse") + { + LeisaiIO eio = (LeisaiIO)io; + apiResult = LTDMC.dmc_read_outbit((ushort)io.CardID, eio.Index); + if (eio.IsReverse) + { + return (short)((~apiResult) & 0x01); + } + else + { + return (short)apiResult; + } + } + else if (io.Card.Vender == "LeisaiPulseEx") + { + LeisaiIO eio = (LeisaiIO)io; + ushort ioValue = 0; + apiResult = LTDMC.nmc_read_outbit((ushort)io.CardID,eio.SlaveNo, eio.Index,ref ioValue); + if(apiResult == 0) + { + if (eio.IsReverse) + { + return (short)((~ioValue) & 0x01); + } + else + { + return (short)ioValue; + } + } + } } return -1; } @@ -371,6 +447,16 @@ namespace Rs.Motion ZtmIO ztm = (ZtmIO)io; short ret = CSZTM.ZTM.ZT_SetOutBit(ztm.mc,(short) ztm.SlaveNo, (short)ztm.Index, value); } + else if (io.Card.Vender == "LeisaiPulse") + { + LeisaiIO gio = (LeisaiIO)io; + LTDMC.dmc_write_outbit((ushort)gio.CardID, gio.Index, value); + } + else if (io.Card.Vender == "LeisaiPulseEx") + { + LeisaiIO gio = (LeisaiIO)io; + LTDMC.nmc_write_outbit((ushort)gio.CardID,gio.SlaveNo, gio.Index, value); + } } return -1; } diff --git a/Rs.Motion/Leisai/LeisaiAxis.cs b/Rs.Motion/Leisai/LeisaiAxis.cs new file mode 100644 index 0000000..765185e --- /dev/null +++ b/Rs.Motion/Leisai/LeisaiAxis.cs @@ -0,0 +1,1438 @@ +锘縰sing csLTDMC; +using CSZTM; +using GTN; +using gts; +using Rs.Framework; +using Rs.Motion.Base; +using Rs.Motion.Base.Config; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using static gts.mc_pulse; + +namespace Rs.Motion.Leisai +{ + public class LeisaiAxis:IAxis + { + public LeisaiAxis(AxisConfig config) + { + Config = config; + } + + private LeisaiCardManager cardManager = LeisaiCardManager.Instance; + private short apiResult = 0; + private double m_dfCommandPosition = 0.0; + private object m_objLocker = new object(); + + + /// + /// 杞村垵濮嬪寲锛岃缃酱鍙傛暟 + /// + /// + public override ErrorCode Init() + { + //璁剧疆鍥炲師鐐逛俊鍙风殑鏈夋晥鐢靛钩 + apiResult = LTDMC.dmc_set_home_pin_logic(Config.CardId, Config.AxisId, Config.HomeOrgLogic, 0); + if(apiResult!=0) + { + LogHelper.Debug($"{apiResult} = LTDMC.dmc_set_home_pin_logic({Config.CardId}, {Config.AxisId}, {Config.HomeOrgLogic}, 0);"); + } + // mc_pulse.GT_ClrSts((short)Config.CardId, (short)Config.AxisId, 1); + IsInitialized = true; + + return ErrorCode.Ok; + } + + /// + /// 鍙嶅垵濮嬪寲杞达紝鍋滄杞 + /// + /// + public override ErrorCode Deinit() + { + IsInitialized = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + else + { + Stop(); + Disable(); + return ErrorCode.Ok; + } + } + + /// + /// 姣背杞剦鍐 + /// 鎬婚暱搴/鐢垫満杞竴鍦堣蛋鐨勯暱搴*鐢垫満杞竴鍦堢殑鑴夊啿鏁 + /// + /// + /// + /// + public override ErrorCode MmToPulse(double mm, out double pulse) + { + pulse = 0; + + if (Config.DistOneRound == 0.0) + { + return ErrorCode.UndefineDistanceOneRound; + } + else + { + pulse = mm / Config.DistOneRound * (double)Config.PulseOneRound; + return ErrorCode.Ok; + } + } + + /// + /// 鑴夊啿杞绫 + /// 鎬昏剦鍐叉暟/鐢垫満杞竴鍦堢殑鑴夊啿鏁*鐢垫満杞竴鍦堣蛋鐨勯暱搴 + /// + /// + /// + /// + public override ErrorCode PulseToMm(double pulse, out double mm) + { + mm = 0; + if (Config.PulseOneRound == 0) + { + return ErrorCode.UndefinePulseOneRound; + } + else + { + mm = pulse / (double)Config.PulseOneRound * Config.DistOneRound; + return ErrorCode.Ok; + } + } + + /// + /// 浣胯兘鐢垫満 + /// + /// + public override ErrorCode Enable() + { + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + else + { + apiResult = LTDMC.dmc_write_sevon_pin(Config.CardId, Config.AxisId, 0); + if (apiResult != 0) + return ErrorCode.Fail; + else + return ErrorCode.Ok; + } + } + + /// + /// 鍘讳娇鑳 + /// + /// + public override ErrorCode Disable() + { + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + apiResult = LTDMC.dmc_write_sevon_pin(Config.CardId, Config.AxisId, 1); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + return ErrorCode.Ok; + } + + /// + /// 鍋滄杩愬姩 + /// + /// + public override ErrorCode Stop() + { + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + apiResult = LTDMC.dmc_stop(Config.CardId, Config.AxisId, 0); + if (apiResult != 0) + return ErrorCode.Fail; + else + return ErrorCode.Ok; + } + + /// + /// 杩愬姩鎺у埗鍗″洖闆 + /// + /// + public override ErrorCode Default_Home_Move() + { + //if (!m_motion_card.IsInitialized) + //{ + // return ErrorCode.CARD_NOT_INIT; + //} + //if (!m_bIsInitialized) + //{ + // return ErrorCode.AXIS_NOT_INIT; + //} + //ErrorCode err = MmToPulse(m_axis_config.HomeOffset, out double dfHome_offset); + //if (err > ErrorCode.OK) + //{ + // return err; + //} + //err = MmToPulse(1.0, out double dfPulseRaio); + //m_LastErrorCode = ZTM.ZT_SetHomePol(m_axis_config.CardMc, (short)m_axis_config.AxisId, (short)m_axis_config.HomeOrgLogic); + //if (m_LastErrorCode != 0) + //{ + // return ErrorCode.FAIL; + //} + //MmToPulse(m_axis_config.HomeSpeed, out double homeSpeedPulse); + + ////acc vel/s mm/s pulse/s pulse/ms mm + //MmToPulse(m_axis_config.MaxSpeed, out double maxSpeedPulse); + + //m_LastErrorCode = ZTM.ZT_SetHomeParam(m_axis_config.CardMc, + // (short)m_axis_config.AxisId, + // (short)m_axis_config.HomeDir, + // (short)m_axis_config.HomeMode, + // (float)((double)(homeSpeedPulse / 4) / 1000.0), + // (float)((double)homeSpeedPulse / 1000.0), + // (float)((maxSpeedPulse / 1000.0) / (m_axis_config.AccTime * 1000.0)), + // (int)dfHome_offset, 0); + //if (m_LastErrorCode != 0) + //{ + // return ErrorCode.FAIL; + //} + ////int axes = SetBit(0, (int)m_axis_config.AxisId, 1); + ////m_LastErrorCode = ZTM.ZT_Home(m_axis_config.CardMc, (uint)axes); + //if (m_LastErrorCode != 0) + //{ + // return ErrorCode.MOVE_FAIL; + //} + //else + //{ + // return ErrorCode.OK; + //} + return ErrorCode.Ok; + } + + /// + /// 缁濆浣嶇疆杩愬姩 + /// + /// + /// + /// + /// + public override ErrorCode MovePos(double dfPosVal, int nSpeedPercent = 4) + { + if (!cardManager.IsInitialized) + return ErrorCode.CardNotInit; + if (!IsInitialized) + return ErrorCode.AxisNotInit; + if (!SafeCheck()) + return ErrorCode.Unsafe; + mc_pulse.GT_ClrSts((short)Config.CardId, (short)Config.AxisId, 1);//娓呴櫎杞寸姸鎬 + //杩愬姩涔嬪墠鍏堟竻涓涓嬬姸鎬 + //ClearAlarm(); + nSpeedPercent = nSpeedPercent <= 0 ? 10 : nSpeedPercent; + nSpeedPercent = nSpeedPercent > 100 ? 100 : nSpeedPercent; + if (HomeStatus != EHomeStatus.Finished) + return ErrorCode.AxisNotHome; + if (Config.EnableSoftwareEL == 1 && (dfPosVal > Config.PelSoftwarePosition || dfPosVal < Config.NelSoftwarePosition))//鍚敤杞檺浣 + { + return ErrorCode.OutOfLimit; + } + ErrorCode err = GetEmgStatus(out bool bEmg); + if (err > ErrorCode.Ok) + return err; + if (bEmg) + return ErrorCode.Emergency; + err = GetAlarmStatus(out bool bAlarm); + if (err > ErrorCode.Ok) + return err; + if (bAlarm) + return ErrorCode.Alarm; + err = IsEnable(out bool bEnable); + if (err > ErrorCode.Ok) + return err; + if (!bEnable) + return ErrorCode.ServoOff; + err = IsStop(out bool bStop); + if (err > ErrorCode.Ok) + return err; + if (!bStop) + return ErrorCode.Moving; + err = MmToPulse(dfPosVal, out double dfPos); + if (err > ErrorCode.Ok) + return err; + double dfPercent = (double)nSpeedPercent / 100.0; + + MmToPulse(Config.MaxSpeed, out double maxSpeedPulse); + MmToPulse(Config.MinSpeed, out double minSpeedPulse); + MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + float fMaxVel = (float)(maxSpeedPulse * dfPercent );//pulse/ms + float fStart = (float)(minSpeedPulse * dfPercent); + float fStop = (float)(stopSpeedPulse * dfPercent); + apiResult = LTDMC.dmc_set_profile(Config.CardId,Config.AxisId, fStart, fMaxVel, Config.AccTime, Config.DecTime, fStop); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + apiResult = LTDMC.dmc_set_s_profile(Config.CardId, Config.AxisId, 0,Config.STime); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + + apiResult = LTDMC.dmc_pmove(Config.CardId, Config.AxisId, (int)dfPos, 1); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + else + { + m_dfCommandPosition = dfPosVal; + return ErrorCode.Ok; + } + } + + /// + /// 鐩稿褰撳墠浣嶇疆杩愬姩 + /// + /// + /// + /// + /// + public override ErrorCode MoveOffset(double offset, int nSpeedPercent = 100) + { + if (!cardManager.IsInitialized) + return ErrorCode.CardNotInit; + if (!IsInitialized) + return ErrorCode.AxisNotInit; + if (!SafeCheck()) + return ErrorCode.Unsafe; + //杩愬姩涔嬪墠鍏堟竻涓涓嬬姸鎬 + //ClearAlarm(); + nSpeedPercent = nSpeedPercent <= 0 ? 10 : nSpeedPercent; + nSpeedPercent = nSpeedPercent > 100 ? 100 : nSpeedPercent; + //if (Config.EnableSoftwareEL == 1 && (dfPosVal > Config.PelSoftwarePosition || dfPosVal < Config.NelSoftwarePosition))//鍚敤杞檺浣 + //{ + // return ErrorCode.OutOfLimit; + //} + ErrorCode err = GetEmgStatus(out bool bEmg); + if (err > ErrorCode.Ok) + return err; + if (bEmg) + return ErrorCode.Emergency; + err = GetAlarmStatus(out bool bAlarm); + if (err > ErrorCode.Ok) + return err; + if (bAlarm) + return ErrorCode.Alarm; + err = IsEnable(out bool bEnable); + if (err > ErrorCode.Ok) + return err; + if (!bEnable) + return ErrorCode.ServoOff; + err = IsStop(out bool bStop); + if (err > ErrorCode.Ok) + return err; + if (!bStop) + return ErrorCode.Moving; + err = MmToPulse(offset, out double dfPos); + if (err > ErrorCode.Ok) + return err; + double dfPercent = (double)nSpeedPercent / 100.0; + + MmToPulse(Config.MaxSpeed, out double maxSpeedPulse); + MmToPulse(Config.MinSpeed, out double minSpeedPulse); + MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + float fMaxVel = (float)(maxSpeedPulse * dfPercent);//pulse/ms + float fStart = (float)(minSpeedPulse * dfPercent); + float fStop = (float)(stopSpeedPulse * dfPercent); + apiResult = LTDMC.dmc_set_profile(Config.CardId, Config.AxisId, fStart, fMaxVel, Config.AccTime, Config.DecTime, fStop); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + apiResult = LTDMC.dmc_set_s_profile(Config.CardId, Config.AxisId, 0, Config.STime); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + + apiResult = LTDMC.dmc_pmove(Config.CardId, Config.AxisId, (int)dfPos, 0); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + else + { + return ErrorCode.Ok; + } + } + + public override ErrorCode MoveJog(short dir, int nSpeedPercent = 10) + { + if (!cardManager.IsInitialized) + return ErrorCode.CardNotInit; + if (!IsInitialized) + return ErrorCode.AxisNotInit; + if (!SafeCheck()) + return ErrorCode.Unsafe; + mc_pulse.GT_ClrSts((short)Config.CardId, (short)Config.AxisId, 1);//娓呴櫎杞寸姸鎬 + //杩愬姩涔嬪墠鍏堟竻涓涓嬬姸鎬 + //ClearAlarm(); + nSpeedPercent = nSpeedPercent <= 0 ? 10 : nSpeedPercent; + nSpeedPercent = nSpeedPercent > 100 ? 100 : nSpeedPercent; + ErrorCode err = GetEmgStatus(out bool bEmg); + if (err > ErrorCode.Ok) + return err; + if (bEmg) + return ErrorCode.Emergency; + err = GetAlarmStatus(out bool bAlarm); + if (err > ErrorCode.Ok) + return err; + if (bAlarm) + return ErrorCode.Alarm; + err = IsEnable(out bool bEnable); + if (err > ErrorCode.Ok) + return err; + if (!bEnable) + return ErrorCode.ServoOff; + err = IsStop(out bool bStop); + if (err > ErrorCode.Ok) + return err; + if (!bStop) + return ErrorCode.Moving; + double dfPercent = (double)nSpeedPercent / 100.0; + + MmToPulse(Config.MaxSpeed, out double maxSpeedPulse); + MmToPulse(Config.MinSpeed, out double minSpeedPulse); + MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + float fMaxVel = (float)(maxSpeedPulse * dfPercent);//pulse/ms + float fStart = (float)(minSpeedPulse * dfPercent); + float fStop = (float)(stopSpeedPulse * dfPercent); + apiResult = LTDMC.dmc_set_profile(Config.CardId, (ushort)(Config.AxisId), fStart, fMaxVel, Config.AccTime, Config.DecTime, fStop); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + apiResult = LTDMC.dmc_set_s_profile(Config.CardId, (ushort)(Config.AxisId), 0, Config.STime); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + + apiResult = LTDMC.dmc_vmove(Config.CardId, (ushort)(Config.AxisId), (ushort)dir); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + else + { + return ErrorCode.Ok; + } + } + + public override ErrorCode UpdateTargetPosition(double dfNewPosVal) + { + //if (!m_motion_card.IsInitialized) + //{ + // return ErrorCode.CARD_NOT_INIT; + //} + //if (!m_bIsInitialized) + //{ + // return ErrorCode.AXIS_NOT_INIT; + //} + //if (_eHomeStatus != EHomeStatus.FINISH) + //{ + // return ErrorCode.NOT_GO_HOME; + //} + //bool isNotSafe = (dfNewPosVal > m_axis_config.PelSoftwarePosition || dfNewPosVal < m_axis_config.NelSoftwarePosition) + // && m_axis_config.PelSoftwarePosition != m_axis_config.NelSoftwarePosition; + //if (isNotSafe) + //{ + // return ErrorCode.POSITION_OUT_OF_RANGE; + //} + //ErrorCode err = GetEmgStatus(out bool bEmg); + //if (err > ErrorCode.OK) + //{ + // return err; + //} + //if (bEmg) + //{ + // return ErrorCode.EMERGENCY; + //} + //err = GetAlarmStatus(out bool bAlarm); + //if (err > ErrorCode.OK) + //{ + // return err; + //} + //if (bAlarm) + //{ + // return ErrorCode.ALARM; + //} + //err = IsEnable(out bool bEnable); + //if (err > ErrorCode.OK) + //{ + // return err; + //} + //if (bEnable) + //{ + // return ErrorCode.SERVO_OFF; + //} + //err = MmToPulse(dfNewPosVal, out double dfPos); + //if (err > ErrorCode.OK) + //{ + // return err; + //} + //else + //{ + // m_dfCommandPosition = dfNewPosVal; + // bool flag19 = m_LastErrorCode != 0; + // if (flag19) + // { + // return ErrorCode.FAIL; + // } + // else + // { + // return ErrorCode.OK; + // } + //} + return ErrorCode.Ok; + } + + // Token: 0x06000256 RID: 598 RVA: 0x0000373C File Offset: 0x0000193C + public override ErrorCode ChangeSpeed(double dfNewSpeed) + { + //if (!m_motion_card.IsInitialized) + //{ + // return ErrorCode.CARD_NOT_INIT; + //} + //if (!m_bIsInitialized) + //{ + // return ErrorCode.AXIS_NOT_INIT; + //} + //if (dfNewSpeed <= m_axis_config.MinSpeed) + //{ + // dfNewSpeed = m_axis_config.MinSpeed; + //} + //if (dfNewSpeed >= m_axis_config.MaxSpeed) + //{ + // dfNewSpeed = m_axis_config.MaxSpeed; + //} + return ErrorCode.Ok; + } + + /// + /// 鍒ゆ柇杞存槸鍚︿娇鑳 + /// + /// + /// + public override ErrorCode IsEnable(out bool bIsEable) + { + bIsEable = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + apiResult = LTDMC.dmc_read_sevon_pin(Config.CardId, Config.AxisId); + bIsEable = apiResult == 0; + return ErrorCode.Ok; + } + + /// + /// 杩愬姩鎺у埗鍗″洖闆 + /// + /// + public void DefaultHome(object obj) + { + if (!SafeCheck()) + { + MessageQueue.Instance.Insert($"{Config.AxisName} go home unsafe"); + return; + } + MessageQueue.Instance.Insert($"{Config.AxisName} go home"); + //鍒ゆ柇鏄惁鍦ㄥ師鐐 + GetOrgStatus(out bool bOrg); + if(bOrg) + { + //濡傛灉鍦ㄥ師鐐癸紝鍚戝洖鍘熸柟鍚戠殑鍙嶆柟鍚戣繍鍔ㄧ洿鍒扮寮鍘熺偣 + if(Config.HomeDir==1) + { + MoveJog(0, 2); + } + else + { + MoveJog(1, 2); + } + while (bOrg) + { + GetOrgStatus(out bOrg); + } + Stop(); + Thread.Sleep(100); + } + apiResult = LTDMC.dmc_set_position(Config.CardId, Config.AxisId, 0); + apiResult = LTDMC.dmc_set_encoder(Config.CardId, Config.AxisId, 0); + HomeStatus = EHomeStatus.Start; + + MmToPulse(Config.HomeOffset, out double dfHome_offset); + MmToPulse(Config.HomeSpeed, out double homeSpeedPulse); + MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + apiResult = LTDMC.dmc_set_profile(Config.CardId, Config.AxisId, homeSpeedPulse / 2, homeSpeedPulse, Config.AccTime, Config.DecTime, stopSpeedPulse); + + apiResult = LTDMC.dmc_set_homemode(Config.CardId, Config.AxisId, (ushort)Config.HomeDir, Config.HomeVelMode, Config.HomeMode, Config.EnableEncoder); + + LTDMC.dmc_home_move(Config.CardId, Config.AxisId); + if (apiResult != 0) + { + MessageQueue.Instance.Insert($"{Config.AxisName} go home fail ret:{apiResult}"); + HomeStatus = EHomeStatus.Fail; + } + Stopwatch timer = new Stopwatch(); + timer.Restart(); + while (HomeStatus != EHomeStatus.Finished && HomeStatus != EHomeStatus.Abort && timer.ElapsedMilliseconds < 2 * 60 * 1000) + { + + apiResult = LTDMC.dmc_check_done(Config.CardId, Config.AxisId); + Thread.Sleep(10); + if(apiResult==1) + { + GetEncoderPosition(out double curPos); + MmToPulse(Config.HomeOffset, out double offsetPulse); + MoveOffset(Config.HomeOffset, 5); + //LTDMC.dmc_pmove(Config.CardId, Config.AxisId, (int)offsetPulse, 0); + do + { + IsStop(out bool stoped); + if (stoped) + break; + } + while (true); + Thread.Sleep(500); + Zero(0); + HomeStatus = EHomeStatus.Finished; + break; + } + } + } + + /// + /// 鍒ゆ柇杞存槸鍚﹀洖闆 + /// + /// + /// + public override ErrorCode IsHomed(out bool bIsHomed) + { + bIsHomed = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + if (HomeStatus == EHomeStatus.Finished) + { + bIsHomed = true; + } + return ErrorCode.Ok; + } + + /// + /// 鍒ゆ柇杞存槸鍚﹀凡鍋滄 + /// + /// + /// + public override ErrorCode IsStop(out bool bIsStop) + { + bIsStop = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + apiResult = LTDMC.dmc_check_done(Config.CardId, Config.AxisId); + + bIsStop = apiResult == 1; + return ErrorCode.Ok; + } + + public override ErrorCode IsArrived(out bool bIsArrived) + { + bIsArrived = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + bool bIsStop = false; + ErrorCode err = IsStop(out bIsStop); + if (err > ErrorCode.Ok) + { + return err; + } + if (!bIsStop) + { + return ErrorCode.Ok; + } + double currentPos = 0.0; + if(Config.EnableEncoder==1) + { + GetEncoderPosition(out currentPos); + } + else + { + GetPrfPosition(out currentPos); + } + bIsArrived = Math.Abs((currentPos - m_dfCommandPosition)) < 0.05; + return ErrorCode.Ok; + } + + /// + /// 鍒ゆ柇杩愬姩鏄惁鍒颁綅 + /// + /// + /// + public override ErrorCode IsInPosition(out bool bIsInPosition) + { + bIsInPosition = false; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + if (0 == Config.EnableEncoder)//姝ヨ繘 + { + return IsStop(out bIsInPosition); + } + bool bIsStop = false; + ErrorCode err = IsStop(out bIsStop); + if (err > ErrorCode.Ok) + { + return err; + } + if (!bIsStop) + { + return ErrorCode.Ok; + } + if(Config.EnableInp==1) + { + bool bINP = false; + err = GetInpStatus(out bINP); + if (err > ErrorCode.Ok) + { + return err; + } + if (!bINP) + { + return ErrorCode.Ok; + } + } + double dfCurrentTorlance = 0.0; + double dfTorlance = Math.Abs(Config.Tolerance); + err = GetTolerance(out dfCurrentTorlance); + if (Math.Abs(dfCurrentTorlance) <= dfTorlance) + { + bIsInPosition = true; + } + return err; + } + + /// + /// 鑾峰彇瑙勫垝浣嶇疆 + /// + /// + /// + public override ErrorCode GetPrfPosition(out double dfCmdPos) + { + dfCmdPos = 0.0; + ErrorCode err = ErrorCode.Fail; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + try + { + lock (m_objLocker) + { + Int32 pulse = LTDMC.dmc_get_position(Config.CardId, Config.AxisId); + err = PulseToMm(pulse, out dfCmdPos); + } + } + catch + { + } + return err; + } + + /// + /// 鑾峰彇缂栫爜鍣ㄤ綅缃 + /// + /// + /// + public override ErrorCode GetEncoderPosition(out double dfEncPos) + { + dfEncPos = 0.0; + ErrorCode err = ErrorCode.Fail; + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + if (0 == Config.EnableEncoder) + { + return GetPrfPosition(out dfEncPos); + } + try + { + lock (m_objLocker) + { + int paulse = LTDMC.dmc_get_encoder(Config.CardId, Config.AxisId); + err = PulseToMm(paulse, out dfEncPos); + } + } + catch + { + } + return err; + } + + public override ErrorCode GetAuEncoderPosition(out double dfCmdPos) + { + dfCmdPos = 0.0; + ErrorCode err = ErrorCode.Fail; + //if (!cardManager.IsInitialized) + //{ + // return ErrorCode.CardNotInit; + //} + //try + //{ + // lock (m_objLocker) + // { + // apiResult = mc_ecat.GTN_ReadAuEncPos(core, (short)Config.AxisId, out double pValue, 1); + // if (apiResult != 0) + // { + // return ErrorCode.Fail; + // } + // err = PulseToMm(pValue, out dfCmdPos); + // } + //} + //catch + //{ + //} + return err; + } + + + /// + /// 鑾峰彇缂栫爜鍣ㄤ綅缃 + /// + /// + /// + public override ErrorCode GetDriverPosition(out double dfDriverPos) + { + dfDriverPos = 0.0; + ErrorCode err = ErrorCode.Fail; + //if (!cardManager.IsInitialized) + //{ + // return ErrorCode.CardNotInit; + //} + //try + //{ + // lock (m_objLocker) + // { + // apiResult = mc_ecat.GTN_GetEcatEncPos(core, (short)Config.AxisId, out int pValue);// ZTM.ZT_GetPosEncoder(m_axis_config.CardMc, (short)m_axis_config.AxisId, ref iPos); + // if (apiResult != 0) + // { + // return ErrorCode.Fail; + // } + // err = PulseToMm(pValue, out dfDriverPos); + // } + //} + //catch + //{ + //} + return err; + } + + /// + /// 鑾峰彇杞村厑璁哥殑鍏樊鍊 + /// + /// + /// + public override ErrorCode GetTolerance(out double dfTolerance) + { + dfTolerance = 0.0; + ErrorCode err; + if (0 == Config.EnableEncoder) + { + return ErrorCode.Ok; + } + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + err = GetPrfPosition(out double dfTargetPos); + if (err > ErrorCode.Ok) + { + return err; + } + err = GetEncoderPosition(out double dfCurrentPos); + if (err > ErrorCode.Ok) + { + return err; + } + dfTolerance = dfCurrentPos - dfTargetPos; + double dfTolerance2 = dfCurrentPos - m_dfCommandPosition; + if (Math.Abs(dfTolerance) < Math.Abs(dfTolerance2)) + { + dfTolerance = dfTolerance2; + } + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇姝i檺浣嶇姸鎬 + /// + /// + /// + public override ErrorCode GetPelStatus(out bool bIsInPel) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsInPel = ((status >> 1) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇璐熼檺浣嶇姸鎬 + /// + /// + /// + public override ErrorCode GetNelStatus(out bool bIsInNel) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsInNel = ((status >> 2) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇鍘熺偣鐨勭姸鎬 + /// + /// + /// + public override ErrorCode GetOrgStatus(out bool bIsInOrg) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsInOrg = ((status >> 4) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇鎶ヨ鐘舵 + /// + /// + /// + public override ErrorCode GetAlarmStatus(out bool bIsAlarm) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsAlarm = ((status >> 0) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇EMG鐘舵 + /// + /// + /// + public override ErrorCode GetEmgStatus(out bool bIsEmg) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsEmg = ((status >> 3) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇鍒颁綅淇″彿 + /// + /// + /// + public override ErrorCode GetInpStatus(out bool bIsInp) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsInp = ((status >> 8) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 鑾峰彇EZ鐘舵 + /// + /// + /// + public override ErrorCode GetEzStatus(out bool bIsInEz) + { + uint status = LTDMC.dmc_axis_io_status(Config.CardId, Config.AxisId); + bIsInEz = ((status >> 9) & 0x01) == 1; + return ErrorCode.Ok; + } + + /// + /// 杞村洖鍘 + /// + /// + /// + public override ErrorCode Home() + { + if (HomeStatus == EHomeStatus.Homing || HomeStatus == EHomeStatus.Start) + { + return ErrorCode.Ok; + } + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + ErrorCode err = GetAlarmStatus(out bool bAlarm); + if (err > ErrorCode.Ok) + { + return err; + } + if (bAlarm) + { + return ErrorCode.Alarm; + } + err = IsEnable(out bool bEnable); + if (err > ErrorCode.Ok) + { + return err; + } + if (!bEnable) + { + return ErrorCode.ServoOff; + } + err = IsStop(out bool bStop); + if (err > ErrorCode.Ok) + { + return err; + } + if (!bStop) + { + return ErrorCode.Moving; + } + Thread t = t = new Thread(new ParameterizedThreadStart(DefaultHome)); + HomeStatus = EHomeStatus.Start; + t.Name = Config.AxisName + " homing thread"; + t.Start(this); + return ErrorCode.Ok; + } + + /// + /// + /// + //protected void AutoHomeMode(object obj) + //{ + // bool bIsStop = false; + // int searchDistance = 1000;//鍥炲師鎼滅储璺濈 + // double searchPulse = 0; + // double curPos = 0.0; + // //鍥洪珮鏉垮潡鐨勫洖鍘熺偣锛屽彲浠ョ敤鎹曡幏鍥炲師锛屽鏋滄槸姝ヨ繘鐢垫満閲囩敤鐩存帴鍥炲師鐨勬柟寮 + + + // int pValue = 0; + // if (Config.HomeDir == 0) + // { + // searchDistance *= -1; + // } + // MmToPulse(searchDistance, out searchPulse); + + // MmToPulse(Config.HomeSpeed, out double homeSpeedPulse); + // MmToPulse(Config.MinSpeed, out double minSpeedPulse); + // MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + // float fMaxVel = (float)(homeSpeedPulse / 1000.0);//pulse/ms + // float fAcc = (float)(homeSpeedPulse / Config.AccTime / 1000000.0);//pulse/ms2 + // float fDec = (float)(homeSpeedPulse / Config.DecTime / 1000000.0);//pulse/ms2 + // float fStart = (float)(minSpeedPulse / 1000.0);//pulse/ms + // float fStop = (float)(stopSpeedPulse / 1000.0);//pulse/ms + + + // mc_pulse.GT_HomeInit((short)Config.CardId); + // mc_pulse.GT_Home(apiResult, (short)Config.AxisId, (int)searchPulse, fMaxVel, fAcc, 0); + // while(true) + // { + // mc_pulse.GT_HomeSts((short)Config.CardId,(short)Config.AxisId, out ushort pStatus); + // if(pStatus==1) + // { + // ClearAlarm(); + // HomeStatus = EHomeStatus.Finished; + // break; + // } + // } + //} + + /// + /// + /// + /// + protected void CaptureHome(object obj) + { + if(HomeJudge()) + { + bool bIsStop = false; + int searchDistance = 1000;//鍥炲師鎼滅储璺濈 + double searchPulse = 0; + double curPos = 0.0; + //鍥洪珮鏉垮潡鐨勫洖鍘熺偣锛屽彲浠ョ敤鎹曡幏鍥炲師锛屽鏋滄槸姝ヨ繘鐢垫満閲囩敤鐩存帴鍥炲師鐨勬柟寮 + + short pStatus = 0; + int pValue = 0; + if (Config.HomeDir == 0) + { + searchDistance *= -1; + } + MmToPulse(searchDistance, out searchPulse); + mc_pulse.GT_SetCaptureSense((short)Config.CardId, (short)Config.AxisId, mc_pulse.CAPTURE_HOME, (short)Config.HomeOrgLogic); + //鍚姩鎹曡幏鍥炲師 + mc_pulse.GT_SetEncPos(0, 1, 0); + mc_pulse.GT_SetPrfPos(0, 1, 0); + if (Config.EnableEncoder == 1) + { + mc_pulse.GT_GetEncPos(0, 1, out curPos, 1, out uint pClock); + } + else + { + mc_pulse.GT_GetPrfPos(0, 1, out curPos, 1, out uint pClock); + } + apiResult = mc_pulse.GT_SetCaptureMode((short)Config.CardId, (short)Config.AxisId, mc_pulse.CAPTURE_HOME); + if (apiResult != 0) + { + return; + } + + double targetPos = curPos + searchPulse; + MmToPulse(Config.HomeSpeed, out double homeSpeedPulse); + MmToPulse(Config.MinSpeed, out double minSpeedPulse); + MmToPulse(Config.StopSpeed, out double stopSpeedPulse); + + float fMaxVel = (float)(homeSpeedPulse / 1000.0);//pulse/ms + float fAcc = (float)(homeSpeedPulse / Config.AccTime / 1000000.0);//pulse/ms2 + float fDec = (float)(homeSpeedPulse / Config.DecTime / 1000000.0);//pulse/ms2 + float fStart = (float)(minSpeedPulse / 1000.0);//pulse/ms + float fStop = (float)(stopSpeedPulse / 1000.0);//pulse/ms + + + apiResult = mc_pulse.GT_PrfTrap((short)Config.CardId, (short)Config.AxisId);//璁剧疆杩愬姩妯″紡涓虹偣浣嶈繍鍔 + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + apiResult = mc_pulse.GT_GetTrapPrm((short)Config.CardId, (short)Config.AxisId, out mc_pulse.TTrapPrm trapPrm);//鑾峰彇鐐逛綅杩愬姩鍙傛暟 + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + trapPrm.acc = fAcc; + trapPrm.dec = fDec; + trapPrm.velStart = fStart; + apiResult = mc_pulse.GT_SetTrapPrm((short)Config.CardId, (short)Config.AxisId, ref trapPrm);//璁剧疆鐐逛綅杩愬姩鍙傛暟 + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + apiResult = mc_pulse.GT_SetPos((short)Config.CardId, (short)Config.AxisId, (int)targetPos);//璁剧疆鐩爣浣嶇疆 + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + apiResult = mc_pulse.GT_SetVel((short)Config.CardId, (short)Config.AxisId, fMaxVel);//璁剧疆鐩爣閫熷害 + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + apiResult = mc_pulse.GT_Update((short)Config.CardId, (1 << Config.AxisId - 1)); + if (apiResult != 0) + { + return;// ErrorCode.Fail; + } + do + { + //鑾峰彇鎹曡幏鐘舵 + apiResult = mc_pulse.GT_GetCaptureStatus((short)Config.CardId, (short)Config.AxisId, out pStatus, out pValue, 1, out uint pClock); + IsStop(out bIsStop); + if (bIsStop) + { + HomeStatus = EHomeStatus.Fail; + return; + } + } while (pStatus == 0); + + MmToPulse(Config.HomeOffset, out double offsetPulse); + targetPos = pValue + (int)offsetPulse; + apiResult = mc_pulse.GT_SetPos((short)Config.CardId, (short)Config.AxisId, (int)targetPos);//璁剧疆鐩爣浣嶇疆 + apiResult = mc_pulse.GT_Update((short)Config.CardId, (1 << Config.AxisId - 1)); + do + { + IsStop(out bIsStop); + } while (!bIsStop && HomeStatus != EHomeStatus.Abort); + Thread.Sleep(500); + Zero(0); + HomeStatus = EHomeStatus.Finished; + } + } + + protected bool HomeJudge() + { + int persent = (int)((Config.HomeSpeed / Config.MaxSpeed) * 100); + if (persent <= 0) + persent = 2; + bool bIsOrg = false; + bool bIsPel = false; + bool bIsNel = false; + int homeStep = 0; + while(homeStep>=0 && HomeStatus!= EHomeStatus.Abort) + { + switch (homeStep) + { + case 0://鍒ゆ柇鏄惁鍦ㄥ師鐐癸紝鍦ㄥ師鐐癸紝灏卞厛绂诲紑鍘熺偣 + GetOrgStatus(out bIsOrg); + if(bIsOrg) + { + //绂诲紑鍘熺偣 + if(Config.HomeDir==0) + { + MoveJog(1, persent); + } + else + { + MoveJog(0, persent); + } + do + { + GetOrgStatus(out bIsOrg); + } while (bIsOrg && HomeStatus!= EHomeStatus.Abort); + Stop(); + Thread.Sleep(500); + homeStep = -1; + } + else + homeStep = 1; + break; + case 1://鍒ゆ柇鏄惁鍦ㄦ闄愪綅 + GetPelStatus(out bIsPel); + if( bIsPel) + { + //鍏堝幓鎵惧師鐐 + MoveJog(0, persent); + do + { + GetOrgStatus(out bIsOrg); + } while (!bIsOrg && HomeStatus != EHomeStatus.Abort); + Stop(); + ClearAlarm(); + Thread.Sleep(100); + homeStep = 0; + } + else + homeStep = 2; + break; + case 2://鍒ゆ柇鏄惁鍦ㄨ礋闄愪綅 + GetNelStatus(out bIsNel); + if( bIsNel ) + { + MoveJog(1, persent); + do + { + GetOrgStatus(out bIsOrg); + } while (!bIsOrg && HomeStatus != EHomeStatus.Abort); + Stop(); + ClearAlarm(); + Thread.Sleep(100); + homeStep = 0; + } + homeStep = 3; + break; + case 3://涓嶅湪鍘熺偣锛屼篃涓嶅湪闄愪綅涓婏紝鍏堟湞鍥炲師鏂瑰悜鎼滅储 + if(Config.HomeDir==0) + { + MoveJog(0, persent); + + } + else + { + MoveJog(1, persent); + } + //鎼滅储鐨勮繃绋嬩腑锛屽彲鑳界鍒板師鐐癸紝涔熷彲鑳界鍒伴檺浣,纰板埌浠讳綍涓涓氨鍋滀笅鏉 + do + { + GetOrgStatus(out bIsOrg); + if (bIsOrg) + { + homeStep = 0; + } + GetPelStatus(out bIsPel); + if (bIsPel) + { + homeStep = 1; + } + GetNelStatus(out bIsNel); + if (bIsNel) + { + homeStep = 2; + } + } while (!bIsOrg && !bIsPel && !bIsNel && HomeStatus != EHomeStatus.Abort); + Stop(); + Thread.Sleep(100); + break; + default: + break; + } + } + + if(HomeStatus!= EHomeStatus.Abort) + { + return true; + } + return false; + } + + /// + /// 鍥炲師瀹屾垚 + /// + /// + /// + public override ErrorCode Zero(int iOrig) + { + if (!cardManager.IsInitialized) + { + return ErrorCode.CardNotInit; + } + if(!IsInitialized) + { + return ErrorCode.AxisNotInit; + } + apiResult = LTDMC.dmc_set_position(Config.CardId, Config.AxisId, 0); + if(apiResult!=0) + { + return ErrorCode.Fail; + } + if(Config.EnableEncoder==1) + { + apiResult = LTDMC.dmc_set_encoder(Config.CardId, Config.AxisId, 0); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + } + return ErrorCode.Ok; + } + + + public void SetHomeFinished() + { + Zero(0); + //base.Set_Home_Finished(); + } + + + /// + /// 鑾峰彇杩愬姩鐨勭洰鏍囦綅缃 + /// + /// + /// + public override ErrorCode Get_Target_Position(out double dfTargetPos) + { + dfTargetPos = m_dfCommandPosition; + return ErrorCode.Ok; + } + + public override ErrorCode SetPosCompare(ushort channel, double[] postions) + { + Int32 remained_points = 0; + Int32 current_point = 0; + Int32 runned_points = 0; + apiResult = LTDMC.dmc_hcmp_get_current_state(Config.CardId, channel, ref remained_points, ref current_point, ref runned_points); + + apiResult = LTDMC.dmc_hcmp_set_mode(Config.CardId, channel, 4); + if(apiResult!=0) + { + LogHelper.Debug($"{apiResult} = mc_pulse.GT_2DCompareStop({(short)Config.CardId}, {(short)(channel - 1)});"); + return ErrorCode.Fail; + } + apiResult = LTDMC.dmc_hcmp_set_config(Config.CardId, channel, Config.AxisId, 1, 0, Config.HcmpPulseWidth); + if(apiResult!=0) + { + LogHelper.Debug($"{apiResult} = mc_pulse.GT_2DCompareMode({(short)Config.CardId}, {(short)(channel - 1)}, mc_pulse.COMPARE2D_MODE_1D);"); + return ErrorCode.Fail; + } + apiResult = LTDMC.dmc_hcmp_clear_points(Config.CardId, channel); + if (apiResult != 0) + { + LogHelper.Debug($"{apiResult} = LTDMC.dmc_hcmp_clear_points({Config.CardId}, {channel});"); + return ErrorCode.Fail; + } + + foreach (double pos in postions) + { + double tarPos = 0.0; + MmToPulse(pos, out tarPos); + apiResult = LTDMC.dmc_hcmp_add_point(Config.CardId, channel, (int)tarPos); + if (apiResult != 0) + return ErrorCode.Fail; + } + return ErrorCode.Ok; + } + + public override ErrorCode CompareStatus(out short _pStatus,out int _pCount) + { + _pStatus = 0; + _pCount = 0; + + return ErrorCode.Ok; + } + + public override ErrorCode ComparePulse(ushort channel,bool dp=true) + { + + apiResult = LTDMC.dmc_write_cmp_pin(Config.CardId, channel, 1); + if (apiResult != 0) + { + LogHelper.Debug($"{apiResult} = LTDMC.dmc_write_cmp_pin({Config.CardId}, {channel}, 1);"); + return ErrorCode.Fail; + } + return ErrorCode.Ok; + } + + public override ErrorCode ClearCompare(ushort uChannel) + { + apiResult = LTDMC.dmc_hcmp_set_mode(Config.CardId, uChannel, 0); + if (apiResult != 0) + { + return ErrorCode.Fail; + } + else + { + apiResult = LTDMC.dmc_hcmp_clear_points(Config.CardId, uChannel); + if (apiResult != 0) + { + LogHelper.Debug($"{apiResult} = LTDMC.dmc_hcmp_clear_points({Config.CardId}, {uChannel});"); + return ErrorCode.Fail; + } + } + return ErrorCode.Ok; + } + + public override ErrorCode ClearAlarm() + { + apiResult = LTDMC.dmc_write_erc_pin(Config.CardId, Config.AxisId, 1); + if (apiResult != 0) + { + LogHelper.Debug($"{apiResult}= LTDMC.dmc_write_erc_pin({Config.CardId},{Config.AxisId}, 1);"); + return ErrorCode.Fail; + } + + return ErrorCode.Ok; + } + + } +} diff --git a/Rs.Motion/Leisai/LeisaiCard.cs b/Rs.Motion/Leisai/LeisaiCard.cs new file mode 100644 index 0000000..2e70014 --- /dev/null +++ b/Rs.Motion/Leisai/LeisaiCard.cs @@ -0,0 +1,119 @@ +锘縰sing Rs.Framework; +using Rs.Motion.Base; +using Rs.Motion.Base.Config; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace Rs.Motion.Leisai +{ + public class LeisaiCard:ICard + { + public LeisaiCard(ushort cardID,ushort axisCount,string cfgName) + { + CardID= cardID; + AxisCount= axisCount; + CfgName= cfgName; + Config = new CardConfig(); + } + + private ushort _CardID; + + /// + /// 鍗$紪鍙 + /// + [XmlIgnore] + public ushort CardID + { + get { return _CardID; } + set { _CardID = value; } + } + + + private ushort _AxisCount; + [XmlIgnore] + public ushort AxisCount + { + get { return _AxisCount; } + set { _AxisCount = value; } + } + + private string _CfgName; + [XmlIgnore] + public string CfgName + { + get { return _CfgName; } + set { _CfgName = value; } + } + + public override ErrorCode Init() + { + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + string filePath=Path.Combine(baseDir,"Config","Motion", CfgName); + //妫娴嬫枃浠跺す鏄惁瀛樺湪锛屼笉瀛樺湪鍒欏垱寤 + if(!Directory.Exists(Path.GetDirectoryName(filePath))) + { + Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + } + //鍒ゆ柇鏂囦欢鏄惁瀛樺湪,濡傛灉涓嶅瓨鍦ㄩ厤缃枃浠讹紝鍒欑敓鎴愰厤缃枃浠 + if(!File.Exists(filePath)) + { + Config.Init(CardID, AxisCount,0); + bool suc = XmlSerializerHelper.Instance.Serialize(filePath, Config); + if(!suc) + { + return ErrorCode.CardLoadConfigFail; + } + } + else + { + bool suc = XmlSerializerHelper.Instance.Deserialize(filePath ,out CardConfig config); + Config=config; + + } + InitAxis(); + return ErrorCode.Ok; + } + + public override ErrorCode Save() + { + if(Config != null) + { + string baseDir = AppDomain.CurrentDomain.BaseDirectory; + string filePath = Path.Combine(baseDir, "Config", "Motion", CfgName); + if (File.Exists(filePath)) + { + File.Delete(filePath); + XmlSerializerHelper.Instance.Serialize(filePath, Config); + return ErrorCode.Ok; + } + } + return ErrorCode.CardNotInit; + } + + private ErrorCode InitAxis() + { + for(int i=0; i + /// 钑惧鑴夊啿鍗 + /// + public class LeisaiCardManager : ICardManager + { + /// + /// 鎵ц搴曞眰鎺ュ彛鐨勮繑鍥炲 + /// + private short apiResult = 0; + /// + /// 淇濆瓨涓鍏辨湁澶氬皯寮犲崱 + /// + Dictionary cardDic= new Dictionary(); + private LeisaiCardManager() { + + } + + private static LeisaiCardManager instance; + public static LeisaiCardManager Instance + { + get + { + if(instance==null) + { + instance = new LeisaiCardManager(); + } + + return instance; + } + } + + public override IIOCard AddIoCard(int cardID, string name, string vender, bool isEthercat, ushort inNum, ushort outNum, int slaveID) + { + + string filename = string.Empty; + LeisaiIOCard ioCard = new LeisaiIOCard(); + if(vender== "LeisaiPulseEx") + { + //鍏堟墦寮鍗 + apiResult = LTDMC.nmc_set_connect_state((ushort)cardID, (ushort)slaveID, 1, 0); + if(apiResult== 0) + { + LogHelper.Debug($"鎵撳紑鎵╁睍鍗slaveID-1}鎴愬姛"); + } + else + { + LogHelper.Debug($"鎵撳紑鎵╁睍鍗slaveID - 1}澶辫触"); + } + filename = $"config/motion/io/LeisaiPulseEx{cardID}.xml"; + } + else + { + filename = $"config/motion/io/leisai{cardID}.xml"; + } + //string filename = $"config/motion/io/gugao{cardID}.xml"; + if (!File.Exists(filename)) + { + ioCard.CardID = (ushort)cardID; + ioCard.Name = name; + ioCard.Vender = vender; + ioCard.IsEtherCat = isEthercat; + ioCard.SlaveID = (ushort)slaveID; + ioCard.Init((short)cardID,inNum, outNum, (ushort)slaveID); + bool suc = XmlSerializerHelper.Instance.Serialize(filename, ioCard); + } + else + XmlSerializerHelper.Instance.Deserialize(filename, out ioCard); + if (ioCard != null) + { + //ztmIOCard.SetMc(0); + //ioCards.Add(ztmIOCard); + //Add(ztmIOCard); + } + return ioCard; + } + + /// + /// 鍚屼竴绫诲崱缁熶竴鍒濆鍖 + /// + /// + public override ErrorCode Init() + { + SqliteHelper db = new SqliteHelper(); + DataTable dt = db.GetDataTable("select * from motioncard where vender='leisai' and enable=1 order by id asc"); + if(dt!=null&&dt.Rows.Count>0) + { + MessageQueue.Instance.Insert($"have {dt.Rows.Count} card need init"); + foreach (DataRow row in dt.Rows) + { + ushort cardid = ushort.Parse(row["cardid"].ToString()); + //鎵撳紑杩愬姩鎺у埗鍗 + apiResult = LTDMC.dmc_board_init_onecard(cardid); + if (apiResult <= 0) + { + MessageQueue.Instance.Warn($"{apiResult} = LTDMC.dmc_board_init_onecard({cardid});"); + return ErrorCode.CardInitFail; + } + else + { + //鍔犺浇閰嶇疆鏂囦欢 + if(File.Exists($"leisai{cardid}.ini")) + { + apiResult = LTDMC.dmc_download_configfile(ushort.Parse(row["cardid"].ToString()), $"leisai{cardid}.ini"); + LogHelper.Debug($"鍔犺浇钑惧閰嶇疆鏂囦欢leisai{cardid},ret={apiResult}"); + } + MessageQueue.Instance.Insert($"{apiResult} = LTDMC.dmc_download_configfile({ushort.Parse(row["cardid"].ToString())}, $\"leisai{{cardid}}.ini\");"); + } + } + } + else + { + return ErrorCode.CardNotExist; + } + IsInitialized = true; + return ErrorCode.Ok; + } + + public ICard GetCard(ushort cardID) + { + + ICard card; + if (cardDic.ContainsKey((ushort)cardID)) return cardDic[(ushort)cardID]; + card = new LeisaiCard(cardID, 8, $"leisai{cardID}.xml"); + card.Init(); + if(!cardDic.ContainsKey((ushort)cardID)) + { + cardDic.Add((ushort)cardID, card); + } + return card; + } + } +} diff --git a/Rs.Motion/Leisai/LeisaiIO.cs b/Rs.Motion/Leisai/LeisaiIO.cs new file mode 100644 index 0000000..617649a --- /dev/null +++ b/Rs.Motion/Leisai/LeisaiIO.cs @@ -0,0 +1,14 @@ +锘縰sing Rs.Motion.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rs.Motion.Leisai +{ + public class LeisaiIO : IIO + { + public ushort SlaveNo { get; set; } + } +} diff --git a/Rs.Motion/Leisai/LeisaiIOCard.cs b/Rs.Motion/Leisai/LeisaiIOCard.cs new file mode 100644 index 0000000..0e3fbfb --- /dev/null +++ b/Rs.Motion/Leisai/LeisaiIOCard.cs @@ -0,0 +1,49 @@ +锘縰sing Rs.Framework; +using Rs.Motion.Base; +using Rs.Motion.Ztm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace Rs.Motion.Leisai +{ + /// + /// GLink鍗 + /// + [XmlInclude(typeof(LeisaiIO))] + public class LeisaiIOCard : IIOCard + { + public override void Init(short cardID,ushort inCount, ushort outCount, ushort slaveNo) + { + for (ushort i = 0; i < outCount; i++) + { + LeisaiIO io = new LeisaiIO(); + io.SlaveNo = slaveNo; + io.CardID = cardID; + io.CardID = (short)CardID; + io.Name = "Out" + i + "_" + slaveNo; + io.Index = i; + DOut.Add(io); + } + for (ushort i = 0; i < inCount; i++) + { + LeisaiIO io = new LeisaiIO(); + io.SlaveNo=slaveNo; + io.CardID = cardID; + io.Card = this; + io.Name = "In" + i + "_" + slaveNo; + io.Index = i; + DIn.Add(io); + } + } + + public override void Save() + { + string filename = $"config/motion/io/leisai{CardID}.xml"; + XmlSerializerHelper.Instance.Serialize(filename, this); + } + } +} diff --git a/Rs.Motion/Rs.Motion.csproj b/Rs.Motion/Rs.Motion.csproj index 1d9d474..666065c 100644 --- a/Rs.Motion/Rs.Motion.csproj +++ b/Rs.Motion/Rs.Motion.csproj @@ -77,8 +77,14 @@ + + + + + + diff --git a/Rs.MotionPlat.sln b/Rs.MotionPlat.sln index 45cb0c6..8c55ddb 100644 --- a/Rs.MotionPlat.sln +++ b/Rs.MotionPlat.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HWindow_Tool", "HWindow_Too EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rs.Cameras", "Rs.Cameras\Rs.Cameras.csproj", "{971D93FF-FD34-4088-9591-C25147290D22}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rs.AutomaticDoubleUpAndDown", "..\Rs.AutomaticDoubleUpAndDown\Rs.AutomaticDoubleUpAndDown\Rs.AutomaticDoubleUpAndDown.csproj", "{983F6B3C-E08A-42F0-8A34-2E6590636811}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +59,10 @@ Global {971D93FF-FD34-4088-9591-C25147290D22}.Debug|Any CPU.Build.0 = Debug|Any CPU {971D93FF-FD34-4088-9591-C25147290D22}.Release|Any CPU.ActiveCfg = Release|Any CPU {971D93FF-FD34-4088-9591-C25147290D22}.Release|Any CPU.Build.0 = Release|Any CPU + {983F6B3C-E08A-42F0-8A34-2E6590636811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {983F6B3C-E08A-42F0-8A34-2E6590636811}.Debug|Any CPU.Build.0 = Debug|Any CPU + {983F6B3C-E08A-42F0-8A34-2E6590636811}.Release|Any CPU.ActiveCfg = Release|Any CPU + {983F6B3C-E08A-42F0-8A34-2E6590636811}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE