PyConPro
PyConPro is a python library that allows us to make multiple consumer connections with multiple PLCs. At some point we would also like to add a feature allowing producer connections, but we don't know when that will happen.
This library has three main classes: Connection, PLC, and Consumer. Each of these are responsible for a different part of the Consumer/Producer protocol.
Usage Guide#
In order to start a connection with any PLC, an instance of the Connection class must be created and then started.
Then, we can add a plc using the addPLC function.
To start a Consumer/Producer, we first need to define the ConsumerHint.
- Set
tagto the name of the tag you would like to log. - Set
datasizeto the bytesize of the tag. - Set
rpito your desired delay between data points (in milliseconds). - Set
otrpito a number slightly higher than yourpi. (More documentation needed)
important
The datasize field must include an extra 2 bytes for the header.
I.e. if the tag has 4 bytes of data, set datasize to 6.
Common Issues
Before logging, make sure the tag is configured to accept a Consumer/Producer connection.
We also need to provide our consumer a function to handle the data we recieve.
Now, we initialize and start the consumer.
You should get an output that looks something like this:
To stop the consumer, call myConsumer.Stop().
Full Example#
Here's a full example showing it's possible to log more than one tag at a time.
The Please Reset Error#
If, after all consumers with a particular PLC are stopped, another consumer connection
with that PLC is started, a PleaseResetError may be thrown. This could occur for
two reasons:
- The PLC stopped listening
- An unhandled part of the Consumer/Producer protocol was used. This particular issue can happen if a consumer is started to soon after all of the other consumers for a particular PLC were stopped.
If either of these issues are encountered, just try to start the consumer again.
Note: this solution is abstracted away by the server.