win2k driver for serial device?

hi,

Iam new to win2000 . I want to write a driver for one
of our custom serial device.
How can i open & write to com ports from the
driver.?.. What is the equivalent of VCOMM_OpenComm as
in vxd’s?

How should i proceed.?

regards
vdharan


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Get the W2K DDK off of Microsoft’s web site. Use the sample source for the
serial driver as a basis for your driver (there’s lots of stuff in there you
can toss away). There is no equivalent in W2K/XP for the VCOMM layer that
Win9x has. Serial drivers in W2K are not VCOMM port drivers.

Jim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Vidhiyadharan
Nadarajah
Sent: Thursday, December 20, 2001 10:18 PM
To: NT Developers Interest List
Subject: [ntdev] win2k driver for serial device?

hi,

Iam new to win2000 . I want to write a driver for one
of our custom serial device.
How can i open & write to com ports from the
driver.?.. What is the equivalent of VCOMM_OpenComm as
in vxd’s?

How should i proceed.?

regards
vdharan


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


You are currently subscribed to ntdev as: xxxxx@youngendeavors.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Thanks Jim,

I went through the samples.It appears to be the source
code of serial.sys.
Iam not trying to write a port driver. I just want to
open up a com port ,do read write from my wdm driver.

How can i go this?.

regards
vdharan

— Jim Young wrote: >
Get the W2K DDK off of Microsoft’s web site. Use the
> sample source for the
> serial driver as a basis for your driver (there’s
> lots of stuff in there you
> can toss away). There is no equivalent in W2K/XP for
> the VCOMM layer that
> Win9x has. Serial drivers in W2K are not VCOMM port
> drivers.
>
> Jim
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of
> Vidhiyadharan
> Nadarajah
> Sent: Thursday, December 20, 2001 10:18 PM
> To: NT Developers Interest List
> Subject: [ntdev] win2k driver for serial device?
>
>
> hi,
>
> Iam new to win2000 . I want to write a driver for
> one
> of our custom serial device.
> How can i open & write to com ports from the
> driver.?.. What is the equivalent of VCOMM_OpenComm
> as
> in vxd’s?
>
> How should i proceed.?
>
> regards
> vdharan
>
>
>
> Do You Yahoo!?
> Everything you’ll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@youngendeavors.com
> To unsubscribe send a blank email to
> leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.co.uk
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

>Iam not trying to write a port driver. I just want to

open up a com port ,do read write from my wdm driver.

The DDK sample for a serial smart card reader (bulltlp3) has code that
accesses a serial port from a driver. Is that what your looking for?

  • Jan

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

hi vidya,
Use ZwCreateFile() to open the com port symbolic link (COM1/COM2). then
use ZwWriteFile & ZwWriteFile.
Regards,
-Naveen

On 12/22/01, “=?iso-8859-1?q?Vidhiyadharan=20Nadarajah?=
” wrote:
> Thanks Jim,
>
> I went through the samples.It appears to be the source
> code of serial.sys.
> Iam not trying to write a port driver. I just want to
> open up a com port ,do read write from my wdm driver.
>
> How can i go this?.
>
> regards
> vdharan
>
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi Vidhiyadharan,

Write a bare skeleton wdm driver for handling pnp
(IRP_MN_START_DEVICE and AddDevice) and to handle the
read and write requests.

Now create a device object with the NT name
\Device\Serial# and then create a symbolic link
\DosDevices\COM(#-1).

Add the following mapping in the registry under
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMMas

\Device\Serial# COM(#-1)

Now, Load the driver and your requirement is
accomplished. See that, calling the ReadFile Api will
give the control to the IRP_MJ_READ handler and so for
the Write …

Cheers,
Jay

— Vidhiyadharan Nadarajah
wrote:
> Thanks Jim,
>
> I went through the samples.It appears to be the
> source
> code of serial.sys.
> Iam not trying to write a port driver. I just want
> to
> open up a com port ,do read write from my wdm
> driver.
>
> How can i go this?.
>
> regards
> vdharan
>
> — Jim Young wrote: >
> Get the W2K DDK off of Microsoft’s web site. Use the
> > sample source for the
> > serial driver as a basis for your driver (there’s
> > lots of stuff in there you
> > can toss away). There is no equivalent in W2K/XP
> for
> > the VCOMM layer that
> > Win9x has. Serial drivers in W2K are not VCOMM
> port
> > drivers.
> >
> > Jim
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf
> Of
> > Vidhiyadharan
> > Nadarajah
> > Sent: Thursday, December 20, 2001 10:18 PM
> > To: NT Developers Interest List
> > Subject: [ntdev] win2k driver for serial device?
> >
> >
> > hi,
> >
> > Iam new to win2000 . I want to write a driver for
> > one
> > of our custom serial device.
> > How can i open & write to com ports from the
> > driver.?.. What is the equivalent of
> VCOMM_OpenComm
> > as
> > in vxd’s?
> >
> > How should i proceed.?
> >
> > regards
> > vdharan
> >
> >
> >
> > Do You Yahoo!?
> > Everything you’ll ever need on one web page
> > from News and Sport to Email and Music Charts
> > http://uk.my.yahoo.com
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@youngendeavors.com
> > To unsubscribe send a blank email to
> > leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@yahoo.co.uk
> > To unsubscribe send a blank email to
> leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>

> Do You Yahoo!?
> Everything you’ll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Thankyou naveen,
I followed the following 2 methods , but i could not
solve the problem.

Method 1

Iam able to open & close the comm port using
ZwCreateFile & ZwClose File.
For setting the Baudrate one has to send an IRP with
IOCTL_SET_SERIAL_BAUD.Here the DeviceObjectPointer of
(target device)serial port is needed. Since I have
already opened the comm port using ZwCreateFile , Iam
getting STATUS_ACCESS_DENIED when I try to get the
DeviceObjectPointer using IoGetDeviceObjectPointer(…)
How can i get the deviceobjectpointer?..

Then I followed method 2

  1. Instead of ZwCreateFile, I opened comm using
    IoGetDeviceObjectPointer(serial0,…
  2. Attach my device to the stack using
    LowerDeviceObject = IoAttachDevicetodeviceStack(…)
  3. Create the irp using
    BuildIoDeviceControlRequest…with
    IOCTL_SET_SERIAL_BAUD.
  4. Sending it to lower driver using
    IoCallDriver(LowerDeviceObject,Irp)

Now the system hangs & the display is lost displaying
uneven lines.How can i overcome this prob?.

How to set the baud rate…?

regards
vdharan

xxxxx@wipro.com wrote: > hi vidya,

Use ZwCreateFile() to open the com port symbolic
link (COM1/COM2). then
use ZwWriteFile & ZwWriteFile.
Regards,
-Naveen

On 12/22/01,
“=?iso-8859-1?q?Vidhiyadharan=20Nadarajah?=
” wrote:
> > Thanks Jim,
> >
> > I went through the samples.It appears to be the
> source
> > code of serial.sys.
> > Iam not trying to write a port driver. I just want
> to
> > open up a com port ,do read write from my wdm
> driver.
> >
> > How can i go this?.
> >
> > regards
> > vdharan
> >
> >
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.co.uk
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi dharan,

This code may be useful for u.

RtlInitUnicodeString( &ObjectName, L"\DosDevices\COM1");

status = IoGetDeviceObjectPointer( &ObjectName,
FILE_ALL_ACCESS,
&FileObject,
&COM_Object
);

if (status == STATUS_SUCCESS)
else
{
DbgPrint(“DeviceCreate:IoGetDeviceObjectPointer failed % X”, status);
return FALSE;
}

LineCntrl.StopBits = STOP_BIT_1;
LineCntrl.Parity = NO_PARITY;
LineCntrl.WordLength = SERIAL_DATABITS_8;

irp_l = IoBuildDeviceIoControlRequest(
IOCTL_SERIAL_SET_LINE_CONTROL,
COM_Object,
&LineCntrl,
sizeof(LineCntrl),
NULL,
0,
FALSE,
Event,
&IoStatusBlock
);
if(irp_l == NULL)
{
DbgPrint(“CreateDevice: IoBuildDeviceIoControlRequest Failed”);
return FALSE;
}

status = IoCallDriver( COM_Object, irp_l);

if(status != STATUS_SUCCESS)
{
DbgPrint(“CreateDevice: The Fail Status if IoCallDriver is :
%X”,status);
return FALSE;
}

status = KeWaitForSingleObject(
Event,
Executive ,
KernelMode ,
TRUE,
0
);

if (status != STATUS_SUCCESS)
{
DbgPrint(“CreateDevice:IRP for serial set LCR was Failed”);
return FALSE;
}

KeClearEvent(Event);

If u still find it difficult to solve the problem; send the code u’ve
written.

Regards,
-Naveen

On 01/03/02, “=?iso-8859-1?q?Vidhiyadharan=20Nadarajah?=
” wrote:
> Thankyou naveen,
> I followed the following 2 methods , but i could not
> solve the problem.
>
>
> Method 1
>
> Iam able to open & close the comm port using
> ZwCreateFile & ZwClose File.
> For setting the Baudrate one has to send an IRP with
> IOCTL_SET_SERIAL_BAUD.Here the DeviceObjectPointer of
> (target device)serial port is needed. Since I have
> already opened the comm port using ZwCreateFile , Iam
> getting STATUS_ACCESS_DENIED when I try to get the
> DeviceObjectPointer using IoGetDeviceObjectPointer(…)
> How can i get the deviceobjectpointer?..
>
> Then I followed method 2
>
> 1. Instead of ZwCreateFile, I opened comm using
> IoGetDeviceObjectPointer(serial0,…
> 2. Attach my device to the stack using
> LowerDeviceObject = IoAttachDevicetodeviceStack(…)
> 3. Create the irp using
> BuildIoDeviceControlRequest…with
> IOCTL_SET_SERIAL_BAUD.
> 4. Sending it to lower driver using
> IoCallDriver(LowerDeviceObject,Irp)
>
> Now the system hangs & the display is lost displaying
> uneven lines.How can i overcome this prob?.
>
> How to set the baud rate…?
>
>
> regards
> vdharan
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

** Reply to message from Vidhiyadharan Nadarajah on
Thu, 3 Jan 2002 06:34:34 +0000 (GMT)

> Then I followed method 2
>
> 1. Instead of ZwCreateFile, I opened comm using
> IoGetDeviceObjectPointer(serial0,…
> 2. Attach my device to the stack using
> LowerDeviceObject = IoAttachDevicetodeviceStack(…)
> 3. Create the irp using
> BuildIoDeviceControlRequest…with
> IOCTL_SET_SERIAL_BAUD.
> 4. Sending it to lower driver using
> IoCallDriver(LowerDeviceObject,Irp)

Delete step 2. You are opening the device in step 1. Use it by sending IRPs
to it. Don’t forget to close the device by calling ObDereferenceObject later.

Actually, it might be fun to look at your own driver’s IOCTL handler first,
since that’s probably where your IRP is going after you insert your driver into
the serial driver’s stack.

Sincerely,

Chris Myers
Senior Project Engineer
Quatech, Inc.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Actually not, as the target device object passed into IoCallDriver is in
fact the device object that will receive the IRP. Otherwise filter drivers
wouldn’t work, would they?

Actually, it might be fun to look at your own driver’s
IOCTL handler first, since that’s probably where your IRP is
going after you insert your driver into the serial driver’s stack.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

** Reply to message from “Roddy, Mark” on Thu, 3 Jan
2002 08:50:59 -0500

> Actually not, as the target device object passed into IoCallDriver is in
> fact the device object that will receive the IRP. Otherwise filter drivers
> wouldn’t work, would they?

I guess I was too busy trying to be cute and forgot that the context was
already inside the stack that code unnecessarily joined. Good thing it does
work, or my own filters would be screwed :wink: !

Sincerely,

Chris Myers
Senior Project Engineer
Quatech, Inc.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi naveen,
The code was very helpful to me. Now iam able to do
synchronous read & write.
The mistake as mentioned by Chris Myers was attaching
my device object with the serialdevice.With out that
step it works fine.

And regarding setting baudrates, the #defines like

#define SERIAL_BAUD_38400 ((ULONG)0x00004000)
#define SERIAL_BAUD_56K ((ULONG)0x00008000)
#define SERIAL_BAUD_128K ((ULONG)0x00010000)
#define SERIAL_BAUD_115200 ((ULONG)0x00020000)

given in ntddser.h dosent seem to work. Instead If i
use the constant directly (eg 115200) for baud rate
then, Iam able to communicate at 115200.

Why this is so ?.

regards
vdharan

— Naveen Mellempudi
wrote: > Hi dharan,
>
> This code may be useful for u.
>
> RtlInitUnicodeString( &ObjectName,
> L"\DosDevices\COM1");
>
> status = IoGetDeviceObjectPointer( &ObjectName,
> FILE_ALL_ACCESS,
> &FileObject,
> &COM_Object
> );
>
> if (status == STATUS_SUCCESS)
> else
> {
> DbgPrint(“DeviceCreate:IoGetDeviceObjectPointer
> failed % X”, status);
> return FALSE;
> }
>
>
> LineCntrl.StopBits = STOP_BIT_1;
> LineCntrl.Parity = NO_PARITY;
> LineCntrl.WordLength = SERIAL_DATABITS_8;
>
> irp_l = IoBuildDeviceIoControlRequest(
> IOCTL_SERIAL_SET_LINE_CONTROL,
> COM_Object,
> &LineCntrl,
> sizeof(LineCntrl),
> NULL,
> 0,
> FALSE,
> Event,
> &IoStatusBlock
> );
> if(irp_l == NULL)
> {
> DbgPrint(“CreateDevice:
> IoBuildDeviceIoControlRequest Failed”);
> return FALSE;
> }
>
> status = IoCallDriver( COM_Object, irp_l);
>
> if(status != STATUS_SUCCESS)
> {
> DbgPrint(“CreateDevice: The Fail Status if
> IoCallDriver is :
> %X”,status);
> return FALSE;
> }
>
> status = KeWaitForSingleObject(
> Event,
> Executive ,
> KernelMode ,
> TRUE,
> 0
> );
>
> if (status != STATUS_SUCCESS)
> {
> DbgPrint(“CreateDevice:IRP for serial set LCR was
> Failed”);
> return FALSE;
> }
>
> KeClearEvent(Event);
>
> If u still find it difficult to solve the problem;
> send the code u’ve
> written.
>
> Regards,
> -Naveen
>
>
> On 01/03/02,
> “=?iso-8859-1?q?Vidhiyadharan=20Nadarajah?=
> ” wrote:
> > Thankyou naveen,
> > I followed the following 2 methods , but i could
> not
> > solve the problem.
> >
> >
> > Method 1
> >
> > Iam able to open & close the comm port using
> > ZwCreateFile & ZwClose File.
> > For setting the Baudrate one has to send an IRP
> with
> > IOCTL_SET_SERIAL_BAUD.Here the DeviceObjectPointer
> of
> > (target device)serial port is needed. Since I have
> > already opened the comm port using ZwCreateFile ,
> Iam
> > getting STATUS_ACCESS_DENIED when I try to get the
> > DeviceObjectPointer using
> IoGetDeviceObjectPointer(…)
> > How can i get the deviceobjectpointer?..
> >
> > Then I followed method 2
> >
> > 1. Instead of ZwCreateFile, I opened comm using
> > IoGetDeviceObjectPointer(serial0,…
> > 2. Attach my device to the stack using
> > LowerDeviceObject =
> IoAttachDevicetodeviceStack(…)
> > 3. Create the irp using
> > BuildIoDeviceControlRequest…with
> > IOCTL_SET_SERIAL_BAUD.
> > 4. Sending it to lower driver using
> > IoCallDriver(LowerDeviceObject,Irp)
> >
> > Now the system hangs & the display is lost
> displaying
> > uneven lines.How can i overcome this prob?.
> >
> > How to set the baud rate…?
> >
> >
> > regards
> > vdharan
> >
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.co.uk
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com