element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog PST.. Experimental event / trigger support for Pico SCPI labTool - 6: Service Request from Instrument to LabVIEW flow
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 14 Oct 2023 1:31 PM Date Created
  • Views 1812 views
  • Likes 7 likes
  • Comments 14 comments
  • pico_usbtmc_scpi
  • pico
  • USBTMC
  • Pico SCPI labTool
  • labview
  • scpi
Related
Recommended

PST.. Experimental event / trigger support for Pico SCPI labTool - 6: Service Request from Instrument to LabVIEW flow

Jan Cumps
Jan Cumps
14 Oct 2023
PST.. Experimental event / trigger support for Pico SCPI labTool - 6: Service Request from Instrument to LabVIEW flow

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.
In this post: I continue to test the USBTMC Service Request Event generation. And the handling in PyVISA and NI's interactive test tool.

image

The current TinyUSB library doesn't make it easy to add this type of functionality in a neat way.
Thank you ggabe for picking this up and for adding the Service Request handling and test script.

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.

image

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:

  1. Enable Service Request Event handling
    image.
  2. Wait on the event with a 2 second timeout. Don't push the button. This should generate a timeout.

  3. 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:
image

Result when button is pressed within the timeout:
image

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

link to all posts

  • Sign in to reply
Parents
  • shabaz
    shabaz over 1 year ago

    Also great to see people contributing to the project!

    Hope this isn't hijacking the post too much (I can create a new thread to discuss this if needed Jan Cumps   )

    Three new feature proposals (I'm not sure I can work on all these, but still it's interesting to maybe add them to the backlog if people think they are useful). Actually one is an enhancement, the other two are new features:

    1) The analog input HIRES module enhanced to also support differential inputs and configurable gain
    Example differential, gain of 4:


    CONfigure:ANA:HIRES DIFFerential,4


    Example single-ended, gain of 2:


    CONfigure:ANA:HIRES SINGle,2

    2) A new Board Memory (BM) module to suport cheap EEPROM on add-on cards for identification or for calibration parameters
    First release to only support SCPI read/write in raw hex, useful for debug purposes

    Example, write to card #0 (there could be several EEPROMs on the I2C bus, they can all be referenced by a card number which gets added to the base address which is 0x50 for most I2C EEPROMs, plus the card value which relates to the address pins on the EEPROM chip), 4 bytes 0xaa, 0xbb, 0xcc, 0xdd from address 16:


    CONfigure:BM:RAW 0,16,aabbccdd

    Read 4 bytes from card #0, from address 16:


    FETch:BM:CARD0:ADDR16:4:RAW?

    3) A new system temperature module to support the measurement of either ambient temperature of the system, or board temperature of individual cards. Card 0 would be ambient temperature.

    Example to read the temperature of card #2 (this is assuming cards begin at #1, if zero will be ambient temperature):


    TEMPerature:CARD2?

    I'm not very good at thinking what the syntax should look like, the above is an attempt to keep some flexibility, but at the same time not making things too complicated or too large a bite for a first release of such functionality. But I suspect I've got things horribly wrong and broken conventions I bet, so I'm not too loyal to my own suggestions, I'd rather take as much advice as possible. Also tagging Andrew J in case he has some advice based on his experience with similar intent type of commands perhaps.

    Any suggestions welcome!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    > I suspect I've [...] broken conventions I bet

    Yes Slight smile - but that doesn't matter for the concepts.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    > I suspect I've [...] broken conventions I bet

    Yes Slight smile - but that doesn't matter for the concepts.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube