This is cross-platform serial port library written in C++, build passing MAC-High-Sierra and Win10.
First - include "Library" folder into your project.
- serialport.h
- serialport.cpp
- enumserial.h
- enumserial.cpp
- Third/dirent.h(MSVC only)
- MAC OS X (POSIX)
- Windows10 (WinAPI)
EnumSerial enumserial;
SerialPort serial;
std::vector<std::string> paths = enumserial.EnumSerialPort(); //Enum device driver of serial port
int choice_path = 0; // get user selection
#ifdef _WIN_
serial.Open(paths[choice_path]);
#elif _MAC_
serial.Open(enumserial.GetRoot() + paths[choice_path]); //root = /dev/
#endif
int baud_rate = 115200;
serial.SetBaudRate(baud_rate);
serial.SetParity(8,1,'N');
unsigned char str[17] = "Hello Terminal \n";
serial.Write(str,17);
unsigned char serial_buffer[5000] = {0};
int length = serial.Read(serial_buffer);
if(length != -1){
std::cout << serial_buffer;
}
#define _MAC_ or g++ -D _MAC_
#define _WIN_ or setting VS2017 property of compile flag _WIN_
wxTerm is cross-platform and Arduino-like IDE serial monitor example.
- wxWidgets 3.x
make
setting compile flag _WIN_
Install STM32 Virtual COM Port Driver(STSW-STM32102 - Windows10 only )
#define USBD_VID 0x0483
#define USBD_PID 0x5740
cd STM32F4/src/STM32F4
make
Load main.elf file with arm-none-eabi-gdb .
wxTerm baud rate - none
Arduino IDE open ArduinoSerialTest.ino file and burning the code on Arduino-board
wxTerm baud rate - 115200
wxArduino - previous version of SerialPortLibrary
MIT License
Copyright (c) 2019 Tony Guo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.