Run Python scripts from Remote host and on Red Pitaya.

Just about everything about Red Pitaya
KKE
Posts: 5
Joined: Fri Jan 08, 2016 3:54 pm

Run Python scripts from Remote host and on Red Pitaya.

Post by KKE » Mon Feb 01, 2016 11:38 am

I just spend about 4 hours to write a "smart" post about the topic above. Only to find the forum software neglects to save a draft after it asked me to relogon.
I'm not inclined to write it again.
My questions:
  • How do write a python script and run it on a remote host?
    How do I write and run a python script on the RedPitaya hardware?
If your reply contains a link to any of these webpages, don't bother, I've tried them. They are either incomplete or wrong!
http://redpitaya.com/examples-new/blink/
http://clade.pierre.free.fr/python-on-r ... vbuild.zip
https://pypi.python.org/pypi/PyRedPitaya/1.0
http://redpitaya.com/control/?with=matlab

Thanks,

KKE

KKE
Posts: 5
Joined: Fri Jan 08, 2016 3:54 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by KKE » Mon Feb 01, 2016 6:37 pm

Nevermind, I solved my problem.

I know this is bad netiquette. But i figure that when one pays €244,00 for a piece of hardware at least the documentation should be up to date.

To get the example running you need to place the module https://raw.githubusercontent.com/RedPi ... ya_scpi.py in the same folder the blink.py example is in. Also don't forget to start the scpi server:

Code: Select all

redpitaya> systemctl start redpitaya_scpi &


Where it says edit the source and enter your RedPitaya's IP address ...

Code: Select all

#!/usr/bin/python

import sys
import time
import redpitaya_scpi as scpi

rp_s = scpi.scpi(sys.argv[1])

if (len(sys.argv) > 2):
  led = int(sys.argv[2])
else:
  led = 0

print ("Blinking LED["+str(led)+"]")

period = 1 # seconds

while 1:
    time.sleep(period/2.0)
    rp_s.tx_txt('DIG:PIN LED' + str(led) + ',' + str(1))
    time.sleep(period/2.0)
    rp_s.tx_txt('DIG:PIN LED' + str(led) + ',' + str(0))
This script should be called from the commandline using:

Code: Select all

./blink.py <IP-address>
Or one could edit the file and replace sys.argv[1] in the scpi.scpi() call with '<IP-address>'

Running scripts directly from RedPitaya is the next step.

jeanminet
Posts: 33
Joined: Tue Aug 25, 2015 12:17 pm
Contact:

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by jeanminet » Mon Feb 29, 2016 8:28 pm

Hi, you can the script on the RedPitaya the same way using localhost ( ip-address = '127.0.0.1').

VincKem
Posts: 2
Joined: Tue Feb 02, 2016 12:37 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by VincKem » Fri Mar 18, 2016 6:05 pm

Thanks a lot guys !!! This is exactly what I was looking for :)
Is there a way to update the http://redpitaya.com/control/ explanation ?
Vincent

luigiraffaele124
Posts: 12
Joined: Sun May 29, 2016 5:26 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by luigiraffaele124 » Sat Oct 15, 2016 3:53 pm

Dear kke
I'm novice in RP.
I'm not understand a step in your explanation.

I start scpi server on redpitaya by means of putty connection and the command redpitaya> systemctl start redpitaya_scpi &
I'm windows 10, so, I copy the blink.py code and save it as blink.py on my w10 desktop.
I copy the redpitaya_scpi.py and save it as redpitaya_scpi.py on my w10 desktop.

And now?
You say "This script should be called from the commandline using: ./blink.py <IP-address>
I intend the IP-address is that of redpitaya card.
But, what are you intending as commnadline: cmd in window 10, cmd in redpitaya accessible by putty (in which directory?), others?

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by Nils Roos » Sat Oct 15, 2016 8:12 pm

the IP-address is that of redpitaya card.
Correct.
But, what are you intending as commnadline: cmd in window 10, cmd in redpitaya accessible by putty (in which directory?), others?
The missing step is that you need to have a python interpreter installed on your computer for this. When you execute a .py file from a linux console, the shell will try to run it by calling python. On Windows, if you have the .py extension associated with the python interpreter, double-clicking the .py file should achieve the same effect.

luigiraffaele124
Posts: 12
Joined: Sun May 29, 2016 5:26 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by luigiraffaele124 » Sun Oct 16, 2016 6:13 pm

I have installed a phyton interpreter and I have launched the blink file, but I have an error. View attachment
You do not have the required permissions to view the files attached to this post.

luigiraffaele124
Posts: 12
Joined: Sun May 29, 2016 5:26 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by luigiraffaele124 » Sun Oct 16, 2016 6:16 pm

This is my scpi file, as modified with my RP IP adress and Port.
Also if I write the port number without the single quote, the situation and the error don't change
You do not have the required permissions to view the files attached to this post.

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by Nils Roos » Sun Oct 16, 2016 6:30 pm

My knowledge of python is very slim, so I can't really tell you why there's a syntax error. It may have to do with the version.

What I can tell you is that the scpi-server listens on port 5000 by default (unless you tell it otherwise on the command line), so you should keep the 5000.

luigiraffaele124
Posts: 12
Joined: Sun May 29, 2016 5:26 pm

Re: Run Python scripts from Remote host and on Red Pitaya.

Post by luigiraffaele124 » Tue Oct 18, 2016 11:03 am

It's just a matter of Python version.
With Python 2.7, the script works fine.
With Python 3.5, there is a incompatibility.
As example, the row:

print 'SCPI >> connect({:s}:{:d}) failed: {:s}' .format (host, port, e)

works fine in 2.7, but in 3.5 it should be transformed in

print ('SCPI >> connect({%s}:{%d}) failed: {%s}'% (host, port, e))

But there is others incompatibility.
As example, in 3.5 there is a problem when digital_led_blink.py is calling a "tx_txt" Method of the "scpi" Class.
Anyway, now I'm using 2.7, so there aren't problems.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 118 guests