Author Topic: Rigol DG800 SCPI, VISA, MATLAB  (Read 3013 times)

0 Members and 1 Guest are viewing this topic.

Offline gossamerTopic starter

  • Contributor
  • Posts: 19
  • Country: ie
Rigol DG800 SCPI, VISA, MATLAB
« on: May 28, 2019, 08:44:01 pm »
I am trying to send generated waveform from Matlab to DG800 and play it as an arbitrary waveform. Documentation is bit cryptic (because I am a newbie in SCPI automation) ..

After installing NI-VISA drivers on my computer I am able to connect to the DG800 and query *IDN?
 
Now the fun begins. I dont have a clue where to start from there and DG800 programming guide is completely useless for beginners .. there are no explanation on the sequences of the commands to load the function into the memory and output it on one of the channels..

I would appreciate if someone could give me an example on how to send and play the data points via SCPI

What I have now, but for some reason it just selects the "Sinc" function and plays that:

Code: [Select]
fprintf(obj1,'%s\r\n','*RST;*CLS;*OPC?');
fprintf(obj1,'%s\r\n',':SOUR1:APPL:ARB 500');
fprintf(obj1,'%s\r\n',':SOUR1:DATA VOLATILE,-0.5, 0.8, 1.2, 0.7, 0.4');
fprintf(obj1,'%s\r\n','OUTP1 ON');

 |O
 

Offline gossamerTopic starter

  • Contributor
  • Posts: 19
  • Country: ie
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #1 on: May 29, 2019, 09:03:42 pm »
I was able to resolve this.
I used the Rigol waveform generator application (Ultrastation). I generated some random curve using few points and sent it over to the DG800 via USB NI-VISA driver.
Before that, of course, I installed this sniffer https://desowin.org/usbpcap/index.html and enabled tracing on the usb controller.
After sending the waveform with Ultrastation, I opened the dump file in Wireshark and voila, protocol was there. Its not really in the nicely readable format, but its easy to connect the dots (pun intended). ::)
 
The following users thanked this post: thm_w

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6378
  • Country: ca
  • Non-expert
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #2 on: May 30, 2019, 10:19:18 pm »
I was able to resolve this.
I used the Rigol waveform generator application (Ultrastation). I generated some random curve using few points and sent it over to the DG800 via USB NI-VISA driver.
Before that, of course, I installed this sniffer https://desowin.org/usbpcap/index.html and enabled tracing on the usb controller.
After sending the waveform with Ultrastation, I opened the dump file in Wireshark and voila, protocol was there. Its not really in the nicely readable format, but its easy to connect the dots (pun intended). ::)

I wonder if they purposefully left this out of the programming guide.

Can you post some of your code here in case someone else needs to perform the same task?
Thanks
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline gossamerTopic starter

  • Contributor
  • Posts: 19
  • Country: ie
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #3 on: May 31, 2019, 07:35:39 am »
Quote
Can you post some of your code here in case someone else needs to perform the same task?

What I end up with is this template:

Code: [Select]
fprintf(obj1,'%s\r\n',':SOURCE1:APPL:SEQ');
fprintf(obj1,'%s\r\n',':SOURCE1:FUNC:SEQ:FILT STEP');
fprintf(obj1,'%s\r\n',':SOURCE1:TRACe:DATA:DAC16 VOLATILE,END,#23200001c2cac4231529e534141ca1ac0e53fb967aff6e1b22699d6a2dd00000a');
fprintf(obj1,'%s\r\n',':SOURCE1:VOLT:UNIT VPP');
fprintf(obj1,'%s\r\n',':SOURCE1:VOLT 4');
fprintf(obj1,'%s\r\n',':SOURCE1:FUNC:SEQ:SRAT 20000');
fprintf(obj1,'%s\r\n','OUTP2 OFF');
fprintf(obj1,'%s\r\n','OUTP1 ON');

Documentation is really bad as from the documentation I would never guess which function should I select if I want to play arbitrary wave (first two commands).
Command 3 is bit cryptic in the beginning, but it makes sense when you read between the lines of the guide :)
For shorter waveforms (minimum is 16 points), command needs to have an "END" flag.

Data parameter starts with #. (#23200001c2cac4231529e534141ca1ac0e53fb967aff6e1b22699d6a2dd00000a) then it has numeric number, which represents the number of digits of the size of the data ( :palm: ) in my case it was 2 as I have 32 bytes of data (3 and 2).
And after number of bytes (numeric value as well), data points are in HEX (4 characters per point; 2 bytes). Also there seems to be an error in the documentation because it says that values for the points can be between 0000 and 3fff, which is 14 bit value, not the 16 bit! And what Rigol software generated and can be seen in the stream I attached, has points (d6a2 dd00) that are 16 bit ?!
« Last Edit: May 31, 2019, 07:46:50 am by gossamer »
 
The following users thanked this post: thm_w

Offline ExclamationMarek

  • Newbie
  • Posts: 4
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #4 on: August 26, 2020, 04:17:08 pm »
I just struggled with getting a DG822 to work, and maybe they changed the firmware, as it worked differently for me (my unit is running firmware 01.08.01.00). I'm posting my findings in case somebody else ends up here when looking for a solution (as I did)


The main difference is that the unit expects the trace data in signed 16-bit binary (little endian), and not text encoded hex. The length declared in the SOURCE:TRACe:DATA:DAC16 call still has the weird format with the length-of-the-length digit first, followed by the length in *bytes*, so double the number of points, both in human readable text.

Example:
Code: [Select]
SOURCE1:TRACe:DATA:DAC16 VOLATILE,END,#216\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00I wrote the raw bytes with python formatting ('\x40' is the byte 0x40), this is not the plain text that the device expects!. The largest possible single transfer is 32768 samples (=65536 bytes), larger transfers can be split into "CON" and "END" packages. Of course none of this matches the DG8xx programming guide, where they suggest a "16-bit binary number from 0000 to 3FFF" :palm:.

Below, a working python3 example

Code: [Select]
import usbtmc, time, struct

sg = usbtmc.Instrument(0x1ab1, 0x0643)

def w(command):
sg.write(command)
time.sleep(0.2)

def rigol_len(length):
rtxt = "#"
rtxt += str(len(str(length))) + str(length)
return rtxt

def uploadSequence(samples):
samplebytes = struct.pack('<' + 'h' * len(samples), *samples)
while(len(samplebytes) > 65536):
sg.write_raw(b"SOURCE1:TRACe:DATA:DAC16 VOLATILE,CON," + rigol_len(65536).encode('utf-8') + samplebytes[0:65536])
time.sleep(0.2)
samplebytes = samplebytes[65536:]

sg.write_raw(b"SOURCE1:TRACe:DATA:DAC16 VOLATILE,END," + rigol_len(len(samplebytes)).encode('utf-8') + samplebytes)
time.sleep(0.2)

pulses = 10
pulse_width = 15
signal_length = 100000

samples = []
for p in range(0, pulses):
samples += [30000] * pulse_width
samples += [-30000] * pulse_width
samples += [0] * (signal_length - len(samples))

w(":SOURCE1:APPL:SEQ")
w(":SOURCE2:APPL:SEQ")

# sg.write_raw(b"SOURCE1:TRACe:DATA:DAC16 VOLATILE,END,#216\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00")
uploadSequence(samples)

w(":SOURCE1:VOLTAGE 5.000000VPP")
w(":SOURCE1:FUNC:SEQ:SRAT 30000000.000000")
w(":OUTPUT1 ON")


Hope this might help somebody in the future.
 
The following users thanked this post: labnet, thm_w, sken

Offline labnet

  • Contributor
  • Posts: 25
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #5 on: May 12, 2023, 01:31:43 am »
gossamers commands also work for the DG2000 series. (Thanks!)
I wrote it in c# and sent command over Ethernet, so didn't need any drivers.

The Rigol Documentation is laughably bad.

Update: Have given up on the Flakey Rigol Software. Every time I send over about 256 bytes to the DG2052, it panics and resets it ethernet interface.
Have also refactored for USB interface. Same deal. When I go over about 64 samples, the USB interface crashes and restarts.
« Last Edit: May 12, 2023, 08:25:09 am by labnet »
 

Offline sken

  • Newbie
  • Posts: 3
  • Country: it
Re: Rigol DG800 SCPI, VISA, MATLAB
« Reply #6 on: November 28, 2023, 02:44:00 pm »
Dear ExclamationMarek, and ALL
Thank you for your code, which has turned my day.

Now I am facing another problem: I am trying to trigger the generation of a "sequence"-like signal in a burst through an external trigger, but the instrument does not seem to allow that, despite the manual says

"In N Cycle mode, the generator will output waveforms with a specified number of cycles after receiving the trigger signal. The waveform functions that support the N cycle burst include Sine, Square, Ramp, Pulse, Arbitrary, PRBS, RS232, and Sequence. For N cycle burst, "Internal", "External", or "Manual" trigger source could be selected. Besides, you can also set the parameters of "Burst Period" (internal trigger), "Delay", "Trig In" (external trigger), and "Trig Out" (internal and manual trigger)."

Any idea why? And does anybody know how to externally trigger a "sequence" signal with the DG800?

Thank you,
Luca
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf