3

I am trying to do some experiments on the Trinamic StepRocker Stepper Motor Controller in Gnu/Linux. 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. 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. 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. 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:

enter image description here

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).

Subhamoy S.
  • 6,566
  • 10
  • 37
  • 53

2 Answers2

1

They says "USB virtual COM port driver", so you don't need libusb: simply open /dev/USBtty0 (/dev/ACM0 or how would your distro create it) in your program like regular RS-232 and work with it.

Eddy_Em
  • 864
  • 6
  • 14
  • Thank you! I do not have any experience in this area. Pointing me to an example or something like that would be greatly appreciated. My distro is Ubuntu. – Subhamoy S. Jan 11 '13 at 13:38
  • 1
    I've write something about it in [my LJ](http://eddy-em.livejournal.com/tag/stm32) (only russian). Shortly: to check whether you can work with that board through USB-CDC install something like tinyserial, run `com /your/device` (maybe you'd have to add speed, but I don't think it'd be needed), then try to send to your device simple commands (you have command protocol, are you?). – Eddy_Em Jan 11 '13 at 13:50
  • I have added some more details of the problem. I can see the datagram being sent and getting received. I just do not know how to send these messages and catch the output over C++. – Subhamoy S. Jan 11 '13 at 18:22
  • If using tinyserial you can make a file with datagram (`echo` can print symbols in octal). Then copy file's contents & paste it into `com` input line. – Eddy_Em Jan 11 '13 at 18:47
  • Starting a serial terminal with picocom or tinyserial is not taking recognizable commands, just drawing ASCII symbols on screen when I press buttons. I did something like this: `sudo picocom -b 115200 /dev/ttyACM0` – Subhamoy S. Jan 11 '13 at 18:55
  • 1
    try so: `echo -e "\x1\x1\x0\x0\x0\x0\x2\xBC\xC0" > datagram` then copy contents of file `datagram` to `com` terminal. Or write a simple program on C or C++. BTW datagram simply decoded. – Eddy_Em Jan 11 '13 at 19:18
  • I have further modified my question. Kindly have a look. – Subhamoy S. Jan 11 '13 at 21:24
  • I don't know details of this board's protocol. Try to send data by-byte and read an answer after each read. Also there could be some "initial" message at begin of data. Do you have developer's manual for this board? – Eddy_Em Jan 11 '13 at 21:29
  • 1
    BTW. `strlen` will return 2, change `wr = write(fd1, moveMsg, strlen(moveMsg));` to `wr = write(fd1, moveMsg, 9);` – Eddy_Em Jan 11 '13 at 21:31
  • I have tried that as well. No difference. [Here](http://www.motioncontrol-community.org/wp-content/forum-file-uploads/stephan-kubisch/TMCM-1110_TMCL-LITE_library_V100.pdf) is the software manual for [this](https://github.com/trinamic/stepRocker-Library) source code. I know it is not exactly a developer manual, but it's all there is, I think. – Subhamoy S. Jan 11 '13 at 21:40
  • Ahhh seems like I took a step in a very wrong direction. I just found [this](http://www.ikp.uni-koeln.de/user/rschulze/files/libtmcl/api/tmcl_8h_source.html)! Although, the original question was about controllers in general, and there is no reason this controller would not be controlled by the usual means. – Subhamoy S. Jan 11 '13 at 21:55
  • Watch file `Commands.c`, it consists a function `ProcessCommand` which reads UART and execute commands getting on it. Commands should be sent continuously (as there is pause check in code). Maybe you should do right setup of UART by termios ioctl. Try to find PC-side GPL code (maybe it exists). – Eddy_Em Jan 11 '13 at 21:59
  • Just out of curiosity, I put the write statement in a very long running loop, and now the motor is turning! What basically happened is, the console was blocked until all iterations were complete, and then the program exited, but the motor kept on turning. Now that I know it can work, how do I do it proper? And I also need to read from it. So I need to set up some non-blocking read/write system somehow. – Subhamoy S. Jan 11 '13 at 22:36
  • To do it proper you should properly read sources of firmware. – Eddy_Em Jan 11 '13 at 22:38
0

You can use libusb + libftdi (no virtual serial ports then).

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • Could you please point me to some examples? In the documentation, it only speaks of issuing commands to its own proprietary tool. For example, `ROL 0, 500` means rotate left with speed 500. But how will I issue such a command through C++ that I do not understand. – Subhamoy S. Jan 11 '13 at 17:34