初始化设置模块设计
private void 启动_Click(object sender, EventArgs e) { if (wether_link == 0) { short res = LTSMC.smc_board_init(CardNum, 2, "192.168.5.11", 115200);// 网口连接类型 if (res != 0) { MessageBox.Show(string.Format("连接控制器失败,错误代码:{0}", res), "错误"); } else { wether_link = 1; link_button.Text = "关闭设备"; timer1.Start(); timer2.Start(); for (int i = 0; i < axis_all.Length; i = i + 1) { LTSMC.smc_set_pulse_outmode(CardNum, axis_all[i], 6);//设置脉冲模式 LTSMC.smc_set_counter_inmode(CardNum, axis_all[i], 3); LTSMC.smc_set_counter_reverse(CardNum, axis_all[i], 1); LTSMC.smc_set_alm_mode(CardNum, axis_all[i], 0, 0, 0); } for (int i = 0; i < axis_all.Length; i++) { ALM[i] = LTSMC.smc_axis_io_status(CardNum, axis_all[i]); ALM[i] = ALM[i] % 2; if (ALM[i] == 1) { ct = i + 1; MessageBox.Show(ct + "号电机报警,请先解决!"); wether_link = 0; link_button.Text = "打开设备"; LTSMC.smc_board_close(CardNum); } } } } else { wether_link = 0; link_button.Text = "打开设备"; LTSMC.smc_conti_stop_list(CardNum, 0, 0);//停止模式, 0: 减速停止, 1: 立即停止 LTSMC.smc_set_pwm_output(CardNum, 0, 0, 0); LTSMC.smc_board_close(CardNum); } link_button.BaseColor = Color.Green; stop_button.BaseColor = Color.Transparent; }