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

Writing pins to the RS232

P: n/a
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?

In summary I'm looking for something like:
ser = serial.Serial(0)
ser.pin0 = 1
ser.pin1 = 1
ser.pin2 = 1
.....
or
ser.write('0xFF')
which would set 8 pins on the RS232 cable to 1's

Nov 25 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
In article <11*********************@g14g2000cwa.googlegroups. com>,
"ja*****@gmail.com" <ja*****@gmail.com> wrote:
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?


This really isn't a Python question -- it's a low-level hardware question.
The short answer, however, is that it's almost certainly impossible to
anything like what you want, for a number of reasons. The output pins on
the connector are driven directly by some sort of serial hardware driver,
and the hardware almost certainly doesn't expose an interface which lets
you do what you're after.

I think want you want to be doing is looking at using a parallel port
(commonly called a printer port on PC's). But in any case, the answer to
"How do I make the parallel port do this?" is a low-level hardware
question, not a Python question.
Nov 25 '05 #2

P: n/a
ja*****@gmail.com wrote:
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?


As Roy indicates, you can't practically make a serial port on a PC do
this. I just wanted to note that you've misunderstood the presence of
the Java stuff in pyserial. If you're running under Jython then that
stuff is used, but if you're on Windows the file win32serial.py (or
something like that... going by memory) is what will be used, not the
java one.

Also, pyparallel should let you get closer to what you want, and in fact
questions about using it are certainly on-topic here, though
troubleshooting hardware issues are probably not.

-Peter

Nov 25 '05 #3

P: n/a
ja*****@gmail.com wrote:
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?

In summary I'm looking for something like:
ser = serial.Serial(0)
ser.pin0 = 1
ser.pin1 = 1
ser.pin2 = 1
....
or
ser.write('0xFF')
which would set 8 pins on the RS232 cable to 1's


Accessing hardware at this level is almost always managed by some form
of device driver in any real operating system. Even Microsoft Windows
has device drivers for serial and parallel ports. This is not your
father's MS-DOS any more. It would be a security breach to allow user
applications direct access at the hardware level.

Also, if you ever hope to run on anything except an IBM-PC clone, then
the hardware will be different. Even systems that run x86 processors
like the NEC PC-98 have 8255 parallel interfaces, but they are located
on different ports in the machine.
Nov 26 '05 #4

P: n/a
First of all I'd like to thank all of you for your input. It's nice to
have a place to throw ideas around and get some feedback.

I think the reason the serial source code I'm using is using javax.comm
stuff which is possibly part of Jython is because I'm on Mac OS X.
However this is just my guess as all of this is translucent to me and
difficult for me to decipher.

While I realize this is more on a driver/hardware level it's
interesting that it's so difficult to use a different protocol for an
existing driver. For example, all serial does is a series of high and
low voltages on specific pins. Why should it be so hard to use an
existing driver and hold a pin on high? I guess the answer is, because
the driver is operating system specific, and because all of the drivers
and code that use that driver use the hardware in a very specific way.
If you ever wanted to use it for a different purpose you'd have to
start all the way at the bottom again. While I can just use a serial
protocol to tell a chip to do what I'm looking for it seems like an
extra piece of hardware I don't need.

Looking into pyparallel, it seems this is much closer to my needs. Now
I just need to purchase a usb to parallel adapter and do some further
experimenting. Looking up some diagrams of how the parallel ports work
and some useful documentation I don't think I'll be running into any
more problems.

Nov 27 '05 #5

P: n/a
"ja*****@gmail.com" <ja*****@gmail.com> wrote:
While I realize this is more on a driver/hardware level it's
interesting that it's so difficult to use a different protocol for an
existing driver. For example, all serial does is a series of high and
low voltages on specific pins. Why should it be so hard to use an
existing driver and hold a pin on high?


It's been a long time since I've looked at this low-level hardware, but the
answer is almost certainly, "No just 'so hard', but 'impossible'".

A serial port is driven by a thing called a UART (Universal Asynchronous
Receiver/Transmitter). Back when I was playing with these things, a UART
was a discrete chip; these days I'm sure it's just a minor part of a more
complex I/O processor, but I suspect the basic idea is the same. You load
a character to be transmitted into a register on the UART and the hardware
takes care of all the low-level gunk like clocking the bits out at the
correct rate, adding start and stop bits, and computing parity. And the
reverse for the receive side of the house (which is usually the more
complicated part). There just isn't any way to tell the hardware to do
anything other than it was designed to do.

Could you design a piece of hardware which could function as both a serial
port and what you want? Sure you could, but it would cost more, and PC
design today is a matter of shaving 10 cents here and 30 cents there.

It's like looking at a microwave oven and saying, "Can't this thing be
reprogrammed to be a communications relay?" Well, sure, it's got some of
the same parts, but the parts were put together in a way that makes food
get hot, not in a way that makes data bits get transmitted to someplace.
Nov 28 '05 #6

P: n/a
ahhh I understand now

Nov 28 '05 #7

P: n/a

"Roy Smith" <ro*@panix.com> wrote in message
news:ro***********************@reader2.panix.com.. .
"ja*****@gmail.com" <ja*****@gmail.com> wrote:
While I realize this is more on a driver/hardware level it's
interesting that it's so difficult to use a different protocol for an
existing driver. For example, all serial does is a series of high and
low voltages on specific pins. Why should it be so hard to use an
existing driver and hold a pin on high?


It's been a long time since I've looked at this low-level hardware, but
the
answer is almost certainly, "No just 'so hard', but 'impossible'".


If you just need one or two signals, then it might be practical to use one
of the control lines, and PySerial supports this (UPS monitoring software
often works this way). Setting 8 pins to 1 would be impossible, because
there plain won't be that number of outputs wired, in addition to all the
good stuff about UARTs Roy said.
Nov 28 '05 #8

P: n/a
Richard Brodie wrote:
If you just need one or two signals, then it might be practical to use one
of the control lines, and PySerial supports this (UPS monitoring software
often works this way). Setting 8 pins to 1 would be impossible, because
there plain won't be that number of outputs wired, in addition to all the
good stuff about UARTs Roy said.


All true, but then Jay might get into electrical compatibility issues,
and may not realize that the output levels of RS-232 serial hardware are
not simply 0 and 5V levels, but rather +9V (or so) and -9V (and with
variations from 6V up to 13V seen in the wild), and without much in the
way of drive capability. Using this to control custom hardware would
probably be an exercise in frustration and kind of pointless in
comparison to using parallel hardware, which at least has more typical
logic voltage levels.

-Peter

Nov 28 '05 #9

P: n/a
Peter Hansen <pe***@engcorp.com> wrote in
news:ma***************************************@pyt hon.org:

All true, but then Jay might get into electrical compatibility issues,
and may not realize that the output levels of RS-232 serial hardware
are not simply 0 and 5V levels, but rather +9V (or so) and -9V (and
with variations from 6V up to 13V seen in the wild), and without much
in the way of drive capability. Using this to control custom hardware
would probably be an exercise in frustration and kind of pointless in
comparison to using parallel hardware, which at least has more typical
logic voltage levels.


You can get ICs that convert RS232 to TTL voltage levels.
Nov 28 '05 #10

P: n/a
Hi,

Some of it should be doable on windows:
http://msdn.microsoft.com/library/de...mmfunction.asp

Yet this might require a new wrapper module for I am not sure what the
current interface lets you do.

Not sure about Linux.

Regards;

Philippe



On Fri, 25 Nov 2005 13:25:44 -0800, ja*****@gmail.com wrote:
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?

In summary I'm looking for something like:
ser = serial.Serial(0)
ser.pin0 = 1
ser.pin1 = 1
ser.pin2 = 1
....
or
ser.write('0xFF')
which would set 8 pins on the RS232 cable to 1's


Nov 28 '05 #11

P: n/a
Richard Brodie <R.******@rl.ac.uk> wrote:
If you just need one or two signals, then it might be practical to use one
of the control lines, and PySerial supports this (UPS monitoring software
often works this way).


I've done this many times (not with PySerial) for misc sensors.

With PySerial you can read 4 pins (ie 4 inputs)

getCD(self)
Read terminal status line: Carrier Detect

getCTS(self)
Read terminal status line: Clear To Send

getDSR(self)
Read terminal status line: Data Set Ready

getRI(self)
Read terminal status line: Ring Indicator

and set two outputs

setDTR(self, on=1)
Set terminal status line: Data Terminal Ready

setRTS(self, on=1)
Set terminal status line: Request To Send

Other than those 6 that you have Rx, Tx and Ground which you can't use
for logic, on a standard 9-way PC serial port.

You need to set the serial port up not to do automatic handshaking
first (eg setDsrDtr() & setRtsCts())

RS232 levels are +/- 12V, though a lot of computers only generate +/-
5V. The threshold is +/- 3V IIRC.

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Nov 29 '05 #12

P: n/a
For those looking, I've already used IC's that convert RS232 to TTL,
look up MAX233. It drops 12 to 5, essentially converting RS232 to TTL
and vice versa. PyParallel is definitely the way I'll go, however,
this project will be on hold for me for my priorities have been
shifted. Thanks again for all of your help.

Dec 20 '05 #13

P: n/a
Jay,

Couple of points that may help you.

1) A serial port does not have data ports 0-n. A serial port takes a
byte (8 bits), then shifts them down a single pipe using a chip called a
UART (feel free to google for unfamiliar terms).

example

Bit pattern 1010 1010

would be shifted one bit at a time

1
0
1
0

1
0
1
0

a one is +5 volts on single send line of the UART and 0 is 0 volts.

RS232 uses a different mapping for 1's and 0's (but is still serial)

1 - ~-3V - -12 V
0 0-12 V

So you slap a chip on between the UART and the RS232 pin (usually a
MAX232) that translates the voltages for you.

On the other end of the wire

232 socket
MAC232
UART (usually built into the microcontroller)
Register in Microcontroller
I like playing at this level. I would recommend using AVR
microcontroller (easiest to program and there is an open source
gcc compiler).

for $20.00 US you can buy the butterfly eval board with:
- microcontroller
- max232 all wired up for rs232 connection from your computer
- lcd display
- temperature sensor
- light sensor
- the avr mega169 has many goodies
- analog - digital converter
- digital -> analog converter
- LCD controller

This is a great bargin.

If you are starting out in microcontrollers. I would suggest that you
go to:

http://smileymicros.com/

They sell a nice package for $90.00

- butterfly eval board
- great, easy to follow book on how to develop on microcontrollers for
the beginer.
- project kit - includes everything you need to build all of the
projects (even includes the wire ;-)
There are python libs that support Ateml Avr connections:
It is easy to use your rs232 serial with a microcontroller at the other
end of the wire. Microcontrollers are cheap. If you fry why is
connected to your devices, you are only out the microcontroller.
Have fun,
Mike

ja*****@gmail.com wrote:
I want to write to the pins of an RS232 without using the serial
protocol. The use would be every pin could act to complete a circuit
in customized hardware. I could use python to communicate serially to
a BASIC stamp or a Javelin stamp and then use the stamp to set however
many pins as 0's or 1's but should it be that hard to do with python.
I've looked through how python does serial with the "serial" module but
it just uses Java's javax.comm libraries. Is there anyway to do very
low level device writing to COM ports?

In summary I'm looking for something like:
ser = serial.Serial(0)
ser.pin0 = 1
ser.pin1 = 1
ser.pin2 = 1
....
or
ser.write('0xFF')
which would set 8 pins on the RS232 cable to 1's

--
The greatest performance improvement occurs on the transition of from
the non-working state to the working state.
Dec 31 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.