Rigol DG800 SCPI, VISA, MATLAB - Page 1
Forum section: electronics / testgear

author: gossamer
author_rank: Contributor
timestamp: May 28, 2019, 08:44:01 pm
content: 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 SCPIWhat I have now, but for some reason it just selects the "Sinc" function and plays that:Code: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');

author: gossamer
author_rank: Contributor
timestamp: May 29, 2019, 09:03:42 pm
content: 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 snifferhttps://desowin.org/usbpcap/index.htmland 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).

author: thm_w
author_rank: Super Contributor
timestamp: May 30, 2019, 10:19:18 pm
content: Quote from: gossamer on May 29, 2019, 09:03:42 pmI 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

author: gossamer
author_rank: Contributor
timestamp: May 31, 2019, 07:35:39 am
content: QuoteWhat I end up with is this template:Code: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 guideFor 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 () in my case it was2as I have32bytes 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 ?!

author: ExclamationMarek
author_rank: Newbie
timestamp: August 26, 2020, 04:17:08 pm
content: 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: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".Below, a working python3 exampleCode:import usbtmc, time, structsg = 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 rtxtdef 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 = 10pulse_width = 15signal_length = 100000samples = []for p in range(0, pulses):samples +=  * pulse_widthsamples += [-30000] * pulse_widthsamples +=  * (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.

author: labnet
author_rank: Contributor
timestamp: May 12, 2023, 01:31:43 am
content: 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.

author: sken
author_rank: Newbie
timestamp: November 28, 2023, 02:44:00 pm
content: Dear ExclamationMarek, and ALLThank 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