向com端口发送大消息 [英] sending a large message to com port

查看:71
本文介绍了向com端口发送大消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过

port.Write(txtMsg.Text.ToLower());



用于在com端口上写入数据但是当我发送一条大消息,它将挂起我的程序任何帮助.............

i Used
port.Write(txtMsg.Text.ToLower());

for write data on com port but when i send a large message it will hang my program any help.............

推荐答案

更改 SerialPort.WriteBufferSize Property [ ^ ] - 它默认为2048,当它填充缓冲区时,它会暂停你的任务,直到它有空间。由于COM端口往往是相当慢的设备(您配置的波特率是以每秒位数为单位,因此9600波特率可达到每秒约1000个字符),如果是,则可能需要等待一段时间才能完成输出。消息是一个重要的大小。
Change the value of your SerialPort.WriteBufferSize Property[^] - it defaults to 2048, and when it fills the buffer, it will pause your task until it has space. Since COM ports tend to be rather slow devices (the baud rate you set when you configured it is in bits per second, so 9600 baud works out to around 1000 characters per second) it may need to wait some time to complete the output if the message is a significant size.


显然,它不仅取决于你的代码(它没有任何问题),还取决于你的RS-232电缆的另一端发生的事情。所有通信参数应该匹配,波特率,停止位,所有这些,但最重要的是,另一端的东西应该读取这些数据;直到它完成,你方的代码将被阻止。怎么回事?



-SA
Apparently, it depends not only on your code (there is nothing wrong with it), but also on what happen on the other end of your RS-232 cable. All communication parameters should match, baud rate, stop bits, all of that, but, most importantly, something on the other end should read this data; until it's done, your side's code will be blocked. How else?

—SA


这篇关于向com端口发送大消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆