473,804 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serial DCB Win32 Structure

I need help declaring this structure in VB.
Particularly the bit flags, like fOutxCtsFlow.
typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD fBinary:1;
DWORD fParity:1;
DWORD fOutxCtsFlow:1;
DWORD fOutxDsrFlow:1;
DWORD fDtrControl:2;
DWORD fDsrSensitivity :1;
DWORD fTXContinueOnXo ff:1;
DWORD fOutX: 1;
DWORD fInX: 1;
DWORD fErrorChar:1;
DWORD fNull:1;
DWORD fRtsControl:2;
DWORD fAbortOnError:1 ;
DWORD fDummy2:17;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;
------------------
Thanks,
Rafael Pivato
Nov 20 '05 #1
5 6200
Rafael,

Structure DCB
Public DCBlength, BaudRate, Flags As Integer
Public wReserved, XonLim, XoffLim As Short
Public ByteSize, Parity, StopBits, XonChar As Byte
Public XoffChar, ErrorChar, EofChar, EvtChar As Byte
Public wReserved1 As Short
End Structure

You'll have to use the bit operators to retrieve the separate flags in
the Flags member (or you could define an Enum with the corresponding
bit values).

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2
Hi,

Your DCB is not correct. It looks like:

typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD Flags;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;

Flags is bit-mapped, and contains bit-flags that control things like parity
and flow control.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
Nov 20 '05 #3
I thought that there was an marshall attribute (or something)
that automates the bit flags access.

But, with your advices I think it's better to implement
a wrapper class to access this structure in a easy manner
for the client.

Thanks

"Dick Grier" <di************ **@msn.com> escreveu na mensagem
news:uF******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

Your DCB is not correct. It looks like:

typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD Flags;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;

Flags is bit-mapped, and contains bit-flags that control things like parity and flow control.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.

Nov 20 '05 #4
Rafael,
When I implemented the DCB structure in VB.NET I defined Flags as a Private
BitVector32. Then used Property procedures that extracted the individual
values, using the methods of BitVector32.

Public enum RtsControl As Byte
Disable = 0
Enable = 1
Handshake = 2
Toggle = 3
End Enum

Public Structure DBC
...
Private Flags As BitVector32
...

Private Shared Readonly m_fBinary As Integer
Private Shared Readonly m_Parity As Integer
...
Private Shared Readonly m_fRtsControl As BitVector32.Sec tion
...

Shared Sub New()
' create boolean masks
m_fBinary = BitVector32.Cre ateMask()
...
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
...
' create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
...
m_fRtsControl = BitVector32.Cre ateSection(3,
previousSection )
...
End Sub

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

...

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

...

End Structure

BitVector32 is marshaled as an Integer (DWORD) so you can use them
interchangeably .

I made Flags Private as its an implementation detail.

The property procedures expose the flags as the respective types, For
example RtsControl & DtrControl as enums with valid values, others as
Boolean. I had to change a couple names as there is a field & a flag
(ErrorChar).

For the BitVector32 masks I had to make two passes, once for the boolean
values, then a second one for the section (enum) values.

Using the BitVector32 class simplified my property procedures at the
"expense" of a little extra setup (the shared constructor).

I have not posted my class on got dot net yet, as I am still working on
making the WaitEvent async.

Hope this helps
Jay
"Rafael Pivato" <rp*****@cpovo. net> wrote in message
news:uZ******** ******@tk2msftn gp13.phx.gbl...
I thought that there was an marshall attribute (or something)
that automates the bit flags access.

But, with your advices I think it's better to implement
a wrapper class to access this structure in a easy manner
for the client.

Thanks

"Dick Grier" <di************ **@msn.com> escreveu na mensagem
news:uF******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

Your DCB is not correct. It looks like:

typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD Flags;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;

Flags is bit-mapped, and contains bit-flags that control things like

parity
and flow control.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.


Nov 20 '05 #5
very, very usefull....
Thanks...
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> escreveu na
mensagem news:O9******** *****@tk2msftng p13.phx.gbl...
Rafael,
When I implemented the DCB structure in VB.NET I defined Flags as a Private BitVector32. Then used Property procedures that extracted the individual
values, using the methods of BitVector32.

Public enum RtsControl As Byte
Disable = 0
Enable = 1
Handshake = 2
Toggle = 3
End Enum

Public Structure DBC
...
Private Flags As BitVector32
...

Private Shared Readonly m_fBinary As Integer
Private Shared Readonly m_Parity As Integer
...
Private Shared Readonly m_fRtsControl As BitVector32.Sec tion
...

Shared Sub New()
' create boolean masks
m_fBinary = BitVector32.Cre ateMask()
...
m_fParity = BitVector32.Cre ateMask(m_fBina ry)
...
' create section masks
Dim previousSection As BitVector32.Sec tion
previousSection = BitVector32.Cre ateSection(1)
...
m_fRtsControl = BitVector32.Cre ateSection(3,
previousSection )
...
End Sub

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

...

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

...

End Structure

BitVector32 is marshaled as an Integer (DWORD) so you can use them
interchangeably .

I made Flags Private as its an implementation detail.

The property procedures expose the flags as the respective types, For
example RtsControl & DtrControl as enums with valid values, others as
Boolean. I had to change a couple names as there is a field & a flag
(ErrorChar).

For the BitVector32 masks I had to make two passes, once for the boolean
values, then a second one for the section (enum) values.

Using the BitVector32 class simplified my property procedures at the
"expense" of a little extra setup (the shared constructor).

I have not posted my class on got dot net yet, as I am still working on
making the WaitEvent async.

Hope this helps
Jay
"Rafael Pivato" <rp*****@cpovo. net> wrote in message
news:uZ******** ******@tk2msftn gp13.phx.gbl...
I thought that there was an marshall attribute (or something)
that automates the bit flags access.

But, with your advices I think it's better to implement
a wrapper class to access this structure in a easy manner
for the client.

Thanks

"Dick Grier" <di************ **@msn.com> escreveu na mensagem
news:uF******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

Your DCB is not correct. It looks like:

typedef struct _DCB {
DWORD DCBlength;
DWORD BaudRate;
DWORD Flags;
WORD wReserved;
WORD XonLim;
WORD XoffLim;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
char XonChar;
char XoffChar;
char ErrorChar;
char EofChar;
char EvtChar;
WORD wReserved1;
} DCB;

Flags is bit-mapped, and contains bit-flags that control things like

parity
and flow control.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Nov 20 '05 #6

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

Similar topics

21
43081
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
10
2656
by: Conrad | last post by:
Greetings, I have a need to print from Win98SE to a little serial label printer provided by United Parcel, so based on Mark Hammond's recommendation in 'Programming on Win32' I decided to try the Sio module at http://starship.python.net/crew/roger/ My problem:
5
5927
by: Silke | last post by:
Hi all! I'm trying to write a program in python using the modules 'serialwin32' and 'thread' to create one thread that writes to a serial port and another one that reads from it at 'the same time'. My definitions are def NetworkToSerial(input): s.write(binascii.unhexlify(input)) print "SENT: %s" % input
79
14128
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current operating system would be appropriate. However, I do not know how to retrieve the information. Could you help? Klaus
2
10262
by: claire | last post by:
I'm trying to open and configure a serial/comm port to talk to another device. I've used the Win32 methods described on MSDN but I get an unexpected error message when I try to configure the port - SetCommState returns error 127 (which I think is ERROR_PROC_NOT_FOUND). Can anyone find the mistake in the code below, or suggest any changes I could make? Thanks for any help. I've only included the relevant sections of code - the...
4
4740
by: Vidya Bhagwath | last post by:
Hello Experts, I am porting the C++ code into the Visual C#.NET. My C++ code is mainly based on the serial communication. So I am using the windows structure such as DCB.. etc and the windows functions frequently in my C++ code. I came to know how to import the windows functions into Visual C#.NET. But what is the method to import windows structure into Visual C#.NET? It will be very helpful for me if anybody can give me the WebID that...
6
3594
by: Casey Bralla | last post by:
I'd like to read ASCII data from a serial port, but (once again) I'm having trouble getting started. (Can't seem to find the basic level of docs to get going <sigh>) I'd like to use only standard "built-in" modules if possible. Could somebody offer a simple code-snippet to get me started reading from a serial port? Thanks!
5
24975
by: George T. | last post by:
I need to access the serial port via python on a windows machine. Reading on the web, there are three solutions: pyserial, siomodule and USPP. pyserial seems to be the best option since the other two are tested with Windows 95 and older versions of python. Would you agree with this or have I missed an option? Can anyone provide me an example of how to access the serial port with pyserial? Thanks
0
2273
saranjegan
by: saranjegan | last post by:
Hello, Am using win32::serial port module to communicate with my serial port, from CPAN i found that communication is done through file handle by tie with configuration file, i need to know about configuration file , how to use it ? it will be great if you give a clear explanation about it , thanks for your time
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
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
7643
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
6870
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
5536
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
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.