sending bytes to parallel port

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Timothy Smith

    #1

    sending bytes to parallel port

    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.
  • Grant Edwards

    #2
    Re: sending bytes to parallel port

    On 2006-07-28, Timothy Smith <timothy@open-networks.netwro te:
    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:



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



    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

    Comment

    • Grant Edwards

      #3
      Re: sending bytes to parallel port

      On 2006-07-29, Grant Edwards <grante@visi.co mwrote:
      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:



      --
      Grant Edwards grante Yow! Here we are in
      at America... when do we
      visi.com collect unemployment?

      Comment

      • Timothy Smith

        #4
        Re: sending bytes to parallel port

        Grant Edwards wrote:
        On 2006-07-28, Timothy Smith <timothy@open-networks.netwro te:
        >
        >
        >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:
        >

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

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

        Comment

        • Timothy Smith

          #5
          Re: sending bytes to parallel port

          Grant Edwards wrote:
          On 2006-07-29, Grant Edwards <grante@visi.co mwrote:
          >
          >
          >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:
          >

          >
          >
          i've had people suggest using fcntl to set the pins status, i'm looking
          to that if anyone has any suggestions

          Comment

          • Timothy Smith

            #6
            Re: sending bytes to parallel port

            Dennis Lee Bieber wrote:
            On Sat, 29 Jul 2006 13:59:02 +1000, Timothy Smith
            <timothy@open-networks.netdec laimed the following in comp.lang.pytho n:
            >
            >
            >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, bidirectionalit y, etc.).
            >
            http://www.amazon.com/gp/product/096...lance&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(f d.fileno(),'PPI SCTRL',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


            Comment

            • Diez B. Roggisch

              #7
              Re: sending bytes to parallel port

              >
              >>fd = open('/dev/ppi0','w')
              >>fcntl.ioctl(f d.fileno(),'PPI SCTRL',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(sel f._fd, EVIOCGBIT(0, len(buf)), buf, True)
              caps = struct.unpack(" I", buf)[0]

              HTH,

              Diez

              Comment

              • Timothy Smith

                #8
                Re: sending bytes to parallel port

                Diez B. Roggisch wrote:
                > >>fd = open('/dev/ppi0','w')
                > >>fcntl.ioctl(f d.fileno(),'PPI SCTRL',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(sel f._fd, EVIOCGBIT(0, len(buf)), buf, True)
                caps = struct.unpack(" I", buf)[0]
                >
                HTH,
                >
                Diez
                >
                *sigh*
                if only pyparallel would install

                Comment

                • Diez B. Roggisch

                  #9
                  Re: sending bytes to parallel port

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

                  Diez

                  Comment

                  • Timothy Smith

                    #10
                    Re: sending bytes to parallel port

                    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_comman ds()
                    File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in
                    run_commands
                    self.run_comman d(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_comman d('build')
                    File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
                    self.distributi on.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_comman d(cmd_name)
                    File "/usr/local/lib/python2.4/distutils/cmd.py", line 333, in run_command
                    self.distributi on.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_finalize d
                    self.finalize_o ptions()
                    File "/usr/local/lib/python2.4/distutils/command/build_py.py", line
                    60, in finalize_option s
                    self.data_files = self.get_data_f iles()
                    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_d ata.get('', [])
                    AttributeError: 'NoneType' object has no attribute 'get'
                    titan#

                    Comment

                    • H J van Rooyen

                      #11
                      Re: sending bytes to parallel port

                      "Timothy Smith" <timothy@open-networks.netwro te:


                      | Grant Edwards wrote:
                      | On 2006-07-28, Timothy Smith <timothy@open-networks.netwro te:
                      | >
                      | >
                      | >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

                      |

                      Comment

                      • Grant Edwards

                        #12
                        Re: sending bytes to parallel port

                        On 2006-07-29, Timothy Smith <timothy@open-networks.netwro te:
                        >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

                        Comment

                        Working...