Ok, but I do not understand , How the Drivers can communicate without help
from User Application ??? I think that all the Routines in Drivers must be
called by User Application , and it's impossible to implement communication
between Routines in one Driver ( for Ex, Routine DispatchRead can not
communicate with Routine DispatchWrite ) . In My Work , how can The Driver
in Client Side do all works by itself without help from User Application ?
My Teacher said about usage of Mutex Object in Client Side to Wait and
implement request from Server , but I don't believe that is possible !
Pls help me to explaint !
Thank you so much !
> Ok, but I do not understand , How the Drivers can communicate without help
> from User Application ???
Easy.
Look for function called PsCreateSystemThread. Well then if you have thread you can do what ever you want without user mode
application interaction, right?
Best regards,
Slobodan
Ok , thank you so much !
I have read about the System Thread after U telt me . But Where must I put
the Start of the Thread ?? In DriverEntry ? or in DispatchCreate ?
I am using Numega , I don't know where to start my thread? .
Thanks!
That will depend on your driver design mostly.
Anyhow you can call it from what ever point that suits your needs as long as you are satisfying following requirement.
"Callers of this routine must be running at IRQL PASSIVE_LEVEL."
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:empBr5aR...@TK2MSFTNGP09.phx.gbl...
My filter driver has worked well . But after I modified like that ( only add
Systhread ) .
Now , when I start my driver , my Computer immediately restarts , Why ??
Pls help me !
thanks
#pragma code_seg("INIT")
DECLARE_DRIVER_CLASS(CommFilterDriver, NULL)
//////////////////////////////////////////////////////////////////////////
// DriverEntry
//
KSystemThread sysThread;
VOID ThreadMain( )
{
DbgPrint("Start Thread ...");
NTSTATUS status;
KTimer timer;
ASSERT( KeGetCurrentIrql() <= DISPATCH_LEVEL );
timer.Initialize( SynchronizationTimer );
LARGE_INTEGER duetime = {0};
#define TIME_INTERVAL 1000
timer.SetPeriodic( duetime, TIME_INTERVAL );
int dwCounter = 0;
while( dwCounter <= 10 )
{
timer.Wait( KernelMode, FALSE, NULL, Executive );
DbgPrint(" Timer counter = %d ", dwCounter );
dwCounter++;
}
timer.Cancel();
DbgPrint(("POLLING - Terminating polling thread\n"));
sysThread.Terminate(STATUS_SUCCESS);
}
VOID StopThread( )
{
if (sysThread)
{ // wait for thread to die
sysThread.Wait( KernelMode, FALSE, NULL ,Executive);
} // wait for thread to die
}
NTSTATUS CommFilterDriver::DriverEntry(PUNICODE_STRING RegistryPath)
//
// Driver initialization entry point
//
{
// Create an instance of the control device
m_ControlDevice = new (NonPagedPool) FilterControlDevice();
ASSERT( KeGetCurrentIrql() <= PASSIVE_LEVEL );
sysThread.Start( (PKSTART_ROUTINE)ThreadMain, NULL, THREAD_ALL_ACCESS );
if ( m_ControlDevice )
{
NTSTATUS status = m_ControlDevice->ConstructorStatus();
if ( !NT_SUCCESS(status) )
delete m_ControlDevice;
return status;
}
else
return STATUS_INSUFFICIENT_RESOURCES;
}
#pragma code_seg()
VOID CommFilterDriver::Unload(void)
{
KPRIORITY OrigPriority;
StopThread( );
// Lower priority temporarily, in order to ensure that all
// other threads in driver have completed before unloading.
// (TBD: find a better way to handle this problem)
OrigPriority = KeSetPriorityThread( KeGetCurrentThread(), 1 );
KeSetPriorityThread( KeGetCurrentThread(), OrigPriority );
// Delete any devices not already deleted
DeleteDevices();
}
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:egKOVDbR...@TK2MSFTNGP09.phx.gbl...
I can't help you here. I'm using DDK functions without third party wrappers.
> Now , when I start my driver , my Computer immediately restarts , Why ??
There is a good thing called remote debugger. KD or windbg from MS you can download new version from site. So you will be able to
step trough your code if you have two computers, if not you are probably doomed while writing drivers blindly.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:%23c65Z7h...@TK2MSFTNGP12.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:uZF7a1iR...@TK2MSFTNGP12.phx.gbl...
In your case you should have one thread. That will use standard read and write major codes for reading and writing data, and for
configuring port you can use IOCTL_SERIAL_* codes.
Use google groups to search trough old NG archives. This will probably give you all help you need for this particular project.
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&group=microsoft.public.win32.programmer.kernel
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:e814b3jR...@tk2msftngp13.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#qdAnUkR...@TK2MSFTNGP12.phx.gbl...
I have no idea what you are trying to do in your project, and why you want to use filter driver.
You can make non filter driver that will open desired com, and use it in similar manners that you would use it from user mode.
You will have your driver (no user mode application). And it will do work you wanted it to do.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:uUdcy2kR...@TK2MSFTNGP12.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#gP3NalR...@tk2msftngp13.phx.gbl...
You can write regular driver (.sys) that execute as any other driver. All drivers share same address space, and can create as many
threads as you need.
From threads you can open/close other driver use all IOCTL, read, write and use all functions defined in DDK for your OS.
I hope that this is understandable enough.
Regards,
Slobodan
PS:
Maybe you have troubles to understand how to install this type of driver?
"Alex" <Chip...@hotmail.com> wrote in message news:%23bj8rMm...@TK2MSFTNGP10.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:OGRlPgm...@TK2MSFTNGP10.phx.gbl...
I have no idea how you are planning to write filter driver.
Lower filter, upper filter, reason behind this (why?).
What is signal?
Byte receive?
Handshake input pins? break condition?
I thought that you want to make regular serial communication, right?
First you need to open and reserve port.
Then you will have to initialize parameters like BPS, flow control etc.
If you do that successfully you will have idea how to proceed with next step using threads.
BTW:
Filter driver is usually only good if you want to monitor and modify already initialized communication.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:Oje3XAqR...@TK2MSFTNGP10.phx.gbl...
HANDLE fileOpen;
OBJECT_ATTRIBUTES objAttr;
UNICODE_STRING sLinkName;
#define COM_NAME L"\\DosDevices\\COM1" /* or L''COM1" */
RtlInitUnicodeString( &sLinkName, COM_NAME);
InitializeObjectAttributes(
&objAttr,
&sLinkName,
OBJ_INHERIT | OBJ_PERMANENT | OBJ_EXCLUSIVE | OBJ_CASE_INSENSITIVE
|OBJ_OPENIF,
NULL,
NULL);
LARGE_INTEGER nSize;
IO_STATUS_BLOCK ioStat;
NTSTATUS statusOpen = ZwCreateFile(
OUT &fileOpen,
IN FILE_READ_DATA,
IN &objAttr,
OUT &ioStat,
&nSize,
IN FILE_ATTRIBUTE_NORMAL,
IN FILE_SHARE_READ,
IN FILE_OPEN,
IN FILE_WRITE_THROUGH,
IN NULL,
IN 0
);
#if DBG
DbgPrint("statusOpen= %X.", statusOpen);
#endif
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:ui7GpJqR...@TK2MSFTNGP12.phx.gbl...
Make sure that your driver start after the serial driver. The easiest way to do this is trough inf file.
Although you can always do this programmatically.
BTW: This is relevant only when you boot your computer. If you just start your driver when system is running then this is no issue.
Also consider using something like functions:
IoCallDriver
IoBuildDeviceIoControlRequest
#define SERIAL_DEVICE_NAME0 L"\\Device\\Serial0"
UNICODE_STRING ntDeviceName;
RtlInitUnicodeString(&ntDeviceName, SERIAL_DEVICE_NAME0);
PFO=0;
PDO=0;
NTSTATUS status=IoGetDeviceObjectPointer(&ntDeviceName, FILE_ALL_ACCESS,
&PFO, &PDO);
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:%23%23EfU7tR...@TK2MSFTNGP09.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:##XxVYwRE...@TK2MSFTNGP12.phx.gbl...
// {Access Denied}
// A process has requested access to an object, but has not been granted those access rights.
//
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)
Try some unopened serial port.
And please use this NG for all your posts so someone else can help you.
Regards,
Slobodan
BTW: What OS are you using for testing purposes.
"Alex" <Chip...@hotmail.com> wrote in message news:%23bpg0Vx...@TK2MSFTNGP10.phx.gbl...
"Alex" <Chip...@hotmail.com> wrote in message
news:%23%23EfU7tR...@TK2MSFTNGP09.phx.gbl...
#define SERIAL_DEVICE_NAME0 L"\\Device\\Serial0"
UNICODE_STRING ntDeviceName;
RtlInitUnicodeString(&ntDeviceName, SERIAL_DEVICE_NAME0);
NTSTATUS status=IoGetDeviceObjectPointer(&ntDeviceName,
FILE_ALL_ACCESS,
&pdx->m_hComm, &pdx->m_pdoComm);
HANDLE m_hFile = (HANDLE) pdx->m_hComm;
IO_STATUS_BLOCK ioStat;
UCHAR pBuffer[8];
ULONG dwRead = 8;
NTSTATUS statusWrite = ZwWriteFile(
m_hFile,
NULL,
NULL,
NULL,
&ioStat,
pBuffer,
dwRead,
NULL,
NULL
);
if( !NT_SUCCESS( status ) )
DbgPrint("Open COMM failed !");
else
DbgPrint("Open COMM OK !\n");
DbgPrint(" status open COMM = %X ", status );
if( !NT_SUCCESS( statusWrite ) )
DbgPrint("Write COMM failed !");
else
DbgPrint("Write COMM OK !\n");
DbgPrint(" status Write COMM = %X ", statusWrite );
and the result :
Example= DriverEntry successfully completed.
Open COMM OK !
status open COMM = 0
Write COMM failed !
status Write COMM = C0000008
Unloaded successfully
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:uH7$BaxREH...@TK2MSFTNGP12.phx.gbl...
Do the read similarly as write.
And please notice that event is used. So you can implement this is a way that fit your requirements.
NTSTATUS SerialWrite( const void *WriteBuffer, ULONG NumBytes, IO_STATUS_BLOCK &iosb)
{
if(!PDO) return STATUS_UNSUCCESSFUL;
NTSTATUS status;
PIRP irp;
LARGE_INTEGER startingOffset;
KEVENT event;
startingOffset.QuadPart = (LONGLONG) 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildSynchronousFsdRequest( IRP_MJ_WRITE, PDO, (PVOID)WriteBuffer, NumBytes, &startingOffset, &event, &iosb );
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
status = IoCallDriver(PDO, irp);
if (status == STATUS_PENDING)
status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL);
if(status!=STATUS_SUCCESS) return status;
return iosb.Status;
}
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:Oj0IRLyR...@TK2MSFTNGP10.phx.gbl...
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Alex" <Chip...@hotmail.com> wrote in message
news:Oj0IRLyR...@TK2MSFTNGP10.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#9ipv0yR...@tk2msftngp13.phx.gbl...
You will have to use things like
irp=IoBuildDeviceIoControlRequest(IOCTL_SERIAL_SET_BAUD_RATE
Read about all IOCTL_SERIAL_* codes since you will need them to initialize your serial port.
So:
1. Open thread.
2. Open serial port.
3. Initialize serial port.
4. Make loop.
5 Wait for read event or thread close.
When you get some info parse them and do the time stuff.
6. go to 4.
7. You can even forget PnP start/stop support so this will simplify your driver even more.
This is very crude but it will work.
Good luck with that.
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:uDtT$2zREH...@tk2msftngp13.phx.gbl...
NTSTATUS SerialWrite( const void *WriteBuffer, ULONG NumBytes,
PIO_STATUS_BLOCK iosb, PDEVICE_OBJECT pdo)
{
if(!pdo) return STATUS_UNSUCCESSFUL;
NTSTATUS status;
PIRP irp;
LARGE_INTEGER startingOffset;
KEVENT event;
startingOffset.QuadPart = (LONGLONG) 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
DbgPrint("initial Event OK in Write ");
irp = IoBuildSynchronousFsdRequest( IRP_MJ_WRITE, pdo,
(PVOID)WriteBuffer, NumBytes, &startingOffset, &event, iosb );
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
DbgPrint("Build IRP OK !");
status = IoCallDriver( pdo, irp );
DbgPrint("maybe waiting...");
if (status == STATUS_PENDING)
status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE,
NULL);
if(status!=STATUS_SUCCESS) return status;
return iosb->Status;
}
and I have get this result :
initial Event OK in Write
Build IRP OK !
maybe waiting...
Best regards !
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#z96JQ0R...@tk2msftngp13.phx.gbl...
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:%23NT$4Y0REH...@TK2MSFTNGP10.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:OzBDqp0R...@TK2MSFTNGP10.phx.gbl...
"Alex" <Chip...@hotmail.com> wrote in message news:uCJi300R...@TK2MSFTNGP10.phx.gbl...
I have set all necessary parameters for COM port, but still not get Result ,
Write always in the wait state ...
////////////////////////////////////////////////////////////////////////
SERIAL_BAUD_RATE serBaudRate;
serBaudRate.BaudRate = SERIAL_BAUD_2400;
NTSTATUS statusBaudRate = SetBaudRate( &serBaudRate, &ioStat, pdo );
////////////////////////////////////////////////////////////////////////
SERIAL_LINE_CONTROL serLineControl;
serLineControl.Parity = SERIAL_EVEN_PARITY ;
serLineControl.StopBits = SERIAL_2_STOP;
serLineControl.WordLength = SERIAL_8_DATA ;
NTSTATUS statusLineControl = SetLineControl( &serLineControl, &ioStat,
pdo );
////////////////////////////////////////////////////////////////////////
#define MAXDWORD 0xffffffff
SERIAL_TIMEOUTS serTimeOuts;
serTimeOuts.ReadIntervalTimeout = MAXDWORD ;
serTimeOuts.ReadTotalTimeoutMultiplier = MAXDWORD ;
serTimeOuts.ReadTotalTimeoutConstant = MAXDWORD - 1;
serTimeOuts.WriteTotalTimeoutMultiplier = 0 ;
serTimeOuts.WriteTotalTimeoutConstant = 0 ;
NTSTATUS timeOutStats = SetTimeOuts( &serTimeOuts, &ioStat, pdo );
////////////////////////////////////////////////////////////////////////
UCHAR pBuffer[2];
ULONG dwRead = 2;
statusWrite = SerialWrite( pBuffer, dwRead, &ioStat, pdo );
NTSTATUS SerialWrite( const void *WriteBuffer, ULONG NumBytes,
PIO_STATUS_BLOCK iosb, PDEVICE_OBJECT pdo)
{
if(!pdo) return STATUS_UNSUCCESSFUL;
NTSTATUS status;
PIRP irp;
LARGE_INTEGER startingOffset;
KEVENT event;
startingOffset.QuadPart = (LONGLONG) 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
DbgPrint("initial Event OK in Write ");
irp = IoBuildSynchronousFsdRequest( IRP_MJ_WRITE, pdo,
(PVOID)WriteBuffer, NumBytes, &startingOffset, &event, iosb );
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
DbgPrint("Build IRP OK !");
status = IoCallDriver( pdo, irp );
DbgPrint("Waiting in SerialWrite...");
if (status == STATUS_PENDING)
status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE,
NULL);
DbgPrint("Jumped out of Wait in SerialWrite !");
if(status!=STATUS_SUCCESS) return status;
DbgPrint(" Write COMM successfully !");
return iosb->Status;
}
NTSTATUS SetBaudRate( PSERIAL_BAUD_RATE serBaudRate, PIO_STATUS_BLOCK iosb,
PDEVICE_OBJECT pdo )
{
NTSTATUS status;
PIRP irp;
LARGE_INTEGER startingOffset;
KEVENT event;
startingOffset.QuadPart = (LONGLONG) 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
DbgPrint("initial Event OK in SetBaudRate ");
irp = IoBuildDeviceIoControlRequest(
IOCTL_SERIAL_SET_BAUD_RATE,
pdo,
serBaudRate,
sizeof(SERIAL_BAUD_RATE),
NULL,
0,
FALSE,
&event,
iosb );
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
DbgPrint("Build IRP SetBaudRate OK !");
status = IoCallDriver( pdo, irp );
DbgPrint("Waiting in setBaundRate...");
if (status == STATUS_PENDING)
status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE,
NULL);
DbgPrint("Jumped out of Wait in SetBaudRate !");
if(status!=STATUS_SUCCESS) return status;
DbgPrint("SetBaudRate successfully !");
return iosb->Status;
}
NTSTATUS SetTimeOuts( PSERIAL_TIMEOUTS serTimeOuts, PIO_STATUS_BLOCK iosb,
PDEVICE_OBJECT pdo )
{
NTSTATUS status;
PIRP irp;
LARGE_INTEGER startingOffset;
KEVENT event;
startingOffset.QuadPart = (LONGLONG) 0;
KeInitializeEvent(&event, NotificationEvent, FALSE);
DbgPrint("initial Event OK in SetTimeOuts ");
irp = IoBuildDeviceIoControlRequest(
IOCTL_SERIAL_SET_TIMEOUTS,
pdo,
serTimeOuts,
sizeof(SERIAL_TIMEOUTS),
NULL,
0,
FALSE,
&event,
iosb );
if(!irp) return STATUS_INSUFFICIENT_RESOURCES;
DbgPrint("Build IRP SetTimeOuts OK !");
status = IoCallDriver( pdo, irp );
DbgPrint("Waiting in SetTimeOuts...");
if (status == STATUS_PENDING)
status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE,
NULL);
DbgPrint("Jumped out of Wait in SetTimeOuts !");
if(status!=STATUS_SUCCESS) return status;
DbgPrint("SetTimeOuts successfully !");
return iosb->Status;
}
And this is the result :
Open COMM successfully !
initial Event OK in SetBaudRate
Build IRP SetBaudRate OK !
Waiting in setBaundRate...
Jumped out of Wait in SetBaudRate !
SetBaudRate successfully !
initial Event OK in SetTimeOuts
Build IRP SetTimeOuts OK !
Waiting in SetTimeOuts...
Jumped out of Wait in SetTimeOuts !
SetTimeOuts successfully !
initial Event OK in Write
Build IRP OK !
Waiting in SerialWrite...
Best Regards!
Idea about this if used is that receiving end can block transmition of data that it can't handle. Also this requires apropriate
cable. If you don't have full cable or you don't want to use this option then you must disable this behaviour.
Also start by receiving data. Make your server send data constantly and try seeing in debuger what happens.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:ePrVL12R...@TK2MSFTNGP12.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:OSeYJR3R...@TK2MSFTNGP12.phx.gbl...
BTW: Make sure that you are using/accessing right serial port number. I don't see the reason for access denied error in one of your
previous posts.
If you have oscilloscope or Voltmeter or nice pass-through with leds that indicate state of you communication lines. You should
drive manually trough codes some of handshake outputs to certain state just to make sure that you are on the right post and that
everything is ok. This is simple operations and do not require proper param initialization to work.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:erEtdf3R...@tk2msftngp13.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:eOpau$3REH...@TK2MSFTNGP10.phx.gbl...
IoBuildSynchronousFsdRequest IoCallDriver, they always talk about Driver Lower in a Driver Chain. That is only matter of point of
view. If you have PDO obtained trough IoGetDeviceObjectPointer that is enough for IoCallDriver to work.
>and why IoBuildSynchronous , a not IoBuildAsynchronous
And why not creating and filling that IRP manually? Do it as you think that it is good for your specific case . All these functions
are there for us to use them.
Slobodan
BTW:
Before you continue asking more and more questions.
How many RS232 cables do you have?
Do you have firewire?
How do you debug your computer?
Do you have started application for receive at all times on your server?
"Alex" <Chip...@hotmail.com> wrote in message news:e%23WGxa5R...@TK2MSFTNGP10.phx.gbl...
Regards !
Waiting for help from you !
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:O0rwFm8R...@TK2MSFTNGP09.phx.gbl...
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:etOhoT%23REH...@TK2MSFTNGP10.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:uJuwZX#REHA...@tk2msftngp13.phx.gbl...
BTW: Try setting time outs for write just to see if it will ever timeout write request.
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:%23sCXWr$REHA...@TK2MSFTNGP10.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#muDC6$REHA...@TK2MSFTNGP10.phx.gbl...
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Alex" <Chip...@hotmail.com> wrote in message
news:uSDx03BS...@TK2MSFTNGP12.phx.gbl...
"Doron Holan [MS]" <dor...@nospam.microsoft.com> wrote in message
news:#dRR#2ESEH...@TK2MSFTNGP10.phx.gbl...
Perhaps your speed does not match on both sides.
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:%23OL9d7H...@TK2MSFTNGP09.phx.gbl...
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#JnDxfIS...@tk2msftngp13.phx.gbl...
SERIAL_BAUD_RATE serBaudRate;
serBaudRate.BaudRate = 2400; //SERIAL_BAUD_2400;
NTSTATUS statusBaudRate = SetBaudRate( &serBaudRate, fdo );
////////////////////////////////////////////////////////////////////////
SERIAL_LINE_CONTROL serLineControl;
serLineControl.Parity = 2; //SERIAL_EVEN_PARITY ;
serLineControl.StopBits = 2; //SERIAL_2_STOP;
serLineControl.WordLength = 8; //SERIAL_8_DATA ;
NTSTATUS statusLineControl = SetLineControl( &serLineControl, fdo );
////////////////////////////////////////////////////////////////////////
#define MAXDWORD 0xffffffff
SERIAL_TIMEOUTS serTimeOuts;
serTimeOuts.ReadIntervalTimeout = MAXDWORD ;
serTimeOuts.ReadTotalTimeoutMultiplier = MAXDWORD ;
serTimeOuts.ReadTotalTimeoutConstant = MAXDWORD - 1;
serTimeOuts.WriteTotalTimeoutMultiplier = MAXDWORD ;
serTimeOuts.WriteTotalTimeoutConstant = MAXDWORD - 1 ;
NTSTATUS timeOutStatus = SetTimeOuts( &serTimeOuts, fdo );
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#JnDxfIS...@tk2msftngp13.phx.gbl...
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:OmrWcDNS...@TK2MSFTNGP09.phx.gbl...
NTSTATUS StopCommPort( PDEVICE_OBJECT fdo )
{
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
NTSTATUS status= STATUS_SUCCESS;
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension;
if (!pdx->isPortOpen)
return STATUS_SUCCESS;
pdx->isPortOpen = FALSE;
KEVENT event;
IO_STATUS_BLOCK iosb;
KeInitializeEvent(&event, NotificationEvent, FALSE);
PIRP Irp = IoBuildSynchronousFsdRequest(IRP_MJ_FLUSH_BUFFERS,
pdx->LowerDeviceObject,
NULL, 0, NULL, &event, &iosb);
if (!Irp)
return STATUS_UNSUCCESSFUL;
PIO_STACK_LOCATION stack = IoGetNextIrpStackLocation(Irp);
stack->MajorFunction = IRP_MJ_CLOSE;
status = IoCallDriver(pdx->LowerDeviceObject, Irp);
if (status == STATUS_PENDING)
status = KeWaitForSingleObject(&event, Executive, KernelMode, FALSE,
NULL);
return status;
}
VOID DriverUnload(IN PDRIVER_OBJECT pDriverObject)
{
PDEVICE_OBJECT pdo = pDriverObject->DeviceObject;
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) pdo->DeviceExtension;
StopCommPort( pdo );
ObDereferenceObject( pdx->LowerDeviceObject);
UNICODE_STRING *pLinkName = &(pdx->ustrSymLinkName);
IoDeleteSymbolicLink(pLinkName);
IoDeleteDevice( pdx->fdo);
DbgPrint("Unloaded successfully !");
}
and the result :
0.00006342 System IRP_MJ_CREATE
Serial0 SUCCESS Options: Open
0.00000391 System IRP_MJ_CLEANUP
Serial0 SUCCESS
0.00001620 System IOCTL_SERIAL_SET_BAUD_RATE Serial0
SUCCESS Rate: 2400
0.00000726 System IOCTL_SERIAL_SET_LINE_CONTROL Serial0
SUCCESS StopBits: ERROR Parity: EVEN WordLength: 8
0.00000251 System IOCTL_SERIAL_SET_TIMEOUTS Serial0
* 0xC0000023
0.00004889 System IRP_MJ_WRITE
Serial0 SUCCESS Length 8: CFIO{...
0.05021700 System IRP_MJ_CLOSE
Serial0 SUCCESS
"Slobodan Brcin (eMVP)" <sbr...@ptt.yu> wrote in message
news:#9xUY6OS...@TK2MSFTNGP11.phx.gbl...
Why not just simple: ObDereferenceObject(PFO);
You never used IRP_MJ_CREATE, so why do you want to use IRP_MJ_CLOSE?
Regards,
Slobodan
"Alex" <Chip...@hotmail.com> wrote in message news:ul8D5hUS...@tk2msftngp13.phx.gbl...