Giter Club home page Giter Club logo

itas109 / cserialport Goto Github PK

View Code? Open in Web Editor NEW
688.0 39.0 335.0 8.92 MB

CSerialPort - lightweight cross-platform serial port library for C++/C/C#/Java/Python/Node.js/Electron

Home Page: https://blog.csdn.net/itas109/article/details/84282860

License: Other

C++ 86.03% C 1.60% Shell 0.03% CMake 5.07% Batchfile 0.01% Python 1.22% SWIG 0.65% JavaScript 4.31% C# 0.50% Java 0.59%
serial-port cserialport cpp communication serialport rs232 uart serial linux-serialport windows-serial

cserialport's Introduction

cserialport's People

Contributors

itas109 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  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

cserialport's Issues

Get Friendly Name

in windows i would like to get the firendly name of the com device.

the windows device manager shows "Prolific 2313... (COM15)" and with your library i'm only able to get "COM15".

is there any way to get the "Prolific 2313..." part?

function writeData hanle leak on windows 函数writeData 在windows上存在写入句柄泄露

Describe the bug
function writeData hanle leak on windows
函数writeData 在windows上存在写入句柄泄露

To Reproduce
open taskmgr.exe -> details -> handle
call function writeData once, the process's handle +1 on taskmgr
打开任务管理器 -> 详细信息 -> 句柄
调用一次writeData 函数,任务管理器中进程对应的句柄数会+1

Expected behavior
call function writeData once, the process's handle +1,and then -1 when write finished。
调用writeData 函数,进程句柄数+1,写入完成后句柄数 -1

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Win10 64bit
  • Compiler: VS2019
  • Version: 4.x

串口通信过程中关闭再开启串口,会出现权限拒绝

描述bug
串口通信过程中关闭再开启串口,会出现权限拒绝

重现步骤
串口通信过程中,通过代码关闭,再紧接着打开串口

运行环境信息:

  • 操作系统: Win7 Ultimate 64bit
  • 编译器:QT 5.6.2 VS2013 update 5
  • 版本号: 2020-04-16主干

FreeBSD itas109::CSerialPortInfo::availablePortInfos() core dumped

Describe the bug
FreeBSD itas109::CSerialPortInfo::availablePortInfos() core dumped

Trace/BPT trap (core dumped)
Illegal instruction (core dumped)

To Reproduce
Steps to reproduce the behavior:
call function itas109::CSerialPortInfo::availablePortInfos()

Screenshots

Program terminated with signal SIGILL, Illegal instruction.
#0  0x00000000002156e4 in getPortInfoList() ()
[Current thread is 1 (LWP 100200)]
(gdb) where
#0  0x00000000002156e4 in getPortInfoList() ()
#1  0x0000000000215834 in CSerialPortInfoUnixBase::availablePortInfos() ()
#2  0x00000000002156b4 in itas109::CSerialPortInfo::availablePortInfos() ()
...

Desktop (please complete the following information):

  • OS: FreeBSD-12.1-RELEASE
  • Compiler: FreeBSD clang version 8.0.1 (based on LLVM 8.0.1)
  • Version: 4.0.3.200429

缓冲区溢出

在订阅后发生,在已损坏了程序内部状态的 CommQT.exe 中发生了缓冲区溢出。按“中断”以调试程序,或按“继续”以终止程序。

使用中发现的一些问题

首先谢谢作者,最近在使用发现几个问题,希望可以改进.
1.内存泄露,在CSerialPort类的析构函数中delete p_serialPortBase可以解决,不知道可否这样做。
2.使用异步模式发送,在CSerialPortWinBase::writeData函数内,WriteFile函数执行后跳到lastError = itas109::WriteError处,导致没有办法获得发送的字节数,可是接收端已接收到正确的数据。
3.在主对话框中的CSerialPort对象刚开始可以正常发送与接收,然后close掉,再弹出的模式对话框中new一个CSerialPort可以正常发送接收,再关闭弹出对话框(有对CSerialPort的delete,close操作),这个时候回到主对话框,open原来的CSerialPort只能发送(确认过发送正常),不能接收,弹出的对话框内CSerialPort始终工作正常(多次打开关闭),只要在弹出对话框中new过一次CSerialPort,主对话框CSerialPort就不能接收。在弹出对话框中使用主对话框的CSerialPort时正常。两个对话框中操作的是一个串口。不知道可否这样操作。vc6 mfc win7.

sigslot can not define static 信号与槽不应该定义为static

Describe the bug
A clear and concise description of what the bug is.

sigslot::signal0<> readReady can not define static.
When there are two classes, the previous one cannot receive data

当存在多个串口类时,只有最后一个可以正常接收数据。

Expected behavior
A clear and concise description of what you expected to happen.

Each CSerialPort class has an independent sigslot::signal0<> readReady
每个串口类拥有独立的sigslot::signal0<> readReady

Desktop (please complete the following information):

  • Version: 4.0.2.200108

超长数据的发送与接收问题

超长数据的发送与接收问题。如超过1024等情况,需要确认上限。

可能导致数据丢失的原因:
1.类库问题
2.传输过程问题
3.USB转串口的丢失

CommThread deal with mutil handle tigger at the same time Bug

Describe the bug
CommThread deal with mutil handle tigger at the same time Bug

Event should begin Event - WAIT_OBJECT_0 not Event - WAIT_OBJECT_0 -1

line 641

//deal with mutil handle tigger at the same time	//by itas109 2017-12-17
if (Event >= WAIT_OBJECT_0 && Event < WAIT_OBJECT_0 + 3)
{
	for (int i = Event - WAIT_OBJECT_0 -1 ; i < 3; i++)
        ...
}

Desktop (please complete the following information):

  • OS: Win7/10 Ultimate 64bit
  • Compiler: VS2013 update 5
  • Version: 3.0.3.180621

纯C++程序如何添加WM_COMM_RXCHAR消息处理函数?

非常感谢您的代码。

我的程序是跑在后台的,写的是纯c++的代码,没有引用任何MFC的东西。我在添加WM_COMM_RXCHAR消息处理函数时遇到了困难。

请问如何在纯C++程序中添加消息处理呢?又或者能够用函数指针的方式去处理接收函数呢?

谢谢

MFC使用UpdateData(false)报错

在接受字符的函数里面,不能使用UpdateData(false) ,会报错的。只能用GetDlgItem(XXXX)->SetWindowTextW(XXX);这样来给控件赋值

关于打开串口open函数,可否添加一个判断是否可以打开这个串口的函数,而不真实打开。主要是我有计时器需求,经常有打开关闭窗口,但如果串口没打开,而我人不在,那一堆的弹出窗口,没法用啊。

描述bug
清楚简明地描述bug

重现步骤
描述出现bug的操作

预期行为
对您期望发生的事情的简洁明了的描述

截图
如果适用,请添加屏幕截图以帮助解释您的问题

运行环境信息:

  • 操作系统: [e.g. DeepIn 15.11 64bit/Win7 Ultimate 64bit]
  • 编译器:[e.g. QT 5.6.2 GCC 6.3.0/VS2013 update 5]
  • 版本号[e.g. 4.0.2.200108]

其他内容
在此处添加有关该问题的任何其他内容

增加设置串口接收最少字符函数

目前程序默认大于1个字符才会触发读取信号,可能引起一定的误解。
// solve 线程中循环的低效率问题 ClearCommError(m_mainHandle, &dwError, &comstat); if (comstat.cbInQue > 1) //设定字符数 { readReady.emit(); }

SerialPortInfoWinBase.cpp _T() cannot convert 'const char*' to 'LPCWSTR

Describe the bug
SerialPortInfoWinBase.cpp _T() cannot convert 'const char*' to 'LPCWSTR

SerialPortInfoWinBase.cpp:93:107: error: cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'LONG RegQueryValueExW(HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD)'

RegQueryValueEx(hDevKey, _T("PortName"), NULL, NULL, (BYTE*)portName, &dwCount);

Desktop (please complete the following information):

  • OS: Win7 Ultimate 64bit
  • Compiler: QT 5.6.3 MinGW 4.9.2 (32-bit)
  • Version: 4.0.3.200429

windows xp unable to locate the program input point in msvcrt.dll 无法定位程序输入点于msvcrt.dll

Describe the bug

_itoa_s Unable to locate the program input point in the dynamic link library msvcrt.dll
_swprintf_s Unable to locate the program input point in the dynamic link library msvcrt.dll

_itoa_s 无法定位程序输入点于动态链接库msvcrt.dll
_swprintf_s无法定位程序输入点于动态链接库msvcrt.dll

Desktop (please complete the following information):

  • OS: windows xp
  • Compiler: QT 5.6.3 mingw492_32
  • Version: 4.0.3.200429

400k braud issue

我需要串口支持400k的波特率 并且支持 Windows macos两种平台 现在还不支持

windows下单字符触发收发QT程序异常问题

VS2013 Comm的例子正常

CommQT例子持续接收程序会崩溃

经过测试发现,如果只在QT中接收数据,不展示到控件上,那么接收结果和数目都是正确的。
因此,可以认为从收到数据到QT控件上展示可能存在问题,需要进一步排查。

一个莫名其妙的问题

Describe the bug
A clear and concise description of what the bug is.
我的的WIN10系统没有这个问题,我朋友的WIN7系统出现一个莫名其妙的问题,MFC程序,COM1串口,在用writedata发送后,断点执行时也能看到说发送了多少字节,这个字节数也是正确的,问题是,硬件没有收到数据,我之后会启动一个mfc的计时器settimer,作用是休息若干时间去执行接收数据的操作,我是设置串口同步的,程序会在这个settimer处卡死,卡死期间,在任务管理器中显示unknown,更奇怪的是,解决方式其实很简单,比如用Demo中的例子打开这个串口,然后关闭这个串口,程序就可以正常了。

我很奇怪,理论上,writedata是调用winapi发送的数据吧,收到发送字节后,应该是发送了才是吧,但为什么没有发送?这个计时器为什么会被串口卡死?我调用的是MFC的实例方法,而不是winapi,理论上应该跟串口无关。请问有解决方向吗?

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. DeepIn 15.11 64bit/Win7 Ultimate 64bit]
  • Compiler: [e.g. QT 5.6.2 GCC 6.3.0/VS2013 update 5]
  • Version: [e.g. 4.0.2.200108]

Additional context
Add any other context about the problem here.

No Gui Application without endless loop, application crash at `(*it)->slot_disconnect(this);`

Describe the bug
No Gui Application without endless loop, application crash at (*it)->slot_disconnect(this);

void disconnect_all()
{
	lock_block<mt_policy> lock(this);
	const_iterator it = m_senders.begin();
	const_iterator itEnd = m_senders.end();

	while(it != itEnd)
	{
		(*it)->slot_disconnect(this);// crash c0000005
		++it;
	}

	m_senders.erase(m_senders.begin(), m_senders.end());
}

test code:

#include <iostream>

#include "SerialPort.h"

using namespace itas109;
using namespace std;

class mySlot : public has_slots<>
{
public:
	mySlot(CSerialPort & sp){ m_sp = sp; };

	void OnSendMessage()
	{
		recLen = m_sp.readAllData(str);
		if (recLen > 0)
		{
			str[recLen] = '\0';
			std::cout << "receive data : " << str << ", receive size : " << recLen << std::endl;
		}
	};

private:
	mySlot(){};

private:
	CSerialPort m_sp;

	char str[1024];
	int recLen;
};

int main()
{
	CSerialPort sp;
	mySlot receive(sp);

       // while(true);
	return 0;
}

Desktop (please complete the following information):

  • OS:Win7 Ultimate 64bit
  • Compiler: VS2013 update 5/MinGW 810
  • Version: [e.g. 4.0.3.200429

some win10 could not enum all avaiable ports with function availablePortInfos()

Describe the bug
some win10 could not enum all avaiable ports with function availablePortInfos()

To Reproduce
call function availablePortInfos()

Desktop (please complete the following information):

  • OS: Win10 64bit
  • Compiler: vs2019
  • Version: 4.1.0.201010

Additional context
Add any other context about the problem here.

linux receive miss 0x11 0x13 0x0d

Describe the bug
linux receive miss 0x11 0x13 0x0d

Desktop (please complete the following information):

  • OS: [e.g. DeepIn 15.11 64bit
  • Compiler: QT 5.12.6 GCC 6.3.0
  • Version: 4.0.2.200108

VS2015 x64 MFC not work

Describe the bug
VS2015 x64 MFC not work

Desktop (please complete the following information):

  • OS: Win7 Ultimate 64bit
  • Compiler: VS2015 update 3 x64
  • Version: 4.0.3.20200429

error source code

signal0::connect
this->m_connected_slots.push_back(conn);

Application based CSerialPort 基于CSerialPort的应用程序

Thank you to use CSerialPort library, Please describe your application (introduce in CSerialPort README)

example

App name:CommMaster
Introduce: name:CommMaster is a cross-platform multi-operating system serial communication assistant, supports windows, linux, macos, raspberrypi, etc., supports the definition of serial ports, baud rate, etc., supports multiple languages and custom skins
HomePage:https://gitee.com/itas109/CommMaster
Contact: [email protected]
Screenshot:

感谢您使用CSerialPort库,请描述您的应用(CSerialPort README中会介绍该应用)

例如

应用名称:CommMaster 通信大师
介绍:通信大师是一款跨平台多操作系统串口通信助手,支持windows、linux、macos、raspberrypi等,支持定义串口、波特率等,支持多国语言及自定义皮肤
主页:https://gitee.com/itas109/CommMaster
联系方式: [email protected]
截图:

requests and suggestions 需求及建议

Thank you to use CSerialPort library, Please leave your requests and suggestions

example

request:need comm monitor hook
use:use to monitor comm

suggestion:add serial port destription, such as COM1 Prolific USB-to-Serial Comm Port

Contact: [email protected]

感谢您使用CSerialPort库,请留下您的需求及建议

例如

需求:需要串口侦听功能
用途:用于从软件层面进行串口侦听

建议:建议增加串口描述功能,如COM1 Prolific USB-to-Serial Comm Port

联系方式: [email protected]

readReady.connect not work

描述bug

m_SerialPort.disconnect_all();
m_SerialPort.readReady.connect(this, &MainWindow::OnReceive);

如果在readReady.connect之前调用disconnect_all,那么异步的接收函数将无法收到数据

If you call disconnect_all before readReady.connect, then the receive function will not receive data

remove disconnect_all is ok

//m_SerialPort.disconnect_all();
m_SerialPort.readReady.connect(this, &MainWindow::OnReceive);

运行环境信息:

  • 版本号 4.0.2.200108

writeDate 返回 -1

打开没有问题,但是写入数据时 失败

winodws7 64位 vs2019 debug x86

readLineData

您好,函数CSerialPortWinBase::readLineData(char *data, int maxSize)是还没有完成吗?

One byte receiving issue

Could change the SerialPortWinBase.cpp line: 294 to follow?
if (comstat.cbInQue > 0) //设定字符数 original: > 1
Otherwise if we only have one byte receive, the library will not detect it.

WriteToPort 接口设计疑问

void CSerialPort::WriteToPort(char* string, size_t n)
{
	assert(m_hComm != 0);
	memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer));
	memcpy(m_szWriteBuffer, string, n);
	m_nWriteSize = n;

	// set event for write
	SetEvent(m_hWriteEvent);
}

这样发送数据,在连续发送的时候应该是有问题的,而且也没有发现有任何通知机制能够确认上一次的数据已经发送完成,可以发送下一次的数据了.
当然 发送->等待->接收应答 这样的顺序使用应该是ok的

eventhandler not executed

when i call .readReady.connect the connected class function never gets called, whilst using a regular readAllData works as expected.

i'm using vs2019. do i have to do more tha calling the connect-function?

WM_COMM_RING_DETECTED振铃信号触发两次

VS2017,C++,打算用WM_COMM_RING_DETECTED信号来触发函数,但发现每次都会触发两次这个函数,也就是说上升沿和下降沿它都会触发,但是按理来说振铃信号应该只有一次呀,有什么办法可以设置吗?因为和该信号关联的这个事件EV_RING是自带的,不知道它指的到底是什么?请求指点 感谢~

read thread high CPU usage on linux(centos 7)

Describe the bug
read thread high CPU usage on linux(centos 7)

To Reproduce
compile and run examples\CommNoGui\CSerialPortDemoNoGui
run top or htop command

$ htop

CPU[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]   Tasks: 40, 59 thr; 1 running

   PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
12165 root     20   0 14980  2884  2684 R 99.1  0.1  0:26.62 ./CSerialPortDemoNoGui

Desktop (please complete the following information):

  • OS: centos 7.6 x86_64
  • Compiler: gcc 4.8.5
  • Version: 4.1.0.201010

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.