sending bytes to parallel port

T

Timothy Smith

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

Grant Edwards

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

Timothy Smith

Grant said:
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.
 
D

Dennis Lee Bieber

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Timothy Smith

Dennis said:
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.
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
 
D

Diez B. Roggisch

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
 
T

Timothy Smith

Diez said:
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
 
D

Dennis Lee Bieber

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Timothy Smith

Diez said:
*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#
 
H

H J van Rooyen

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

|
 
G

Grant Edwards

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top