hzpyl 发表于 2018-9-7 19:32:33

【原创】给VC++6.0初学者:VC++ 6.0 串口通讯 编程过程详解

本帖最后由 hzpyl 于 2018-9-7 19:49 编辑

近期,在学习VC++6.0的编程,
参考了网络上许多串口通讯程序,
自己试着编了一个串口通讯程序,
详细记录编程过程。
给初学者。 大牛略过。

运行画面:










ibichao 发表于 2018-9-7 20:08:48

传个微软的串口编程例程,很有参考价值

ibichao 发表于 2018-9-7 20:12:40

建议楼主用vs2015,有些新特性,可提高生产效率,比如“Dynamic Layout"

041012js 发表于 2018-9-7 21:21:15

现在用vc 6.0很少了,虽然我上学那会这个挺流行的

funnynypd 发表于 2018-9-8 00:09:50

How do you handle the EDIT control, if there are a lot of incoming data?
on my case, it always stay on the top of the display, and if the data flow is large, the programs seem not response until you turn off the serial port.

funnynypd 发表于 2018-9-8 03:54:00

I use the serial port to monitoring incoming data stream, it seemed that the MCU generates too much data for edit control, which eventually makes the edit control looks frozen until the incoming data stops.

huangqi412 发表于 2018-9-8 07:12:01

还在vc6啊

hzpyl 发表于 2018-9-8 07:28:49

funnynypd 发表于 2018-9-8 00:09
How do you handle the EDIT control, if there are a lot of incoming data?
on my case, it always stay...

BYTE rxdata;
缓冲器开了2048,
超过缓冲器,我没有试验过。

heimareed 发表于 2018-9-10 13:15:14

ibichao 发表于 2018-9-7 20:12
建议楼主用vs2015,有些新特性,可提高生产效率,比如“Dynamic Layout"

已经抛弃了VC上位机了(多半是因为我Cpp太菜了吧…{:titter:} ),现在换用C#来做Win端上位机软件,做简单调试工具和小应用,开发效率高。

justdomyself 发表于 2018-9-10 16:45:51

CSerial 类?

maimaige 发表于 2018-9-10 16:54:45

这个是 和什么 串口器件 通信

maimaige 发表于 2018-9-10 16:55:05

使用的是 串口控件

hzpyl 发表于 2018-9-10 18:25:27

maimaige 发表于 2018-9-10 16:54
这个是 和什么 串口器件 通信

公司生产的带RS485接口 或 M-BUS接口 的产品。

su33691 发表于 2018-9-10 18:41:32

收下了,谢谢楼主。

funnynypd 发表于 2018-9-10 23:50:02

>BYTE rxdata;
>缓冲器开了2048,
>超过缓冲器,我没有试验过。
Actually, it is not about the Rx buffer.
It is about the end application will receive up to infinite amount of data, I cannot count on the edit control to hold that many data, is there a class, database or MFC control to recommend?
The Edit control cannot hold more than 65536 bytes of data. So something else must be used to hold the data, the edit control can only be used as a human machine interface (HMI).
Any idea or recommendataion?

hzpyl 发表于 2018-9-11 07:24:23

to   funnynypd

到一定长度,譬如4K字节时,剪切缓冲器,保存文件。再清除缓冲器。
这样行不行?
我没有试验啊!

longhun26 发表于 2018-9-11 16:24:45

这个好,必须顶一下

funnynypd 发表于 2018-9-11 21:28:20

>到一定长度,譬如4K字节时,剪切缓冲器,保存文件。再清除缓冲器。
>这样行不行?
That is not the challenge.
The challenge is the "Edit control" which is used to display the contents. It has a maximum number of bytes can be loaded.

biansf2001 发表于 2018-9-12 09:20:22

C#,VC太难搞了

wkman 发表于 2018-9-12 10:53:08

{:shocked:}重复造车仑子呵

hzpyl 发表于 2018-9-12 15:35:36

wkman 发表于 2018-9-12 10:53
重复造车仑子呵

我没有 车轮,
要不 买? 要不 造?

我不过是选择:造,且是用20年前的工具造。

dongwang_fl 发表于 2018-9-12 16:39:37


C#,VC太难搞了

hzpyl 发表于 2018-9-15 13:13:54

funnynypd 发表于 2018-9-11 21:28
>到一定长度,譬如4K字节时,剪切缓冲器,保存文件。再清除缓冲器。
>这样行不行?
That is not the challe ...

我测试了一下,1秒发送、接收一次。
到大约900次后,写缓冲器会出错误。
现在没有找到好办法。

zhouyan 发表于 2018-9-15 19:38:46

lz为什么不用C#?

funnynypd 发表于 2018-9-16 10:33:56

>我不过是选择:造,且是用20年前的工具造。
Good.

>到大约900次后,写缓冲器会出错误。
>现在没有找到好办法。
This is exactly what I am talking about.

funnynypd 发表于 2018-9-16 10:35:07

>lz为什么不用C#?
It needs .net.

skype 发表于 2018-9-16 10:57:59

VC用PCOMM,基本上和单片机串口中断操作一样。

hzpyl 发表于 2018-9-16 11:28:03

>到大约900次后,写缓冲器会出错误。
>现在没有找到好办法。
This is exactly what I am talking about.

我试验好像是: 操作SCtring 引起的
如: m_strRXData += m_strRXDataTemp;

显示SCtring有没有影响,还没有试验。

请问,你有没有好的办法?

funnynypd 发表于 2018-9-17 05:19:57

>你有没有好的办法?
No. I am beginner level.

TKZXJ 发表于 2018-12-21 11:00:08

谢谢分享,学习了

TCMCU 发表于 2018-12-21 11:23:12

感谢分享,学习了

hyf88 发表于 2018-12-22 11:03:56

hzpyl 发表于 2018-9-15 13:13
我测试了一下,1秒发送、接收一次。
到大约900次后,写缓冲器会出错误。
现在没有找到好办法。 ...

环形缓冲区 +读写各自线程,读缓冲区的线程延时一定要比写缓冲区的时间短,这样就不会出现数据丢失,
这种模型我一直使用很多年了,在两个线程的场景很合适,
页: [1]
查看完整版本: 【原创】给VC++6.0初学者:VC++ 6.0 串口通讯 编程过程详解