SCPI process to wait for long command to complete - Page 1
Forum section: electronics / testgear

author: Ross
author_rank: Contributor
timestamp: April 06, 2023, 02:38:35 am
content: Hi,I am using a Siglent SSA 3015X and my aim is to trigger a scan and then get some indication of the scan completing via SCPI commands. I am using Python PyVisa and want to know when the scan is complete so I can do something else in the python program.A web search came up with the sequence (generic not specific to my device):*CLS*TRG*OPC?This sequence is supposed to clear any event or status registers, trigger a scan and the OPC command is supposed to return 1 when the previous command is complete. What actually happens is the scan starts but the scan takes 10 seconds or so and the OPC query times out.Alternative option is:*CLS*OPC*TRG*ESR?This sequence should clear status and event registers, trigger the scan and then polling the event status register to look for bit zero to be true. What actually happens is the scan is triggered but the *ESR? response is always zero. I thought it might have been my python program so I tried the commands in the web SCPI command terminal of the analyzer and the same thing happens.What my question to the community is am I using the correct sequence of commands and if I am is the Siglent device not honoring them?Thanks,Ross

author: tautech
author_rank: Super Contributor
timestamp: April 06, 2023, 03:06:47 am
content: Are you working from this programming guide Ross ?https://int.siglent.com/u_file/document/ProgrammingGuide_PG0703P_E02B.pdfThere are some App notes on the US site:https://siglentna.com/application-notes/ssa3000x-plus/And BTW, your model is SSA3015X Plus.

author: alm
author_rank: Super Contributor
timestamp: April 06, 2023, 09:59:51 am
content: I don't own or have used this specific instrument, but I have dealt with slow SCPI commands quite a lot. Here's a couple of possible solutions that I've used:Increase the timeout. This is something you might be able to set on the transport layer you use to transport the GPIB commands. For example for VXI-11, theDeviceandInstrumentclasses in python-vxi11 have a timeout attribute.For status registers like ESR you often have to configure a bit mask of which events trigger it if you want certain bits to be set. Sometimes this even goes two layers deep: set bitmask y so a bit in the Y register is set, and then set bit mask x so the bit corresponding to register Y in the X register are set. Check the manual. These commands might be called something like ESE or MESE. (Programming) manuals will normally show the bits of the various status registers and how they interact between registers.You can often program an instrument to send an SRQ interrupt when a command is complete. How you listen to SRQ depends on the transport you use. I don't think python-vxi11 supports SRQ, so I have not used them recently.Sometimes the best solution is to just insert a sleep if you know the command is going to take at least two minutes, just sleep for two minutes before you do your status query. The downside is that if a command fails, it will take two minutes to find out. But for hobby, where you're not blocking a production line, this is usually not a problem.

author: Ross
author_rank: Contributor
timestamp: April 11, 2023, 02:06:25 am
content: Quote from: tautech on April 06, 2023, 03:06:47 amThanks for the resources, I have been working with the programming guide before posting and have found it light on detail when it comes to the registers. The application notes do have some useful information, but not about this issue.

author: Ross
author_rank: Contributor
timestamp: April 11, 2023, 11:42:10 pm
content: Quote from: alm on April 06, 2023, 09:59:51 amThanks for your ideas. As far as I can tell there is SRO in this instrument. I checked the ESE and have set it to 255, but still the same result. I am now using:*CLS*ESE 255*OPC*TRGBut it still doesn't work. I have done more googling regarding the sequence in general and I think I have it right which leads me to think that the analyzer is not doing what it should. I guess I will have to implement a delay.

author: PatrickB
author_rank: Regular Contributor
timestamp: April 12, 2023, 12:19:58 pm
content: *OPC? should returns 1 when the previous command is finished.I don't know your device but why not use something like this:*CLS....*TRGwhile (*OPC? == 0){ }// loop that does nothing, just to wait for OPC to be = 1. Add a small delay in this loop to avoid constantly polling the device.keep on going

author: dietert1
author_rank: Super Contributor
timestamp: April 12, 2023, 04:11:38 pm
content: Implementing GPIB SRQ driven data taking can be difficult. One needs to implement full error handling and recovery to make things work reliably. And an interrupt scheme eventually means multithreading, i mean if you want to use the wait interval for other operations. For example with multiple instruments in the setup.I just got it working on a Keithley 3706 - after several days of try and error. For a SCPI instrument it should be somewhat easier. The Keithley has a status bit for "output available". If i enable that for the SRQ, i can submit the data request and then it produces the SRQ after the measurements are complete and in the output queue, in my case about 6 seconds. After the interrupt i just listen to the instrument in order to fetch the result.Regards, Dieter

author: rcjoy
author_rank: Regular Contributor
timestamp: April 12, 2023, 09:02:32 pm
content: Regarding SRQ, here's a link to an example from Keysight using PyVisa and SRQ for their instrument, but the conceptshould apply in general.https://rfmw.em.keysight.com/wireless/helpfiles/pxivna/Programming/GPIB_Example_Programs/SRQ_Example.htmYou would only do that if you wanted the program to do something else while waiting.

author: tautech
author_rank: Super Contributor
timestamp: April 13, 2023, 10:05:17 pm
content: Siglent provided a beta patch through us to Ross which improved things but apparently didn't irradicate his issue.Any further help from members is appreciated and detailed info taken to Siglent for their consideration.Thanks chaps.

author: Someone
author_rank: Super Contributor
timestamp: April 13, 2023, 11:52:17 pm
content: Quote from: rcjoy on April 12, 2023, 09:02:32 pmpyvisa, pyvisa-py, Keithley DMM6500enable_eventNotImplementedError:

author: dietert1
author_rank: Super Contributor
timestamp: April 14, 2023, 06:36:13 am
content: Yes, that's what i meant by error handling. When something doesn't work at least you want to see an error message or a warning.Regards, Dieter