Okay, I think I have a linux solution for you. You need to put the terminal into “raw mode” using the tcsetattr() function so that it does not wait for a newline character before actually sending the bytes. Here is a complete program that works for me:
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
int main()
{
int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
char message[] = {161};
unsigned char buf[2];
struct termios options;
if (fd == -1)
{
fprintf(stderr, "error opening");
exit(1);
}
tcgetattr(fd, &options);
options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
options.c_oflag &= ~(ONLCR | OCRNL);
tcsetattr(fd, TCSANOW, &options);
if(write(fd,message,4) == EOF)
{
fprintf(stderr, "error writing");
exit(1);
}
int bytes_read = read(fd,buf,2);
if(bytes_read != 2)
{
fprintf(stderr, "error reading: %d bytes read", bytes_read);
exit(1);
}
printf("Received: 0x%02x 0x%02x\n",buf[0],buf[1]);
exit(0);
}
As for your question - no, the device does not return a special final character. It does not even append a CRC when it is in CRC mode.
-Paul
Edit: c_oflag line added by David.
