This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial Communication in LUbuntu 16.04

I'm using the following code for serial communication in Ubuntu 16.04 and is working fine with the same environment.
But on switching to Tinkerboard Lubuntu,the same code doesn't provides me the expected output.

Can some one tell me ,how I can fix this

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>  /* File Control Definitions          */
#include <termios.h>/* POSIX Terminal Control Definitions*/
#include <unistd.h> /* UNIX Standard Definitions         */
#include <errno.h>  /* ERROR Number Definitions          */
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <time.h>   // time calls
#include <iomanip>
#include <sstream>

using namespace std;

int main(void)
   int fd;
   fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY);
   if(fd == 1)
       printf("\n  Error! in Opening ttyUSB0\n");
       printf("\n  ttyUSB0 Opened Successfully\n");
   struct termios SerialPortSettings;
   tcgetattr(fd, &SerialPortSettings);

   SerialPortSettings.c_cflag |=  PARENB; /*SET   Parity Bit PARENB*/
   SerialPortSettings.c_cflag &= ~PARODD;
   SerialPortSettings.c_cflag &= ~CSTOPB;
   SerialPortSettings.c_cflag &= ~CSIZE;
   SerialPortSettings.c_cflag |= CS8;
   SerialPortSettings.c_cflag |= CREAD | CLOCAL;//enable receiver
   SerialPortSettings.c_lflag &= ~ICANON; /* canonical mode */
   SerialPortSettings.c_iflag |= IGNBRK;
   SerialPortSettings.c_oflag &= ~OPOST; /* raw output */
   SerialPortSettings.c_cc[VMIN]  =21; /* Read 10 characters */
   SerialPortSettings.c_cc[VTIME] = 5;  /* Wait indefinitely   */
   tcsetattr(fd,TCSANOW,&SerialPortSettings); /* apply the settings */
   //tcflush(fd, TCOFLUSH);

   unsigned char initiate_bytes[] = {0xEC,0x13};
   unsigned char send_bytes[] = {0xC8,0x37};
   unsigned char read_buffer[25];
   int  bytes_read = 0;

   write(fd, initiate_bytes, sizeof(initiate_bytes));


       write(fd, send_bytes, sizeof(send_bytes));  //Send data
       bytes_read = read(fd,&read_buffer,25);
       fcntl(fd, F_SETFL, FNDELAY);
       Do some functions


   return 0;
What is your error message?

"Error! in Opening ttyUSB0"??
If yes, you need to check your which is your tty device node first.
It's not showing "Error! in Opening ttyUSB0".

But the sensor data that I used to read with Ubuntu 16.04 and same code is node working with tinker board.
The data may be coming once in a while,that too at time of restarting the code .But values are not getting updating.

Just for understanding, will the same code is supposed to work for serial communication in Ubuntu 16.04 and Lubuntu ?Or will there be any kernal issues?
Go here download and all this will work OOB.
Armbian. Lightweight Debian Stretch or Ubuntu Bionic for Tinker Board.
Does it support ROS framework?
(01-31-2019, 01:05 PM)rajmohan747 Wrote: Does it  support ROS framework?

I don't know. Is stock image supporting that?
Armbian. Lightweight Debian Stretch or Ubuntu Bionic for Tinker Board.

Forum Jump:

Users browsing this thread: 1 Guest(s)