

- Purebasic Serial Port Example software#
- Purebasic Serial Port Example code#
- Purebasic Serial Port Example windows#
However, when I try to read from the serial port read() returns -1 almost all the time, until suddenly at a seemingly random point I get a massive dump of messages all at once. The read() is supposed to block until an EOL (end of line) character is received. The results you describe are similar to blocking canonical mode (when you actually want (blocking) raw mode).
Purebasic Serial Port Example code#
I've tried setting it up in a blocking configuration but if I do that the code just hangs indefinitely at the first read(). So the issue seems to be when I try to read from the port. I've connected my laptop to the serial port as well so I can spy on the transmissions using RealTerm, and I've verified that commands are being sent by the MIO-3260 correctly AND being responded to correctly by the drive. Let me know if there's anymore information I can provide. Sometimes I run it and it responds most of the time and then mysteriously it just stops and then comes back intermittently. I've been troubleshooting it for the last few days and have no idea what's going on. Instead I receive a huge number all at once and none at other times (for example I just received 810 bytes at once after sending 946 commands with no response). Here's a sample of the kind of message I should be receiving. To read from the serial port, my code is as follows: uint8_t buf //Rx bufferįor(int i=0 i SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG) //Non-canonical mode SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY) //Turn off software SerialPortSettings.c_cflag |= CREAD | CLOCAL //Turn on the reciever SerialPortSettings.c_cflag &= ~CRTSCTS //turn off hardwar based flow ctrl SerialPortSettings.c_cflag |= CS8 //set data bits = 8 SerialPortSettings.c_cflag &= ~CSIZE //clears the mask SerialPortSettings.c_cflag &= ~CSTOPB //Stop bits = 1 SerialPortSettings.c_cflag &= ~PARENB //clear parity bit (no parity) Tcgetattr(fd, &SerialPortSettings) //get current settings of serial portĬfsetispeed(&SerialPortSettings,B115200) //set input baud rateĬfsetospeed(&SerialPortSettings,B115200) //set output baud rate int fd įd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY) I'm using termios to set up the serial port. When I try it in realTerm on windows this works well so I don't think it's an issue with the drive. The program sends a string of hex codes to the drive and is supposed to receive a response for every message it sends. I'm writing a program that runs on a MIO-3260 single board computer running Ubuntu server 14.04 and communicates with a AMC DPRANIE C100A400 drive.
Purebasic Serial Port Example software#
Purebasic Serial Port Example windows#