By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,484 Members | 1,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,484 IT Pros & Developers. It's quick & easy.

sending bytes to parallel port

P: n/a
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.
Jul 28 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 2006-07-28, Timothy Smith <ti*****@open-networks.netwrote:
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
Jul 29 '06 #2

P: n/a
On 2006-07-29, Grant Edwards <gr****@visi.comwrote:
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?
Jul 29 '06 #3

P: n/a
Grant Edwards wrote:
On 2006-07-28, Timothy Smith <ti*****@open-networks.netwrote:

>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.
Jul 29 '06 #4

P: n/a
Grant Edwards wrote:
On 2006-07-29, Grant Edwards <gr****@visi.comwrote:

>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
Jul 29 '06 #5

P: n/a
Dennis Lee Bieber wrote:
On Sat, 29 Jul 2006 13:59:02 +1000, Timothy Smith
<ti*****@open-networks.netdeclaimed 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/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(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
Jul 29 '06 #6

P: n/a
>
>>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
Jul 29 '06 #7

P: n/a
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

Jul 29 '06 #8

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

Diez
Jul 29 '06 #9

P: n/a
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#

Jul 29 '06 #10

P: n/a
"Timothy Smith" <ti*****@open-networks.netwrote:
| Grant Edwards wrote:
| On 2006-07-28, Timothy Smith <ti*****@open-networks.netwrote:
| >
| >
| >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

|

Jul 29 '06 #11

P: n/a
On 2006-07-29, Timothy Smith <ti*****@open-networks.netwrote:
>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
Jul 29 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.