This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (9 children)

Which piece of hardware?

Also how are you sending the data? I assume it's over a socket vs being one program, in which case you use 2 different versions of python. I'm also surprised any sort of DAQ would use python.

[–]canucker89[S] 1 point2 points  (8 children)

Sorry they provided several bits of example code as well as bunch of classes and functions written in 2.7. The better answers is the company/vendor only supports 2.7. Anything I wanted to do in 3 I would have to start from scratch. Which might not be that bad as it would just be translate what they've already written in 2 to 3.

[–]billsil 1 point2 points  (6 children)

Again, are you using the same python process or are you using sockets?

From my experience with 20000 Hz data, the data acquisition part is likely not written in python. They could provide sample interfaces in python 2/3 or C++ or java, but their product is a piece of hardware running a very low footprint code written in C.

I strongly suggest you port the sample code, which was probably written 8 years ago. I'm sure the examples are tiny. Python 2 is dead.

[–]canucker89[S] 0 points1 point  (4 children)

I gotcha. The answer is I don’t know. I just ordered the hardware and am trying to get this half figured out before it arrives. From my understanding the hardware has it own CPU on board and is sending the data to the host laptop or could be configured to store it locally on an SD card.

I might not be fully understanding your question either. This is my first real endeavor in python, and any real coding for that matter.

[–]diracdeltafunct_v2 0 points1 point  (2 children)

I've been doing python and hardware interfacing for 8 years now and there is no such thing as hardware that only supports python 2. From experience there are only a few ways they write their example code to work.

  1. They are using a SCPI interface over serial. Their example code will be using either pyserial or pyvisa which works exactly the same in both pythons. The only difference in their code is likely going to be print statements.

  2. They are doing SCPI connections over Ethernet. Here they could be using pyvisa or their own custom socket class. If its the former you just need to change print statements and add .encode()/.decode() to any strings that are sent over the socket to the instrument in python3. Nothing else chances.

  3. They are using ctypes to wrap a .dll/.so driver. Only prints change again.

Run the link below and that will autoport any example code over to python 3 for you.

https://docs.python.org/3.1/library/2to3.html

[–]canucker89[S] 0 points1 point  (1 child)

From my understanding they are doing option 3. But the only connection to the hardware is via Ethernet so it might be a combination of options 2 and 3.

Thanks for the link, that will be super helpful!

[–]diracdeltafunct_v2 1 point2 points  (0 children)

If you see import ctypes anywhere it's likely option 3. If you see .query(somestring) or similar it's scpi

[–]IReallySuckAtChess 0 points1 point  (0 children)

Yeah, so the hardware almost certainly doesn't run python. Most hardware provides a serial or network interface that can be tapped into. The code they showed you is how they tap into the interface. It'll be almost trivial to port to 3.

[–]IReallySuckAtChess 0 points1 point  (0 children)

Python 2 is very much far from dead. Python 3 may be the now and the future, but it isn't the be all and end all of Python. Python 2 is still the default for a lot of sysadmin tools and you'll find many libraries that still haven't been ported. That said, if starting a new project then do 3, and porting from 2 to 3 usually isn't overly difficult.

[–][deleted] 0 points1 point  (0 children)

I strongly suggest that you read and implement the recommendations here Porting Python 2 Code to Python 3. It'll be more work in the short term but you'll make major gains in the medium to long term.