设置 rs232 中 rts cts dtr 的波特率 (或比特率?) 该怎么处理。
设置波特率用这个函数
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;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;
如何实现单片机与相位计串口RS232通信? 相位计需要用到CTS,RTS;不能只用三线通信。
串口半双工方式下会用到cts (clear to send)rts (ready to send)dsr (data set ready)
没什么大不了的,这些都是流量控制,也就是说你没响应cts之前对方不会发送数据,会等你响应。
两个方法:
1,多使用两个单片机引脚来做CTS和RTS,按串口协议操作这两个信号,也就是根据读到的信号改变另一个信号通知对方可以发送,或者通知对方我要发送然后等对方响应再发送而已,半双工的数据收发就是有控制的收发,需要根据信号量来决定是否执行动作。
2,你单片机是全双工的,所以不存在收发状态等待的问题,也就是只要对方有动作,你随时都可以收发,根本不需要信号状态控制,那么就把对端的CTS和RTS和DSR短接在一起就好了,这样对端任何时候有请求都可以直接发送,不需要你单片机确认

