Simple Serial Port Program

Posted on  by 

Programmer

Simple Serial Port Monitor is, as the name says, simple serial port monitoring tool. User interface is clear and extremely easy to use. As one of it's handly. Oct 13, 2017  Download RealTerm: Serial/TCP. Serial terminal program for. An extensive commandline interface supports batch files and simple automatic. Now that we have created our serial port object and opened the port, we now want to read from the serial. For your program) with a simple for. This topic describes how to use My.Computer.Ports to receive strings from the computer's serial ports in Visual Basic. Determine which serial port should provide the strings. This example assumes it is COM1. Use the My.Computer.Ports.OpenSerialPort method to obtain a reference to the port.

Simple Serial Port Program

During a university project which used an Arduino and a C++ program, we had some issues establishing a quick and easy serial port communication system. This project was then created, after the semester, to create an easy to use lightweight serial communication library.

This library allows a simple-serial-port communication integration into any Windows C++ application that intends to communicate with any Ardunio. Reading from the Serial port uses common delimiters, such as JSONs, which are then concatonated at the beginning and at end of each string sent from the Ardunio. Examples are provided further below.

  • Write to Serial port
  • Read from Serial port
  • Close connection when needed

You can also:

  • Set the waiting time for the reply from the Arduino
  • Use common delimiters
  • Add custom delimiters via a local config file

Initialization the program

The program allows you to set the specific COM PORT and the BAUD RATE through the constructor. To properly use the BAUD RATE, due to Windows a API, a CBR_ notation must be added, as shown below. The constructor also sets connected_ to true if the connection has been established successfully.

Reading from Serial port

To read from the Serial port you must call the ReadSerialPort function. It takes two parameters, first an integer which represents the specific time the function should wait for a reply from the Ardunio in seconds, then the name of the syntax or delimiter type expected from the Arduino. It can either be the two default ones (JSON or greater_less_than), or the ones you create in the config file. Config file is described further below.

Serial Port Rs-232

The received string is then returned without the delimiters. If no delimiters are found in the config file, or the reading has failed for certain reason, the function will return an appropriate warning message.

Simple Serial Port Based Pic Programmer

Writing to Serial port

Call this function and input your char* that you would like to write. Returns true if writing was successful.

It is also easy to send strings, however, you will have to declare a pointer to your string. Example code:

WriteSerialPort function does not append any delimiters by default. This is done due to the fact some JSON constructing libraries append their own delimiters. So if you choose to use a JSON library just put your parsed JSON into a string and add it as a parameter:

To check for delimiters on the Ardunio, I highly recommend using this tutorial, especially, Example 3 - A more complete system.

Closing Serial port

Simple. Call this function when you would like to close the Serial port. Returns true if successful.

Creating custom syntax

There is an option to create custom delimtier syntaxes in the local config file. The config file is generated locally when the program is run for the first time. To create your own custom syntaxes you can either add it manually into the program,

or insert it directly into the sytax_config.txt file as a new line, sperated with spaces:

Arduino side

It is rather simple to send back information with your own delimiters from the Arduino. You'll have to concatonate your message at the first index and at the last one with your delimiters:

Afterwards, as mentioned before, you just create a pointer to the first index of your complete message string and write that into the Serial port:

Coments are closed