补充:
测试了一下使用左面的结构定义,使用字符串(baud=1111 parity=E data=8 stop=1)构造DCB只能改变波特率,对校验方式无效
可以用构造后用xDCB.parity=E来解决
右面的结构上面的对校验位有效,但是操作errorchar之类的比较麻烦
----------------------------------------------------------------------------------------------------------------------------------
下面两个DCB结构网上流传很广
其实在XP + VB6环境下右边这个才是准确的
虽然左边这个可以用于设置某些串口参数,但是要进行一些更深入的设置就会出问题,不报错但是设置不起作用
fBitFields:
' The fourteen actual DCB bit-sized data fields within the four bytes of fBitFields can be manipulated by bitwise logical And/Or operations.
' FieldName Bit # Description
' ----------------- ----- ------------------------------
' fBinary 1 1 binary mode,no EOF check
' fParity 2 1 enable parity checking
' fOutxCtsFlow 3 0 CTS output flow control
' fOutxDsrFlow 4 0 DSR output flow control
' fDtrControl 5 0 DTR flow control type (2 bits)
' fDsrSensitivity 7 0 DSR sensitivity
' fTXContinueOnXoff 8 0 XOFF continues Tx
' fOutX 9 0 XON/XOFF out flow control
' fInX 10 0 XON/XOFF in flow control
' fErrorChar 11 1 enable error replacement
' fNull 12 1 enable null stripping
' fRtsControl 13 0 RTS flow control (2 bits)
' fAbortOnError 15 1 abort reads/writes on error
' fDummy2 16 0 reserved
Type DCB Type DCB DCBlength As Long DCBlength As Long BaudRate As Long BaudRate As Long fBinary As Long fBitFields As Long fParity As Long wReserved As Integer fOutxCtsFlow As Long XonLim As Integer fOutxDsrFlow As Long XoffLim As Integer fDtrControl As Long ByteSize As Byte fDsrSensitivity As Long Parity As Byte fTXContinueOnXoff As Long StopBits As Byte fOutX As Long XonChar As Byte fInX As Long XoffChar As Byte fErrorChar As Long ErrorChar As Byte fNull As Long EofChar As Byte fRtsControl As Long EvtChar As Byte fAbortOnError As Long wReserved1 As Integer 'Reserved; Do Not Use fDummy2 As Long End Type wReserved As Integer XonLim As Integer XoffLim As Integer ByteSize As Byte Parity As Byte StopBits As Byte XonChar As Byte XoffChar As Byte ErrorChar As Byte EofChar As Byte EvtChar As Byte End Type
原文链接:https://www.f2er.com/vb/261061.html