The Pico SCPI labTool (PST) allows you to connect your PC to equipment to control and monitor all sorts of things. It runs on a Raspberry Pico. It would be nice if the PST could supports device dependent SCPI registers. They can be used to notify a LabVIEW flow from the device. We finally managed to notify LabVIEW when a GPIO input changed logic level. The current TinyUSB library doesn't make it easy to add this type of functionality in a neat way. |
part 1: PST.. Experimental event / trigger support for Pico SCPI labTool - 1: investigate
part 2: PST.. Experimental event / trigger support for Pico SCPI labTool - 2: design the registers
part 3: PST.. Experimental event / trigger support for Pico SCPI labTool - 3: Instrument Specific Registers Test
part 4: PST.. Experimental event / trigger support for Pico SCPI labTool - 4: let TinyUSB USBTMC code use SCPI-LIB's Status Byte register
part 5: PST.. Experimental event / trigger support for Pico SCPI labTool - 5: Propagation to IEEE488.2 SCPI Registers Test
part 6: PST.. Experimental event / trigger support for Pico SCPI labTool - 6: Service Request from Instrument to LabVIEW flow
part 7: PST.. Experimental event / trigger support for Pico SCPI labTool - 7: Test Service Request from Instrument to LabVIEW flow
Test Setup
Again, I continue from the previous post: PST.. Experimental event / trigger support for Pico SCPI labTool - 5: Propagation to IEEE488.2 SCPI Registers Test
We managed to fan a negative transition on Digital In PIN 2 (a button connected to GPI27), to the standard Operation Status register. And to stream the notifications upstream up to STB and SRE. Now we test that the USBTMC protocol pushes the notification from the Pico to the PC software.
Tests will systematically validate
- (tested in post 5) can I propagate an event from the Operation Status register to the Status Byte register?
- (tested in post 5) did I land in the SCPI-LIB and USBTMC Service Request invocation code?
- can I set up a SRQ handler and let it run when expected (button press)
Test SRQ with NI VISA Interactive Control
Let's first bring the device in the condition that button presses fan out to OPERATION STATUS EVENT register, and propagate all up.
STATus:OPERation:DIGItal:INPut:NTRansition 4\n
STATus:OPERation:DIGItal:INPut:ENABle 4\n
*CLS\n
STATus:OPERation:ENABle 1\n
Enable propagation by setting SRE Bit 7 (OPER Bit) to 1
*SRE 128\n
test 1: Register the Event Handler and prime. Request should time out because we don't generate the event that it's waiting for.
condition:
- Enable Service Request Event handling
. - Wait on the event with a 2 second timeout. Don't push the button. This should generate a timeout.
- Wait on the event with a 2 second timeout. Push the button within those 2 seconds to generate the event.
result:
Result when button is not pushed while we wait for the event:
Result when button is pressed within the timeout:
pass
Test SRQ with PyVISA
Here, the code sets up the right condition, and will loop until the button is pressed
test 1: validate that the code loops until button is pressed
def handle_event(resource, event, user_handle): print(f"Handled event {event.event_type} on {resource}") stb = inst.read_stb() inst.write("*CLS") rm = visa.ResourceManager() reslist = rm.list_resources("USB?::?*::INSTR") print(reslist) if (len(reslist) == 0): sys.exit() i = 0 inst = None while i < len(reslist): inst = rm.open_resource(reslist[i]); inst.timeout = 3000 inst.clear() print("Experimental test") inst.called = False event_type = constants.EventType.service_request event_mech = constants.EventMechanism.handler wrapped = inst.wrap_handler(handle_event) user_handle = inst.install_handler(event_type, wrapped, 42) inst.enable_event(event_type, event_mech, None) inst.write("STAT:OPER:DIGI:INP:NTR 4\n") inst.write("STAT:OPER:DIGI:INP:ENAB 4\n") inst.write("STAT:OPER:ENAB 1\n") inst.write("*CLS") inst.write("*SRE 128") #leaving Bit6 MSS - off print('Done setting up. Drive DIGI:INP0 low (push button connected to GP27)') try: while not inst.called: time.sleep(0.01) except: inst.close() # logging.exception("While looping") try: inst.disable_event(event_type, event_mech) except: print('err while disabling event') try: inst.uninstall_handler(event_type, wrapped, user_handle) except: print('err while disabling event') inst.close() i += 1 print("All Test complete")
result:
Experimental test Done setting up. Drive DIGI:INP0 low (push button connected to GP27) Handled event 1073684491 on USBInstrument at USB0::0xCAFE::0x4000::E6614104036A9438::0::INSTR
pass