设置 rs232 中 rts cts dtr 的波特率 (或比特率?) 该怎么处理。

来源:百度知道 编辑:UC知道 时间:2024/09/22 17:23:44
我想用电脑的 rs232 串口中的rts cts dtr 等控制和接收一个芯片。芯片要求速率100kbps。如何设置 ?因为没用txd 所以不知道 波特率设置是否对rts cts dtr 起作用?具体用那个语句?
我可能没说明白我的问题,结合我刚做的实验,我重新说一下吧:我想控制DTR和RTS的频率,刚做实验,发现改变波特率具体语句:
HANDLE hCom;
hCom=CreateFile(
"COM1",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
NULL);

DCB dcb;
DWORD ModemStat=0;

BOOL fsuccess;

fsuccess = GetCommState(hCom, &dcb);
if (!fsuccess) cout<<"Error GetCommState(hCom, &dcb)\n";

dcb.BaudRate =9600; //注意这里,改变这个
fsuccess=SetCommState(hCom, &dcb);
if (!fsuccess) cout<<"Error SetCommState(hCom, &dcb)\n";

并不能改变DTR和RTS的频率。有没有什么好方法。
如果这个问题在百度知道里太专业的话,能否指点一个专业的网站,那个板块上提问较好?

设置波特率用这个函数
BOOL SetCommState(
HANDLE hFile, // handle to communications device
LPDCB lpDCB // device-control block
);
Parameters
hFile
[in] Handle to the communications device. The CreateFile function returns this handle.
lpDCB
[in] Pointer to a DCB structure that contains the configuration information for the specified communications device.

DCB的定义如下:

typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD fBinary: 1;
DWORD fParity: 1;
DWORD fOutxCtsFlow:1;
DWORD fOutxDsrFlow:1;
DWORD fDtrControl:2;
DWORD fDsrSensitivity:1;
DWORD fTXContinueOnXoff:1;
DWORD fOutX: 1;
DWORD fInX: 1;
DWORD fErrorChar: 1;
DWORD fNull: 1;
DWORD fRtsControl:2;
DWORD fAbortOnError:1;
DWORD fDummy2:17;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;