Author Topic: Best programming language for lab experiments  (Read 9456 times)

0 Members and 1 Guest are viewing this topic.

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Best programming language for lab experiments
« on: April 20, 2020, 03:54:41 pm »
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!

--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14299
  • Country: fr
Re: Best programming language for lab experiments
« Reply #1 on: April 20, 2020, 04:05:46 pm »
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.
 
The following users thanked this post: BurnedResistor

Offline guenthert

  • Frequent Contributor
  • **
  • Posts: 706
  • Country: de
Re: Best programming language for lab experiments
« Reply #2 on: April 20, 2020, 04:53:01 pm »
  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/
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14299
  • Country: fr
Re: Best programming language for lab experiments
« Reply #3 on: April 20, 2020, 05:43:45 pm »
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++).

Ah, 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.
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2281
  • Country: gb
Re: Best programming language for lab experiments
« Reply #4 on: April 20, 2020, 06:00:56 pm »
Python
pyserial
pyvisapy
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6145
  • Country: ro
Re: Best programming language for lab experiments
« Reply #5 on: April 20, 2020, 06:18:49 pm »
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 a free LabVIEW, too.

A much lighter and free alternative for LabVIEW could be MyOpenLab.

Another interesting graphic programming platform might be IBM's Node-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.
« Last Edit: April 20, 2020, 06:38:27 pm by RoGeorge »
 
The following users thanked this post: cdev

Offline 16bitanalogue

  • Regular Contributor
  • *
  • Posts: 53
  • Country: us
Re: Best programming language for lab experiments
« Reply #6 on: April 20, 2020, 06:43:25 pm »
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.
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19281
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Best programming language for lab experiments
« Reply #7 on: April 20, 2020, 09:37:48 pm »
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!

That'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.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: 0db

Offline ChristofferBTopic starter

  • Frequent Contributor
  • **
  • Posts: 929
  • Country: dk
  • Chemistry phd student!
    • My channel:
Re: Best programming language for lab experiments
« Reply #8 on: April 21, 2020, 01:14:07 pm »
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.


That'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.


This 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.




--Christoffer //IG:Chromatogiraffery
Check out my scientific instruments diy (GC, HPLC, NMR, etc) Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6145
  • Country: ro
Re: Best programming language for lab experiments
« Reply #9 on: April 21, 2020, 02:16:18 pm »
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 into Jupyter 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 give Anaconda a 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.

« Last Edit: April 21, 2020, 02:23:47 pm by RoGeorge »
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3322
  • Country: nl
Re: Best programming language for lab experiments
« Reply #10 on: April 21, 2020, 02:20:46 pm »
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-30ddc5339b66
https://towardsdatascience.com/pythons-expiration-date-b1a55f368f1a
https://www.quora.com/What-are-the-main-weaknesses-of-Python-as-a-programming-language

That 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".
« Last Edit: April 21, 2020, 02:47:55 pm by Doctorandus_P »
 
The following users thanked this post: SiliconWizard

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7307
  • Country: nl
  • Current job: ATEX product design
Re: Best programming language for lab experiments
« Reply #11 on: April 21, 2020, 03:31:30 pm »
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.


That'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.


This 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.
Yes. 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.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3322
  • Country: nl
Re: Best programming language for lab experiments
« Reply #12 on: April 21, 2020, 03:50:42 pm »
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
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14299
  • Country: fr
Re: Best programming language for lab experiments
« Reply #13 on: April 21, 2020, 04:53:13 pm »
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

Yep. Pretty nice tool.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Best programming language for lab experiments
« Reply #14 on: April 21, 2020, 05:14:13 pm »
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.
 

Offline arno

  • Contributor
  • Posts: 37
  • Country: de
Re: Best programming language for lab experiments
« Reply #15 on: April 28, 2020, 04:33:39 pm »
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
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14299
  • Country: fr
Re: Best programming language for lab experiments
« Reply #16 on: April 28, 2020, 06:46:47 pm »
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.

That'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.

 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3452
  • Country: it
Re: Best programming language for lab experiments
« Reply #17 on: April 28, 2020, 06:47:25 pm »
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
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2117
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Best programming language for lab experiments
« Reply #18 on: April 28, 2020, 07:17:23 pm »
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.
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline arno

  • Contributor
  • Posts: 37
  • Country: de
Re: Best programming language for lab experiments
« Reply #19 on: April 29, 2020, 02:21:05 pm »
Hi,

And that said, how easy would it be to use GPIB interfaces from Elixir?

I have never interfaced GPIB, but if there is a C library you can use that in Elixir/Erlang:

http://erlang.org/doc/tutorial/nif.html

73 de DL2SSB
 

Offline 0db

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: zm
Re: Best programming language for lab experiments
« Reply #20 on: April 29, 2020, 02:37:05 pm »
Labview has support.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14299
  • Country: fr
Re: Best programming language for lab experiments
« Reply #21 on: April 29, 2020, 02:47:06 pm »
I have never interfaced GPIB, but if there is a C library you can use that in Elixir/Erlang:

http://erlang.org/doc/tutorial/nif.html

Thanks - 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.
 

Offline arno

  • Contributor
  • Posts: 37
  • Country: de
Re: Best programming language for lab experiments
« Reply #22 on: April 29, 2020, 09:49:59 pm »
Thanks - 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...)

You 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
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3322
  • Country: nl
Re: Best programming language for lab experiments
« Reply #23 on: April 30, 2020, 01:28:55 pm »
A quick look of: https://www.startpage.com/row/search?q=gpib+to+usb+interface&l=english brings 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...
 

Online Wolfgang

  • Super Contributor
  • ***
  • Posts: 1773
  • Country: de
  • Its great if it finally works !
    • Electronic Projects for Fun
Re: Best programming language for lab experiments
« Reply #24 on: May 01, 2020, 02:31:23 am »
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!

Python, bar none.
Why:

- Free
- Powerful
- Huge bunch of libraries available (Graphs, Analyis, math, ...)
- a lot of instrument drivers already exists for common instruments
- Futureproof
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf