<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><description>There&amp;#39;s a standard profile for USB test and measurement devices, called USBTMC. If your instrument supports it, it becomes a plug-and-play device for the likes of LabVIEW. The Raspberry Pico examples come with a set of TinyUSB profile e...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><pubDate>Fri, 03 Feb 2023 14:18:38 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a9f996e2-a31e-4a71-948b-fe8464ef4d84</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;span&gt;If you use this project as starting point,&amp;nbsp;part 2:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The main file does not use (or know) the instrument api in the source/gpio folder. Except for the initialisation function.&lt;br /&gt;That function prepares the hardware used in the instrument - in this case: sets the gpios to out and low.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Putting this initialisation call in the main file was a design decision, not random, but maybe not the best.&lt;br /&gt;I&amp;nbsp;usually make my instruments like this, to have the hardware ready before I initialise the SCPI parser. In particular when I make an instrument with a screen / buttons in parallel with the SCPI engine, this makes sense. I make the user interface call the instrument functions directly. I don&amp;#39;t make them call the SCPI parser.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In this particular case, where I made an instrument that&amp;#39;s only controllable via SCPI, it makes sense to do the initialisation in the&amp;nbsp;&lt;/span&gt;scpi_instrument_init() body.&lt;br /&gt;That would give the advantage that the USBTMC core does not have to know *anything* about what SCPI commands are supported or what the instrument does. You could reuse the code for any instrument.&lt;br /&gt;In particular, because that same initialisation code could (should?) also be used in the *RST handler ...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25167&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><pubDate>Fri, 03 Feb 2023 13:38:42 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a9f996e2-a31e-4a71-948b-fe8464ef4d84</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;If you use this project as starting point, I tried to keep the code modular:&lt;/p&gt;
&lt;p&gt;there&amp;#39;s only&amp;nbsp;two files that knows the instrument-specific scpi commands. Both are located in&amp;nbsp;source\scpi:&lt;br /&gt;scpi.h has the *IDN? reply settings.&lt;br /&gt;scpi.c has the supported commands, and what instrument code they should call.&lt;/p&gt;
&lt;p&gt;In my case, there is only one custom command that the device supports:&lt;/p&gt;
&lt;div&gt;
&lt;pre&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; {.pattern = &lt;/span&gt;&lt;span&gt;&amp;quot;DIGItal:OUTPut#&amp;quot;&lt;/span&gt;&lt;span&gt;, .callback = &lt;/span&gt;&lt;span&gt;SCPI_DigitalOutput&lt;/span&gt;&lt;span&gt;,},&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Implementation:&lt;/div&gt;
&lt;div&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:e4ac1b79-0f32-4e5f-abfd-fd3149b1b814:type=c_cpp&amp;text=static%20scpi_result_t%20SCPI_DigitalOutput%28scpi_t%20%2A%20context%29%20%7B%0D%0A%0D%0A%0D%0A%20%20scpi_bool_t%20param1%3B%0D%0A%20%20int32_t%20numbers%5B1%5D%3B%0D%0A%0D%0A%20%20%2F%2F%20retrieve%20the%20output%20index%0D%0A%20%20SCPI_CommandNumbers%28context%2C%20numbers%2C%201%2C%200%29%3B%0D%0A%20%20if%20%28%21%20%28%28numbers%5B0%5D%20%3E%20-1%29%20%26%26%20%28numbers%5B0%5D%20%3C%20pinCount%28%29%29%29%29%20%7B%0D%0A%20%20%20%20SCPI_ErrorPush%28context%2C%20SCPI_ERROR_INVALID_SUFFIX%29%3B%0D%0A%20%20%20%20return%20SCPI_RES_ERR%3B%0D%0A%20%20%7D%0D%0A%0D%0A%20%20%2F%2A%20read%20first%20parameter%20if%20present%20%2A%2F%0D%0A%20%20if%20%28%21SCPI_ParamBool%28context%2C%20%26param1%2C%20TRUE%29%29%20%7B%0D%0A%20%20%20%20return%20SCPI_RES_ERR%3B%0D%0A%20%20%7D%0D%0A%0D%0A%20%20setPinAt%28numbers%5B0%5D%2C%20param1%20%3F%20true%20%3A%20false%29%3B%0D%0A%0D%0A%20%20return%20SCPI_RES_OK%3B%0D%0A%7D]&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;All instrument code is in&amp;nbsp;source\gpio. Here I wrote the functions that can be called by the parser:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:9e8119c6-3d0d-48f6-a28d-033529c1d103:type=c_cpp&amp;text=uint32_t%20pinCount%28%29%20%7B%0D%0A%20%20%20%20return%20sizeof%28pins%29%2Fsizeof%28pins%5B0%5D%29%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20...%0D%0A%0D%0Avoid%20setPinAt%28uint32_t%20index%2C%20bool%20on%29%20%7B%0D%0A%20%20%20%20gpio_put%28pins%5Bindex%5D%2C%20on%29%3B%0D%0A%7D]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25167&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><pubDate>Tue, 31 Jan 2023 19:59:05 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a9f996e2-a31e-4a71-948b-fe8464ef4d84</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Great blog Jan.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25167&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><pubDate>Mon, 30 Jan 2023 23:16:47 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a9f996e2-a31e-4a71-948b-fe8464ef4d84</guid><dc:creator>shabaz</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Very useful blog post! This will come in handy, because the Pico is being used more and more in testbeds for all sorts of&amp;nbsp;measurement or control purposes.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m looking forward to giving this code a shot, as a starting point for creating such projects.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25167&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Raspberry Pico as USB test device - part 2: a working USBTMC compliant instrument</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/raspberry-pico-as-usb-test-device---part-2-functional-usbtmc-compliant-instrument</link><pubDate>Mon, 30 Jan 2023 20:08:35 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:a9f996e2-a31e-4a71-948b-fe8464ef4d84</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;And maybe investigate in the SCPI library how you can detect if a query is fully replied to.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I did the investigation for you: the current implementation of the SCPI libs takes care that the&amp;nbsp;&lt;strong&gt;scpi_instrument_input()&lt;/strong&gt; only returns when data is written. You could start the semaphore just before calling that function (when data arrived via usb) and release it right after the function returns.&lt;br /&gt;Not tested by me, but confidence by reading code [emoticon:c4563cd7d5574777a71c318021cbbcc8]&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25167&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>