I am having a strange problem that I haven't been able to find the cause of.
On the teensy, I am writing the byte "0xd" to USB serial. My teensy code is as follows:
On my computer running Ubuntu 16.04, I am reading the USB port using the following code and printing the output. I am expecting "d" to get printed, but instead "a" gets printed. I have tried sending other bytes from the teensy and they get printed correctly. It is only happening with 0xd. Does anyone know what could be causing this?
The following was compiled with "g++ d_test.cpp -o d_test" and run with "./d_test"
On the teensy, I am writing the byte "0xd" to USB serial. My teensy code is as follows:
Code:
void setup() {
}
void loop() {
Serial.write(0xd);
}
On my computer running Ubuntu 16.04, I am reading the USB port using the following code and printing the output. I am expecting "d" to get printed, but instead "a" gets printed. I have tried sending other bytes from the teensy and they get printed correctly. It is only happening with 0xd. Does anyone know what could be causing this?
The following was compiled with "g++ d_test.cpp -o d_test" and run with "./d_test"
Code:
#include <stdint.h>
#include <iostream>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char** argv){
int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
// If the device has been opened successfully, configure it
if(fd != -1) {
// set non blocking
fcntl(fd, F_SETFL, FNDELAY);
struct termios options;
tcgetattr(fd, &options);
// set baud rate
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
// ignore modem lines and enable receiver
options.c_cflag |= (CLOCAL | CREAD);
// set size of character to 8
options.c_cflag |= CS8;
// disable hardware flow control
options.c_cflag &= ~CRTSCTS;
// disable canonaical mode, echo, and signal generation
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
// apply the changes
tcsetattr(fd, TCSANOW, &options);
}
else{
std::cout << "Failed to open teensy" << std::endl;
return 1;
}
while(true){
// try reading a byte from the teensy
uint8_t byte = 0;
int ret = read(fd, &byte, sizeof(uint8_t));
// if a byte was read, print it
if(ret == 1){
std::cout << std::hex << (unsigned int)byte << std::endl;
}
}
return 0;
}