3rd Party Python Library PySerial

I am attempting to use the PySerial library in a similar scenario to the one in topic "Using 3rd Party Python Library - PySerial".
I don't see the resolution mentioned and was wondering if "mdia" ever got it working.
I get an error "ImportError: No module named serial" when I test my code in the Script Console. I am using "import serial" and it works fine in my Python test program.
I tried putting the PySerial files in the "C:\Inductive Automation\Ignition\user-lib\pylib"but that doesnt work.
If this should work, I would like a brief description of which files I need and which directory they need to be in.

Does that library use any DLLs? If so, it won't work in jython.

Ignition supplies APIs for using serial ports. You should use them.

2 Likes

I am aware of the Ignition API but can't go that route for what I am doing. I am not sure if DLL's are involved but I can look into that. Assuming there are no DLL's where should the py library files go?

Where you already tried.

That it failed suggests that PySerial has dependencies you are missing, or you've used a python3 version (jython is v2.7), or some similar incompatibility. If PySerial supplies a DLL or .so, or any dependency supplies one, you simply cannot use it.

You want this to run inside Ignition? Use the Ignition API. :man_shrugging:

Ah, yes, I have python 3.12 installed. I can install the older 2.7 Verion if it includes the correct libraries. I am still checking to see if DLL's are involved.
Again, I am NOT using the API so I need to figure a solution out.

Ignition is a managed environment where you use Jython, the language, that's generally compatible with Python 2.7's language semantics. However, your execution environment is the JVM, not CPython's C-based runtime.

It is simply not possible to take arbitrary libraries written without care for this distinction, drop them into Ignition, and have them work.

It sounds like you're trying to take some higher level script/library that you've got working against the PySerial API and drop it directly into Ignition, but you're not being very clear about why you can't use the system.serial API (I'll echo Phil - absolutely the recommended path here) so we can't really advise anything further.

5 Likes

In reading through Github, it looks like version 1.0 supported it, but then was broke later on and possibly fixed again. Not sure, but as others have stated, you're pretty much on your own once you start importing 3rd party libraries especially since there's an API already built-in.

It's always better to do something natively inside Ignition if it's possible rather than trying to get 3rd party libraries to work if what you need to do is possible in Ignition. That way you can get some help from official support.

Here's the Github link I found the changelog on: pyserial/CHANGES.rst at 7aeea35429d15f3eefed10bbb659674638903e3a · pyserial/pyserial · GitHub

Edit: Also read this section on Older Versions: pySerial — pySerial 3.4 documentation

3 Likes

I understand the explanations and the underlying issues involved with attempting to use the PySerial library. I will pursue another solution for what I am attempting to accomplish. Thanks for everyone's input on this!

Yes, you are correct. I have perfectly functional Python code that doesn't translate properly after substituting the serial port functions from the Ignition API. The problem is that the parsing features I am using are not available n Jython. I spent some time trying to rewrite my code to work and just gave up out of frustration. Another problem is that scripting tool is horrible when it comes to debugging code. It doesn't support breakpoints or any of the nice debugging features I have available in VS Code. It just sucks for troubleshooting. Bottom using the API is a poor substitute for what I already have working which is why I was trying to find a better way of accomplishing what I wanted. I can send you a python code example if you are willing to take a stab at replicating it in Jython.

Shoot. You'll find a bunch of people around here that actually LOVE an occasion to code.

3 Likes

aii you stuck in meetings all day ?

1 Like

Serial Test 6-5-24.py (1.9 KB)

This is a simple test file

Something far more evil.

2 Likes