Float to string conversion error on python

Just about everything about Red Pitaya
Post Reply
shiraznantogma
Posts: 3
Joined: Sun Sep 03, 2023 1:02 am

Float to string conversion error on python

Post by shiraznantogma » Mon Sep 04, 2023 5:43 am

I have this python code as a signal generator. But it keeps giving me string to float conversion error.

import sys
import redpitaya_scpi as scpi
import numpy as np
import matplotlib.pyplot as plt

# Define signal parameters
wave_form = 'sine'
freq = 10000
ampl = 1

# Connect to the Red Pitaya device
rp_s = scpi.scpi(sys.argv[1])

# Reset the signal generator settings
rp_s.tx_txt('GEN:RST')

# Configure the signal generator
rp_s.tx_txt('SOUR1:FUNC ' + str(wave_form).upper())
rp_s.tx_txt('SOUR1:FREQ:FIX ' + str(freq))
rp_s.tx_txt('SOUR1:VOLT ' + str(ampl))

# Enable output
rp_s.tx_txt('OUTPUT1:STATE ON')
rp_s.tx_txt('SOUR1:TRIG:INT')

# Generate a time axis
sample_rate = 125000000 # Sample rate of the Red Pitaya
duration = 0.1 # Duration of the signal in seconds
num_samples = int(sample_rate * duration)
time_axis = np.arange(0, num_samples) / sample_rate

# Query the generated waveform data
try:
rp_s.tx_txt('SOUR1:DATA:DATA?')
data_string = rp_s.rx_txt()
print(data_string)
data_string = data_string.strip('{}\n\r').replace(" ", "").split(',')
print(f"Received data: {data_string}")
data = list(map(float, data_string))
except Exception as e:
print(f"An error occurred: {e}")

data = list(map(float, data_string))
# Plot the generated signal
plt.figure(figsize=(10, 4))
plt.plot(time_axis, data)
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.title("Generated Signal")
plt.grid(True)
plt.show()

User avatar
redpitaya
Site Admin
Posts: 912
Joined: Wed Mar 26, 2014 7:04 pm

Re: Float to string conversion error on python

Post by redpitaya » Mon Sep 04, 2023 11:30 am

Hello shiraznantogma,

Thank you for writing to us.

A couple of commands on the acquisition side are missing in your code which start the acquisition and define the trigger type. Also, the command for acquiring data from the Red Pitaya should be:

ACQ:SOUR1:DATA?

Most likely, this is the reason you are receiving a string ("ERR") instead of the data.

Please check the available SCPI commands and acquisition examples on this link:
https://redpitaya.readthedocs.io/en/lat ... -or-python

The examples will help you with the correct acquisition command sequence.

shiraznantogma
Posts: 3
Joined: Sun Sep 03, 2023 1:02 am

Re: Float to string conversion error on python

Post by shiraznantogma » Wed Sep 06, 2023 5:44 pm

Thank you very much

shiraznantogma
Posts: 3
Joined: Sun Sep 03, 2023 1:02 am

Re: Float to string conversion error on python

Post by shiraznantogma » Wed Sep 06, 2023 5:44 pm

redpitaya wrote:
Mon Sep 04, 2023 11:30 am
Hello shiraznantogma,

Thank you for writing to us.

A couple of commands on the acquisition side are missing in your code which start the acquisition and define the trigger type. Also, the command for acquiring data from the Red Pitaya should be:

ACQ:SOUR1:DATA?

Most likely, this is the reason you are receiving a string ("ERR") instead of the data.

Please check the available SCPI commands and acquisition examples on this link:
https://redpitaya.readthedocs.io/en/lat ... -or-python

The examples will help you with the correct acquisition command sequence.
Thank you very much

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 112 guests