473,473 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Writing pins to the RS232

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
13 6826
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
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
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
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
"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
ahhh I understand now

Nov 28 '05 #7

"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan | last post by:
I wnat to see in browser an status from an device connected on rs232 port The java class for read from serial port is: //Serial.java import java.io.*; import java.util.*; import...
6
by: Przemo | last post by:
Hi, Do you know some good RS232C class? There is one in VB.NET 101 Examples, but I think it is poor. 1. I can't for e.g. read into my application all data received. I must tell how many...
6
by: eson | last post by:
hi i would like to make some software for steering devices through lpt port therefore i need to know who to control pins on the lpt port and how to gain direct access to them. Shortly speaking I...
8
by: Terry Olsen | last post by:
I'm trying to use the RS232 class that was in the Platform SDK (i think). Has anyone else used this with events successfully? Here's what i've got: ====================== Public WithEvents...
0
by: Piotrekk | last post by:
Hi My question is: How to conrol output pins of ( for example ) COM1 I found in .net System.IO.Ports.SerialPort class. Is there any posibility to set or not set pins D0-7? Thanks PK
14
by: Bobus | last post by:
Hi, I have a table which contains a bunch of prepaid PINs. What is the best way to fetch a unique pin from the table in a high-traffic environment with lots of concurrent requests? For...
12
by: Sven | last post by:
Can someone point out source code for a safe circular buffer receiver transmitter? It's for sending and receiving bytes via RS232. Thanks in advance.
0
by: JNL via DotNetMonster.com | last post by:
hi guys! i need help on how to read signals from pins 10 and 12 of the parallel port do i need to add a reference or a COM component to read signals from the pins? all i need to do is get a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.