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

    Help with Hardware interfacing with parallel port

    I need to interface hardware through parallel port. More specifically I need to read and write data into the registors of an IC (MT8888C). If you know anything related to hardware interfacing, Please do reply!

    [email protected]


  2. #2
    Join Date
    Apr 1999
    Posts
    4

    Re: Help with Hardware interfacing with parallel port

    It depends on what operatingsystem you are using. Until now you can use in Win 95/98 the "in" and "out" standard C functions to read and write your parr. port from within your program. A much better solution (and the only one in NT) is writing a driver to access your port.
    If you know the address of your port, the offset adresses of the different registers of the I/O chip can be found in the data-sheets (mostly you can find them on Internet.

    I hope I've put you on the way
    Greetings

    Jean Paul Mertens
    ON1AMI
    jpmsoft-at-glo.be (repl -at- with @)
    http://user.online.be/~gd30347

  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: Help with Hardware interfacing with parallel port

    I worked on a program last year to write to hardware via the parallel port. Fortunately I was writing code for Win95/98 which is very easy since Win95/98 allows you to talk directly to the hardware. Check-out http://www.lvr.com/parport.htm.


  4. #4
    Join Date
    May 1999
    Posts
    388

    Re: Help with Hardware interfacing with parallel port

    In visual C++ there are command like _out _in etc that start with the underscore. Are they counter part of those 'in' and 'out' of C++. Are the similar to those more or less?
    Shahzad
    [email protected]


  5. #5
    Join Date
    May 1999
    Posts
    388

    Re: Help with Hardware interfacing with parallel port

    Thankx for the web site address.


  6. #6

    Re: Help with Hardware interfacing with parallel port

    nt or 95/98, they both recognize LPT1 as parallel port 1 device and so on. Use createfile() to open the device, readfile() & writefile() to perform i/o, .DeviceIoControl() to control and monitor control lines,closehandle to close the handle.
    in createfile();

    The fdwShareMode parameter must be zero, opening the resource for exclusive access.
    The fdwCreate parameter must specify the OPEN_EXISTING flag.
    The hTemplateFile parameter must be NULL.

    Search online help for these functions for details.


  7. #7
    Join Date
    Sep 1999
    Location
    Trivandrum, Kerala, INDIA.
    Posts
    32

    Re: Help with Hardware interfacing with parallel port

    I want to read signals from a user defined H/W unit connected to the LPT1 port, interpret it and display some valuable information at the front-end.
    I'm using CreateFile, ReadFile CloseFile functions. I was able to successfully open the port, read the current comm status using GetCommState(...). But ReadFile(...) function returned a failure, reading zero bytes, even when the signal from the H/W unit was given to the Data pins of the port.
    1] Is there any value to be set using the SetCommState(...) funtion before calling ReadFile(...), in the DCB(Device control block structure), to facilitate parallel port communication?
    2] Is there a need of a generating a STROBE signal in the H/W unit, to intimate the arrival/availibility of data at the port?
    3] What are the other bare minimum signals to be generated from the H/W unit, so as to facilitate efficient reading from the s/w side?
    4] Is there any signal to be generated from the part of the s/w, like an acknowledgement, and written back to LPT1, in between each read cycle?
    Thankx for any help.


  8. #8
    Join Date
    Oct 1999
    Location
    USA Mn
    Posts
    5

    Re: Help with Hardware interfacing with parallel port

    I have a simple class that allows direct access to the parallel port. NOT NT compat of course...
    I will EMail you a copy
    Keith

    ( I suppose I should post the code here at CG :-)


  9. #9
    Join Date
    Oct 1999
    Location
    USA Mn
    Posts
    5

    Re: Help with Hardware interfacing with parallel port

    Here is the code...
    Code:
    Header...
    class CParPort  
    {
    public:
    	void Address(unsigned int address );
    	bool Set(BYTE Byte);
    	BYTE Get();
    
    	CParPort();
    	virtual ~CParPort();
    
    protected:
    	void Init();
    	unsigned int m_Address;
    	unsigned int m_Status;
    	unsigned int m_Control;
    };
    
    CPP
    CParPort::CParPort()
    {
    	m_Address = 0x378;
    }
    
    CParPort::~CParPort()
    {
    
    }
    
    //Write the byte to the parallel port
    bool CParPort::Set(BYTE Byte)
    {
    	_outp(m_Address,Byte);
    
    	return true;
    }
    
    //Read a Byte from the parallel port
    BYTE CParPort::Get()
    {
    
    	BYTE Lowbyte = _inp(m_Status);// & 0xF0; /* Read MSnibble */
    
    	return Lowbyte;//Byte;
    }
    
    //Set the address for the port
    void CParPort::Address(unsigned int address)
    {
    	m_Address = address;
    	m_Status = address +1;
    	m_Control = address +2;
    
    	Init();
    }
    
    void CParPort::Init()
    {
    
    	BYTE Old = _inp(m_Control +1);
    	
    	_outp(m_Control, Old & 0xF0 | 0x04 );
    }
    Just create it, set the address then read and write bytes to the parallel port..
    Yea it's simple, but easy to understand :-)

    Keith


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