C# 怎样设置RTS和DTR
答案:2 悬赏:70
解决时间 2021-03-05 22:57
- 提问者网友:雨之落き
- 2021-03-05 07:57
C# 怎样设置RTS和DTR
最佳答案
- 二级知识专家网友:都不是誰的誰
- 2021-03-05 09:06
设置波特率用这个函数
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;
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;
全部回答
- 1楼网友:情战凌云蔡小葵
- 2021-03-05 09:39
看一下windows api 里面的setcommstate函数
pc与单片机的通讯一般都是3线制的,即rxd txd gnd,
dsr与dtr没有连接,理论上没什么影响
一般的通讯设置都是
波特率,校验位,长度,停止位
常用的都是 9600,0,8,1 等,看看你的校验位,长度,停止位pc上设置的是否与单片机相符
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯