Reading output data from COM port using C++ - c++

i have a board and a GPS,accelerometer,gyroscope onboard.
I'm connecting the board to the computer by using a TTL-232R-3V3 ,which is a USB to TTL Serial Cable (3.3V).
After installing the drivers, the assigned COM port is the number 3.
I'm able to read the output simply by using a serial monitor (i've tried with the one included in the Arduino IDE, just for try).
Now i need to create a C++ program which allows me to take the output of the board and store the datas in vectors.
Do i need any libraries? What's the best procedure to do it?
Thanks in advance!

In my company I used the boost library to read from a COM port. It includes the boost::asio::serial_port class to handle this kind of communication.
I used this code snippet for orientation and wrote my own wrapper class, for the needs of the project I was in.

You can take this:
http://www.codeproject.com/Articles/992/Serial-library-for-C
Or if you use Qt, i think there is also a lib from Qt to do this.

Related

Easiest way to control USB TMC device on Windows/C++

I am developing C++/Qt application which interacts with Tektronix TDS2002 oscilloscope via USB. The oscilloscope appears as "USB Test and Measurement device (IVI)".
Currently I use TekVISA library supplied by the oscilloscope's vendor. It works, but it is huge, old, buggy and poorly maintained. Therefore I would like to bypass the library and interface the device directly.
So far I have found this simple library: https://github.com/xyphro/WinUsbTmc It is exactly what I am looking for, but it uses libusb which requires to install some device filter and in addition it is advised to be more development tool than customer solution. Do you have any experience on this?
What is the easiest way to interact with USB Test and Measurement device in Windows/C++/Qt?
Thank you for your suggestions :)
You need a USB driver. My oscilloscope works with the driver included in this VISA package (the driver can be extracted very easily): http://www.keysight.com/main/software.jspx?cc=CZ&lc=eng&nid=-11143.0.00&id=2504667&pageMode=CV I assume all USB TMC devices can use the same driver, but I have no possibility to check this.
USB driver can be accessed via standard Windows functions. Guys on this forum were really close:
https://forum.tek.com/viewtopic.php?f=568&t=137573 and also this document was very useful: http://www.ivifoundation.org/downloads/Class%20Specifications/Ivi-6%202_USBTMC_2010-03-23.doc
You cannot write commands to OSC directly - data you send and receive have certain header which has to be in the correct format, otherwise the oscilloscope ignores the message. See reading and writting implementation in this simple library: https://github.com/xyphro/WinUsbTmc I didn't use this library because it uses libusb library which uses some kind of device filter and I personally do not like this concept (and in addition I have genuine working driver).
Data you read have also a simple header. To ensure you fit the header structure on input data well, you should first flush the input buffer. Then you issue reading request (using write command - see WinUsbTmc library above) and finally you receive the data and fit the header on its beginning.
I hope this will help to somebody :)
With regards
klasyc

How to control arduino by a pc with c++

I want to control my arduino board by my own c++ or java programme. Basically I want to get values from arduino. And perform some tasks based on that values. Simply,I have connected a potentiometer to arduino and I want to read its value in my programme.
You can use the telecommand to control the arduino from your pc. pc will send a string, and a program for the control of the input string on arduino
Your question is very broad so its difficult to give a direct answer, but the normal way is to use serial coms via a USB cable. In your Arduino code use either Serial or SoftwareSerial to open a connection. In your C++ application you will open a connection to the same COM port your Arduino is connected to.
There is some example code on the Arduino website:
http://playground.arduino.cc/Interfacing/CPPWindows
It's then up to you to decide on a protocol for passing data back and forth. This depends entirely on your needs, so we can't really help you unless you give more information.

Errors occur when trying including SerialStram.h from LibSerial

I try to use LibSerial’s class for serial communication (with an ATMega32A) through a COM port.
As soon as I include the SerialStream.h I get several error messages from the file SerialPort.h.
#include "SerialStream.h"
You can see the errors I get here.
http://i.stack.imgur.com/s8ZdC.png
Since I did not fully understand the installation of LibSerial, I think I use the class the wrong way.
I use the compiler QT Creator and the OS is Windows 7.
Feel free to ask for more information if you need it.
The question is not answerable in it's current format.
Nevertheless, if you are willing to use Qt's features to read from a serial port, I could point you to a demo I wrote a while ago.
Quick notes: main.cpp retrieves information and detects all serial ports on the computer and presents a menu to let the user choose which port to read from. Then it uses QSerialPort to open a connection to that specific port, and the reading part is done by SerialPortReader, a class implemented on that project.

C++ USB library

Is there a library/method for communicating with a microcontroller (Arduino)?
Basically, I need a method of receiving and sending data between the PC and the Arduino. I don't know what library to use, so I'm asking you. The data I'm going to send is little. Maybe 500 bytes back and forth. Everything is happening in Visual C++ 2010, in a console application.
libusb seems to be one of the best choices in your case. This is a lightweight, widely-used, open-source, cross-platform and well-documented C library.
termios also works fine. I've been using it to connect an Arduino to a Raspberry Pi (Linux) via serial link (USB). You could find some useful code snippets here.
Boost ASIO works well. Have a look at Stack Overflow question Reading messages from a serial port with Boost Asio. I recently had to write some code for communicating through the serial port, and I used an Arduino Uno to test it.
If you install the FTDI driver for your Arduino board, Windows will recognise it as a COM port, and you can communicate with it as if it is a normal serial port.
Yes, ArduSerail is a SUPER easy to use C++ library to interface with Arduinos on Windows platforms via USB.

how can i access serial port data in c++ using wxwidgets

i am electronics and communication engineering student. i am working on a project in which a microcontroller send data to serial port of computer (asynchronously).
i currently learning wxWidgets for my GUI work.
my question-
is it possible to do using wxWidgets to get data and display. is it very difficult to implement this.
i search for it but not get direct answer that how to implement this. so suggest me what i need to read for this. and what alternative available to do this. i use windows 7.
i also need to upload this data to web server (it is needed later)
wxWidgets, to the best of my knowledge, does not implement serial I/O facilities. There are other libraries available that provide this. One of the best choices is probably boost::asio (see http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/overview/serial_ports.html)
wxWidgets is a cross-platform GUI framework.
Reading a serial port is nothing to do with the GUI, and not cross platform.
So wxWidgets has nothing to do with reading serial ports.
You can read/write from/to a serial port using the windows API.
CreateFile opens the port
ReadFile reads data from the port
Difficult? Kinda!
I've never used it myself but there is wxCTB.