sending bytes to parallel port

Discussion in 'Python' started by Timothy Smith, Jul 29, 2006.

  1. hello people.

    i've been trying to send an 8 byte string to my parallel port under
    freebsd. the purpose is it to control a relay board.
    the board simply responds to the output byte coming from the port. eg.
    00000001 will set pin 1 high and flick the relay open.
    todate i've attempted this with merely open() on /dev/ppi0 and numpy for
    the byte array, but i just can't seem to get it working.
    i know the parallel port works and i know the relay board works (tested
    it with it's own windows ultility) so it's just my crappy programming
    keeping me from success.
     
    Timothy Smith, Jul 29, 2006
    #1
    1. Advertising

  2. On 2006-07-28, Timothy Smith <> wrote:

    > i've been trying to send an 8 byte string to my parallel port
    > under freebsd. the purpose is it to control a relay board. the
    > board simply responds to the output byte coming from the port.
    > eg. 00000001 will set pin 1 high and flick the relay open.
    > todate i've attempted this with merely open() on /dev/ppi0 and
    > numpy for the byte array, but i just can't seem to get it
    > working. i know the parallel port works and i know the relay
    > board works (tested it with it's own windows ultility) so it's
    > just my crappy programming keeping me from success.


    I'm guessing there's an implied request for help there
    somewhere. This would be a good start:

    http://www.google.com/search?q=python parallel port

    I'd particularly recommend taking a look at the pyparallel
    module found here:

    http://pyserial.sourceforge.net/

    I've not used pyparallel, but based on my experience with
    pyserial and some of Chris Liechti's other work, I'd bet
    dollars to doughnuts it's your best option.

    --
    Grant Edwards grante Yow! It's so OBVIOUS!!
    at
    visi.com
     
    Grant Edwards, Jul 29, 2006
    #2
    1. Advertising

  3. On 2006-07-29, Grant Edwards <> wrote:

    > I'd particularly recommend taking a look at the pyparallel
    > module found here:
    >
    > http://pyserial.sourceforge.net/


    Oops, there isn't actually a link to pyparallel from that page
    (I swear there used to be). Here's the pyparallel page:

    http://pyserial.sourceforge.net/pyparallel.html

    --
    Grant Edwards grante Yow! Here we are in
    at America... when do we
    visi.com collect unemployment?
     
    Grant Edwards, Jul 29, 2006
    #3
  4. Grant Edwards wrote:
    > On 2006-07-28, Timothy Smith <> wrote:
    >
    >
    >> i've been trying to send an 8 byte string to my parallel port
    >> under freebsd. the purpose is it to control a relay board. the
    >> board simply responds to the output byte coming from the port.
    >> eg. 00000001 will set pin 1 high and flick the relay open.
    >> todate i've attempted this with merely open() on /dev/ppi0 and
    >> numpy for the byte array, but i just can't seem to get it
    >> working. i know the parallel port works and i know the relay
    >> board works (tested it with it's own windows ultility) so it's
    >> just my crappy programming keeping me from success.
    >>

    >
    > I'm guessing there's an implied request for help there
    > somewhere. This would be a good start:
    >
    > http://www.google.com/search?q=python parallel port
    >
    > I'd particularly recommend taking a look at the pyparallel
    > module found here:
    >
    > http://pyserial.sourceforge.net/
    >
    > I've not used pyparallel, but based on my experience with
    > pyserial and some of Chris Liechti's other work, I'd bet
    > dollars to doughnuts it's your best option.
    >
    >

    yes, i did try pyparallel however it will not install on freebsd,
    setup.py errors.

    and yes i've done quite a bit of googling, i never expected it to be
    this difficult. i've done work with serial ports before. never parallel but.
     
    Timothy Smith, Jul 29, 2006
    #4
  5. Grant Edwards wrote:
    > On 2006-07-29, Grant Edwards <> wrote:
    >
    >
    >> I'd particularly recommend taking a look at the pyparallel
    >> module found here:
    >>
    >> http://pyserial.sourceforge.net/
    >>

    >
    > Oops, there isn't actually a link to pyparallel from that page
    > (I swear there used to be). Here's the pyparallel page:
    >
    > http://pyserial.sourceforge.net/pyparallel.html
    >
    >

    i've had people suggest using fcntl to set the pins status, i'm looking
    to that if anyone has any suggestions
     
    Timothy Smith, Jul 29, 2006
    #5
  6. On Sat, 29 Jul 2006 13:59:02 +1000, Timothy Smith
    <> declaimed the following in comp.lang.python:

    >
    > and yes i've done quite a bit of googling, i never expected it to be
    > this difficult. i've done work with serial ports before. never parallel but.


    Parallel gets ugly -- there are something like three different types
    of parallel port hardware, and they behave slightly differently (status
    bits, bidirectionality, etc.).

    http://www.amazon.com/gp/product/09...002-3804298-8662433?s=books&v=glance&n=283155

    is MS-DOS/Windows biased, but may give hints...


    (a few years ago I had to program a W98 laptop to write 6 data pins --
    representing three rs-422 style balanced signals -- in response to a
    1KHz clock signal coming in on another pin... I had it working, but
    couldn't get rid of every last W98 OS interrupt, such that I had a 1-3
    clock length skip about every 700 clocks)
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Jul 29, 2006
    #6
  7. Dennis Lee Bieber wrote:
    > On Sat, 29 Jul 2006 13:59:02 +1000, Timothy Smith
    > <> declaimed the following in comp.lang.python:
    >
    >
    >> and yes i've done quite a bit of googling, i never expected it to be
    >> this difficult. i've done work with serial ports before. never parallel but.
    >>

    >
    > Parallel gets ugly -- there are something like three different types
    > of parallel port hardware, and they behave slightly differently (status
    > bits, bidirectionality, etc.).
    >
    > http://www.amazon.com/gp/product/09...002-3804298-8662433?s=books&v=glance&n=283155
    >
    > is MS-DOS/Windows biased, but may give hints...
    >
    >
    > (a few years ago I had to program a W98 laptop to write 6 data pins --
    > representing three rs-422 style balanced signals -- in response to a
    > 1KHz clock signal coming in on another pin... I had it working, but
    > couldn't get rid of every last W98 OS interrupt, such that I had a 1-3
    > clock length skip about every 700 clocks)
    >

    i think fcntl is what i'm after, although i've never done any system
    level stuff like this before so it's a learning curve for me.
    right now i'm attempting to use it like so and getting the following error.

    >>> fd = open('/dev/ppi0','w')
    >>> fcntl.ioctl(fd.fileno(),'PPISCTRL',10000000)

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: an integer is required

    i guess i'm failing to properly define the int i need for the 8byte
    value ineed to send the port to set pins high /low
     
    Timothy Smith, Jul 29, 2006
    #7
  8. >
    > >>> fd = open('/dev/ppi0','w')
    > >>> fcntl.ioctl(fd.fileno(),'PPISCTRL',10000000)

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > TypeError: an integer is required
    >
    > i guess i'm failing to properly define the int i need for the 8byte
    > value ineed to send the port to set pins high /low


    Python doesn't know about PPISCTRL - it has no way of knowing all
    "secret", OS-specific constants for ioctl-calls.

    So, you need to figure out the numeric value of that constant .- look it
    up in the appropriate header-file.

    Then, you do have the next problem with passing that 10000000 value of
    yours. ioctl expects strings or buffers as parameters which contain a
    byte-representation of the value you want to set. This is an snippet I
    use to read the event device capabilities under linnux:


    buf = array.array('c', [' ' for i in xrange(EV_MAX / 8 + 1)])
    fcntl.ioctl(self._fd, EVIOCGBIT(0, len(buf)), buf, True)
    caps = struct.unpack("I", buf)[0]

    HTH,

    Diez
     
    Diez B. Roggisch, Jul 29, 2006
    #8
  9. Diez B. Roggisch wrote:
    >> >>> fd = open('/dev/ppi0','w')
    >> >>> fcntl.ioctl(fd.fileno(),'PPISCTRL',10000000)

    >> Traceback (most recent call last):
    >> File "<stdin>", line 1, in ?
    >> TypeError: an integer is required
    >>
    >> i guess i'm failing to properly define the int i need for the 8byte
    >> value ineed to send the port to set pins high /low
    >>

    >
    > Python doesn't know about PPISCTRL - it has no way of knowing all
    > "secret", OS-specific constants for ioctl-calls.
    >
    > So, you need to figure out the numeric value of that constant .- look it
    > up in the appropriate header-file.
    >
    > Then, you do have the next problem with passing that 10000000 value of
    > yours. ioctl expects strings or buffers as parameters which contain a
    > byte-representation of the value you want to set. This is an snippet I
    > use to read the event device capabilities under linnux:
    >
    >
    > buf = array.array('c', [' ' for i in xrange(EV_MAX / 8 + 1)])
    > fcntl.ioctl(self._fd, EVIOCGBIT(0, len(buf)), buf, True)
    > caps = struct.unpack("I", buf)[0]
    >
    > HTH,
    >
    > Diez
    >

    *sigh*
    if only pyparallel would install
     
    Timothy Smith, Jul 29, 2006
    #9
  10. On Sat, 29 Jul 2006 15:26:36 +1000, Timothy Smith
    <> declaimed the following in comp.lang.python:


    > >>> fd = open('/dev/ppi0','w')
    > >>> fcntl.ioctl(fd.fileno(),'PPISCTRL',10000000)

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > TypeError: an integer is required
    >
    > i guess i'm failing to properly define the int i need for the 8byte
    > value ineed to send the port to set pins high /low
    >

    No... (well, it didn't get that far)...

    You are passing a string "PPISCTRL" where an integer opcode is
    wanted. If I read the documentation, they are defined in termios. I'm on
    Windows and don't have such a module.

    Try importing termios and specifying termios.PPISCTRL (or maybe
    dir(termios) to see what is defined).

    Are you sure you need an 8-BYTE value to set bits? or an 8-BIT
    value? 0x80
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Jul 29, 2006
    #10
  11. > *sigh*
    > if only pyparallel would install


    *sigh* If only you said _what_ failed we could maybe help you make it
    work... :)

    Diez
     
    Diez B. Roggisch, Jul 29, 2006
    #11
  12. Diez B. Roggisch wrote:
    >> *sigh*
    >> if only pyparallel would install
    >>

    >
    > *sigh* If only you said _what_ failed we could maybe help you make it
    > work... :)
    >
    > Diez
    >

    titan# python setup.py install
    running install
    running build
    running build_py
    Traceback (most recent call last):
    File "setup.py", line 19, in ?
    package_data = data_files
    File "/usr/local/lib/python2.4/distutils/core.py", line 149, in setup
    dist.run_commands()
    File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in
    run_commands
    self.run_command(cmd)
    File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in
    run_command
    cmd_obj.run()
    File "/usr/local/lib/python2.4/distutils/command/install.py", line
    506, in run
    self.run_command('build')
    File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
    self.distribution.run_command(command)
    File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in
    run_command
    cmd_obj.run()
    File "/usr/local/lib/python2.4/distutils/command/build.py", line 112,
    in run
    self.run_command(cmd_name)
    File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
    self.distribution.run_command(command)
    File "/usr/local/lib/python2.4/distutils/dist.py", line 965, in
    run_command
    cmd_obj.ensure_finalized()
    File "/usr/local/lib/python2.4/distutils/cmd.py", line 117, in
    ensure_finalized
    self.finalize_options()
    File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
    60, in finalize_options
    self.data_files = self.get_data_files()
    File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
    120, in get_data_files
    filenames = [
    File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
    128, in find_data_files
    globs = (self.package_data.get('', [])
    AttributeError: 'NoneType' object has no attribute 'get'
    titan#
     
    Timothy Smith, Jul 29, 2006
    #12
  13. "Timothy Smith" <> wrote:


    | Grant Edwards wrote:
    | > On 2006-07-28, Timothy Smith <> wrote:
    | >
    | >
    | >> i've been trying to send an 8 byte string to my parallel port
    | >> under freebsd. the purpose is it to control a relay board. the
    | >> board simply responds to the output byte coming from the port.
    | >> eg. 00000001 will set pin 1 high and flick the relay open.
    | >> todate i've attempted this with merely open() on /dev/ppi0 and
    | >> numpy for the byte array, but i just can't seem to get it
    | >> working. i know the parallel port works and i know the relay
    | >> board works (tested it with it's own windows ultility) so it's
    | >> just my crappy programming keeping me from success.
    | >>
    | >
    | > I'm guessing there's an implied request for help there
    | > somewhere. This would be a good start:
    | >
    | > http://www.google.com/search?q=python parallel port
    | >
    | > I'd particularly recommend taking a look at the pyparallel
    | > module found here:
    | >
    | > http://pyserial.sourceforge.net/
    | >
    | > I've not used pyparallel, but based on my experience with
    | > pyserial and some of Chris Liechti's other work, I'd bet
    | > dollars to doughnuts it's your best option.
    | >
    | >
    | yes, i did try pyparallel however it will not install on freebsd,
    | setup.py errors.
    |
    | and yes i've done quite a bit of googling, i never expected it to be
    | this difficult. i've done work with serial ports before. never parallel but.

    What is on the other side of the link? - if its a small 8 bit micro - you may
    simply be going too fast...

    - Hendrik

    |
     
    H J van Rooyen, Jul 29, 2006
    #13
  14. On 2006-07-29, Timothy Smith <> wrote:

    >> I'd particularly recommend taking a look at the pyparallel
    >> module found here:


    > yes, i did try pyparallel however it will not install on
    > freebsd, setup.py errors.


    Ah. I guess freebsd wasn't one of the systems listed on the
    pyparallel page -- I should have paid closer attention.

    > and yes i've done quite a bit of googling, i never expected it
    > to be this difficult. i've done work with serial ports before.
    > never parallel but.


    Serial ports on PCs are pretty standardized as 16550 UARTs, and
    The Unix serial port API was mostly nailed down years ago.

    There are at least three different schemes for parallel ports,
    and not everybody implements those identically even if they do
    claim to be one of the three. Many motherboard chipsets claim
    to do do all three. On top of that, there doesn't seem to be a
    common Unix prallel port API.

    --
    Grant Edwards grante Yow! Is this ANYWHERE,
    at USA?
    visi.com
     
    Grant Edwards, Jul 29, 2006
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. b3ny
    Replies:
    11
    Views:
    943
    Babu Kalakrishnan
    Nov 20, 2004
  2. MNQ

    Sending data to the parallel port

    MNQ, Jan 6, 2004, in forum: C Programming
    Replies:
    9
    Views:
    498
    Richard Heathfield
    Jan 10, 2004
  3. David
    Replies:
    4
    Views:
    390
    john_walczak
    Nov 5, 2005
  4. Soren
    Replies:
    4
    Views:
    1,306
    c d saunter
    Feb 14, 2008
  5. Vivek Menon
    Replies:
    5
    Views:
    3,447
    Paul Uiterlinden
    Jun 8, 2011
Loading...

Share This Page