Chua Wen Ching,
1) Yes the order is related to the C structure.
2) Read the help again, specifically the NEXT page (from the one you gave):
http://msdn.microsoft.com/library/d...alizedBitVector32ClassCreateSectionTopic1.asp
3) fDummy is filler, unless you have a need to fill it with something, yes
you can leave it off...
Hope this helps
Jay
Hi Jay,
Thanks again. I had couple more questions to confirm.
1)
The order here:
Dim previousSection As BitVector32.Section
previousSection = BitVector32.CreateSection(1)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
m_fDtrControl = BitVector32.CreateSection(2, previousSection)
previousSection = BitVector32.CreateSection(1, m_fDtrControl)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
previousSection = BitVector32.CreateSection(1, previousSection)
m_fRtsControl = BitVector32.CreateSection(3, previousSection)
previousSection = BitVector32.CreateSection(1, m_fRtsControl)
is related to the C structure (am i right?):
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 */
2)
I can see the order, but hmm, why fRtsControl is still 3 instead of 2.
You say that:
Read the help on the BitVector32CreateSection method, it takes the max
value
for that field. Hence 3.
--> I had checked the msdn here
http://msdn.microsoft.com/library/d...ializedbitvector32classcreatesectiontopic.asp
I don't see it why it must be 3?
3) I notice you left out:
DWORD fDummy 2:17;
why? Can we just left out the bit flag just like that?
Thanks for taking the time to reply.

--
Regards,
Chua Wen Ching
:
Chua Wen Ching,
1) Can you give me an example of vb.net of how you call that
structure?
Just say i want to assign value of true and false to each of those.
Dim dcb As DCB
dcb.Binary = true
dcb.DtrControl = DtrControl.Disable
If dcb.Binary Then
' do something exciting
End if
2) I still not sure why is shared sub New(), there, why can't i
initialize
everything inside the structure, example:
Two reasons:
1 - the previousSection local variable
2 - the static constructor ensures on the order of the
initialization
(both in relation to each field and in relation to any constructors).
Also I rarely using field initialization for member fields, I almost
always
use constructors to initialize member fields. However local variables I
will
use initialization on...
Why is there so many repeated code here?
Look at the C++ structure fDtrControl is in the 5 bit, if you skip the
first
4 CreateSections, then fDtrControl would be in the first bit.
I also curious, that fRtsControl contains the value of 2, why will you
place it as value 3?
Read the help on the BitVector32CreateSection method, it takes the max
value
for that field. Hence 3.
Hope this helps
Jay
Hi Jay,
I had 4 more questions on the previous threads. I wll copy paste it
here
again:
1) Can you give me an example of vb.net of how you call that
structure?
Just say i want to assign value of true and false to each of those.
Please help! I am trying to think how to use it in my client app side.
2) I still not sure why is shared sub New(), there, why can't i
initialize
everything inside the structure, example:
private shared readonly m_fbinary as integer =
BitVector32.CreateMask()
rather than inside a sub New()
3)
Why is there so many repeated code here?
Is there any purpose why you do that?
Dim previousSection As BitVector32.Section
previousSection = BitVector32.CreateSection(1)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
m_fDtrControl = BitVector32.CreateSection(2, previousSection)
previousSection = BitVector32.CreateSection(1, m_fDtrControl)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
m_fRtsControl = BitVector32.CreateSection(3, previousSection)
previousSection = BitVector32.CreateSection(1, m_fRtsControl)
and not this?
Dim previousSection As BitVector32.Section
previousSection = BitVector32.CreateSection(1)
m_fDtrControl = BitVector32.CreateSection(2, previousSection)
m_fRtsControl = BitVector32.CreateSection(3, previousSection)
previousSection = BitVector32.CreateSection(1, m_fRtsControl)
4)
I also curious, that fRtsControl contains the value of 2, why will you
place it as value 3?
Thanks a lot.
--
Regards,
Chua Wen Ching
:
Chua,
I even email you through your blog.
I do not respond to private emails. If I did respond to a private
email
only
you would benefit, others wanting to know the answer will not see
it.
Thanks
for understanding.
1) How do i get Flags.Item()?
In VB.NET Item is the indexer, VB.NET allows including or excluding
Item
return (RtsControl) Flags[m_fRtsControl]
2) In the FXCop rules, it recommends me not to use the static void
New(),
Are you calling it "New" or are you calling it DCB? "Shared Sub New"
is
a
static constructor you need to use valid C# syntax for the static
constructors (I believe it should be "static DCB()").
My sample "requires" a static constructor I'm not sure why FXCop
would
complain about a static constructor...
3)
-> in C#
return (RtsControl) Flags[m_fRtsControl]
a) first it can't identify Flags.Item
b) second, cannot cast from BitVector to RtsControl, i assume
RtsControl
is a enum
RtsControl is an enum...
Hope this helps
Jay
message
Hi Jay,
Thanks a lot. I read all those threads already. I even email you
through
your blog.
Ok i had a few doubts:
1) How do i get Flags.Item()?
When i do this:
BitVector Flags;
Flags.(intellisense, i can't find Item() ).. any idea? Thanks.
2)
In the FXCop rules, it recommends me not to use the static void
New(),
ask
me to prevent to use static inside structure. Any idea why? Coz you
used
shared sub new().
3)
Return CType(Flags.Item(m_fRtsControl), RtsControl)
-> in C#, suppose to be:
return (RtsControl) Flags.Item(m_fRtsControl) ???
a) first it can't identify Flags.Item
b) second, cannot cast from BitVector to RtsControl, i assume
RtsControl
is a enum
Thanks for the help!
--
Regards,
Chua Wen Ching
:
Chua Wen Ching,
Have you looked at this thread?
http://groups.google.com/groups?hl=...x.gbl&rnum=7&prev=/groups?hl=en&lr=&ie=UTF-8%
26q%3DfBinary%253A1%26btnG%3DSearch%26meta%3Dgroup%253Dmicrosoft.public.dotn
et.*
Here is my complete DCB structure in VB.NET:
Option Strict On
Option Explicit On
Imports System.Collections.Specialized
Imports System.Runtime.InteropServices
Public Enum DtrControl As Byte
Disable = &H0
Enable = &H1
Handshake = &H2
End Enum
Public Enum RtsControl As Byte
Disable = &H0
Enable = &H1
Handshake = &H2
Toggle = &H3
End Enum
Public Enum Parity As Byte
None = 0
Odd = 1
Even = 2
Mark = 3
Space = 4
End Enum
Public Enum StopBits As Byte
One = 0
One5 = 1
Two = 2
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure DCB
Public Size As Int32
Public BaudRate As Int32
Private Flags As BitVector32
Private Reserved As Int16
Public XonLim As Int16
Public XoffLim As Int16
Public ByteSize As Byte
Public Parity As Parity
Public StopBits As StopBits
Public XonChar As Byte
Public XoffChar As Byte
Public ErrorChar As Byte
Public EofChar As Byte
Public EvtChar As Byte
Private Reserved1 As Int16
#Region " Shared Flags support "
Private Shared ReadOnly m_fBinary As Integer
Private Shared ReadOnly m_fParity As Integer
Private Shared ReadOnly m_fOutxCtsFlow As Integer
Private Shared ReadOnly m_fOutxDsrFlow As Integer
Private Shared ReadOnly m_fDtrControl As BitVector32.Section
Private Shared ReadOnly m_fDsrSensitivity As Integer
Private Shared ReadOnly m_fTXContinueOnXoff As Integer
Private Shared ReadOnly m_fOutX As Integer
Private Shared ReadOnly m_fInX As Integer
Private Shared ReadOnly m_fErrorChar As Integer
Private Shared ReadOnly m_fNull As Integer
Private Shared ReadOnly m_fRtsControl As BitVector32.Section
Private Shared ReadOnly m_fAbortOnError As Integer
Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.CreateMask()
m_fParity = BitVector32.CreateMask(m_fBinary)
m_fOutxCtsFlow = BitVector32.CreateMask(m_fParity)
m_fOutxDsrFlow = BitVector32.CreateMask(m_fOutxCtsFlow)
previosMask = BitVector32.CreateMask(m_fOutxDsrFlow)
previosMask = BitVector32.CreateMask(previosMask)
m_fDsrSensitivity = BitVector32.CreateMask(previosMask)
m_fTXContinueOnXoff =
BitVector32.CreateMask(m_fDsrSensitivity)
m_fOutX = BitVector32.CreateMask(m_fTXContinueOnXoff)
m_fInX = BitVector32.CreateMask(m_fOutX)
m_fErrorChar = BitVector32.CreateMask(m_fInX)
m_fNull = BitVector32.CreateMask(m_fErrorChar)
previosMask = BitVector32.CreateMask(m_fNull)
previosMask = BitVector32.CreateMask(previosMask)
m_fAbortOnError = BitVector32.CreateMask(previosMask)
' Create section masks
Dim previousSection As BitVector32.Section
previousSection = BitVector32.CreateSection(1)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
m_fDtrControl = BitVector32.CreateSection(2,
previousSection)
previousSection = BitVector32.CreateSection(1,
m_fDtrControl)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
previousSection = BitVector32.CreateSection(1,
previousSection)
m_fRtsControl = BitVector32.CreateSection(3,
previousSection)
previousSection = BitVector32.CreateSection(1,
m_fRtsControl)
End Sub
#End Region
'DWORD fBinary :1;
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
'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fParity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fParity) = value
End Set
End Property
'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fOutxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fOutxCtsFlow) = value
End Set
End Property
'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fOutxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fOutxDsrFlow) = value
End Set
End Property
'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Item(m_fDtrControl), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fDtrControl) = value
End Set
End Property
'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity() As Boolean
Get
Return Flags.Item(m_fDsrSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fDsrSensitivity) = value
End Set
End Property
'DWORD fTXContinueOnXoff :1;
Public Property TxContinueOnXoff() As Boolean
Get
Return Flags.Item(m_fTXContinueOnXoff)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fTXContinueOnXoff) = value
End Set
End Property
'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fOutX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fOutX) = value
End Set
End Property
'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fInX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fInX) = value
End Set
End Property
'DWORD fErrorChar :1;
Public Property ReplaceErrorChar() As Boolean
Get
Return Flags.Item(m_fErrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fErrorChar) = value
End Set
End Property
'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fNull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fNull) = value
End Set
End Property
'DWORD fRtsControl :2;
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
'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fAbortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fAbortOnError) = value
End Set
End Property
End Structure
The VB.NET code should be easily converted to C#, post if you
need
help.
Hope this helps
Jay
message
Hi there,
I saw this article here in vb.net.
http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx
and
http://www.opennetcf.org/forums/post.asp?method=ReplyQuote&REPLY_ID=3922&TOPIC_ID=2224&FORUM_ID=35
But i had a question.
Can anyone show me how to code the part, for example:
DWORD fBinary:1;
DWORD fParity:1;
DWORD fOutxCtsFlow:1;
DWORD fOutxDsrFlow:1;
DWORD fDtrControl:2;
...
...
I am not that sure. If more examples, i will know what to do
next.
Coz
the
author just skip off to RTS.
Please help! Thanks.