{"id":3330,"date":"2021-06-12T09:59:41","date_gmt":"2021-06-12T16:59:41","guid":{"rendered":"https:\/\/www.rbdinstruments.com\/blog\/?p=3330"},"modified":"2021-06-12T10:22:08","modified_gmt":"2021-06-12T17:22:08","slug":"programming-the-9103-with-python-part-1-standard-speed","status":"publish","type":"post","link":"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-1-standard-speed\/","title":{"rendered":"Programming the 9103 With Python &#8211; Part 1: Standard Speed"},"content":{"rendered":"\n<p>New <a href=\"https:\/\/rbdinstruments.com\/products\/picoammeter\/tech.html#resources\">sample Python co<\/a><a rel=\"noreferrer noopener\" aria-label=\"de for the 9103 (opens in a new tab)\" href=\"https:\/\/rbdinstruments.com\/products\/picoammeter\/tech.html#resources\" target=\"_blank\">de for the 9103<\/a> is now available on RBD&#8217;s website. The 9103&#8217;s API is easy to program with any language and<a href=\"https:\/\/rbdinstruments.com\/products\/picoammeter\/tech.html#resources\"> <\/a><a href=\"https:\/\/rbdinstruments.com\/products\/picoammeter\/tech.html#resources\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"documented (opens in a new tab)\">documented<\/a> fully, but as always with any device programming, a few examples always help. We chose Python because it&#8217;s well supported, easy to understand even if you&#8217;re using another language and compatible with a number of popular lab control and analysis environments.<\/p>\n\n\n\n<p>The sample code we provide is open-source and free for you to use and distribute as you see fit.<br><br><em>(If you haven&#8217;t taken a look at the 9103 USB auto-ranging picoammeter, everything you need to know can be <a href=\"https:\/\/rbdinstruments.com\/products\/picoammeter.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"found here (opens in a new tab)\">found here<\/a>. Measure bi-polar DC current from picoamps to milliamps, with optional built-in bias and 5 kV isolation.)<\/em><br><br> <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-attachment-id=\"3331\" data-permalink=\"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-1-standard-speed\/9103-python-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=2200%2C1400&amp;ssl=1\" data-orig-size=\"2200,1400\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"9103-python-1\" data-image-description=\"&lt;p&gt;RBD 9103 usb picoammeter&lt;\/p&gt;\n\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=300%2C191&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=584%2C372&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" width=\"584\" height=\"372\" src=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/plugins\/jquery-image-lazy-loading\/images\/grey.gif?resize=584%2C372&#038;ssl=1\" data-original=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=584%2C372&amp;ssl=1\" alt=\"Programming the 9103 with Python\" class=\"lazy wp-image-3331\" srcset=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=2200&amp;ssl=1 2200w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=300%2C191&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=768%2C489&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=1024%2C652&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=471%2C300&amp;ssl=1 471w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=1168&amp;ssl=1 1168w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=1752&amp;ssl=1 1752w\" sizes=\"(max-width: 584px) 100vw, 584px\" data-recalc-dims=\"1\" \/><noscript><img data-attachment-id=\"3331\" data-permalink=\"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-1-standard-speed\/9103-python-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=2200%2C1400&amp;ssl=1\" data-orig-size=\"2200,1400\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"9103-python-1\" data-image-description=\"&lt;p&gt;RBD 9103 usb picoammeter&lt;\/p&gt;\n\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=300%2C191&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=584%2C372&amp;ssl=1\" decoding=\"async\" loading=\"lazy\" width=\"2200\" height=\"1400\" src=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=584%2C372&amp;ssl=1\" alt=\"Programming the 9103 with Python\" class=\"wp-image-3331\" srcset=\"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=2200&amp;ssl=1 2200w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=300%2C191&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=768%2C489&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=1024%2C652&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?resize=471%2C300&amp;ssl=1 471w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=1168&amp;ssl=1 1168w, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?w=1752&amp;ssl=1 1752w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/noscript><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>A Quick Look at the Standard Speed Sampling Code<\/strong><\/p>\n\n\n\n<p>Python&#8217;s pySerial module abstracts the calls to class-compliant USB serial COM port drivers, so setting up communications with the 9103 is a matter of a few simple calls:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>port=serial.Serial(\n    'com' + port_number,\n    baudrate=57600,\n    bytesize=serial.EIGHTBITS,\n    parity=serial.PARITY_NONE,\n    stopbits=serial.STOPBITS_ONE,\n    xonxoff=False,\n    timeout=1)<\/code><\/pre>\n\n\n\n<p>With the addition of a few helper functions for handling ASCII, it&#8217;s simple to write functions to send individual commands to the 9103. The following sets the auto-range and filter settings:<\/p>\n\n\n\n<p><code>def message(message_string):<br>     return bytes('&amp;'+ message_string + '\\n','utf-8')<br><br> def command_range_auto():<br>     port.write(message('R0')) # put in autorange <br><br> def command_default_filter_32():<br>     port.write(message('F032')) <\/code><br><\/p>\n\n\n\n<p>Similarly, with the addition of a few helper functions, the 9103 samples can be read with a simple loop that reads lines from the port buffer: In this case, we&#8217;ve setup the 9103 to read in interval mode, and poll the port for incoming samples, with a simple keyboard interrupt. This code also writes the sample information to a text file.<\/p>\n\n\n\n<p><code>try:<br>     while True:<br>         msg=port.readline().decode('utf-8').rstrip()<br>         print(msg)<br>         parsed = parse_message_for_sample(msg)<br>         if parsed:<br>             samplefile.write( parsed + '\\n')<br><br> except KeyboardInterrupt:<br>     pass <\/code><\/p>\n\n\n\n<p> All of the code is commented and documented in the Python file. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Using Python with LabView and MATLAB<\/strong><\/p>\n\n\n\n<p>The Python code samples can be helpful to both LabView and MATLAB users.<br>LabVIEW now supports Python through the <a rel=\"noreferrer noopener\" aria-label=\"Python Node (opens in a new tab)\" href=\"https:\/\/zone.ni.com\/reference\/en-XX\/help\/371361R-01\/glang\/python_node\/\" target=\"_blank\">Python Node<\/a>, which features low-latency calls from a LabVIEW Block Diagram using  LabVIEW primitives. <br><br>The <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab-engine-for-python.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">MATLAB Engine API for Python<\/a> allows you to call MATLAB as a computational engine from Python, and you can call functions and objects in Python from MATLAB.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>More to Come\u2026<\/strong><\/p>\n\n\n\n<p>Next up we&#8217;ll be posting some sample code to write and read using the high-speed version of the 9103. Since high-speed data from the 9103 arrives in packets, there are some minor differences in parsing the message samples. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>New sample Python code for the 9103 is now available on RBD&#8217;s website. The 9103&#8217;s API is easy to program with any language and documented fully, but as always with any device programming, a few examples always help. We chose &hellip; <a href=\"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-1-standard-speed\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[159,163],"tags":[116,123,371],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2DEXo-RI","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3844,"url":"https:\/\/www.rbdinstruments.com\/blog\/9103-usb-picoammeter-blog-list\/","url_meta":{"origin":3330,"position":0},"title":"9103 USB Picoammeter Blog list","author":"Randy","date":"September 7, 2023","format":false,"excerpt":"A summary of all of the 9103 USB picoammeter blog posts at RBD Techspot","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"9103 HV Picoammeter","src":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2018\/11\/9103-hv.png?fit=530%2C261&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3381,"url":"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-3-high-speed\/","url_meta":{"origin":3330,"position":1},"title":"Programming the 9103 With Python \u2013 Part 3: High Speed","author":"Joe Caterinicchio","date":"August 25, 2021","format":false,"excerpt":"Part 3 of programing the 9103 USB picoammeter with Python - High Speed","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3364,"url":"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-with-python-part-2-switching-between-standard-and-high-speed-modes\/","url_meta":{"origin":3330,"position":2},"title":"Programming the 9103 With Python \u2013 Part 2: Switching Between Standard and High-Speed Modes","author":"Joe Caterinicchio","date":"August 16, 2021","format":false,"excerpt":"A Python Utility App for Switching Speed Modes with the 9103 usb picoammeter","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2021\/06\/9103-python-1.png?fit=1200%2C764&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":900,"url":"https:\/\/www.rbdinstruments.com\/blog\/programming-the-9103-picoammeter\/","url_meta":{"origin":3330,"position":3},"title":"Programming the 9103 Picoammeter","author":"Joe Caterinicchio","date":"December 22, 2013","format":false,"excerpt":"Progamming the 9103 Picoammeter RBD\u2019s 9103 USB PIcoammeter is packaged with Windows application software for control, current display, data-logging, and graphing. However, it's often desirable to use the 9103 with other operating systems, integrate it with other hardware or software systems, and\/or extend the capabilities of the application software. Fortunately,\u2026","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2717,"url":"https:\/\/www.rbdinstruments.com\/blog\/9103-usb-picoammeter-winter-2020-news\/","url_meta":{"origin":3330,"position":4},"title":"9103 USB Picoammeter Winter 2020 News","author":"Joe Caterinicchio","date":"February 12, 2020","format":false,"excerpt":"Last year, RBD introduced an updated 9103 USB Picoammeter, with 3 new models: High-speed: 500 reads \/ second compared to 40 for the Standard Model High-voltage: an isolated signal input with the ability to float the 9103 Picoammeter to \u00b15000 VDC. High-speed \/ High Voltage: One model combining both features.\u2026","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2020\/02\/actuel-1-6.png?fit=727%2C371&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2020\/02\/actuel-1-6.png?fit=727%2C371&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2020\/02\/actuel-1-6.png?fit=727%2C371&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":826,"url":"https:\/\/www.rbdinstruments.com\/blog\/a-guide-to-9103-picoammeter-compatibility\/","url_meta":{"origin":3330,"position":5},"title":"A Guide to 9103 Picoammeter Compatibility","author":"Joe Caterinicchio","date":"November 4, 2013","format":false,"excerpt":"RBD's 9103 USB Picoammeter and Actuel application (included in your purchase) are compatible with a number of hardware devices and operating systems. The complex nature of operating systems and hardware, as well as the differences between 9103 hardware and software compatibility, render a simple compatibility table somewhat lacking in clarity.\u2026","rel":"","context":"In &quot;9103 USB Picoammeter&quot;","block_context":{"text":"9103 USB Picoammeter","link":"https:\/\/www.rbdinstruments.com\/blog\/category\/9103-usb-picoammeter\/"},"img":{"alt_text":"9103 Picoammeter","src":"https:\/\/i0.wp.com\/www.rbdinstruments.com\/blog\/wp-content\/uploads\/2013\/11\/Picoammeter.jpg?fit=358%2C212&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/posts\/3330"}],"collection":[{"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/comments?post=3330"}],"version-history":[{"count":2,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/posts\/3330\/revisions"}],"predecessor-version":[{"id":3339,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/posts\/3330\/revisions\/3339"}],"wp:attachment":[{"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/media?parent=3330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/categories?post=3330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rbdinstruments.com\/blog\/wp-json\/wp\/v2\/tags?post=3330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}