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

0 Members and 1 Guest are viewing this topic.

Offline ChristofferB

  • Frequent Contributor
  • **
  • Posts: 662
  • Country: dk
  • Chemistry grad 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
Check out my scientific instruments diy (GC, HPLC, NMR, etc):
Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5345
  • 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: 390
  • Country: us
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/
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5345
  • 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: 885
  • 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: 2399
  • 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 »
 

Offline 16bitanalogue

  • Contributor
  • Posts: 33
  • 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.
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 11850
  • Country: gb
    • 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 ChristofferB

  • Frequent Contributor
  • **
  • Posts: 662
  • Country: dk
  • Chemistry grad 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
Check out my scientific instruments diy (GC, HPLC, NMR, etc):
Channel: https://www.youtube.com/channel/UCZ8l6SdZuRuoSdze1dIpzAQ
 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 2399
  • 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

  • Frequent Contributor
  • **
  • Posts: 789
  • 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

Offline NANDBlog

  • Super Contributor
  • ***
  • Posts: 4649
  • Country: nl
  • Current job: ATEX certified 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

  • Frequent Contributor
  • **
  • Posts: 789
  • 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
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5345
  • 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: 12069
  • 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: 23
  • 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
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5345
  • 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: 2645
  • 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: 1630
  • Country: gb
  • Test instrument designer/maker 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.
 

Offline arno

  • Contributor
  • Posts: 23
  • 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
 

Online 0db

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

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5345
  • 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: 23
  • 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

  • Frequent Contributor
  • **
  • Posts: 789
  • 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...
 

Offline Wolfgang

  • Super Contributor
  • ***
  • Posts: 1420
  • 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
 

Offline PKTKS

  • Frequent Contributor
  • **
  • Posts: 577
  • Country: br
Re: Best programming language for lab experiments
« Reply #25 on: May 02, 2020, 04:09:45 pm »
On more opinion to the list:

- It is pointed above the pathetic dependency of spaces in Python
- Actually python lacks "closures" - which any experienced programmer
  will 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 interaction
that 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 that

So 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 cents
Paul

« Last Edit: May 02, 2020, 04:16:27 pm by PKTKS »
 

Offline Mattjd

  • Regular Contributor
  • *
  • Posts: 207
  • Country: us
Re: Best programming language for lab experiments
« Reply #26 on: May 06, 2020, 12:38:03 am »
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.

 
The following users thanked this post: hendorog

Offline spudboy488

  • Regular Contributor
  • *
  • Posts: 129
« Last Edit: May 07, 2020, 12:32:37 pm by spudboy488 »
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 1972
  • Country: au
Re: Best programming language for lab experiments
« Reply #28 on: May 06, 2020, 12:48:35 pm »
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.  :P
 
The following users thanked this post: JustSquareEnough

Offline Doctorandus_P

  • Frequent Contributor
  • **
  • Posts: 789
  • Country: nl
Re: Best programming language for lab experiments
« Reply #29 on: May 09, 2020, 08:33:30 pm »
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.
 

Offline PKTKS

  • Frequent Contributor
  • **
  • Posts: 577
  • Country: br
Re: Best programming language for lab experiments
« Reply #30 on: May 10, 2020, 10:32:12 am »
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.

That 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 PIPES
  using 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 that

Now look how a simple version "upgrade"  will write a totally new
  library set of *ALL* that crappy objects...

Honestly.. python is far from consideration being a proper SHELL
script admin tool..  more likely a VB kinda wanna be

Flames are welcome - I know some die hard folks are python enthusiasts..
I just do not figure out why

Paul
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf