联营板卡 工具类

联营板卡 工具类

/// <summary>
/// 联营板卡
/// </summary>
public class UWC7000
{
    //与uwc7000建立连接,并初始化控制器参数
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_initial", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_initial();

    //断开与控制器的数据连接
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_close", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_close();

    //读取最小运动当量
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_displacement", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_displacement(Int32 axis_id, double[] displacement);

    //读取所有轴光栅尺/编码器位置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_coordinate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_coordinate(double[] position);

    //重置指定轴编码器位置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_coordinate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_coordinate(Int32 axis_id, double position);

    //读取64轴指令脉冲计数
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_command_count", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_command_count(Int32[] command_count);

    //设置指定轴指令计数器
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_command_count", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_command_count(Int32 axis_id, Int32 command_count);

    //判断指定轴是否已停止
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_done", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_done(Int32 axis_id, Int32[] status);

    //判断所有轴是否已停止
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_all_done", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_all_done(Int32[] status);

    //判断指定轴是否已回原点(应用软件启动时)
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_homed", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_homed(Int32 axis_id, Int32[] status);

    //判断指定轴电机驱动器是否已报警
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_alarm", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_alarm(Int32 axis_id, Int32[] status);

    //判断指定轴正/负限位是否已触发
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_limit_switch", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_limit_switch(Int32 axis_id, Int32[] pos_status, Int32[] neg_status);

    //读取最后一个出错状态码
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_last_err", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_last_err(Int32[] new_err_flag, Int32[] l_err_code);

    //回原点运动 
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_go_home", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_go_home(Int32 axis_id, double speed);

    //单轴点位运动 
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_single_move_to", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_single_move_to(Int32 axis_id, double speed, double target_pos);

    //多轴直线插补到指定位置 
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_linear_move_to", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_linear_move_to(Int32[] axis_array, double speed, double[] target_pos);

    //在XOY平面作圆弧插补运动,以line_speed为线速度, x_center,y_center为圆心相对起点的相对坐标位置,angle为旋转角度:-360--+360
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_arc_move_xy", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_arc_move_xy(double x_center, double y_center, double line_speed, double angle);

    //在YOZ平面作圆弧插补运动,以line_speed为线速度, y_center,z_center为圆心相对起点的相对坐标位置,angle为旋转角度:-360--+360
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_arc_move_yz", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_arc_move_yz(double y_center, double z_center, double line_speed, double angle);

    //在ZOX平面作圆弧插补运动,以line_speed为线速度, z_center,x_center为圆心相对起点的相对坐标位置,angle为旋转角度:-360--+360
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_arc_move_zx", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_arc_move_zx(double z_center, double x_center, double line_speed, double angle);

    //示教运动 
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_jog_move", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_jog_move(Int32 axis_id, double jog_speed);

    //停车指令 
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_stop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_stop(Int32 axis_id, Int32 mode);

    /// <summary>
    /// 按通道编号设置输出口状态。
    /// 设置控制器DO中的某一路输出
    /// </summary>
    /// <param name="bit_id">位编号,从1开始,具体参考“IO模块的实际IO数”</param>
    /// <param name="hi1_low0">为0时输出晶体管对0V导通(NPN输出有效),为1时输出无效,通电后默认为1,输出无效状态。</param>
    /// <returns></returns>
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_output(Int32 bit_id, Int32 hi1_low0);

    /// <summary>
    /// 一次性设置指定IO模块所有输出状态
    /// </summary>
    /// <param name="io_module_id">0-控制器内置DO;1-第一扩展IO模块;2- 第二扩展IO模块。</param>
    /// <param name="status">DO输出状态,bit0-bit31对应32个DO状态</param>
    /// <returns></returns>
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_all_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_all_output(Int32 io_module_id, Int32 status);

    //按通道编号读取输出口状态(整体读取输出口状态见uwc7000_get_controller_msg)
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_output", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_output(Int32 bit_id, Int32[] hi1_low0);

    //按通道编号读取输入口状态(整体读取输入口状态见uwc7000_get_controller_msg)
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_input", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_input(Int32 bit_id, Int32[] hi1_low0);

    //伺服使能信号控制输出
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_servo_on", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_servo_on(Int32 axis_id, Int32 hi1_low0);

    //伺服(报警)复位信号控制输出
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_servo_reset", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_servo_reset(Int32 axis_id, Int32 hi1_low0);

    //读取指定轴最大速度和加速度
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_profile", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_profile(Int32 axis_id, double[] acc_time, double[] max_speed);

    //读取软件限位坐标(相对于机械零位)
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_soft_limit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_soft_limit(Int32 axis_id, double[] pos_limit, double[] neg_limit);

    //设置定位精度
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_inposition_window", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_inposition_window(Int32 axis_id, double window);

    //读取定位精度设置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_inposition_window", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_inposition_window(Int32 axis_id, double[] window);

    //读2通道取模拟电压输入ADC转换结果
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_adc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_adc(Int32 ch, Int32[] adc);

    //设置2通道模拟输出(电压或电流)
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_dac", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_dac(Int32 ch, Int32 dac);

    //超级指令
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_super_command", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_super_command(Int32 ch, Int32 Slen, Int32 Rlen, char[] ucIn, char[] ucOut);

    //读取所有轴光栅尺/编码器位置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_encoder_count", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_encoder_count(Int32[] encoder_count);

    //重置指定轴编码器位置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_encoder_count", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_encoder_count(Int32 axis_id, Int32 encoder_count);

    //判定轴是否跟随误差超限
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_follow", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_follow(Int32 axis_id, Int32[] status);

    //判定轴是否伺服使能
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_check_axis_servo", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_check_axis_servo(Int32 axis_id, Int32[] status);

    //读取DLL版本信息
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_DLL_version", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_DLL_version(char[] pStr);

    //读取轴总数量
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_get_axis_numbers", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_get_axis_numbers(Int32[] numbers);

    // 设置触发捕获信号的有效边沿及延时产生触发信号
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_set_trigger", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_set_trigger(Int32 rise1_fall0, Int32 latch_delay, Int32 output_trig1_delay, Int32 output1_id, Int32 output_trig2_delay, Int32 output2_id);

    // 读锁存数据
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_read_capture_buffer", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_read_capture_buffer(Int32[] read_numbers, Int32[] data_buf);

    // 设置触发脉冲的参数
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_pluse_generator_set", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_pluse_generator_set(Int32 polarity, Int32 pluse_num, Int32 period, Int32 do_id);

    //脉冲开关
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_enable_Pluse_generator", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_enable_Pluse_generator(Int32 enable1_disable0);

    // 位置匹配输出信号设置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_compare_output_set", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_compare_output_set(Int32 compare_target_sel, Int32 signal_type, Int32 pulse_width);

    //预置匹配位置
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_compare_load", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_compare_load(Int32 x, Int32 y, Int32 z, Int32 u, Int32 compare_mode, Int32 trig_sel);

    // 清空缓存区域,可以能是捕获缓存区也可能是比较位置缓存区。
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_clean_buf", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_clean_buf(Int32 buf_type);

    // 查询缓存区是不是空。
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_is_buf_empty", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern Int32 uwc7000_is_buf_empty(Int32 buf_type, Int32[] free_nums, Int32[] overflow);

    // 写UMS中的变量值。
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_ums_write", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
    public static extern long uwc7000_ums_write(long v_type, long add, long l, float f);

    // 读UMS中的变量值。
    [DllImport("UWC7000.dll", EntryPoint = "uwc7000_ums_read", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

    // public static extern Int32 uwc7000_ums_read(long v_type, long add, Int32[] 1, float[] f);//整数有效/浮点数无效

    public static extern Int32 uwc7000_ums_read(Int32 v_type, Int32 add, Int32[] ldata, float[] fdata);

    internal static uint uwc7000_get_input(ushort cardNum, ushort axisNum)
    {
        throw new NotImplementedException();
    }
}

 

 

posted @ 2023-08-31 10:53  baivfhpwxf  阅读(16)  评论(0编辑  收藏  举报