||

控制 ComXim 可编程电动转盘:使用 COM 端口与 C# 的指南


1 ComXim 可编程电动转盘的操控非常直观。它提供了一套全面的指令集,涵盖角度控制、速度控制、动作控制和组合行为控制等多种控制功能。此外,转盘在完成指定动作后会向控制设备发送反馈。

2 连接与指令基础

3 无论你通过 USB(安装驱动后会在操作系统中创建一个 COM 端口)、蓝牙还是 WiFi 连接,控制指令都保持不变。主要区别在于连接过程。连接成功后,编程和控制指令完全相同。

4 以下介绍如何使用 COM 端口通信来控制转盘,示例使用 C# 和 Visual Studio:



Buy programmable electric rotary table now



See how to install the driver



Get the command list for the ComXim rotary table with secondary development capabilities now

5 使用 COM 端口控制转盘的步骤

6 1. 在 Visual Studio 中创建项目

  1. 7 打开 Visual Studio。
  2. Create a new project:
    • Go to File > New > Project.
    • 8 根据个人偏好,选择 Windows Forms App (.NET Framework) 或 Console App (.NET Framework)。
    • 9 为项目命名并点击 创建。

10 2. 添加并配置 SerialPort

  1. 11 在解决方案资源管理器中,右键点击你的项目,选择 添加 > 新建项。
  2. 12 从可用组件中选择 SerialPort。这会在你的项目中添加一个 SerialPort 组件,默认命名为 serialPort1。
  3. Configure the serial port properties:
    • BaudRate: 115200
    • 13 Parity(奇偶校验):None
    • 14 DataBits(数据位):8(默认)
    • 15 StopBits(停止位):One(默认)
    • 16 HandShake(握手):None

17 3. 打开串口

18 添加以下代码以打开串口并处理异常:

using System;
using System.IO.Ports;
using System.Windows.Forms;

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

// Configure the serial port
serialPort1.BaudRate = 115200;
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.Handshake = Handshake.None;

// Open the serial port
try
{
serialPort1.Open();
MessageBox.Show("Serial port opened successfully.");
}
catch (Exception ex)
{
MessageBox.Show("Error opening serial port: " + ex.Message);
}
}
}

19 4. 发送指令以控制转盘

20 要向转盘发送指令,请使用 SerialPort 类的 Write 方法。例如:

private void SendCommand(string command)
{
if (serialPort1.IsOpen)
{
try
{
serialPort1.Write(command);
MessageBox.Show("Command sent: " + command);
}
catch (Exception ex)
{
MessageBox.Show("Error sending command: " + ex.Message);
}
}
else
{
MessageBox.Show("Serial port is not open.");
}
}

private void buttonSendCommand_Click(object sender, EventArgs e)
{
SendCommand("CT+START(1,1,1,90,3,4);");
}

21 指令字符串示例

22 示例 1:向右旋转的指令

  • Command: CT+START(1,1,1,90,3,4);

    • Direction: 1 (Right/Counterclockwise)
    • 23 Turn Mode(转动模式):1(间歇旋转)
    • 24 Angle(角度):90 度
    • 25 Pause Time(停顿时间):每次旋转 90 度后停顿 3 秒
    • 26 Times(次数):4 次旋转
    • 27 Shutter Control(快门控制):1(每次停顿后触发快门拍照)

28 说明:该指令将转盘设置为向右旋转 90 度,停顿 3 秒,重复此动作 4 次,并在每次停顿后触发快门。

29 示例 2:向左旋转的指令

  • Command: CT+START(0,1,1,90,3,4);

    • Direction: 0 (Left/Clockwise)
    • 30 Turn Mode(转动模式):1(间歇旋转)
    • 31 Angle(角度):90 度
    • 32 Pause Time(停顿时间):每次旋转 90 度后停顿 3 秒
    • 33 Times(次数):4 次旋转
    • 34 Shutter Control(快门控制):1(每次停顿后触发快门拍照)

35 说明:该指令将转盘设置为向左旋转 90 度,停顿 3 秒,重复此动作 4 次,并在每次停顿后触发快门。

36 按照这些步骤,你就可以在 C# 和 Visual Studio 中通过 COM 端口通信有效地控制 ComXim 可编程电动转盘。

类似文章

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注