ubuntu - How do I write commands to a ttyACM0 device and obtain the resultant information data using C/C++ -
i stuck task of retrieving data decoder monitors 6 joint positions of robot arm. device has usb interface runs serial cdc device. ascii command set allows host configure each axis resolution , set access method. current position of each axis output in engineering units or raw binary (converted ascii) @ user defined rate. command protocol similar usb serial protocol (here's link decoder's technical manual: http://www.soc-robotics.com/pdfs/quad6x%20technical%20manual.pdf)
using ubuntu, device comes 'ttyacm0' device when type "dmesg" terminal. furthest i've gotten using "screen /dev/ttyacm0" , allows me input these serial commands , see output information through terminal, however, doesn't accomplish task i'm trying achieve.
i'm trying write c/c++ code enable program write these serial commands ttyacm0 device retrieve information data device outputs result. code used in ros allow position feedback control in each of robot arm joints using obtained data.
this best come in feeble attempt write in 1 of commands ttyacm0 file information i've gathered:
#include <stdio.h> #include <stdlib.h> int main() { file *fp; fp = fopen("/dev/ttyacm0", "w"); if(fp == null) { perror("file failed open"); exit(1); } fprintf(fp, "i"); fclose(fp); return 0; }
anybody know how solve problem? there way take code lets me i've achieved in terminal suit needs? i've hit many dead ends in forums tell how through terminal or how arduino , compiler. @ wits end trying figure out, appreciated.
the definitive resource on serial link programming in posix environments "serial programming guide posix operating systems". note in case of cdc acm device there not can configured. , if try device can happily ignore regarding baudrate, word length , on.
actually cdc acm did there right. buffering of stdio going in way. liberately adding fflush
calls help.
Comments
Post a Comment