Rafael,
When I implemented the DCB structure in VB.NET I defined Flags as a Private
BitVector32. Then used Property procedures that extracted the individual
values, using the methods of BitVector32.
Public enum RtsControl As Byte
Disable = 0
Enable = 1
Handshake = 2
Toggle = 3
End Enum
Public Structure DBC
...
Private Flags As BitVector32
...
Private Shared Readonly m_fBinary As Integer
Private Shared Readonly m_Parity As Integer
...
Private Shared Readonly m_fRtsControl As BitVector32.Section
...
Shared Sub New()
' create boolean masks
m_fBinary = BitVector32.CreateMask()
...
m_fParity = BitVector32.CreateMask(m_fBinary)
...
' create section masks
Dim previousSection As BitVector32.Section
previousSection = BitVector32.CreateSection(1)
...
m_fRtsControl = BitVector32.CreateSection(3,
previousSection)
...
End Sub
Public Property Binary As Boolean
Get
Return Flags.Item(m_fBinary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fBinary) = value
End Set
End Property
...
Public Property RtsControl As RtsControl
Get
Return CType(Flags.Item(m_fRtsControl), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fRtsControl) = value
End Set
End Property
...
End Structure
BitVector32 is marshaled as an Integer (DWORD) so you can use them
interchangeably.
I made Flags Private as its an implementation detail.
The property procedures expose the flags as the respective types, For
example RtsControl & DtrControl as enums with valid values, others as
Boolean. I had to change a couple names as there is a field & a flag
(ErrorChar).
For the BitVector32 masks I had to make two passes, once for the boolean
values, then a second one for the section (enum) values.
Using the BitVector32 class simplified my property procedures at the
"expense" of a little extra setup (the shared constructor).
I have not posted my class on got dot net yet, as I am still working on
making the WaitEvent async.
Hope this helps
Jay
"Rafael Pivato" <rp*****@cpovo.net> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
I thought that there was an marshall attribute (or something)
that automates the bit flags access.
But, with your advices I think it's better to implement
a wrapper class to access this structure in a easy manner
for the client.
Thanks
"Dick Grier" <di**************@msn.com> escreveu na mensagem
news:uF*************@TK2MSFTNGP10.phx.gbl... Hi,
Your DCB is not correct. It looks like:
typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD Flags;
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;
Flags is bit-mapped, and contains bit-flags that control things like
parity and flow control.
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.