473,770 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# BitVector32 for DCB Struct - any help?

Hi there,

I saw this article here in vb.net.

http://www.error-bank.com/microsoft....92_Thread.aspx

and

http://www.opennetcf.org/forums/post...24&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.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
13 3709
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*

Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
Hi there,

I saw this article here in vb.net.

http://www.error-bank.com/microsoft....92_Thread.aspx
and

http://www.opennetcf.org/forums/post...24&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.
--
Regards,
Chua Wen Ching :)

Nov 16 '05 #2
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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*

Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
Hi there,

I saw this article here in vb.net.

http://www.error-bank.com/microsoft....92_Thread.aspx

and

http://www.opennetcf.org/forums/post...24&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.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #3
H Jay,

2 more question.

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.Cre ateMask()

rather than inside a sub New()

Thanks again.
--
Regards,
Chua Wen Ching :)
"Chua Wen Ching" wrote:
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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*

Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
Hi there,

I saw this article here in vb.net.

http://www.error-bank.com/microsoft....92_Thread.aspx

and

http://www.opennetcf.org/forums/post...24&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.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #4
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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:12******** *************** ***********@mic rosoft.com... 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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*

Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
Hi there,

I saw this article here in vb.net.

http://www.error-bank.com/microsoft....92_Thread.aspx

and

http://www.opennetcf.org/forums/post...24&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.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #5
Hi Jay,

Last 2 question.

1)
Why is there so many repeated code here?

Is there any purpose why you do that?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

and not this?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)

m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )

m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

2)
I also curious, that fRtsControl contains the value of 2, why will you place it as value 3?

Thanks again. I feel so shy asking so many at the time.
--
Regards,
Chua Wen Ching :)
"Chua Wen Ching" wrote:
H Jay,

2 more question.

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.Cre ateMask()

rather than inside a sub New()

Thanks again.
--
Regards,
Chua Wen Ching :)
"Chua Wen Ching" wrote:
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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*

Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
> Hi there,
>
> I saw this article here in vb.net.
>
>
http://www.error-bank.com/microsoft....92_Thread.aspx
>
> and
>
>
http://www.opennetcf.org/forums/post...24&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.
> --
> Regards,
> Chua Wen Ching :)

Nov 16 '05 #6
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.Cre ateMask()

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.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

and not this?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)

m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )

m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:12******** *************** ***********@mic rosoft.com...
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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
Chua Wen Ching,
Have you looked at this thread?

http://groups.google.com/groups?hl=e...ublic.dotnet.*
Here is my complete DCB structure in VB.NET:

Option Strict On
Option Explicit On

Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
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.Sec tion
Private Shared ReadOnly m_fDsrSensitivi ty As Integer
Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
Private Shared ReadOnly m_fAbortOnError As Integer

Shared Sub New()
' Create boolean masks
Dim previosMask As Integer
m_fBinary = BitVector32.Cre ateMask()
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity)
m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
m_fInX = BitVector32.Cre ateMask(m_fOutX )
m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
previosMask = BitVector32.Cre ateMask(m_fNull )
previosMask = BitVector32.Cre ateMask(previos Mask)
m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)

' Create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)
End Sub

#End Region

'DWORD fBinary :1;
Public Property Binary() As Boolean
Get
Return Flags.Item(m_fB inary)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fB inary) = value
End Set
End Property

'DWORD fParity :1;
Public Property CheckParity() As Boolean
Get
Return Flags.Item(m_fP arity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fP arity) = value
End Set
End Property

'DWORD fOutxCtsFlow :1;
Public Property OutxCtsFlow() As Boolean
Get
Return Flags.Item(m_fO utxCtsFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxCtsFlow) = value
End Set
End Property

'DWORD fOutxDsrFlow :1;
Public Property OutxDsrFlow() As Boolean
Get
Return Flags.Item(m_fO utxDsrFlow)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utxDsrFlow) = value
End Set
End Property

'DWORD fDtrControl :2;
Public Property DtrControl() As DtrControl
Get
Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
End Get
Set(ByVal value As DtrControl)
Flags.Item(m_fD trControl) = value
End Set
End Property

'DWORD fDsrSensitivity :1;
Public Property DsrSensitivity( ) As Boolean
Get
Return Flags.Item(m_fD srSensitivity)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fD srSensitivity) = value
End Set
End Property

'DWORD fTXContinueOnXo ff :1;
Public Property TxContinueOnXof f() As Boolean
Get
Return Flags.Item(m_fT XContinueOnXoff )
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fT XContinueOnXoff ) = value
End Set
End Property

'DWORD fOutX :1;
Public Property OutX() As Boolean
Get
Return Flags.Item(m_fO utX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fO utX) = value
End Set
End Property

'DWORD fInX :1;
Public Property InX() As Boolean
Get
Return Flags.Item(m_fI nX)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fI nX) = value
End Set
End Property

'DWORD fErrorChar :1;
Public Property ReplaceErrorCha r() As Boolean
Get
Return Flags.Item(m_fE rrorChar)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fE rrorChar) = value
End Set
End Property

'DWORD fNull :1;
Public Property Null() As Boolean
Get
Return Flags.Item(m_fN ull)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fN ull) = value
End Set
End Property

'DWORD fRtsControl :2;
Public Property RtsControl() As RtsControl
Get
Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
End Get
Set(ByVal value As RtsControl)
Flags.Item(m_fR tsControl) = value
End Set
End Property

'DWORD fAbortOnError :1;
Public Property AbortOnError() As Boolean
Get
Return Flags.Item(m_fA bortOnError)
End Get
Set(ByVal value As Boolean)
Flags.Item(m_fA bortOnError) = 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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:C5******** *************** ***********@mic rosoft.com...
> Hi there,
>
> I saw this article here in vb.net.
>
>
http://www.error-bank.com/microsoft....92_Thread.aspx >
> and
>
>
http://www.opennetcf.org/forums/post...24&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.
> --
> Regards,
> Chua Wen Ching :)


Nov 16 '05 #7
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.Disa ble

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 BitVector32Crea teSection method, it takes the max value
for that field. Hence 3.
Hope this helps
Jay
"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:8B******** *************** ***********@mic rosoft.com... 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.Cre ateMask()

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.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

and not this?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)

m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )

m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:12******** *************** ***********@mic rosoft.com...
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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)

-> in C#, suppose to be:

return (RtsControl) Flags.Item(m_fR tsControl) ???

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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:

> Chua Wen Ching,
> Have you looked at this thread?
>
>

http://groups.google.com/groups?hl=e...%26ie%3DUTF-8%
26q%3DfBinary%2 53A1%26btnG%3DS earch%26meta%3D group%253Dmicro soft.public.dot n
et.* >
> Here is my complete DCB structure in VB.NET:
>
> Option Strict On
> Option Explicit On
>
> Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
> 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.Sec tion
> Private Shared ReadOnly m_fDsrSensitivi ty As Integer
> Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
> Private Shared ReadOnly m_fAbortOnError As Integer
>
> Shared Sub New()
> ' Create boolean masks
> Dim previosMask As Integer
> m_fBinary = BitVector32.Cre ateMask()
> m_fParity = BitVector32.Cre ateMask(m_fBina ry)
> m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
> m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
> previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
> previosMask = BitVector32.Cre ateMask(previos Mask)
> m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
> m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity) > m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
> m_fInX = BitVector32.Cre ateMask(m_fOutX )
> m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
> m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
> previosMask = BitVector32.Cre ateMask(m_fNull )
> previosMask = BitVector32.Cre ateMask(previos Mask)
> m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)
>
> ' Create section masks
> Dim previousSection As BitVector32.Sec tion
> previousSection = BitVector32.Cre ateSection(1)
> previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > m_fDtrControl = BitVector32.Cre ateSection(2, previousSection ) > previousSection = BitVector32.Cre ateSection(1, m_fDtrControl) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > previousSection = BitVector32.Cre ateSection(1, previousSection ) > m_fRtsControl = BitVector32.Cre ateSection(3, previousSection ) > previousSection = BitVector32.Cre ateSection(1, m_fRtsControl) > End Sub
>
> #End Region
>
> 'DWORD fBinary :1;
> Public Property Binary() As Boolean
> Get
> Return Flags.Item(m_fB inary)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fB inary) = value
> End Set
> End Property
>
> 'DWORD fParity :1;
> Public Property CheckParity() As Boolean
> Get
> Return Flags.Item(m_fP arity)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fP arity) = value
> End Set
> End Property
>
> 'DWORD fOutxCtsFlow :1;
> Public Property OutxCtsFlow() As Boolean
> Get
> Return Flags.Item(m_fO utxCtsFlow)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fO utxCtsFlow) = value
> End Set
> End Property
>
> 'DWORD fOutxDsrFlow :1;
> Public Property OutxDsrFlow() As Boolean
> Get
> Return Flags.Item(m_fO utxDsrFlow)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fO utxDsrFlow) = value
> End Set
> End Property
>
> 'DWORD fDtrControl :2;
> Public Property DtrControl() As DtrControl
> Get
> Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
> End Get
> Set(ByVal value As DtrControl)
> Flags.Item(m_fD trControl) = value
> End Set
> End Property
>
> 'DWORD fDsrSensitivity :1;
> Public Property DsrSensitivity( ) As Boolean
> Get
> Return Flags.Item(m_fD srSensitivity)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fD srSensitivity) = value
> End Set
> End Property
>
> 'DWORD fTXContinueOnXo ff :1;
> Public Property TxContinueOnXof f() As Boolean
> Get
> Return Flags.Item(m_fT XContinueOnXoff )
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fT XContinueOnXoff ) = value
> End Set
> End Property
>
> 'DWORD fOutX :1;
> Public Property OutX() As Boolean
> Get
> Return Flags.Item(m_fO utX)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fO utX) = value
> End Set
> End Property
>
> 'DWORD fInX :1;
> Public Property InX() As Boolean
> Get
> Return Flags.Item(m_fI nX)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fI nX) = value
> End Set
> End Property
>
> 'DWORD fErrorChar :1;
> Public Property ReplaceErrorCha r() As Boolean
> Get
> Return Flags.Item(m_fE rrorChar)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fE rrorChar) = value
> End Set
> End Property
>
> 'DWORD fNull :1;
> Public Property Null() As Boolean
> Get
> Return Flags.Item(m_fN ull)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fN ull) = value
> End Set
> End Property
>
> 'DWORD fRtsControl :2;
> Public Property RtsControl() As RtsControl
> Get
> Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
> End Get
> Set(ByVal value As RtsControl)
> Flags.Item(m_fR tsControl) = value
> End Set
> End Property
>
> 'DWORD fAbortOnError :1;
> Public Property AbortOnError() As Boolean
> Get
> Return Flags.Item(m_fA bortOnError)
> End Get
> Set(ByVal value As Boolean)
> Flags.Item(m_fA bortOnError) = 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
>
> "Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message > news:C5******** *************** ***********@mic rosoft.com...
> > Hi there,
> >
> > I saw this article here in vb.net.
> >
> >
>

http://www.error-bank.com/microsoft....92_Thread.aspx
> >
> > and
> >
> >
>

http://www.opennetcf.org/forums/post...24&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.
> > --
> > Regards,
> > Chua Wen Ching :)
>
>
>


Nov 16 '05 #8
Hi Jay,

Thanks again. I had couple more questions to confirm.

1)

The order here:

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 fTXContinueOnXo ff: 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 BitVector32Crea teSection method, it takes the max value
for that field. Hence 3.
--> I had checked the msdn here

http://msdn.microsoft.com/library/de...ctiontopic.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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
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.Disa ble

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 BitVector32Crea teSection method, it takes the max value
for that field. Hence 3.
Hope this helps
Jay
"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
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.Cre ateMask()

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.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

and not this?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)

m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )

m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:12******** *************** ***********@mic rosoft.com...
> 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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)
>
> -> in C#, suppose to be:
>
> return (RtsControl) Flags.Item(m_fR tsControl) ???
>
> 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 :)
>
>
> "Jay B. Harlow [MVP - Outlook]" wrote:
>
> > Chua Wen Ching,
> > Have you looked at this thread?
> >
> >
http://groups.google.com/groups?hl=e...%26ie%3DUTF-8%
26q%3DfBinary%2 53A1%26btnG%3DS earch%26meta%3D group%253Dmicro soft.public.dot n
et.* > >
> > Here is my complete DCB structure in VB.NET:
> >
> > Option Strict On
> > Option Explicit On
> >
> > Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
> > 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.Sec tion
> > Private Shared ReadOnly m_fDsrSensitivi ty As Integer
> > Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
> > Private Shared ReadOnly m_fAbortOnError As Integer
> >
> > Shared Sub New()
> > ' Create boolean masks
> > Dim previosMask As Integer
> > m_fBinary = BitVector32.Cre ateMask()
> > m_fParity = BitVector32.Cre ateMask(m_fBina ry)
> > m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
> > m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
> > previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
> > previosMask = BitVector32.Cre ateMask(previos Mask)
> > m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
> > m_fTXContinueOn Xoff = BitVector32.Cre ateMask(m_fDsrS ensitivity) > > m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
> > m_fInX = BitVector32.Cre ateMask(m_fOutX )
> > m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
> > m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
> > previosMask = BitVector32.Cre ateMask(m_fNull )
> > previosMask = BitVector32.Cre ateMask(previos Mask)
> > m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)
> >
> > ' Create section masks
> > Dim previousSection As BitVector32.Sec tion
> > previousSection = BitVector32.Cre ateSection(1)
> > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > m_fDtrControl = BitVector32.Cre ateSection(2, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, m_fDtrControl) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, previousSection ) > > m_fRtsControl = BitVector32.Cre ateSection(3, previousSection ) > > previousSection = BitVector32.Cre ateSection(1, m_fRtsControl) > > End Sub
> >
> > #End Region
> >
> > 'DWORD fBinary :1;
> > Public Property Binary() As Boolean
> > Get
> > Return Flags.Item(m_fB inary)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fB inary) = value
> > End Set
> > End Property
> >
> > 'DWORD fParity :1;
> > Public Property CheckParity() As Boolean
> > Get
> > Return Flags.Item(m_fP arity)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fP arity) = value
> > End Set
> > End Property
> >
> > 'DWORD fOutxCtsFlow :1;
> > Public Property OutxCtsFlow() As Boolean
> > Get
> > Return Flags.Item(m_fO utxCtsFlow)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fO utxCtsFlow) = value
> > End Set
> > End Property
> >
> > 'DWORD fOutxDsrFlow :1;
> > Public Property OutxDsrFlow() As Boolean
> > Get
> > Return Flags.Item(m_fO utxDsrFlow)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fO utxDsrFlow) = value
> > End Set
> > End Property
> >
> > 'DWORD fDtrControl :2;
> > Public Property DtrControl() As DtrControl
> > Get
> > Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
> > End Get
> > Set(ByVal value As DtrControl)
> > Flags.Item(m_fD trControl) = value
> > End Set
> > End Property
> >
> > 'DWORD fDsrSensitivity :1;
> > Public Property DsrSensitivity( ) As Boolean
> > Get
> > Return Flags.Item(m_fD srSensitivity)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fD srSensitivity) = value
> > End Set
> > End Property
> >
> > 'DWORD fTXContinueOnXo ff :1;
> > Public Property TxContinueOnXof f() As Boolean
> > Get
> > Return Flags.Item(m_fT XContinueOnXoff )
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fT XContinueOnXoff ) = value
> > End Set
> > End Property
> >
> > 'DWORD fOutX :1;
> > Public Property OutX() As Boolean
> > Get
> > Return Flags.Item(m_fO utX)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fO utX) = value
> > End Set
> > End Property
> >
> > 'DWORD fInX :1;
> > Public Property InX() As Boolean
> > Get
> > Return Flags.Item(m_fI nX)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fI nX) = value
> > End Set
> > End Property
> >
> > 'DWORD fErrorChar :1;
> > Public Property ReplaceErrorCha r() As Boolean
> > Get
> > Return Flags.Item(m_fE rrorChar)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fE rrorChar) = value
> > End Set
> > End Property
> >
> > 'DWORD fNull :1;
> > Public Property Null() As Boolean
> > Get
> > Return Flags.Item(m_fN ull)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fN ull) = value
> > End Set
> > End Property
> >
> > 'DWORD fRtsControl :2;
> > Public Property RtsControl() As RtsControl
> > Get
> > Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
> > End Get
> > Set(ByVal value As RtsControl)
> > Flags.Item(m_fR tsControl) = value
> > End Set
> > End Property
> >
> > 'DWORD fAbortOnError :1;
> > Public Property AbortOnError() As Boolean
> > Get
> > Return Flags.Item(m_fA bortOnError)
> > End Get
> > Set(ByVal value As Boolean)
> > Flags.Item(m_fA bortOnError) = 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
> >
> > "Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message > > news:C5******** *************** ***********@mic rosoft.com...
> > > Hi there,
> > >
> > > I saw this article here in vb.net.
> > >
> > >
> >
http://www.error-bank.com/microsoft....92_Thread.aspx > > >
> > > and
> > >
> > >
> >
http://www.opennetcf.org/forums/post...24&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.
> > > --
> > > Regards,
> > > Chua Wen Ching :)
> >
> >
> >


Nov 16 '05 #9
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/de...tionTopic1.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

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:97******** *************** ***********@mic rosoft.com...
Hi Jay,

Thanks again. I had couple more questions to confirm.

1)

The order here:

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
previousSection = BitVector32.Cre ateSection(1, previousSection )
m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 fTXContinueOnXo ff: 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 BitVector32Crea teSection method, it takes the max value for that field. Hence 3.
--> I had checked the msdn here

http://msdn.microsoft.com/library/de...ctiontopic.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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:
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.Disa ble

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 BitVector32Crea teSection method, it takes the max value for that field. Hence 3.
Hope this helps
Jay
"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
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.Cre ateMask()
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.Sec tion
previousSection = BitVector32.Cre ateSection(1)
previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fDtrControl)
previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) previousSection = BitVector32.Cre ateSection(1, previousSection ) m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(1, m_fRtsControl)

and not this?

Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)

m_fDtrControl = BitVector32.Cre ateSection(2, previousSection )

m_fRtsControl = BitVector32.Cre ateSection(3, previousSection )
previousSection = BitVector32.Cre ateSection(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 :)
"Jay B. Harlow [MVP - Outlook]" wrote:

> 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
>
> "Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message > news:12******** *************** ***********@mic rosoft.com...
> > 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.(intellis ense, 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.Ite m(m_fRtsControl ), RtsControl)
> >
> > -> in C#, suppose to be:
> >
> > return (RtsControl) Flags.Item(m_fR tsControl) ???
> >
> > 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 :)
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" wrote:
> >
> > > Chua Wen Ching,
> > > Have you looked at this thread?
> > >
> > >
>

http://groups.google.com/groups?hl=e...%26ie%3DUTF-8% 26q%3DfBinary%2 53A1%26btnG%3DS earch%26meta%3D group%253Dmicro soft.public.dot n et.*
> > >
> > > Here is my complete DCB structure in VB.NET:
> > >
> > > Option Strict On
> > > Option Explicit On
> > >
> > > Imports System.Collecti ons.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(L ayoutKind.Seque ntial)> _
> > > 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.Sec tion
> > > Private Shared ReadOnly m_fDsrSensitivi ty As Integer
> > > Private Shared ReadOnly m_fTXContinueOn Xoff 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.Sec tion
> > > Private Shared ReadOnly m_fAbortOnError As Integer
> > >
> > > Shared Sub New()
> > > ' Create boolean masks
> > > Dim previosMask As Integer
> > > m_fBinary = BitVector32.Cre ateMask()
> > > m_fParity = BitVector32.Cre ateMask(m_fBina ry)
> > > m_fOutxCtsFlow = BitVector32.Cre ateMask(m_fPari ty)
> > > m_fOutxDsrFlow = BitVector32.Cre ateMask(m_fOutx CtsFlow)
> > > previosMask = BitVector32.Cre ateMask(m_fOutx DsrFlow)
> > > previosMask = BitVector32.Cre ateMask(previos Mask)
> > > m_fDsrSensitivi ty = BitVector32.Cre ateMask(previos Mask)
> > > m_fTXContinueOn Xoff =

BitVector32.Cre ateMask(m_fDsrS ensitivity)
> > > m_fOutX = BitVector32.Cre ateMask(m_fTXCo ntinueOnXoff)
> > > m_fInX = BitVector32.Cre ateMask(m_fOutX )
> > > m_fErrorChar = BitVector32.Cre ateMask(m_fInX)
> > > m_fNull = BitVector32.Cre ateMask(m_fErro rChar)
> > > previosMask = BitVector32.Cre ateMask(m_fNull )
> > > previosMask = BitVector32.Cre ateMask(previos Mask)
> > > m_fAbortOnError = BitVector32.Cre ateMask(previos Mask)
> > >
> > > ' Create section masks
> > > Dim previousSection As BitVector32.Sec tion
> > > previousSection = BitVector32.Cre ateSection(1)
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > m_fDtrControl = BitVector32.Cre ateSection(2,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

m_fDtrControl)
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

previousSection )
> > > m_fRtsControl = BitVector32.Cre ateSection(3,

previousSection )
> > > previousSection = BitVector32.Cre ateSection(1,

m_fRtsControl)
> > > End Sub
> > >
> > > #End Region
> > >
> > > 'DWORD fBinary :1;
> > > Public Property Binary() As Boolean
> > > Get
> > > Return Flags.Item(m_fB inary)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fB inary) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fParity :1;
> > > Public Property CheckParity() As Boolean
> > > Get
> > > Return Flags.Item(m_fP arity)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fP arity) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fOutxCtsFlow :1;
> > > Public Property OutxCtsFlow() As Boolean
> > > Get
> > > Return Flags.Item(m_fO utxCtsFlow)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fO utxCtsFlow) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fOutxDsrFlow :1;
> > > Public Property OutxDsrFlow() As Boolean
> > > Get
> > > Return Flags.Item(m_fO utxDsrFlow)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fO utxDsrFlow) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fDtrControl :2;
> > > Public Property DtrControl() As DtrControl
> > > Get
> > > Return CType(Flags.Ite m(m_fDtrControl ), DtrControl)
> > > End Get
> > > Set(ByVal value As DtrControl)
> > > Flags.Item(m_fD trControl) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fDsrSensitivity :1;
> > > Public Property DsrSensitivity( ) As Boolean
> > > Get
> > > Return Flags.Item(m_fD srSensitivity)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fD srSensitivity) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fTXContinueOnXo ff :1;
> > > Public Property TxContinueOnXof f() As Boolean
> > > Get
> > > Return Flags.Item(m_fT XContinueOnXoff )
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fT XContinueOnXoff ) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fOutX :1;
> > > Public Property OutX() As Boolean
> > > Get
> > > Return Flags.Item(m_fO utX)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fO utX) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fInX :1;
> > > Public Property InX() As Boolean
> > > Get
> > > Return Flags.Item(m_fI nX)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fI nX) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fErrorChar :1;
> > > Public Property ReplaceErrorCha r() As Boolean
> > > Get
> > > Return Flags.Item(m_fE rrorChar)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fE rrorChar) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fNull :1;
> > > Public Property Null() As Boolean
> > > Get
> > > Return Flags.Item(m_fN ull)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fN ull) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fRtsControl :2;
> > > Public Property RtsControl() As RtsControl
> > > Get
> > > Return CType(Flags.Ite m(m_fRtsControl ), RtsControl)
> > > End Get
> > > Set(ByVal value As RtsControl)
> > > Flags.Item(m_fR tsControl) = value
> > > End Set
> > > End Property
> > >
> > > 'DWORD fAbortOnError :1;
> > > Public Property AbortOnError() As Boolean
> > > Get
> > > Return Flags.Item(m_fA bortOnError)
> > > End Get
> > > Set(ByVal value As Boolean)
> > > Flags.Item(m_fA bortOnError) = 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
> > >
> > > "Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in

message
> > > news:C5******** *************** ***********@mic rosoft.com...
> > > > Hi there,
> > > >
> > > > I saw this article here in vb.net.
> > > >
> > > >
> > >
>

http://www.error-bank.com/microsoft....92_Thread.aspx > > > >
> > > > and
> > > >
> > > >
> > >
>

http://www.opennetcf.org/forums/post...24&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.
> > > > --
> > > > Regards,
> > > > Chua Wen Ching :)
> > >
> > >
> > >
>
>
>


Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2061
by: Angelo Secchi | last post by:
I'm trying to use the unpack method in the struct module to parse a binary file without success. I have a binary file with records that include many fields for a total length of 1970. Few days ago I was suggested by the list to use the struct module to parse it using the following code in the hypothesis that for each records I have just two fields: import struct fmt='10s1960s' size=struct.calcsize(fmt)
4
5603
by: Angus Comber | last post by:
Hello I have received a lot of help on my little project here. Many thanks. I have a struct with a string and a long member. I have worked out how to qsort the struct on both members. I can do a bsearch on the long member (nKey) but I am struggling to do a search using the string member. The code I am running appears below. It doesn't crash or anything. It is just that when I do the last bsearch using "192.168.1.3" I SHOULD find...
20
2975
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes) struct, I am storing an array of 27 pointers and a void pointer that can point to anything. typedef struct trieNode { struct trieNode *children; // The children nodes void *obj; // The object stored } TrieNode;
2
2468
by: Arne Styve | last post by:
Hi, I have an API written in C that came with some graphics cards we are going to use in a project. I need to write a small application where this API is to be used, and I decided to try out C#. The API is imported by using the ; unsigned short DeviceType; unsigned long Reserved0; unsigned long Reserved1;
28
3067
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
4
2141
by: JR | last post by:
I need some help. I am trying to return a dirent struct location so i can access what the function found in main(). I dont understand pointers very well and think that is were i am getting it wrong. If i print everything from getdirlist everything is fine. I just cant pass along the namelist scandir creates. Any help would be great. JR
9
5717
by: sean.scanlon | last post by:
can someone help understand how i can could access a struct field dymanically like: foo->fields ? when i try to compile this i get the following error: 'struct pwd' has no member named 'fields' is there a way to treat fields as the member name of the struct?
5
2131
by: =?Utf-8?B?SGFucw==?= | last post by:
Hello, I need some help on the BitVector32 class. I'm trying to create a function like: Private Sub Function (ByVal Input as integer, ByVal Bitnr as integer, ByVal BitHigh as Boolean) As Integer Return Output
4
2425
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the function "int reg(struct Member listm, int msize);", the data Ive entered was not stored in the array. #include <stdio.h> #include <conio.h> #include <string.h>
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.