On 01/02/15 14:28, Alan Gauld wrote:

So, in Python I found pyserial and wish to use it to send binary to
controlled devices (in this case to a Modbus protocol solar charge
controller (TriStar TS-60).

In C++ I would setup ‘structs’ or class attributes to hold the byte
oriented commands and controller responses and then send them to rs232
as binary.  I do not see how to do that with pyserial.

Its not a PySerial function but Python allows you to define classes which can hold yoiuur data for you just like C++ Any reasonable python tutorial will tell you about the syntax.

Alternatively you could use the more advanced data types in Python to do the same thing, either a dictionary or even a list or tuple could be used.

What I need is to send and receive binary (not strings) over rs232.

The struct module is possibly what you need.
It contains functions somewhat like sprintf() and sscanf() in C.
You can convert binary data into byte strings and vice versa.

this case from/to a Raspberry Pi (RPI) controller to/from the solar
charge controller.  The RPI runs apache server to handle the network.

The type of computer is probably irrelevant for this case, although the OS and python version are not. Lets assume Linux and Python 2.7

Pyserial and struct and a dictionary or class should do all you need.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to