{"id":353,"date":"2023-10-13T15:04:11","date_gmt":"2023-10-13T13:04:11","guid":{"rendered":"https:\/\/bowfinger.de\/blog\/?p=353"},"modified":"2023-10-13T15:04:12","modified_gmt":"2023-10-13T13:04:12","slug":"red-pitaya-using-only-pyvisa","status":"publish","type":"post","link":"https:\/\/bowfinger.de\/blog\/2023\/10\/red-pitaya-using-only-pyvisa\/","title":{"rendered":"Red Pitaya using only pyVISA"},"content":{"rendered":"\n<p>The Red Pitaya boards offer an SCPI server over an TCP\/IP Socket connection. The makers describe how to use it. But instead of using plain pyVISA, they provide their own SCPI class.<\/p>\n\n\n\n<p>That&#8217;s fine, because that class also provides handy functions to set the various in-built applications (signal generator and the likes).<\/p>\n\n\n\n<p>But it is unnecessary complicated for a blinky example. And in my case, where I only needed some scriptable DIOs, it was quite cumbersome.<\/p>\n\n\n\n<p>So, here is the blinky re-written in plain pyVISA:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">import pyvisa as visa\nfrom time import sleep\n\nrm = visa.ResourceManager()\nrp = rm.open_resource(\"TCPIP::169.254.XXX.XXX::5000::SOCKET\",\n                 read_termination=\"\\r\\n\",\n                 write_termination=\"\\r\\n\"\n                 )\n\nprint(rp.query(\"*IDN?\"))\n\nwhile True:\n    rp.write(\"DIG:PIN LED0,1\")\n    sleep(.5)\n    rp.write(\"DIG:PIN LED0,0\")\n    sleep(.5)\n<\/code><\/pre>\n\n\n\n<p>The magic lies in the read and write terminations. They have to be set to <code>'\\r\\n'<\/code>(in that order), or else the communication simply won&#8217;t work and time out.<\/p>\n\n\n\n<p>Make sure you install a reasonably recent <code>pyVISA<\/code> and <code>pyVISA-py<\/code> (from pip) or <code>libvisa<\/code> (from your distro&#8217;s repository) before you start. For me (Ubuntu) this works as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">pip install -U pyvisa pyvisa-py\nsudo apt install libvisa<\/code><\/pre>\n\n\n\n<p>This integrates nicely with existing instrument command structures and allows for quick testing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Red Pitaya boards offer an SCPI server over an TCP\/IP Socket connection. The makers describe how to use it. But instead of using plain pyVISA, they provide their own SCPI class. That&#8217;s fine, because that class also provides handy functions to set the various in-built applications (signal generator and the likes). But it is&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[38,36,16,35],"tags":[12,92,93],"class_list":["post-353","post","type-post","status-publish","format-standard","hentry","category-embedded","category-engineering","category-linux","category-python","tag-python","tag-pyvisa","tag-red-pitaya"],"_links":{"self":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/comments?post=353"}],"version-history":[{"count":1,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":354,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/posts\/353\/revisions\/354"}],"wp:attachment":[{"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/media?parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/categories?post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bowfinger.de\/blog\/wp-json\/wp\/v2\/tags?post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}