CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 1999
    Posts
    19

    HELP: parallel communication

    how can I communicate through parallel port under NT?


  2. #2
    Join Date
    May 1999
    Location
    Karnataka, Bangalore
    Posts
    121

    Re: HELP: parallel communication

    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


  3. #3
    Join Date
    May 1999
    Posts
    19

    Re: HELP: parallel communication

    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!


  4. #4
    Join Date
    May 1999
    Location
    Karnataka, Bangalore
    Posts
    121

    Re: HELP: parallel communication

    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


  5. #5
    Join Date
    May 1999
    Posts
    19

    Re: HELP: parallel communication

    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


  6. #6
    Guest

    Re: HELP: parallel communication

    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.


  7. #7
    Join Date
    May 1999
    Location
    Karnataka, Bangalore
    Posts
    121

    Re: HELP: parallel communication

    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


  8. #8
    Join Date
    May 1999
    Posts
    19

    Re: HELP: parallel communication

    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


  9. #9
    Join Date
    Apr 1999
    Location
    Malaysia
    Posts
    224

    Re: HELP: parallel communication

    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!!!

  10. #10
    Join Date
    May 1999
    Posts
    19

    Re: HELP: parallel communication

    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!



  11. #11
    Join Date
    May 1999
    Posts
    11

    Re: HELP: parallel communication

    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

  12. #12
    Join Date
    May 1999
    Posts
    11

    Re: HELP: parallel communication

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured