I work with various instruments such as scopes, rs232, rs422, serial to usb converters, and so on. I am having a hard time finding the differences between PyVISA and Pyserial. Is one strictly better than the other (unlikely I'm sure)? Does each have it's own strengths and weaknesses? Is a mixed approach most common?
I have worked with both PySerial and PyVISA and they generally seem to do the same thing. The internet has suggested: PyVISA for instrumentation automation control with scopes and GPIB devices, and PySerial for RS232 & other serial protocols.
So, in short, when should I use PyVISA versus PySerial?
-
This question is likely to lead to opinion-based answers.Péter Szilvási– Péter Szilvási2024年02月08日 19:43:20 +00:00Commented Feb 8, 2024 at 19:43
-
@PéterSzilvási, that's fine, as long as the answer is that it is purely preference. I won't waste my time researching further if the differences are negligible.tbickford– tbickford2024年02月08日 21:12:53 +00:00Commented Feb 8, 2024 at 21:12
-
"I work with various instruments such as ..." - Only the first item in your list is actually an "instrument". The next two are low-level, electrical protocols. The third is an interface and peripheral. I don't use Python, but from the descriptions, PySerial seems to consist of routines for using a UART or an interface that emulates one (e.g. USB CDC). There's no assumptions about what is connected on the remote end, and you're expected to implement everything to build or process messages/packets. Whereas PyVISA assumes/expects that the connected device is a measurement/test instrument.sawdust– sawdust2024年02月09日 00:55:09 +00:00Commented Feb 9, 2024 at 0:55
-
"Whereas PyVISA assumes/expects that the connected device is a measurement/test instrument." I don't believe that's the case. Serial communication is serial communication. VISA is just an overall industry standard for serial-based instrumentation but is not exclusive to instrumentation-oriented serial communication. I've used VISA (not specifically PyVISA) to communicate will all sorts of instruments, devices, sensors, etc.bmitc– bmitc2024年05月02日 18:25:40 +00:00Commented May 2, 2024 at 18:25
1 Answer 1
Put aside the opinions, there are some cases that forces you to choose one even only for RS232 access. As far as I know:
- If you want to read and write data using numpy, use pyVISA
- If you want to access RS232 as read/write a normal file, use pySerial. e.g. using readline()
- If you want import name be that same as pip install name, use pyVISA (just a joke. I hope someday I can import pyserial instead of serial for using it)
Of course there are many other key differences beyond my experience.
Comments
Explore related questions
See similar questions with these tags.