itas109 < [email protected] >
大道至简 Road to Jane
QQ群 : 129518033
C/C++,NodeJS,Linux
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
itas109 < [email protected] >
大道至简 Road to Jane
QQ群 : 129518033
C/C++,NodeJS,Linux
It is caused by
p_serialPortBase = new CSERIALPORTBASE(portName);
in construction CSerialPort, but has no place to delete it ,
I think the place could be the destructor of the CSerialPort::~CSerialPort()
what's your idea?
B/R
VS2013 Comm的例子正常
CommQT例子持续接收程序会崩溃
经过测试发现,如果只在QT中接收数据,不展示到控件上,那么接收结果和数目都是正确的。
因此,可以认为从收到数据到QT控件上展示可能存在问题,需要进一步排查。
请问怎么以hex写入?
打开没有问题,但是写入数据时 失败
winodws7 64位 vs2019 debug x86
Describe the bug
linux receive miss 0x11 0x13 0x0d
Desktop (please complete the following information):
描述bug
清楚简明地描述bug
重现步骤
描述出现bug的操作
预期行为
对您期望发生的事情的简洁明了的描述
截图
如果适用,请添加屏幕截图以帮助解释您的问题
运行环境信息:
其他内容
在此处添加有关该问题的任何其他内容
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):
Describe the bug
windows vs2008 vs2010 Cannot open include file: 'ntddser.h'
Desktop (please complete the following information):
写入特定指令,不经过物理串口,直接返回特定数据
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:
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):
Additional context
Add any other context about the problem here.
Describe the bug
open mutile times ok on linux
在linux上可以多次成功打开串口
测试用例test case : open_1_2
Desktop (please complete the following information):
串口同步读写
首先谢谢作者,最近在使用发现几个问题,希望可以改进.
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.
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):
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]
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):
目前程序默认大于1个字符才会触发读取信号,可能引起一定的误解。
// solve 线程中循环的低效率问题 ClearCommError(m_mainHandle, &dwError, &comstat); if (comstat.cbInQue > 1) //设定字符数 { readReady.emit(); }
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.
描述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);
运行环境信息:
我需要串口支持400k的波特率 并且支持 Windows macos两种平台 现在还不支持
非常感谢您的代码。
我的程序是跑在后台的,写的是纯c++的代码,没有引用任何MFC的东西。我在添加WM_COMM_RXCHAR消息处理函数时遇到了困难。
请问如何在纯C++程序中添加消息处理呢?又或者能够用函数指针的方式去处理接收函数呢?
谢谢
m_readBufferSize 这个变量好像没有使用到。
在订阅后发生,在已损坏了程序内部状态的 CommQT.exe 中发生了缓冲区溢出。按“中断”以调试程序,或按“继续”以终止程序。
您好,函数CSerialPortWinBase::readLineData(char *data, int maxSize)是还没有完成吗?
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):
i think the title says everything...
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):
1、WriteToPort中对m_bufferList操作需要加锁:
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):
Additional context
Add any other context about the problem here.
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?
超长数据的发送与接收问题。如超过1024等情况,需要确认上限。
可能导致数据丢失的原因:
1.类库问题
2.传输过程问题
3.USB转串口的丢失
setMinByteReadNoify(1)数据接收正常
setMinByteReadNoify(2)会丢失数据
测试环境:
windows 7 64bit
VS2013
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):
How to send/write Hex Data
如何发送/写入hex十六进制数据
Describe the bug
function init/setReadBufferSize/getReadBufferSize not work
Desktop (please complete the following information):
你好,该项目能否支持监听已打开串口?
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的
析构函数抛出异常
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]
截图:
在接受字符的函数里面,不能使用UpdateData(false) ,会报错的。只能用GetDlgItem(XXXX)->SetWindowTextW(XXX);这样来给控件赋值
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?
VS2017,C++,打算用WM_COMM_RING_DETECTED信号来触发函数,但发现每次都会触发两次这个函数,也就是说上升沿和下降沿它都会触发,但是按理来说振铃信号应该只有一次呀,有什么办法可以设置吗?因为和该信号关联的这个事件EV_RING是自带的,不知道它指的到底是什么?请求指点 感谢~
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):
Describe the bug
Visual Studio 2013 - Windows XP (v120_xp) compile error : ntddser.h No such file or directory.
Visual Studio 2010 has the same problem.
Desktop (please complete the following information):
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):
Describe the bug
VS2015 x64 MFC not work
Desktop (please complete the following information):
error source code
signal0::connect
this->m_connected_slots.push_back(conn);
当我以10毫秒的速度同时访问2个串口一段时间后,停止之后再访问其他串口会出现无反应的情况
描述bug
串口通信过程中关闭再开启串口,会出现权限拒绝
重现步骤
串口通信过程中,通过代码关闭,再紧接着打开串口
运行环境信息:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.