Best programming language for lab experiments - Page 1
Forum section: electronics / general

author: ChristofferB
author_rank: Frequent Contributor
timestamp: April 20, 2020, 03:54:41 pm
content: Hey all!I'm trying to find a programming language or environment (for PC) suitable for doing a lot of interfacing with serial ports, parallel ports (possible GPIB), and so on, and then dumping to files.Is there something in the experimental physics/ test and measurement world that's ideal for this? Oh, and most importantly: it needs to be not Labview, because I'm aware what I'm looking for is pretty much labview.Any hints would be appreciated!

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 20, 2020, 04:05:46 pm
content: Although I'm not a huge fan of Python myself, I guess it would be a decent fit here. You can find libraries for serial port comm, GPIB interfaces, etc.

author: guenthert
author_rank: Frequent Contributor
timestamp: April 20, 2020, 04:53:01 pm
content: Yes, Python seems most popular these days (the BASIC of the early WWW age) and perfectly capable of such tasks, if performance is irrelevant. Reading from serial/parallel ports and dumping into files sounds to me like a job for C, but that depends on programming background, I suppose. It might even be sensible to code the performance critical parts in C or C++ and the less critical parts in python, but that's already a more challenging approach.If this is for a private one person lab, then use whatever you prefer. If this is a shared lab application, don't use something others will hate you for later (e.g. FORTH or perhaps aforementioned C/C++).If you like Labview, but not its price and tu habla espanol, then MyOpenLab might suit you:https://myopenlab.org/inicio/en/

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 20, 2020, 05:43:45 pm
content: Quote from: guenthert on April 20, 2020, 04:53:01 pmAh, yes indeed. That's also why I suggested Python while not a fan of it.I have written quite a few lab/production tools in C, and they all performed very well. But yes, most people having to/willing to modify them were not too happy about them written in C. Not just because C had become less popular itself, but mainly because it certainly had become not popular at all for technicians/lab people.

author: voltsandjolts
author_rank: Unknown
timestamp: April 20, 2020, 06:00:56 pm
content: Pythonpyserialpyvisapy

author: RoGeorge
author_rank: Super Contributor
timestamp: April 20, 2020, 06:18:49 pm
content: Any language can do that, so the best is the one you are used to.1. Try Python. It already has plenty of modules including those related with instruments control (SCPI, MODBUS, etc.) data processing, charting and so on. Probably the most productive choice.2. Another approach might be Octave (or Matlab if you don't like free of charge). Their automation tools (if you need more than just data harvesting, for example if you want an Arduino board to control a temperature loop while measuring the response of a circuit under test) are SciLab (respectively Simulink)3. A 3rd option would be LabVIEW, a graphical programing language from National Instruments, where instead of typing code, you drag and drop symbols, like in a schematic editor. Can also build panels with knobs, buttons, displays, charts, and so on. Not free, but full of features and of high level processing blocks, also works with any NI hardware/instrument. LabVIEW is the one where the free NI-VISA is from (the GPIB/SCPI/etc. drivers for instruments). There is a very cheap home use license, and by now there should be afree LabVIEW, too.A much lighter and free alternative for LabVIEW could beMyOpenLab.Another interesting graphic programming platform might be IBM'sNode-RED. Not sure if you'll find all the nodes you'll need (the ones you enumerated should already be easy to find), and it's free, open, and very good looking, so why not.

author: 16bitanalogue
author_rank: Regular Contributor
timestamp: April 20, 2020, 06:43:25 pm
content: I absolutely love Python.1. Plenty of libraries as deep as your imagination and plenty of support.2. It's fantastic for lab automation and data manipulation.I have automated my lab bench in Python where I can control settings for my scope, PSU, meters to capture, analyze, and plot data.I do not need memory optimization or speed, so my goto is Python with the PyCharm IDE.

author: tggzzz
author_rank: Super Contributor
timestamp: April 20, 2020, 09:37:48 pm
content: Quote from: ChristofferB on April 20, 2020, 03:54:41 pmThat's probably the wrong question...A better one would be "what environment, operating system, application, and libraries best support my devices and computations?". The language will emerge from the answer to that question.

author: ChristofferB
author_rank: Frequent Contributor
timestamp: April 21, 2020, 01:14:07 pm
content: Thanks for the suggestions! I already know some python, so that might be the place to start.I have approximately the same level of experience with C as with Python, but I get the feeling python might be more ideal for rapid 'thrown together' programming.Quote from: tggzzz on April 20, 2020, 09:37:48 pmThis is universally true for any programming challenge, but I'm just trying to figure out if there's some kind of standard that's most commonly used.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 21, 2020, 02:16:18 pm
content: Python is a very good choice.Also has the advantage that it doesn't need compiling, like C needs. Being interactive is a big plus for Python while prototyping, when you want to quick test an idea during an experiment, etc.You may also want to look intoJupyter Notebook, too. You can have many tools and languages under the Jupyter Notebook, and it's easy to try and see the results on the spot. Also good for sharing data analysis results.If you don't mind an even higher level platform wrapper (some might call it bloatware, but if disk space is not an issue, and you are interested in productivity/functionality more than in ideological purism), than you might want to giveAnacondaa try, too. All major science and data processing software including Scientific Python (ScyPy), Jupyter Notebook, virtual environments and so on can be installed from Anaconda.Anaconda's advantage is you just click and install any meta package you want (can be anything, not Python only), that otherwise might take you days to find out what components you need and how to install them, then later how to manage that mixed toolchain. With Anaconda you just click on them and install everything in one go, without worrying about what components you need, or versions compatibility.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 21, 2020, 02:20:46 pm
content: I've been programming uC's as a hobby in C for some 25 years. Started with the at90s2313 when it was brand new and I discovered GCC had a port to it.Before that, uC's were always difficult and expensive for various reasons.Lately I've also learning Python. It is not a language I particularly like. It feels like it's developed by hobbyists. It has a completely ridiculous dependency on whitespace for example. It has also taken over 10 years for python2 to finally go obsolete, and in the last year some open source projects were struggling to convert to Python3 because they depended on some Python libraries that were still not available for Python 3.Here some more about the limitations of Python:https://towardsdatascience.com/why-python-is-not-the-programming-language-of-the-future-30ddc5339b66https://towardsdatascience.com/pythons-expiration-date-b1a55f368f1ahttps://www.quora.com/What-are-the-main-weaknesses-of-Python-as-a-programming-languageThat said, the decision to start learning Python3 was not a light one for me. It seems that Python has become the de facto standard for scripting stuff.Sigrok uses Python for the protocol decoders, so you fairly easily modify one for your own lab needs.KiCad uses Python as a scripting language for the footprint wizards, the "replicate layout" script and more.FreeCAD also uses Python for scripting.Python is not a fast language, but the amount of data generated by a serial port or GPIB bus is minimal for an even 15 year old PC.Python is pretty good at file (and data) manipulation. Opening a file, reading it into a buffer, searching through it, and conditionally replace something in the file is about 5 lines of python code.In the last 2 weeks or so I've been working on my first real Python program, which I have named MumarPlot and attached to this post. It is a prgram that catches data from a Socket, and uses that data to draw graphs with it with matplotlib. It can also store the data to a file, and read those files back.As it is, it's very preliminary, has some serious bugs and half the comment is in Dutch, but still, I attach it here because it seems to be very near to what you want. There is also lots of debug info in the program which are mostly left overs from the earliest stages of the MumarPlot. Note that I am still learning Python.You can test MumarPlot by starting netcat in listening mode: "netcat localhost 3000 -l" , and after starting MumarPlot (which has it's own command interpreter) type "feed localhost 3000" on the command prompt. After that you can Copy & Paste "Motor.txt" in netcat to see a graph being drawn of some PID parameters of a motor controller.You do have to install matplotlib to run MumarPlot. If I remember well I did it with "sudo apt install python3-matplotlib".

author: tszaboo
author_rank: Super Contributor
timestamp: April 21, 2020, 03:31:30 pm
content: Quote from: ChristofferB on April 21, 2020, 01:14:07 pmYes. You can log from a desktop DMM to a CSV file in 10 lines of code through Ethernet. Nothing even comes close to being as simple.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 21, 2020, 03:50:42 pm
content: About logging from existing DMM's and such...Have a look at the Sigrok project.It's not only a very usable Logic Analyser (with USD 10 hardware in the form of the CY7C680something dongles) but it can also log data from lots of existing DMM's. Sigrok supports some 200+ devices. Some of these use weird formats, such as sending the segments of the LCD over a serial connection instead of numbers.https://sigrok.org/wiki/Supported_hardware

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 21, 2020, 04:53:13 pm
content: Quote from: Doctorandus_P on April 21, 2020, 03:50:42 pmYep. Pretty nice tool.

author: james_s
author_rank: Super Contributor
timestamp: April 21, 2020, 05:14:13 pm
content: I would also vote Python, it's a great language, very easy to use and there is a large demand for Python developers and SDETs so it's a useful language to know.Really though any language will work for what you're trying to do, so if you already know a general purpose language try using that one.

author: arno
author_rank: Contributor
timestamp: April 28, 2020, 04:33:39 pm
content: Dear all,I found that Elixir (based on Erlang) is a pretty decent language handling serial communication. When it comes to logging data, Elixir, including Phoenix web server, might be the tool you want.73 de DL2SSB

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 28, 2020, 06:46:47 pm
content: Quote from: arno on April 28, 2020, 04:33:39 pmThat's an interesting suggestion. Unfortunately, using Elixir to control lab instruments, I'm sure it would have high potential to make you look like a weirdo. That's already a bit the case when you use C in this context these days... so Elixir... ahem.And that said, how easy would it be to use GPIB interfaces from Elixir?Not saying Elixir is bad though. Your post should IMO be an opportunity for people reading this thread to have a look at it.

author: JPortici
author_rank: Super Contributor
timestamp: April 28, 2020, 06:47:25 pm
content: what i used for this: VB6,Visual C#what i'm using now for this: Qt and C++. i like qt much much much much more than dotnet for pretty much everything

author: fcb
author_rank: Super Contributor
timestamp: April 28, 2020, 07:17:23 pm
content: Python probably the best choice as your likely to find something you can bootstrap off.LibertyBasic is super easy and can deal with serial OK.That said, we write most of our PC stuff in PureBasic.

author: arno
author_rank: Contributor
timestamp: April 29, 2020, 02:21:05 pm
content: Hi,Quote from: SiliconWizard on April 28, 2020, 06:46:47 pmI have never interfaced GPIB, but if there is a C library you can use that in Elixir/Erlang:http://erlang.org/doc/tutorial/nif.html73 de DL2SSB

author: 0db
author_rank: Frequent Contributor
timestamp: April 29, 2020, 02:37:05 pm
content: Labview has support.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 29, 2020, 02:47:06 pm
content: Quote from: arno on April 29, 2020, 02:21:05 pmThanks - alright that should be doable through NIF. I doubt there is any ready-made NIF code for GPIB though, so that would be some extra work, and probably requires good knowledge of Erlang (which is not very likely for someone just learning...)Not sure I would suggest that to the OP as I said... but hey, if someone's ready to do it, that should be interesting.

author: arno
author_rank: Contributor
timestamp: April 29, 2020, 09:49:59 pm
content: Quote from: SiliconWizard on April 29, 2020, 02:47:06 pmYou will also need good knowledge of C - there is a good chance that you can crash the Erlang VM if the NIF crashes.73 de DL2SSB

author: Doctorandus_P
author_rank: Super Contributor
timestamp: April 30, 2020, 01:28:55 pm
content: A quick look of:https://www.startpage.com/row/search?q=gpib+to+usb+interface&l=englishbrings up lots of results, from hobby projects to commercial products.Al those small linux computers have plenty of I/O for making a GPIB interface...

author: Wolfgang
author_rank: Super Contributor
timestamp: May 01, 2020, 02:31:23 am
content: Quote from: ChristofferB on April 20, 2020, 03:54:41 pmPython, bar none.Why:- Free- Powerful- Huge bunch of libraries available (Graphs, Analyis, math, ...)- a lot of instrument drivers already exists for common instruments- Futureproof

author: PKTKS
author_rank: Super Contributor
timestamp: May 02, 2020, 04:09:45 pm
content: On more opinion to the list:- It is pointed above the pathetic dependency of spaces in Python- Actually python lacks "closures" - which any experienced programmerwill certainly be radically against such odd "feature"- Python lacks proper OS low level features- It totally relies on a stupid "each version" each run byte compiled LIB set- It may seem easy for a novice with those libs and that "object" like look- Experienced OO folks will obviously ask where are the templates ?- without them OO is pure bullshit.- PERL is not stupid like python with the libs - PERL is not "byte compiled"- and no dependency of that stupid "tree" library - CPAN confirm that- but even far more low level to OS PERL still is interpreted- Although order of magnitude better and cleaner than Python- Serious folks will of course require: low level interactionthat means possibly assembly and in line code- TEMPLATES of course - there is nothing more high level so far.- Fast and clean memory bitmap and canvas OPS - that is C of course.- STL and libc are handy - C does not put "version" crap - the linker resolves thatSo a serious fast and more suitable option is still C/C++novices folks are scary as that may take a decade to manage - and more.2 centsPaul

author: Mattjd
author_rank: Regular Contributor
timestamp: May 06, 2020, 12:38:03 am
content: I dont know what it is about this forum but it seriously always has so much hate against anything remotely mainstream.OP, use Python.Its a great language, not the fastest, but the parts that need to be fast (numpy, pandas, sklearn) are just as fast as Matlab if not faster in some areas. Its got huge amounts of open source libraries for all sorts of things. Theres multiple libraries for control Rigol instruments, and I am sure others.Cherry on the cake is that Python is actually relevant, and jobs look for it. Mainly because its free and the huge amount of open source support it has.

author: spudboy488
author_rank: Regular Contributor
timestamp: May 06, 2020, 12:07:21 pm
content: LabView NXG ?See the link inhttps://www.eevblog.com/forum/general-computing/labview-community-edition-released-(free-noncommercial!)

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: May 06, 2020, 12:48:35 pm
content: Obviously only applies if your OS is Windows.I find C# a far better language than python and that is what I would choose.Stronger Typing, no ridiculous white space mistakes, better multithreading apparently, very nice GUI controls, fantastic IDE.Also no Zen of Python bullshit. This used to aggravate me no end when I was doing python.If they thought explicit was better than implicit then they should've used semicolons.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 09, 2020, 08:33:30 pm
content: Python uses duck typing.If it looks like a duck, and if it quacks like a duck then it is probably something that wants you to think it is a duck.I would prefer perl above python if the language alone was taken into consideration.Unfortunately I have a limited amount of space in my head and time is also a one-way street.As I wrote before, I started using python because it's used as a scripting language in almost all the open source tools I use. And I'm really hoping for Python4 with strong typing and without the ridiculous whitespace dependency, but it's one of the compromises in life.

author: PKTKS
author_rank: Super Contributor
timestamp: May 10, 2020, 10:32:12 am
content: Quote from: Doctorandus_P on May 09, 2020, 08:33:30 pmThat is mostly a perfect definition.I need to reinforce it with some worth points as well:- While python insists of being strangely "object" only dependent..- It will not suit a *NIX environment properly- Example *before* the flames arise:** Look how python interact with "PIPES" (primary building block of good OS)** they crafted a totally wacko object "module" with a more odd thing...** which oddly enough they call "template" (which you derive a pipe from)- Now compare that with how PERL interacts *DIRECTLY* with PIPESusing a dozen direct ways to handle PIPES.- Just a simple start point of comparison.. extend that to signals- sockets... and process handling. Python is brain damaged doing thatNow look how a simple version "upgrade" will write a totally newlibrary set of *ALL* that crappy objects...Honestly.. python is far from consideration being a proper SHELLscript admin tool.. more likely a VB kinda wanna beFlames are welcome - I know some die hard folks are python enthusiasts..I just do not figure out whyPaul