[英]Commanding a Stepper Motor Controller over USB
I am trying to do some experiments on the Trinamic StepRocker Stepper Motor Controller in Gnu/Linux. 我正在尝试在Gnu / Linux中对Trinamic StepRocker步进电机控制器进行一些实验。 I had attahched the device through USB to a Windows machine previously and used Trinamic's proprietary software to test if the controller is functional as expected, and it seems to be.
我曾经通过USB将设备连接到Windows机器,并使用Trinamic的专有软件来测试控制器是否按预期运行,而且似乎是。 The beginner's manual of the StepRocker mentions certain commands that should be sent over the serial interface to rotate the motor left, right, or bring it to a halt.
StepRocker的初学者手册提到了应该通过串行接口发送的某些命令,以便向左,向右旋转电机或使其停止。 But when I connect this controller over USB to a Gnu/Linux computer, and want to write my own C++ (libusb) program to make the motor move, I am not quite sure what my starting point should be.
但是当我通过USB将这个控制器连接到Gnu / Linux计算机,并且想要编写我自己的C ++(libusb)程序来使电机移动时,我不太清楚我的起点应该是什么。 The console application (which I plan to write) should be non-blocking.
控制台应用程序(我打算写)应该是非阻塞的。
Here is an image of the datagrams being sent and response received while a rotate command is issued: 下面是发送旋转命令时发送的数据报和响应的图像:
I tried to write a simple program to feed the rotation value datagram shown in the picture to the motor controller: 我试着编写一个简单的程序,将图中显示的旋转值数据报输入电机控制器:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
int fd1;
int wr;
int main()
{
fd1=open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd1 == -1 )
{
perror("open_port: Unable to open /dev/ttyACM0");
}
else
{
fcntl(fd1, F_SETFL,0);
printf("Port 1 has been sucessfully opened and %d is the file description\n",fd1);
char moveMsg[9]={0x01,0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0xbc, 0xc0};
wr = write(fd1, moveMsg, 9);
}
close(fd1);
return 0;
}
But this does not alter the LED behaviour of the controller in any way (and does not move the motor, of course). 但这并不会以任何方式改变控制器的LED行为(当然也不会移动电机)。
他们说“USB虚拟COM端口驱动程序”,所以你不需要libusb:只需在你的程序中打开/ dev / USBtty0(/ dev / ACM0或你的发行版如何创建它)就像常规的RS-232一样使用它。
您可以使用libusb + libftdi(然后没有虚拟串行端口)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.