Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 version #13

Open
N0ury opened this issue Jun 10, 2019 · 16 comments
Open

Python 3 version #13

N0ury opened this issue Jun 10, 2019 · 16 comments

Comments

@N0ury
Copy link

N0ury commented Jun 10, 2019

Python 2 will be shortly deprecated.
Do you intend to port DS1054Z_screen_capture to Python 3 ?
Some people like me, have completely removed Python 2.

@ehiverson
Copy link

I ran the 2to3 script in an attempt to port it over. But I quickly ran into other issues: https://stackoverflow.com/questions/33003498/typeerror-a-bytes-like-object-is-required-not-str The top rated answer there explains the issue. I haven't solved the problem, either.

@DavidAntliff
Copy link

I have some experience porting Python code from 2 to 3 and may be able to help - is there a branch or fork currently underway?

@asyd
Copy link

asyd commented Jun 12, 2019

You should create a Pull Requests! I'll try to help as well.

@ehiverson You can convert a string to bytes by using 'string'.encode('ascii')

@ehiverson
Copy link

Ok! Here it is so far:
github.com/ehiverson/DS1054Z_screen_capture
All I've done is run 2to3 and used @anielson001 fix for pip_installed_distributions()

@ehiverson
Copy link

I made really good progress and have the port complete. I have a GUI using pyqt5. Right now it works over USB only, but soon I'll have it working over LAN too.

@DavidAntliff
Copy link

@ehiverson how's it going? Do you have LAN working yet? That's my use-case and I'd be happy to help test it.

@ehiverson
Copy link

@DavidAntliff yes I do. I added a small user interface so it is no longer a command line tool. It also works with a tektronix 2024b. I couldn't confirm why the telnet library didn't work out of the box for RoGeorge, so I started using the regular telnet library and it works fine. For the rigol, one can also save the full memory of the scope, not just what is on the screen.

@N0ury
Copy link
Author

N0ury commented Sep 9, 2019

Here's what I'm doing now:
echo ":DISPLAY:DATA? ON,OFF,PNG" | nc -w1 192.168.1.24 5555 | tail -c +12 > captures/DS1104Z_$(date '+%Y-%m-%d_%H.%M.%S').png
or
echo ":DISPLAY:DATA? ON,OFF,PNG" | nc -w1 192.168.1.24 5555 | dd bs=1 skip=11 of=captures/DS1104Z_$(date '+%Y-%m-%d_%H.%M.%S').png
with
param1: color ON or OFF (default: ON)
param2: inversion ON or OFF (default: OFF)
param3: BMP24|BMP8|PNG|JPEG|TIFF (default: BMP24)
192.168.1.24 is the Rigol's IP address

@N0ury
Copy link
Author

N0ury commented Sep 9, 2019

To get data only, you can do this (example with channel 1):

echo ":WAV:SOUR CHAN1
:WAV:MODE NORM
:WAV:FORM ASCii
:WAV:DATA?" | nc -w1 192.168.1.24 5555 > fic_out

You can then plot a graph in the way you like (matplotlib...)

@DavidAntliff
Copy link

Here's what I'm doing now:
echo ":DISPLAY:DATA? ON,OFF,PNG" | nc -w1 192.168.1.24 5555 | tail -c +12 > captures/DS1104Z_$(date '+%Y-%m-%d_%H.%M.%S').png
or
echo ":DISPLAY:DATA? ON,OFF,PNG" | nc -w1 192.168.1.24 5555 | dd bs=1 skip=11 of=captures/DS1104Z_$(date '+%Y-%m-%d_%H.%M.%S').png
with
param1: color ON or OFF (default: ON)
param2: inversion ON or OFF (default: OFF)
param3: BMP24|BMP8|PNG|JPEG|TIFF (default: BMP24)
192.168.1.24 is the Rigol's IP address

Thanks @nbenm, this is useful to know because it doesn't require the heavier dependencies of this or @ehiverson's project.

For me, the first method creates a PNG that looks OK in an image viewer for about a split second, then turns all blue. The file size is a few kilobytes smaller than those generated by the second method. The second method seems to create a proper PNG that I can view properly. However both methods require manually terminating the capture with CTRL-C - is that expected?

@N0ury
Copy link
Author

N0ury commented Nov 20, 2019

@DavidAntliff this is how this works:
the main command is "nc". It sends the string ":DISPLAY:DATA? ON,OFF,PNG" to rigol's ip on port 5555. Rigol in turn, executes the command (which is a capture), and sends the result back. This result goes then to "dd" or "tail" command.
We need then to skip the first 11 characters. They are not part of the PNG data.
Last result goes to the output file.
"dd" works better than "tail" with binary data. "tail" doesn't work always. That's why the second method is better.
But there's no reason to type CTRL-C to end the capture. I don't need to do this.

@DavidAntliff
Copy link

@nbenm ah, so your capture ends automatically? I'm running your command on Mac so I wonder if that accounts for the difference - maybe nc from brew doesn't support timeouts. I'll look into it.

@N0ury
Copy link
Author

N0ury commented Nov 20, 2019

@DavidAntliff try -w duration (in seconds) option.
That said, I use homebrew nc on Mac, and don't have any problem.

@N0ury
Copy link
Author

N0ury commented Nov 21, 2019

If you want to get real data, and not just a screen capture, you can do this:

echo ":WAV:SOUR CHAN1
:WAV:MODE NORM
:WAV:FORM ASCii
:WAV:DATA?" | nc -w1 192.168.1.24 5555 > file_out

replace 192.168.1.24 with your ip address
Here we get data from channel 1 (CHAN1)

You can then use matplotlib to draw graph, or simply use these data.

@DavidAntliff
Copy link

DavidAntliff commented Nov 23, 2019

@nbenm I'm using netcat installed with brew:

$ which nc
/usr/local/bin/nc
$ brew list netcat
/usr/local/Cellar/netcat/0.7.1/bin/nc
/usr/local/Cellar/netcat/0.7.1/bin/netcat
/usr/local/Cellar/netcat/0.7.1/share/info/netcat.info
/usr/local/Cellar/netcat/0.7.1/share/man/man1/netcat.1
$ /usr/local/bin/nc --version
netcat (The GNU Netcat) 0.7.1
Copyright (C) 2002 - 2003  Giovanni Giacobbi
..  -w, --wait=SECS            timeout for connects and final net reads
...

The timeout option doesn't seem to work for me if a valid connection is made. It just waits for data on the socket indefinitely regardless of the -w X value. The timeout only applies if the connection is bad (wrong IP address or port number).

However OSX's nc (in /usr/bin) does honour the timeout, so this works:

$ /usr/bin/nc -w1 $ipaddress $port

Can you check you're not inadvertently using the OSX nc rather than brew's nc?

@N0ury
Copy link
Author

N0ury commented Nov 23, 2019

@DavidAntliff you are right. I use OSX nc.
brew's nc isn't even installed.
I'm sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants