在調(diào)試ICU通信設(shè)備的時(shí)候,由于串口通信老出現(xiàn)故障,所以就懷疑CF實(shí)現(xiàn)的SerialPort類是否有問(wèn)題,所以最后決定用純API函數(shù)實(shí)現(xiàn)串口讀寫。
C#通訊調(diào)試工具主要功能
1、串口,TCP服務(wù)端/客戶端,UDP服務(wù)端/客戶端通訊調(diào)試;
2、支持Hex,ASCII兩種格式的命令調(diào)試;
3、接收數(shù)據(jù)可通過(guò)右鍵菜單一鍵計(jì)算Hex對(duì)應(yīng)的數(shù)值;
4、字節(jié)計(jì)算器/檢驗(yàn)值計(jì)算器(CRC16,自定義多項(xiàng)式CRC16,XOR)。
其實(shí)這個(gè)示例代碼是有問(wèn)題的,也就是說(shuō)DCB結(jié)構(gòu)體聲明的有問(wèn)題,雖然該代碼可以正常通信,不過(guò)如果你設(shè)置了奇偶校驗(yàn)的話,你會(huì)發(fā)現(xiàn)奇偶校驗(yàn)無(wú)效。
VC中的DCB結(jié)構(gòu)聲明如下:
typedef struct _DCB {
DWORD DCBlength; /* sizeof(DCB) */
DWORD BaudRate; /* Baudrate at which running */
DWORD fBinary: 1; /* Binary Mode (skip EOF check) */
DWORD fParity: 1; /* Enable parity checking */
DWORD fOutxCtsFlow:1; /* CTS handshaking on output */
DWORD fOutxDsrFlow:1; /* DSR handshaking on output */
DWORD fDtrControl:2; /* DTR Flow control */
DWORD fDsrSensitivity:1; /* DSR Sensitivity */
DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
DWORD fOutX: 1; /* Enable output X-ON/X-OFF */
DWORD fInX: 1; /* Enable input X-ON/X-OFF */
DWORD fErrorChar: 1; /* Enable Err Replacement */
DWORD fNull: 1; /* Enable Null stripping */
DWORD fRtsControl:2; /* Rts Flow control */
DWORD fAbortOnError:1; /* Abort all reads and writes on Error */
DWORD fDummy2:17; /* Reserved */
WORD wReserved; /* Not currently used */
WORD XonLim; /* Transmit X-ON threshold */
WORD XoffLim; /* Transmit X-OFF threshold */
BYTE ByteSize; /* Number of bits/byte, 4-8 */
BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */
BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */
char XonChar; /* Tx and Rx X-ON character */
char XoffChar; /* Tx and Rx X-OFF character */
char ErrorChar; /* Error replacement char */
char EofChar; /* End of Input character */
char EvtChar; /* Received Event character */
WORD wReserved1; /* Fill for now. */
} DCB, *LPDCB;
- PC官方版
- 安卓官方手機(jī)版
- IOS官方手機(jī)版