Code Monkey home page Code Monkey logo

serialport's Introduction

SerialPort

C++ Library for Serial Communication with following criteria

  • Plain C++ Compatible
  • Windows Supported
  • Include and Run Type Library
  • supports softwareserial
  • supports serial event
  • fixed minor bugs

Documentation

Here is a blog post about the library

Initialization

#include "SerialPort.hpp"
#include <iostream>

const char *portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

int main(void)
{
  arduino = new SerialPort(portName);
  std::cout << "Is connected: " << arduino->isConnected() << std::endl;
}

Sending Data

#define DATA_LENGTH 255

#include "SerialPort.hpp"
#include <iostream>

const char *portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

//Here '\n' is a delimiter 
const char *sendString = "Hello World\n"; 

int main(void)
{
  arduino = new SerialPort(portName);
  if (arduino->isConnected()){
    bool hasWritten = arduino->writeSerialPort(sendString, DATA_LENGTH);
    if (hasWritten) std::cout << "Data Written Successfully" << std::endl;
    else std::cerr << "Data was not written" << std::endl;
  }
}

Receiving Data

#define DATA_LENGTH 255

#include "SerialPort.hpp"
#include <iostream>

const char *portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

char receivedString[DATA_LENGTH];

int main(void)
{
  arduino = new SerialPort(portName);
  if (arduino->isConnected()){
    int hasRead = arduino->readSerialPort(receivedString, DATA_LENGTH);
    if (hasRead) std::cout <<  receivedString << "\n";
    else std::cerr << "Error occured reading data" << "\n";
  }
}

serialport's People

Contributors

darkworks avatar f3lda avatar julien-mustiere avatar manashmandal avatar nullptr-deref avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serialport's Issues

Undefined behavior in writeSerialPort() caused by developer error

In the Sending Data section of the README, DATA_LENGTH is defined as 255, but the string that is actually passed to writeSerialPort() has a length of 12 characters. If 255 is, indeed, passed as DATA_LENGTH, undefined behavior may occur and can manifest itself as incomplete strings, and some may even be created automatically rather than explicitly defined by the developer.

I propose that writeSerialPort() should find the length of the *buffer string parameter instead of relying on developer input in order to prevent this issue from occurring in the future.

Does this library work on linux?

Hi, this is a great library. Thanks for making this open.

I would like to connect to a serial port on linux. In the header file, I noticed that windows.h is imported, which most likely means that the library does not support linux. Is that true? If yes, can you recommend a library for communicating with a serial port on linux?

Issue with "using namespace cv"

I would report this conflict after i using OpenCV Library with this library.
The conflict result when declare "using namespace cv". In my opinion it might have conflict on Window serial library.

Windows receive wrong sentence

I run the exampleReceiveData on windows7, it first receive true sentence "Hello, world!", but afterwards the sentence has been cluttered for example "llo, wororld!", "ld!", "wororld!", "Hel", "wororld!", "lo, worrorld!".

A simulation page for the SerialPort library

Hi There,

I am happy to see the useful library for the serial port. I tried it as well and also changed the text and other options and it works totally fine.

I have been working on a free Arduino playground online where one can run their code online and verify the library. A small demo is shared for you in the below link:

https://drive.google.com/file/d/1DlQstihcLmphZwvce6FPvNNLRsnI0Cj6/view?usp=sharing

The users will be able to see the code working without any hardware! Also, they don't have to install or download anything.

If you find this useful and interesting for the users, I will send a pull request to update the ReadMe file with the direct simulation link for your library. Also, I can try to create simulation pages for other libraries as well.

Kindly let me know your thoughts
Thanks
Puneeth

SerialPort class constructor

When defining class member we provide unique port name of type char *portName. In readme quick guide you initialize it as const char * assigning it's value to char * which is prohibited.
I think you should change constructor argument to type const char * or let me open the pull request where I'll fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.