Click to See Complete Forum and Search --> : HELP: parallel communication


yuaner
May 18th, 1999, 07:29 PM
how can I communicate through parallel port under NT?

bala.j
May 19th, 1999, 12:27 AM
There are routines that help u to communicate thro parallel ports. All u need to know is ur parallel port addresses. Once if u know them u can use these routines to communicate thro the //el port.

_inp(port address) Read one byte from specified I/O port
_inpd(port address) Read double word from specified I/O port
_inpw(port address) Read 2-byte word from specified I/O port

_outp(port address) Write one byte to specified I/O port
_outpd(port address) Write double word to specified I/O port
_outpw(port address) Write word to specified I/O port

Hope this helps u
Bala
S/W Engineer
Wipro GE Medical Systems

yuaner
May 19th, 1999, 05:00 AM
hello bala !
Thanks a lot for your advice.
I've tried those routines.They all work good under WIN95 and WIN98, but not supported by WINNT.
I also have tried
CrearteFile()
WriteFile()
ReadFile()
NT just not support.
NT doesn't allow operate on hardware directly ,It always tell me that I have no privilege .
What should I do under NT?
THANKS!

bala.j
May 19th, 1999, 09:14 AM
Hi,

Check if ur port addresses are right. Hope u would have given OPEN_EXISTING for dwCreationDisposition in CreateFile. It should work properly if u would have used these ReadFile and WriteFile. Try debugging ur application with GetCommProperties() where u would get the details of ur //el port. Also make sure u give PST_PARALLELPORT for dwProvSubType inside the COMMPROP structure which is supposed to be a parameter for GetCommProperties().


Bala

yuaner
May 19th, 1999, 08:44 PM
Hi Bala
I just do as below:
///////////////////////////////
HANDLE lpt1; if((lpt1=CreateFile("LPT1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL)) ==INVALID_HANDLE_VALUE)
{CString str;
str.Format("create error :%d",GetLastError());}
else AfxMessageBox(" create ok!");
BYTE m_signal=8;
LPDWORD lpbynm;
if(WriteFile( lpt1, &m_signal,1, lpbynm,NULL))AfxMessageBox("write ok!");
/////////////////////////////////////
///each time the system tell me that" the [0x7000d4da]instruction quote the [0x00000001]EMS ///memory,the memory can't be written."here.
But these code can perform successful under WIN95?

THANKS
yuaner

May 20th, 1999, 12:53 AM
Why do you mess with FILE_SHARE_DELETE? It is only valid in Windows NT abd, basically, is not required here. Try to use
FILE_SHARE_READ|FILE_SHARE_WRITE.
You correctly using FILE_FLAG_BACKUP_SEMANTICS for opening directories.

bala.j
May 20th, 1999, 02:38 AM
Hi
I tried accessing the //el port in my system. It worked fine. The code that I have written is just similar to what u have written. The problem in ur code is that u have not allocated memory for the no_of_bytes returned by the WriteFile function. I tried correcting ur code and also executed that one in my system. It worked fine. I hope it should work fine in urs too, if it doesnt work then it means there is some problem in ur //el port. Hope this would have helped u.

Bala

yuaner
May 20th, 1999, 03:21 AM
Hi Bala!
You say"u have not allocated memory for the no_of_bytes returned by the WriteFile function",this awake me.
Now it work fine .
Thank you verymuch!!!

yuaner

balak yap
May 20th, 1999, 03:37 AM
Hello
I am so happy finally you get it work....
Can you pls give me the rountine which can access to parallel port?
Thanks..

Hello World!!!

yuaner
May 20th, 1999, 06:00 AM
Hi
below just what I'v done:
///////////////////////////////////////////////////
HANDLE lpt1;
if((lpt1=CreateFile("LPT1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL)) ==INVALID_HANDLE_VALUE)
{CString str;
str.Format("create error :%d",GetLastError());
AfxMessageBox(str);}
else AfxMessageBox(" create ok!");
/////////////////////////////////
DWORD no_by_wt;
/////// This just what I was added.
////////////////////////////////////////
LPDWORD lpbynm=&no_by_wt;
if(WriteFile( lpt1, &m_signal, 1,lpbynm,NULL))
AfxMessageBox("write ok!");
else
{CString str;
str.Format(" write error :%d",GetLastError());
AfxMessageBox(str);}

if(CloseHandle( lpt1)) AfxMessageBox("close ok!");
else
{
CString str;
str.Format(" close error :%d",GetLastError());
AfxMessageBox(str);
}
// handle to object to close

wish such be ur want!

Surinder
May 20th, 1999, 06:27 AM
NT will not allow you to access the h/w directly. For this u will have to write the VXD programs.

Refer the book -
1. Windows-NT -Device driver Development by Peter G.Viscarola.
2. Wiriting Windows Virtual Device drivers --David Thielen (Addison Weseley Pub.
Bye
Surinder

ICQ #3760 3760

Surinder
May 20th, 1999, 06:43 AM
Hi ,
I have learned a lot from ur discussion on parrallel communication. I am new to windows platform. Can u tell me how to synchronize the windows event with the system timer at the rate faster than 44Khz. I want to get the samples from the parallel port at this speed. The system timer message WM_TIMER has the resulotion of 1ms that too through message queue.
Can u suggest me some other ways of achieving this.
Bye
surinder


ICQ #3760 3760