1

I'm trying to initialize a serial port using the SerialPort.h library but I just can't get it working. I want to use the SerialPort functions but when I coded it this way:

std::string port= "/dev/ttyUSB0";
SerialPort serial(const SerialPort serial);
serial.GetBaudRate();

The complier tells me "error: request for member ‘GetBaudRate’ in ‘serial’, which is of non-class type ‘SerialPort(SerialPort)’".

How do I fix this? I am totally inexperience with object oriented programming.

Demyx
  • 11
  • 7
  • Try passing `port` into the constructor of `SerialPort`. `SerialPort serial(port);` – James Moore Feb 05 '15 at 17:54
  • @JamesMoore it just gave me additional errors. undefined reference to `SerialPort::SerialPort(std::string const&)' – Demyx Feb 05 '15 at 17:59
  • Do you have `#include ` at the top of the file? – James Moore Feb 05 '15 at 18:14
  • @JamesMoore Yes i have. I've read the SerialPort class refference from (http://libserial.sourceforge.net/doxygen/class_serial_port.html) and was wondering how the constructors work. I was trying to tinker with it but it gave me the same problem. The constructors were: `SerialPort (const std::string &serialPortName)` `SerialPort (const SerialPort &otherSerialPort)` – Demyx Feb 05 '15 at 18:20
  • You can use `SerialStream` instead of `SerialPort` to read/write, [this may help](http://stackoverflow.com/questions/9046649/read-and-write-on-serial-port-in-ubuntu-with-c-c-and-libserial), – James Moore Feb 05 '15 at 18:37
  • @JamesMoore I tried the code but it only gives me garbage values – Demyx Feb 08 '15 at 04:40

0 Answers0