搜索
bottom↓
回复: 31

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

  [复制链接]

出90入0汤圆

发表于 2018-9-7 19:32:33 | 显示全部楼层 |阅读模式
本帖最后由 hzpyl 于 2018-9-7 19:49 编辑

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

运行画面:










本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入4汤圆

发表于 2018-9-7 20:08:48 | 显示全部楼层
传个微软的串口编程例程,很有参考价值

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入4汤圆

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

出0入0汤圆

发表于 2018-9-7 21:21:15 | 显示全部楼层
现在用vc 6.0很少了,虽然我上学那会这个挺流行的

出0入0汤圆

发表于 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.

出0入0汤圆

发表于 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.

出0入0汤圆

发表于 2018-9-8 07:12:01 来自手机 | 显示全部楼层
还在vc6啊

出90入0汤圆

 楼主| 发表于 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];
缓冲器开了2048,
超过缓冲器,我没有试验过。

出0入0汤圆

发表于 2018-9-10 13:15:14 | 显示全部楼层
ibichao 发表于 2018-9-7 20:12
建议楼主用vs2015,有些新特性,可提高生产效率,比如“Dynamic Layout"

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

出0入8汤圆

发表于 2018-9-10 16:45:51 | 显示全部楼层
CSerial 类?

出0入0汤圆

发表于 2018-9-10 16:54:45 | 显示全部楼层
这个是 和什么 串口器件 通信

出0入0汤圆

发表于 2018-9-10 16:55:05 | 显示全部楼层
使用的是 串口控件

出90入0汤圆

 楼主| 发表于 2018-9-10 18:25:27 | 显示全部楼层
maimaige 发表于 2018-9-10 16:54
这个是 和什么 串口器件 通信

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

出0入0汤圆

发表于 2018-9-10 18:41:32 | 显示全部楼层
收下了,谢谢楼主。

出0入0汤圆

发表于 2018-9-10 23:50:02 | 显示全部楼层
>BYTE rxdata[2048];
>缓冲器开了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?

出90入0汤圆

 楼主| 发表于 2018-9-11 07:24:23 | 显示全部楼层
to   funnynypd

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

出0入0汤圆

发表于 2018-9-11 16:24:45 | 显示全部楼层
这个好,必须顶一下

出0入0汤圆

发表于 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.

出0入0汤圆

发表于 2018-9-12 09:20:22 | 显示全部楼层
C#,VC太难搞了

出0入0汤圆

发表于 2018-9-12 10:53:08 | 显示全部楼层
重复造车仑子呵

出90入0汤圆

 楼主| 发表于 2018-9-12 15:35:36 | 显示全部楼层
wkman 发表于 2018-9-12 10:53
重复造车仑子呵

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

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

出0入0汤圆

发表于 2018-9-12 16:39:37 | 显示全部楼层

C#,VC太难搞了

出90入0汤圆

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

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

出0入0汤圆

发表于 2018-9-15 19:38:46 来自手机 | 显示全部楼层
lz为什么不用C#?

出0入0汤圆

发表于 2018-9-16 10:33:56 | 显示全部楼层
>我不过是选择:造,且是用20年前的工具造。
Good.

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

出0入0汤圆

发表于 2018-9-16 10:35:07 | 显示全部楼层
>lz为什么不用C#?
It needs .net.

出0入8汤圆

发表于 2018-9-16 10:57:59 | 显示全部楼层
VC用PCOMM,基本上和单片机串口中断操作一样。

出90入0汤圆

 楼主| 发表于 2018-9-16 11:28:03 | 显示全部楼层
>到大约900次后,写缓冲器会出错误。
>现在没有找到好办法。
This is exactly what I am talking about.

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

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

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

出0入0汤圆

发表于 2018-9-17 05:19:57 | 显示全部楼层
>你有没有好的办法?
No. I am beginner level.

出0入0汤圆

发表于 2018-12-21 11:00:08 | 显示全部楼层
谢谢分享,学习了

出0入0汤圆

发表于 2018-12-21 11:23:12 | 显示全部楼层
感谢分享,学习了

出0入0汤圆

发表于 2018-12-22 11:03:56 | 显示全部楼层
hzpyl 发表于 2018-9-15 13:13
我测试了一下,1秒发送、接收一次。
到大约900次后,写缓冲器会出错误。
现在没有找到好办法。 ...

环形缓冲区 +读写各自线程,读缓冲区的线程延时一定要比写缓冲区的时间短,这样就不会出现数据丢失,
这种模型我一直使用很多年了,在两个线程的场景很合适,
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-20 07:49

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表