1

Topic: RS-485 & Python - Help!

To all,

I’m trying to get a Rane SR3 working with a Nion using the RS-485 serial port.  Both are half-duplex, and I’m also monitoring the line with a full duplex USB/RS-485 box.

Intializing the SR3 requires several writes, and it should respond after every write.  Here’s a few lines of code (one pair of write/read) –

port = serial_port.create( "/dev/ttyS1", 38400, 8, "none", 1, 0 )
sBeg = '%c@1 ' % (128 + id)
port.write( sBeg + "ILK,127,N\r" )
t1 = port.read(250, 100)
message.string_set( "Opened %i" % len(t1) )

I have checked many times and places in the code, the port read never returns anything.  The port monitor also shows nothing being written by the SR3.  All of the writes work fine.

Is something wrong with my code such that the Nion is not releasing the port for other node(s) to write?  Maybe something in the port.create parameters?

BTW, using 1.5.1.

TIA,

Greg

2

Re: RS-485 & Python - Help!

Although I am not familiar with the operation of the SR3, there are few things I would check. RS-485, being half duplex, typically requires software to handle medium access. This is usually done with a master-slave arrangement with the master polling the slaves, thereby controlling who is allowed to transmit. Is the packet you are sending intended to be a poll?

On the electrical side of things, the RS485 line must be biased correctly, which can be verified with a volt meter. You can also use a scope to see of the line is going to tristate after the Nion transmits to allow the SR3 to transmit.

3

Re: RS-485 & Python - Help!

Thanks for the reply.

As I mentioned, the Nion and the SR3 are both half duplex, but RS-485 can be either.  Part of my problem is that my port monitor, being full duplex, cannot be used to test the SR3 (or the Nion.)

1. Every message sent to the SR3 ends with a CR.   I assume that implies that a CR is what tells it to transmit when the line is accessible.

2. My real code has multiple send/receive pairs.  Port monitor shows all of the Nion transmissions, but nothing from the SR3.

3. I suspect the line is 'biased' correctly, or my monitor wouldn't see anything.  I would also suspect that standard RS-485 transceiver circuits have pull-ups and/or pull-downs for line noise.

I wonder if my problem is the port.create parameters.  Does anyone have any info as to the parameters for it, and the other calls in the serial_port module?  I can't help but wonder if the "none" parameter is something similar to flow control.

Thanks,

Greg

4

Re: RS-485 & Python - Help!

1. That may be the case, but remains an assumption without a protocol specification. Even if it is, you need to ensure your transmitting node(the Nion) goes into tristate before the SR3 attempts transmission.

3. Likely, but good to double check. Nodes typically do have biasing circuitry installed, but sometimes this requires additional biasing depending on the number of nodes on the network and their impedances. Biasing is not done for noise immunity, but rather to keep the logic voltage levels within specification.

Your port monitor may work for monitoring purposes if you just use two wires. Just tag the RX pair across the two wire network. The RX pair of a full duplex device should always be in tristate, and should operate correctly as a receive-only node.

The 'none' parameter is probably the parity selection.

5

Re: RS-485 & Python - Help!

In response to Greg's questions about the correct method to initialize the serial port with Python, we are adding the following information into the NWare Help system:

The 485 mode in Python is controlled by the 'duplex' argument to the serial_port.create() method. 485 is assumed when half duplex is chosen.

The arguments to serial_port.create() are:
name - string: port name, COM# convention on nControl (e.g. "COM1"), path to port on Nion (e.g. "/dev/ttyS1")
baud rate - integer
data bits - integer; defaults to 8
parity - string: none, even, odd, mark, space; defaults to none
stop bits - float: 1, 1.5, 2; defaults to 1
duplex - integer: 0 = full duplex, 1 = half duplex; defaults to 0

name and baud rate are required. The others are optional.


Please let us know if you have questions!

Thanks!

Josh Millward
Burnt Orange Studios

6

Re: RS-485 & Python - Help!

Hi Josh,
Thanks for the info: could solve a few other questions.
Could you please add an example string? I find any protocol/syntax description makes much more sense when it can be read in conjunction with a couple of examples.
Please pass this comment on to Andy as well.

"The single biggest problem in communication is the illusion that it has taken place."
                                                                                        - George Bernard Shaw

7

Re: RS-485 & Python - Help!

GregL, one suggestion... grab a 232/485 convertor (or 485 serial port) and test your messages using Hyperterminal or PuTTY.  In other words, take the NION out of the equation to verify your message syntax and timings are correct.  Once that is verified, put the NION back in the equasion.

Thanks,

Joe

8

Re: RS-485 & Python - Help!

jvalenzuela wrote:

You can also use a scope to see of the line is going to tristate after the Nion transmits to allow the SR3 to transmit.

Back to it!  Scope is kind of buried.  Meter shows over 4 volts when all that should be happening is reads in the script.

Coversely, when I add a few writes to my script, my RS-485 monitor (full duplex, only read connected) shows the writes coming from the Nion.

Hence, in RS-485 / half-duplex, I don't believe the port is going tristate at any time.

Has anyone used the port in half-duplex mode and got it to communicate both ways?

Greg

9

Re: RS-485 & Python - Help!

To all,

I'm using a full duplex port monitor, and things are a little odd.  Setting this down until I can get a half duplex RS-485 unit on my pc so I can go back and forth with the Nion...

Greg

10

Re: RS-485 & Python - Help!

GregL wrote:

Has anyone used the port in half-duplex mode and got it to communicate both ways?

Yes, I have but ages ago.  There was one thing that hung me up (that I think got fixed since).  The 485 port had to be put in the correct mode from the GUI (enable serial, deploy, set the mode, baud, etc) first.  After that, you could then disable the port in the GUI, redeploy and interact with the port via a script.

Deploying multiple times was generally OK as long as the unit didn't loose power!

In other words, the Python implementation was not able to properly initialize the port fully (and persist it).  Again, it was a long time ago...

Last edited by Joe Kurta (2010-02-19 22:48:09)

Thanks,

Joe

11

Re: RS-485 & Python - Help!

Joe,

Thanks for the reply.

Joe Kurta wrote:

There was one thing that hung me up (that I think got fixed since).

Yes, that has been fixed.  I can boot the Nion with no pc conection and it's jumps right into transmitting on the RS-485.

I'm still having problems with the half-duplex.  I have two USB - RS-485 port monitors, but they're both normally used full duplex.  This weekend I could not get them to talk half-duplex.  Hence, I've got some more work to do before I even bring the Nion back into the equation...

Thanks,

Greg

12

Re: RS-485 & Python - Help!

Greg-

I would expect that for the purposes of monitoring, a full duplex unit would be fine. You can simply connect the Rx pair to the line you wish to monitor. However, this means that you will only be able to monitor and not send commands to the 485 network. So, this assumes that you already have some sort of 485 network set up and working that you can monitor.

So, I would suggest setting up a NION with an xControl or two and getting that working correctly first.
Then try attaching the Rx pair of your port monitor to the network to see if you can see the traffic that is happening.
I think this would at least get you moving in the right direction to make sure you really are seeing what you think you are seeing.

Josh Millward
Burnt Orange Studios

13

Re: RS-485 & Python - Help!

phils wrote:

Hi Josh,
Thanks for the info: could solve a few other questions.
Could you please add an example string? I find any protocol/syntax description makes much more sense when it can be read in conjunction with a couple of examples.
Please pass this comment on to Andy as well.

Hi Phil-

Sorry about the delay in answering this question. To be honest, the question slipped by while I was tied up with other stuff. Here is an example of how to initialize the port:

RS-232 port for 9600 baud:
port = serial_port.create( "/dev/ttyS0", 9600, 8, "none", 1, 0 )

EIA-485 port for 9600 baud:
port = serial_port.create( "/dev/ttyS1", 9600, 8, "none", 1, 1 )

So, each of these configurations is saying the following:
/dev/ttyS0 or /dev/ttyS1 = Identify which port you are using
9600 = baud rate
8 = data bits
"none" = parity
1 = stop bits
0/1 = duplex

I hope this helps!

Thanks!
-Josh

Josh Millward
Burnt Orange Studios

14

Re: RS-485 & Python - Help!

Josh,

With the full-duplex units as monitors, I could see what was happening wiht the rx pair, but I couldn't get the Nion to receive anything when going back and forth with transmitting.  That's when I thought I'd see if I could use the monitors by themselves.  They just wouldn't work half-duplex (I've got two of them).

Took one apart, got the chip data sheets, and turns out they can't do half duplex because there is no way to tristate the tx pair.  It's designed for a full-duplex fall over system, so a BU unit could pickup the line up if the 'master' dropped off.  The tx pairs only go tristate if the USB port is suspended.

Now, I've got to get a normal serial port monitor from B&B Electronics or something.  Any suggestions?  I'll need to control it with C# code.

Thanks,

Greg