且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

请回答我的问题

更新时间:2023-01-23 19:04:23

对不起,但这是很简单的问题.
实际上,它们看起来非常像您的家庭作业,我们不为您做这件事!通过您的一些研究,可以很容易地回答所有这些问题.

Google是您的朋友:很好,经常拜访他.与在此处发布问题相比,他可以更快地回答问题...
I''m sorry, but these are pretty simple questions to answer.
As it is, they look very strongly like your homework, and we don''t do that for you! All of those could be answered very easily by a little bit of research on your part.

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...


您的意思是"如何在同一时间"?
您的代码可能会打开端口并将相同的数据写入所有端口.

Do you mean "how to write to multiple COM ports at the same time"?
Your code might open the ports and write the same data to all of them.

naraayanan写道:
naraayanan wrote:

INVALID_HANDLE_VALUE是什么意思?

What is mean by INVALID_HANDLE_VALUE?

这是CreateFile函数用来通知您的特殊返回值通话失败.您必须立即调用GetLastError以获得有意义的错误代码.


It is a special return value the CreateFile function uses to inform you that the call failed. You have to immediately call GetLastError to obtain a meaningful error code.


naraayanan写道:
naraayanan wrote:

SetupComm(hCom,16000,16000)是什么意思?

what is mean by SetupComm(hCom,16000,16000)?

将I/O缓冲区的大小设置为16000字节.


Sets the sizes of the I/O buffers to 16000 bytes.


naraayanan写道:
naraayanan wrote:

GetCommState(hCom,& dcb)是什么意思?

what is mean by GetCommState(hCom,&dcb)?

检索DCB [

Retrieves the current value of the DCB[^] configuration struct.


naraayanan写道:
naraayanan wrote:

GetCommTimeouts(hCom,& commtime)是什么意思?

what is mean by GetCommTimeouts(hCom,&commtime)?


naraayanan写道:
naraayanan wrote:

SetCommTimeouts(hCom,& commtime)是什么意思?

what is mean by SetCommTimeouts(hCom,&commtime)?


分别获取并设置 COMMTIMEOUTS 的当前值> [ ^ ]结构.该结构包含发送/接收超时参数.



串行端口配置(建议)过程按以下方式工作:在结构中检索所有当前配置参数,更改(在结构上)您感兴趣的几个参数的值,然后使用该结构将所有参数设置回去.


Windows上的BTW串行端口编程并不是一项艰巨的任务,但是您必须阅读文档. MSDN还提供了一些不错的代码示例,例如,参见: [ ^ ].


Respectively gets and sets the current value of the COMMTIMEOUTS[^] struct. The struct contains the send/receive timeout parameters.



Serial port configuration (suggested) process works this way: retrieve all the current configuration parameters in a struct, change (on the struct) the values of the few parameters you are interested in, then, using such struct set all the parameters back.


BTW serial port programming on Windows isn''t really a daunting task, however you have to read the documentation. MSDN provides some nice code samples as well, see, for instance: "Using Communications Resources"[^].


可以打开多个COM端口并对其进行写入.无法多次打开同一COM端口(如果已被任何应用程序打开,则无法打开COM端口).

要打开COM端口,请使用CreateFile() [ ^ ]函数:

It is possible to open multiple COM ports and write to them. It''s not possible to open the same COM port multiple times (a COM port can''t be opened if already opened by any application).

To open a COM port, use the CreateFile() [^] function:

LPCTSTR lpszPort = _T("COM1");
HANDLE hCom = ::CreateFile(lpszPort, GENERIC_READ | GENERIC_WRITE,
    0, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == hCom)
    AfxMessageBox(_T("Can't open COM port"));




当打开指定的文件或COM端口失败(例如尝试打开已打开的COM端口)时,INVALID_HANDLE_VALUECreateFile()返回.
有关通信功能,请参见MSDN [ ^ ].




INVALID_HANDLE_VALUE is returned by CreateFile() when opening the specified file or COM port fails (like trying to open a COM port that is already opened).

For the communication functions see the MSDN [^].