diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..6ee4e5a --- /dev/null +++ b/404.html @@ -0,0 +1,985 @@ + + + + + + + + + + + + + + + + + + The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ +

404 - Not found

+ +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/about/index.html b/about/index.html new file mode 100644 index 0000000..3117142 --- /dev/null +++ b/about/index.html @@ -0,0 +1,1064 @@ + + + + + + + + + + + + + + + + + + + + + + About - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

REPORTING ISSUES

+

If you wish to report an issue with this library, please use +this link.

+

For any of the servers, please use +this link.

+

When filing an issue, please provide:

+
    +
  1. Any console output.
  2. +
  3. A description of the issue.
  4. +
  5. Sample code demonstrating the problem.
  6. +
+

For bugs, comments, or questions, please use the links above. +
+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/about_the_apis/index.html b/about_the_apis/index.html new file mode 100644 index 0000000..a426b4b --- /dev/null +++ b/about_the_apis/index.html @@ -0,0 +1,1201 @@ + + + + + + + + + + + + + + + + + + + + + + General Principles - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

General Principles

+ +

Setting Pin Modes

+

Pin modes must be set before interacting with a pin. All the methods listed +below have a consistent API across all API classes.

+

Input Pin Modes

+

Requiring A Callback To Be Specified

+
    +
  • set_pin_mode_analog_input
  • +
  • set_pin_mode_dht
  • +
  • set_pin_mode_digital_input
  • +
  • set_pin_mode_digital_input_pullup
  • +
  • set_pin_mode_sonar
  • +
+

Callback Specified In Read Commands

+
    +
  • set_pin_mode_i2c
  • +
  • set_pin_mode_spi
  • +
+

Output Pin Modes

+
    +
  • set_pin_mode_analog_output
  • +
  • set_pin_mode_digital_output
  • +
  • set_pin_mode_servo
  • +
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/app_creation/index.html b/app_creation/index.html new file mode 100644 index 0000000..e295432 --- /dev/null +++ b/app_creation/index.html @@ -0,0 +1,1114 @@ + + + + + + + + + + + + + + + + + + + + + + Application Creation - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Application Creation

+ +

A Word About The Application Templates

+

The following section contains a set of application templates for each of the four +servers. +The templates are based on the included examples.

+ +

As you will see, your application needs to import the correct API +and instantiate the API class. +You then use the API method calls in writing your application.

+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/arduino_ide/index.html b/arduino_ide/index.html new file mode 100644 index 0000000..8a75fa3 --- /dev/null +++ b/arduino_ide/index.html @@ -0,0 +1,1121 @@ + + + + + + + + + + + + + + + + + + + + + + Install The Arduino IDE - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Install The Arduino IDE

+ +

Download And Install The Arduino IDE

+

Arduino IDE version 2.1.X is used to upload a server to the Minima or WIFI. It is also +used to modify server source code when configuration is necessary.

+

To install a copy of the IDE, go to the Arduino Software Download page, and +select the version for your +operating system. Follow the installation instructions.

+

+

A Note For Linux Users

+

You may need to add your login to the dialout group to upload to the Arduino.

+

To do so, follow these instructions.

+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/assets/_mkdocstrings.css b/assets/_mkdocstrings.css new file mode 100644 index 0000000..049a254 --- /dev/null +++ b/assets/_mkdocstrings.css @@ -0,0 +1,64 @@ + +/* Avoid breaking parameter names, etc. in table cells. */ +.doc-contents td code { + word-break: normal !important; +} + +/* No line break before first paragraph of descriptions. */ +.doc-md-description, +.doc-md-description>p:first-child { + display: inline; +} + +/* Max width for docstring sections tables. */ +.doc .md-typeset__table, +.doc .md-typeset__table table { + display: table !important; + width: 100%; +} + +.doc .md-typeset__table tr { + display: table-row; +} + +/* Defaults in Spacy table style. */ +.doc-param-default { + float: right; +} + +/* Keep headings consistent. */ +h1.doc-heading, +h2.doc-heading, +h3.doc-heading, +h4.doc-heading, +h5.doc-heading, +h6.doc-heading { + font-weight: 400; + line-height: 1.5; + color: inherit; + text-transform: none; +} + +h1.doc-heading { + font-size: 1.6rem; +} + +h2.doc-heading { + font-size: 1.2rem; +} + +h3.doc-heading { + font-size: 1.15rem; +} + +h4.doc-heading { + font-size: 1.10rem; +} + +h5.doc-heading { + font-size: 1.05rem; +} + +h6.doc-heading { + font-size: 1rem; +} \ No newline at end of file diff --git a/assets/images/favicon.png b/assets/images/favicon.png new file mode 100644 index 0000000..1cf13b9 Binary files /dev/null and b/assets/images/favicon.png differ diff --git a/assets/javascripts/bundle.220ee61c.min.js b/assets/javascripts/bundle.220ee61c.min.js new file mode 100644 index 0000000..116072a --- /dev/null +++ b/assets/javascripts/bundle.220ee61c.min.js @@ -0,0 +1,29 @@ +"use strict";(()=>{var Ci=Object.create;var gr=Object.defineProperty;var Ri=Object.getOwnPropertyDescriptor;var ki=Object.getOwnPropertyNames,Ht=Object.getOwnPropertySymbols,Hi=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable;var rn=(e,t,r)=>t in e?gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,P=(e,t)=>{for(var r in t||(t={}))yr.call(t,r)&&rn(e,r,t[r]);if(Ht)for(var r of Ht(t))nn.call(t,r)&&rn(e,r,t[r]);return e};var on=(e,t)=>{var r={};for(var n in e)yr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Ht)for(var n of Ht(e))t.indexOf(n)<0&&nn.call(e,n)&&(r[n]=e[n]);return r};var Pt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Pi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ki(t))!yr.call(e,o)&&o!==r&&gr(e,o,{get:()=>t[o],enumerable:!(n=Ri(t,o))||n.enumerable});return e};var yt=(e,t,r)=>(r=e!=null?Ci(Hi(e)):{},Pi(t||!e||!e.__esModule?gr(r,"default",{value:e,enumerable:!0}):r,e));var sn=Pt((xr,an)=>{(function(e,t){typeof xr=="object"&&typeof an!="undefined"?t():typeof define=="function"&&define.amd?define(t):t()})(xr,function(){"use strict";function e(r){var n=!0,o=!1,i=null,s={text:!0,search:!0,url:!0,tel:!0,email:!0,password:!0,number:!0,date:!0,month:!0,week:!0,time:!0,datetime:!0,"datetime-local":!0};function a(O){return!!(O&&O!==document&&O.nodeName!=="HTML"&&O.nodeName!=="BODY"&&"classList"in O&&"contains"in O.classList)}function f(O){var Qe=O.type,De=O.tagName;return!!(De==="INPUT"&&s[Qe]&&!O.readOnly||De==="TEXTAREA"&&!O.readOnly||O.isContentEditable)}function c(O){O.classList.contains("focus-visible")||(O.classList.add("focus-visible"),O.setAttribute("data-focus-visible-added",""))}function u(O){O.hasAttribute("data-focus-visible-added")&&(O.classList.remove("focus-visible"),O.removeAttribute("data-focus-visible-added"))}function p(O){O.metaKey||O.altKey||O.ctrlKey||(a(r.activeElement)&&c(r.activeElement),n=!0)}function m(O){n=!1}function d(O){a(O.target)&&(n||f(O.target))&&c(O.target)}function h(O){a(O.target)&&(O.target.classList.contains("focus-visible")||O.target.hasAttribute("data-focus-visible-added"))&&(o=!0,window.clearTimeout(i),i=window.setTimeout(function(){o=!1},100),u(O.target))}function v(O){document.visibilityState==="hidden"&&(o&&(n=!0),Y())}function Y(){document.addEventListener("mousemove",N),document.addEventListener("mousedown",N),document.addEventListener("mouseup",N),document.addEventListener("pointermove",N),document.addEventListener("pointerdown",N),document.addEventListener("pointerup",N),document.addEventListener("touchmove",N),document.addEventListener("touchstart",N),document.addEventListener("touchend",N)}function B(){document.removeEventListener("mousemove",N),document.removeEventListener("mousedown",N),document.removeEventListener("mouseup",N),document.removeEventListener("pointermove",N),document.removeEventListener("pointerdown",N),document.removeEventListener("pointerup",N),document.removeEventListener("touchmove",N),document.removeEventListener("touchstart",N),document.removeEventListener("touchend",N)}function N(O){O.target.nodeName&&O.target.nodeName.toLowerCase()==="html"||(n=!1,B())}document.addEventListener("keydown",p,!0),document.addEventListener("mousedown",m,!0),document.addEventListener("pointerdown",m,!0),document.addEventListener("touchstart",m,!0),document.addEventListener("visibilitychange",v,!0),Y(),r.addEventListener("focus",d,!0),r.addEventListener("blur",h,!0),r.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&r.host?r.host.setAttribute("data-js-focus-visible",""):r.nodeType===Node.DOCUMENT_NODE&&(document.documentElement.classList.add("js-focus-visible"),document.documentElement.setAttribute("data-js-focus-visible",""))}if(typeof window!="undefined"&&typeof document!="undefined"){window.applyFocusVisiblePolyfill=e;var t;try{t=new CustomEvent("focus-visible-polyfill-ready")}catch(r){t=document.createEvent("CustomEvent"),t.initCustomEvent("focus-visible-polyfill-ready",!1,!1,{})}window.dispatchEvent(t)}typeof document!="undefined"&&e(document)})});var cn=Pt(Er=>{(function(e){var t=function(){try{return!!Symbol.iterator}catch(c){return!1}},r=t(),n=function(c){var u={next:function(){var p=c.shift();return{done:p===void 0,value:p}}};return r&&(u[Symbol.iterator]=function(){return u}),u},o=function(c){return encodeURIComponent(c).replace(/%20/g,"+")},i=function(c){return decodeURIComponent(String(c).replace(/\+/g," "))},s=function(){var c=function(p){Object.defineProperty(this,"_entries",{writable:!0,value:{}});var m=typeof p;if(m!=="undefined")if(m==="string")p!==""&&this._fromString(p);else if(p instanceof c){var d=this;p.forEach(function(B,N){d.append(N,B)})}else if(p!==null&&m==="object")if(Object.prototype.toString.call(p)==="[object Array]")for(var h=0;hd[0]?1:0}),c._entries&&(c._entries={});for(var p=0;p1?i(d[1]):"")}})})(typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Er);(function(e){var t=function(){try{var o=new e.URL("b","http://a");return o.pathname="c d",o.href==="http://a/c%20d"&&o.searchParams}catch(i){return!1}},r=function(){var o=e.URL,i=function(f,c){typeof f!="string"&&(f=String(f)),c&&typeof c!="string"&&(c=String(c));var u=document,p;if(c&&(e.location===void 0||c!==e.location.href)){c=c.toLowerCase(),u=document.implementation.createHTMLDocument(""),p=u.createElement("base"),p.href=c,u.head.appendChild(p);try{if(p.href.indexOf(c)!==0)throw new Error(p.href)}catch(O){throw new Error("URL unable to set base "+c+" due to "+O)}}var m=u.createElement("a");m.href=f,p&&(u.body.appendChild(m),m.href=m.href);var d=u.createElement("input");if(d.type="url",d.value=f,m.protocol===":"||!/:/.test(m.href)||!d.checkValidity()&&!c)throw new TypeError("Invalid URL");Object.defineProperty(this,"_anchorElement",{value:m});var h=new e.URLSearchParams(this.search),v=!0,Y=!0,B=this;["append","delete","set"].forEach(function(O){var Qe=h[O];h[O]=function(){Qe.apply(h,arguments),v&&(Y=!1,B.search=h.toString(),Y=!0)}}),Object.defineProperty(this,"searchParams",{value:h,enumerable:!0});var N=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:!1,configurable:!1,writable:!1,value:function(){this.search!==N&&(N=this.search,Y&&(v=!1,this.searchParams._fromString(this.search),v=!0))}})},s=i.prototype,a=function(f){Object.defineProperty(s,f,{get:function(){return this._anchorElement[f]},set:function(c){this._anchorElement[f]=c},enumerable:!0})};["hash","host","hostname","port","protocol"].forEach(function(f){a(f)}),Object.defineProperty(s,"search",{get:function(){return this._anchorElement.search},set:function(f){this._anchorElement.search=f,this._updateSearchParams()},enumerable:!0}),Object.defineProperties(s,{toString:{get:function(){var f=this;return function(){return f.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(f){this._anchorElement.href=f,this._updateSearchParams()},enumerable:!0},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(f){this._anchorElement.pathname=f},enumerable:!0},origin:{get:function(){var f={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol],c=this._anchorElement.port!=f&&this._anchorElement.port!=="";return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(c?":"+this._anchorElement.port:"")},enumerable:!0},password:{get:function(){return""},set:function(f){},enumerable:!0},username:{get:function(){return""},set:function(f){},enumerable:!0}}),i.createObjectURL=function(f){return o.createObjectURL.apply(o,arguments)},i.revokeObjectURL=function(f){return o.revokeObjectURL.apply(o,arguments)},e.URL=i};if(t()||r(),e.location!==void 0&&!("origin"in e.location)){var n=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:n,enumerable:!0})}catch(o){setInterval(function(){e.location.origin=n()},100)}}})(typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Er)});var qr=Pt((Mt,Nr)=>{/*! + * clipboard.js v2.0.11 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */(function(t,r){typeof Mt=="object"&&typeof Nr=="object"?Nr.exports=r():typeof define=="function"&&define.amd?define([],r):typeof Mt=="object"?Mt.ClipboardJS=r():t.ClipboardJS=r()})(Mt,function(){return function(){var e={686:function(n,o,i){"use strict";i.d(o,{default:function(){return Ai}});var s=i(279),a=i.n(s),f=i(370),c=i.n(f),u=i(817),p=i.n(u);function m(j){try{return document.execCommand(j)}catch(T){return!1}}var d=function(T){var E=p()(T);return m("cut"),E},h=d;function v(j){var T=document.documentElement.getAttribute("dir")==="rtl",E=document.createElement("textarea");E.style.fontSize="12pt",E.style.border="0",E.style.padding="0",E.style.margin="0",E.style.position="absolute",E.style[T?"right":"left"]="-9999px";var H=window.pageYOffset||document.documentElement.scrollTop;return E.style.top="".concat(H,"px"),E.setAttribute("readonly",""),E.value=j,E}var Y=function(T,E){var H=v(T);E.container.appendChild(H);var I=p()(H);return m("copy"),H.remove(),I},B=function(T){var E=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},H="";return typeof T=="string"?H=Y(T,E):T instanceof HTMLInputElement&&!["text","search","url","tel","password"].includes(T==null?void 0:T.type)?H=Y(T.value,E):(H=p()(T),m("copy")),H},N=B;function O(j){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?O=function(E){return typeof E}:O=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},O(j)}var Qe=function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.action,H=E===void 0?"copy":E,I=T.container,q=T.target,Me=T.text;if(H!=="copy"&&H!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(q!==void 0)if(q&&O(q)==="object"&&q.nodeType===1){if(H==="copy"&&q.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(H==="cut"&&(q.hasAttribute("readonly")||q.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(Me)return N(Me,{container:I});if(q)return H==="cut"?h(q):N(q,{container:I})},De=Qe;function $e(j){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?$e=function(E){return typeof E}:$e=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},$e(j)}function Ei(j,T){if(!(j instanceof T))throw new TypeError("Cannot call a class as a function")}function tn(j,T){for(var E=0;E0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof I.action=="function"?I.action:this.defaultAction,this.target=typeof I.target=="function"?I.target:this.defaultTarget,this.text=typeof I.text=="function"?I.text:this.defaultText,this.container=$e(I.container)==="object"?I.container:document.body}},{key:"listenClick",value:function(I){var q=this;this.listener=c()(I,"click",function(Me){return q.onClick(Me)})}},{key:"onClick",value:function(I){var q=I.delegateTarget||I.currentTarget,Me=this.action(q)||"copy",kt=De({action:Me,container:this.container,target:this.target(q),text:this.text(q)});this.emit(kt?"success":"error",{action:Me,text:kt,trigger:q,clearSelection:function(){q&&q.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return vr("action",I)}},{key:"defaultTarget",value:function(I){var q=vr("target",I);if(q)return document.querySelector(q)}},{key:"defaultText",value:function(I){return vr("text",I)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(I){var q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return N(I,q)}},{key:"cut",value:function(I){return h(I)}},{key:"isSupported",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],q=typeof I=="string"?[I]:I,Me=!!document.queryCommandSupported;return q.forEach(function(kt){Me=Me&&!!document.queryCommandSupported(kt)}),Me}}]),E}(a()),Ai=Li},828:function(n){var o=9;if(typeof Element!="undefined"&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}function s(a,f){for(;a&&a.nodeType!==o;){if(typeof a.matches=="function"&&a.matches(f))return a;a=a.parentNode}}n.exports=s},438:function(n,o,i){var s=i(828);function a(u,p,m,d,h){var v=c.apply(this,arguments);return u.addEventListener(m,v,h),{destroy:function(){u.removeEventListener(m,v,h)}}}function f(u,p,m,d,h){return typeof u.addEventListener=="function"?a.apply(null,arguments):typeof m=="function"?a.bind(null,document).apply(null,arguments):(typeof u=="string"&&(u=document.querySelectorAll(u)),Array.prototype.map.call(u,function(v){return a(v,p,m,d,h)}))}function c(u,p,m,d){return function(h){h.delegateTarget=s(h.target,p),h.delegateTarget&&d.call(u,h)}}n.exports=f},879:function(n,o){o.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},o.nodeList=function(i){var s=Object.prototype.toString.call(i);return i!==void 0&&(s==="[object NodeList]"||s==="[object HTMLCollection]")&&"length"in i&&(i.length===0||o.node(i[0]))},o.string=function(i){return typeof i=="string"||i instanceof String},o.fn=function(i){var s=Object.prototype.toString.call(i);return s==="[object Function]"}},370:function(n,o,i){var s=i(879),a=i(438);function f(m,d,h){if(!m&&!d&&!h)throw new Error("Missing required arguments");if(!s.string(d))throw new TypeError("Second argument must be a String");if(!s.fn(h))throw new TypeError("Third argument must be a Function");if(s.node(m))return c(m,d,h);if(s.nodeList(m))return u(m,d,h);if(s.string(m))return p(m,d,h);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function c(m,d,h){return m.addEventListener(d,h),{destroy:function(){m.removeEventListener(d,h)}}}function u(m,d,h){return Array.prototype.forEach.call(m,function(v){v.addEventListener(d,h)}),{destroy:function(){Array.prototype.forEach.call(m,function(v){v.removeEventListener(d,h)})}}}function p(m,d,h){return a(document.body,m,d,h)}n.exports=f},817:function(n){function o(i){var s;if(i.nodeName==="SELECT")i.focus(),s=i.value;else if(i.nodeName==="INPUT"||i.nodeName==="TEXTAREA"){var a=i.hasAttribute("readonly");a||i.setAttribute("readonly",""),i.select(),i.setSelectionRange(0,i.value.length),a||i.removeAttribute("readonly"),s=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var f=window.getSelection(),c=document.createRange();c.selectNodeContents(i),f.removeAllRanges(),f.addRange(c),s=f.toString()}return s}n.exports=o},279:function(n){function o(){}o.prototype={on:function(i,s,a){var f=this.e||(this.e={});return(f[i]||(f[i]=[])).push({fn:s,ctx:a}),this},once:function(i,s,a){var f=this;function c(){f.off(i,c),s.apply(a,arguments)}return c._=s,this.on(i,c,a)},emit:function(i){var s=[].slice.call(arguments,1),a=((this.e||(this.e={}))[i]||[]).slice(),f=0,c=a.length;for(f;f{"use strict";/*! + * escape-html + * Copyright(c) 2012-2013 TJ Holowaychuk + * Copyright(c) 2015 Andreas Lubbe + * Copyright(c) 2015 Tiancheng "Timothy" Gu + * MIT Licensed + */var rs=/["'&<>]/;Yo.exports=ns;function ns(e){var t=""+e,r=rs.exec(t);if(!r)return t;var n,o="",i=0,s=0;for(i=r.index;i0&&i[i.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function W(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),o,i=[],s;try{for(;(t===void 0||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function D(e,t,r){if(r||arguments.length===2)for(var n=0,o=t.length,i;n1||a(m,d)})})}function a(m,d){try{f(n[m](d))}catch(h){p(i[0][3],h)}}function f(m){m.value instanceof et?Promise.resolve(m.value.v).then(c,u):p(i[0][2],m)}function c(m){a("next",m)}function u(m){a("throw",m)}function p(m,d){m(d),i.shift(),i.length&&a(i[0][0],i[0][1])}}function pn(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ee=="function"?Ee(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(a,f){s=e[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(c){i({value:c,done:a})},s)}}function C(e){return typeof e=="function"}function at(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var It=at(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: +`+r.map(function(n,o){return o+1+") "+n.toString()}).join(` + `):"",this.name="UnsubscriptionError",this.errors=r}});function Ve(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Ie=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=Ee(s),f=a.next();!f.done;f=a.next()){var c=f.value;c.remove(this)}}catch(v){t={error:v}}finally{try{f&&!f.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}else s.remove(this);var u=this.initialTeardown;if(C(u))try{u()}catch(v){i=v instanceof It?v.errors:[v]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var m=Ee(p),d=m.next();!d.done;d=m.next()){var h=d.value;try{ln(h)}catch(v){i=i!=null?i:[],v instanceof It?i=D(D([],W(i)),W(v.errors)):i.push(v)}}}catch(v){n={error:v}}finally{try{d&&!d.done&&(o=m.return)&&o.call(m)}finally{if(n)throw n.error}}}if(i)throw new It(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ln(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&Ve(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&Ve(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();var Sr=Ie.EMPTY;function jt(e){return e instanceof Ie||e&&"closed"in e&&C(e.remove)&&C(e.add)&&C(e.unsubscribe)}function ln(e){C(e)?e():e.unsubscribe()}var Le={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var st={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Sr:(this.currentObservers=null,a.push(r),new Ie(function(){n.currentObservers=null,Ve(a,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new F;return r.source=this,r},t.create=function(r,n){return new xn(r,n)},t}(F);var xn=function(e){ie(t,e);function t(r,n){var o=e.call(this)||this;return o.destination=r,o.source=n,o}return t.prototype.next=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,r)},t.prototype.error=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&o!==void 0?o:Sr},t}(x);var Et={now:function(){return(Et.delegate||Date).now()},delegate:void 0};var wt=function(e){ie(t,e);function t(r,n,o){r===void 0&&(r=1/0),n===void 0&&(n=1/0),o===void 0&&(o=Et);var i=e.call(this)||this;return i._bufferSize=r,i._windowTime=n,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,r),i._windowTime=Math.max(1,n),i}return t.prototype.next=function(r){var n=this,o=n.isStopped,i=n._buffer,s=n._infiniteTimeWindow,a=n._timestampProvider,f=n._windowTime;o||(i.push(r),!s&&i.push(a.now()+f)),this._trimBuffer(),e.prototype.next.call(this,r)},t.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(r),o=this,i=o._infiniteTimeWindow,s=o._buffer,a=s.slice(),f=0;f0?e.prototype.requestAsyncId.call(this,r,n,o):(r.actions.push(this),r._scheduled||(r._scheduled=ut.requestAnimationFrame(function(){return r.flush(void 0)})))},t.prototype.recycleAsyncId=function(r,n,o){var i;if(o===void 0&&(o=0),o!=null?o>0:this.delay>0)return e.prototype.recycleAsyncId.call(this,r,n,o);var s=r.actions;n!=null&&((i=s[s.length-1])===null||i===void 0?void 0:i.id)!==n&&(ut.cancelAnimationFrame(n),r._scheduled=void 0)},t}(Wt);var Sn=function(e){ie(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.flush=function(r){this._active=!0;var n=this._scheduled;this._scheduled=void 0;var o=this.actions,i;r=r||o.shift();do if(i=r.execute(r.state,r.delay))break;while((r=o[0])&&r.id===n&&o.shift());if(this._active=!1,i){for(;(r=o[0])&&r.id===n&&o.shift();)r.unsubscribe();throw i}},t}(Dt);var Oe=new Sn(wn);var M=new F(function(e){return e.complete()});function Vt(e){return e&&C(e.schedule)}function Cr(e){return e[e.length-1]}function Ye(e){return C(Cr(e))?e.pop():void 0}function Te(e){return Vt(Cr(e))?e.pop():void 0}function zt(e,t){return typeof Cr(e)=="number"?e.pop():t}var pt=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function Nt(e){return C(e==null?void 0:e.then)}function qt(e){return C(e[ft])}function Kt(e){return Symbol.asyncIterator&&C(e==null?void 0:e[Symbol.asyncIterator])}function Qt(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function zi(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Yt=zi();function Gt(e){return C(e==null?void 0:e[Yt])}function Bt(e){return un(this,arguments,function(){var r,n,o,i;return $t(this,function(s){switch(s.label){case 0:r=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,et(r.read())];case 3:return n=s.sent(),o=n.value,i=n.done,i?[4,et(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,et(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function Jt(e){return C(e==null?void 0:e.getReader)}function U(e){if(e instanceof F)return e;if(e!=null){if(qt(e))return Ni(e);if(pt(e))return qi(e);if(Nt(e))return Ki(e);if(Kt(e))return On(e);if(Gt(e))return Qi(e);if(Jt(e))return Yi(e)}throw Qt(e)}function Ni(e){return new F(function(t){var r=e[ft]();if(C(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function qi(e){return new F(function(t){for(var r=0;r=2;return function(n){return n.pipe(e?A(function(o,i){return e(o,i,n)}):de,ge(1),r?He(t):Dn(function(){return new Zt}))}}function Vn(){for(var e=[],t=0;t=2,!0))}function pe(e){e===void 0&&(e={});var t=e.connector,r=t===void 0?function(){return new x}:t,n=e.resetOnError,o=n===void 0?!0:n,i=e.resetOnComplete,s=i===void 0?!0:i,a=e.resetOnRefCountZero,f=a===void 0?!0:a;return function(c){var u,p,m,d=0,h=!1,v=!1,Y=function(){p==null||p.unsubscribe(),p=void 0},B=function(){Y(),u=m=void 0,h=v=!1},N=function(){var O=u;B(),O==null||O.unsubscribe()};return y(function(O,Qe){d++,!v&&!h&&Y();var De=m=m!=null?m:r();Qe.add(function(){d--,d===0&&!v&&!h&&(p=$r(N,f))}),De.subscribe(Qe),!u&&d>0&&(u=new rt({next:function($e){return De.next($e)},error:function($e){v=!0,Y(),p=$r(B,o,$e),De.error($e)},complete:function(){h=!0,Y(),p=$r(B,s),De.complete()}}),U(O).subscribe(u))})(c)}}function $r(e,t){for(var r=[],n=2;ne.next(document)),e}function K(e,t=document){return Array.from(t.querySelectorAll(e))}function z(e,t=document){let r=ce(e,t);if(typeof r=="undefined")throw new ReferenceError(`Missing element: expected "${e}" to be present`);return r}function ce(e,t=document){return t.querySelector(e)||void 0}function _e(){return document.activeElement instanceof HTMLElement&&document.activeElement||void 0}function tr(e){return L(b(document.body,"focusin"),b(document.body,"focusout")).pipe(ke(1),l(()=>{let t=_e();return typeof t!="undefined"?e.contains(t):!1}),V(e===_e()),J())}function Xe(e){return{x:e.offsetLeft,y:e.offsetTop}}function Kn(e){return L(b(window,"load"),b(window,"resize")).pipe(Ce(0,Oe),l(()=>Xe(e)),V(Xe(e)))}function rr(e){return{x:e.scrollLeft,y:e.scrollTop}}function dt(e){return L(b(e,"scroll"),b(window,"resize")).pipe(Ce(0,Oe),l(()=>rr(e)),V(rr(e)))}var Yn=function(){if(typeof Map!="undefined")return Map;function e(t,r){var n=-1;return t.some(function(o,i){return o[0]===r?(n=i,!0):!1}),n}return function(){function t(){this.__entries__=[]}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),t.prototype.get=function(r){var n=e(this.__entries__,r),o=this.__entries__[n];return o&&o[1]},t.prototype.set=function(r,n){var o=e(this.__entries__,r);~o?this.__entries__[o][1]=n:this.__entries__.push([r,n])},t.prototype.delete=function(r){var n=this.__entries__,o=e(n,r);~o&&n.splice(o,1)},t.prototype.has=function(r){return!!~e(this.__entries__,r)},t.prototype.clear=function(){this.__entries__.splice(0)},t.prototype.forEach=function(r,n){n===void 0&&(n=null);for(var o=0,i=this.__entries__;o0},e.prototype.connect_=function(){!Wr||this.connected_||(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),va?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},e.prototype.disconnect_=function(){!Wr||!this.connected_||(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},e.prototype.onTransitionEnd_=function(t){var r=t.propertyName,n=r===void 0?"":r,o=ba.some(function(i){return!!~n.indexOf(i)});o&&this.refresh()},e.getInstance=function(){return this.instance_||(this.instance_=new e),this.instance_},e.instance_=null,e}(),Gn=function(e,t){for(var r=0,n=Object.keys(t);r0},e}(),Jn=typeof WeakMap!="undefined"?new WeakMap:new Yn,Xn=function(){function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var r=ga.getInstance(),n=new La(t,r,this);Jn.set(this,n)}return e}();["observe","unobserve","disconnect"].forEach(function(e){Xn.prototype[e]=function(){var t;return(t=Jn.get(this))[e].apply(t,arguments)}});var Aa=function(){return typeof nr.ResizeObserver!="undefined"?nr.ResizeObserver:Xn}(),Zn=Aa;var eo=new x,Ca=$(()=>k(new Zn(e=>{for(let t of e)eo.next(t)}))).pipe(g(e=>L(ze,k(e)).pipe(R(()=>e.disconnect()))),X(1));function he(e){return{width:e.offsetWidth,height:e.offsetHeight}}function ye(e){return Ca.pipe(S(t=>t.observe(e)),g(t=>eo.pipe(A(({target:r})=>r===e),R(()=>t.unobserve(e)),l(()=>he(e)))),V(he(e)))}function bt(e){return{width:e.scrollWidth,height:e.scrollHeight}}function ar(e){let t=e.parentElement;for(;t&&(e.scrollWidth<=t.scrollWidth&&e.scrollHeight<=t.scrollHeight);)t=(e=t).parentElement;return t?e:void 0}var to=new x,Ra=$(()=>k(new IntersectionObserver(e=>{for(let t of e)to.next(t)},{threshold:0}))).pipe(g(e=>L(ze,k(e)).pipe(R(()=>e.disconnect()))),X(1));function sr(e){return Ra.pipe(S(t=>t.observe(e)),g(t=>to.pipe(A(({target:r})=>r===e),R(()=>t.unobserve(e)),l(({isIntersecting:r})=>r))))}function ro(e,t=16){return dt(e).pipe(l(({y:r})=>{let n=he(e),o=bt(e);return r>=o.height-n.height-t}),J())}var cr={drawer:z("[data-md-toggle=drawer]"),search:z("[data-md-toggle=search]")};function no(e){return cr[e].checked}function Ke(e,t){cr[e].checked!==t&&cr[e].click()}function Ue(e){let t=cr[e];return b(t,"change").pipe(l(()=>t.checked),V(t.checked))}function ka(e,t){switch(e.constructor){case HTMLInputElement:return e.type==="radio"?/^Arrow/.test(t):!0;case HTMLSelectElement:case HTMLTextAreaElement:return!0;default:return e.isContentEditable}}function Ha(){return L(b(window,"compositionstart").pipe(l(()=>!0)),b(window,"compositionend").pipe(l(()=>!1))).pipe(V(!1))}function oo(){let e=b(window,"keydown").pipe(A(t=>!(t.metaKey||t.ctrlKey)),l(t=>({mode:no("search")?"search":"global",type:t.key,claim(){t.preventDefault(),t.stopPropagation()}})),A(({mode:t,type:r})=>{if(t==="global"){let n=_e();if(typeof n!="undefined")return!ka(n,r)}return!0}),pe());return Ha().pipe(g(t=>t?M:e))}function le(){return new URL(location.href)}function ot(e){location.href=e.href}function io(){return new x}function ao(e,t){if(typeof t=="string"||typeof t=="number")e.innerHTML+=t.toString();else if(t instanceof Node)e.appendChild(t);else if(Array.isArray(t))for(let r of t)ao(e,r)}function _(e,t,...r){let n=document.createElement(e);if(t)for(let o of Object.keys(t))typeof t[o]!="undefined"&&(typeof t[o]!="boolean"?n.setAttribute(o,t[o]):n.setAttribute(o,""));for(let o of r)ao(n,o);return n}function fr(e){if(e>999){let t=+((e-950)%1e3>99);return`${((e+1e-6)/1e3).toFixed(t)}k`}else return e.toString()}function so(){return location.hash.substring(1)}function Dr(e){let t=_("a",{href:e});t.addEventListener("click",r=>r.stopPropagation()),t.click()}function Pa(e){return L(b(window,"hashchange"),e).pipe(l(so),V(so()),A(t=>t.length>0),X(1))}function co(e){return Pa(e).pipe(l(t=>ce(`[id="${t}"]`)),A(t=>typeof t!="undefined"))}function Vr(e){let t=matchMedia(e);return er(r=>t.addListener(()=>r(t.matches))).pipe(V(t.matches))}function fo(){let e=matchMedia("print");return L(b(window,"beforeprint").pipe(l(()=>!0)),b(window,"afterprint").pipe(l(()=>!1))).pipe(V(e.matches))}function zr(e,t){return e.pipe(g(r=>r?t():M))}function ur(e,t={credentials:"same-origin"}){return ue(fetch(`${e}`,t)).pipe(fe(()=>M),g(r=>r.status!==200?Ot(()=>new Error(r.statusText)):k(r)))}function We(e,t){return ur(e,t).pipe(g(r=>r.json()),X(1))}function uo(e,t){let r=new DOMParser;return ur(e,t).pipe(g(n=>n.text()),l(n=>r.parseFromString(n,"text/xml")),X(1))}function pr(e){let t=_("script",{src:e});return $(()=>(document.head.appendChild(t),L(b(t,"load"),b(t,"error").pipe(g(()=>Ot(()=>new ReferenceError(`Invalid script: ${e}`))))).pipe(l(()=>{}),R(()=>document.head.removeChild(t)),ge(1))))}function po(){return{x:Math.max(0,scrollX),y:Math.max(0,scrollY)}}function lo(){return L(b(window,"scroll",{passive:!0}),b(window,"resize",{passive:!0})).pipe(l(po),V(po()))}function mo(){return{width:innerWidth,height:innerHeight}}function ho(){return b(window,"resize",{passive:!0}).pipe(l(mo),V(mo()))}function bo(){return G([lo(),ho()]).pipe(l(([e,t])=>({offset:e,size:t})),X(1))}function lr(e,{viewport$:t,header$:r}){let n=t.pipe(ee("size")),o=G([n,r]).pipe(l(()=>Xe(e)));return G([r,t,o]).pipe(l(([{height:i},{offset:s,size:a},{x:f,y:c}])=>({offset:{x:s.x-f,y:s.y-c+i},size:a})))}(()=>{function e(n,o){parent.postMessage(n,o||"*")}function t(...n){return n.reduce((o,i)=>o.then(()=>new Promise(s=>{let a=document.createElement("script");a.src=i,a.onload=s,document.body.appendChild(a)})),Promise.resolve())}var r=class extends EventTarget{constructor(n){super(),this.url=n,this.m=i=>{i.source===this.w&&(this.dispatchEvent(new MessageEvent("message",{data:i.data})),this.onmessage&&this.onmessage(i))},this.e=(i,s,a,f,c)=>{if(s===`${this.url}`){let u=new ErrorEvent("error",{message:i,filename:s,lineno:a,colno:f,error:c});this.dispatchEvent(u),this.onerror&&this.onerror(u)}};let o=document.createElement("iframe");o.hidden=!0,document.body.appendChild(this.iframe=o),this.w.document.open(),this.w.document.write(` + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Callbacks

+ +

Registering A Callback

+

A callback function must be registered when you set a pin to an input mode.

+

The code below illustrates a typical callback function.

+
def the_callback(data):
+    """
+    A callback function to report data changes.
+    This will print the pin number, its reported value and
+    the date and time when the change occurred
+
+    :param data: [pin mode, pin, current reported value,timestamp]
+    """
+    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+    print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '
+          f'Value: {data[CB_VALUE]} Time Stamp: {date}')
+
+

And here, the callback is registered when the set_pin_mode is called:

+
board.set_pin_mode_digital_input_pullup(12, the_callback)
+
+

If you forget to register a callback, +a RunTime exception will be thrown.

+
Traceback (most recent call last):
+  File "/home/afy/PycharmProjects/telemetrix-rpi-pico-w/ play/no_callback_registered.py", line 5, in <module>
+    board.set_pin_mode_digital_input(5)
+  File "/home/afy/PycharmProjects/telemetrix-rpi-pico-w/telemetrix_rpi_pico_w/telemetrix_rpi_pico_w.py", line 752, in set_pin_mode_digital_input
+    raise RuntimeError('A callback must be specified')
+RuntimeError: A callback must be specified
+
+

Callback Function Parameter

+

A callback function or method must accept a single parameter. The client +automatically fills in this parameter as a list +when receiving an input data change notification.
+For "the_callback" above, this parameter is named data.

+

The list contents vary from input pin type to input pin type and +are described in detail for each set_pin_mode_XXX method in the +API documentation. +The first element in the list identifies the pin type, and the last element +is a timestamp of the data change occurrence. Other elements identify the GPIO pin, +the current data value, and additional relevant information.

+

For example, the list may contain

+
[DIGITAL_REPORT, pin_number, pin_value, raw_time_stamp]
+
+DIGITAL_REPORT = 2
+
+

NOTE:

+

**Telemetrix does not support polling or direct read methods for +inputs. Instead, the pin's associated callback is called as soon +as a data change is detected, allowing immediate response to data +changes and, generally, a more straightforward application design. +**

+

Pin Types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Pin ModePin Mode Value
Digital Input (including pullup and pulldown)2
Analog Input (ADC)3
I2C10
SONAR Distance11
DHT12
+

Converting The Raw Timestamp

+

To convert the raw timestamp field to a human-readable time, use time.localtime().

+
date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/examples/index.html b/examples/index.html new file mode 100644 index 0000000..2c640d7 --- /dev/null +++ b/examples/index.html @@ -0,0 +1,1138 @@ + + + + + + + + + + + + + + + + + + + + + + Downloading And Running The Examples - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Downloading And Running The Examples

+ +

Once the client and server software have been installed, +it would be an excellent time to try the examples.

+

Examples are provided for all four of the servers.

+

Example Naming Conventions

+

The naming convention used for the examples prefixes each example with three letters. +The first letter is for the board type:

+
    +
  • m = Minima
  • +
  • w = Wifi
  • +
+

The second letter is for the transport type:

+
    +
  • b = BLE
  • +
  • s = serial
  • +
  • w = WIFI
  • +
+

The third is for the concurrency type:

+
    +
  • a = asyncio
  • +
  • t = threaded
  • +
+ + +


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/images/add_zip3.png b/images/add_zip3.png new file mode 100644 index 0000000..185474d Binary files /dev/null and b/images/add_zip3.png differ diff --git a/images/arduino_ide_download.png b/images/arduino_ide_download.png new file mode 100644 index 0000000..f964c71 Binary files /dev/null and b/images/arduino_ide_download.png differ diff --git a/images/arduino_lib_install.png b/images/arduino_lib_install.png new file mode 100644 index 0000000..6015fd1 Binary files /dev/null and b/images/arduino_lib_install.png differ diff --git a/images/ble_ino.png b/images/ble_ino.png new file mode 100644 index 0000000..420551a Binary files /dev/null and b/images/ble_ino.png differ diff --git a/images/board_select_1.png b/images/board_select_1.png new file mode 100644 index 0000000..0179052 Binary files /dev/null and b/images/board_select_1.png differ diff --git a/images/board_select_2.png b/images/board_select_2.png new file mode 100644 index 0000000..69e44b4 Binary files /dev/null and b/images/board_select_2.png differ diff --git a/images/board_select_3.png b/images/board_select_3.png new file mode 100644 index 0000000..591d330 Binary files /dev/null and b/images/board_select_3.png differ diff --git a/images/board_select_4.png b/images/board_select_4.png new file mode 100644 index 0000000..43f149c Binary files /dev/null and b/images/board_select_4.png differ diff --git a/images/config_ble_server.png b/images/config_ble_server.png new file mode 100644 index 0000000..ce51148 Binary files /dev/null and b/images/config_ble_server.png differ diff --git a/images/config_serial_server.png b/images/config_serial_server.png new file mode 100644 index 0000000..35bf7ff Binary files /dev/null and b/images/config_serial_server.png differ diff --git a/images/config_wifi_server.png b/images/config_wifi_server.png new file mode 100644 index 0000000..40d789b Binary files /dev/null and b/images/config_wifi_server.png differ diff --git a/images/delay.png b/images/delay.png new file mode 100644 index 0000000..e925d37 Binary files /dev/null and b/images/delay.png differ diff --git a/images/downloads.png b/images/downloads.png new file mode 100644 index 0000000..b0c63b2 Binary files /dev/null and b/images/downloads.png differ diff --git a/images/example_1.png b/images/example_1.png new file mode 100644 index 0000000..01bb557 Binary files /dev/null and b/images/example_1.png differ diff --git a/images/example_2.png b/images/example_2.png new file mode 100644 index 0000000..66181b2 Binary files /dev/null and b/images/example_2.png differ diff --git a/images/example_3.png b/images/example_3.png new file mode 100644 index 0000000..db04e05 Binary files /dev/null and b/images/example_3.png differ diff --git a/images/example_4.png b/images/example_4.png new file mode 100644 index 0000000..db3c427 Binary files /dev/null and b/images/example_4.png differ diff --git a/images/example_5.png b/images/example_5.png new file mode 100644 index 0000000..289a47b Binary files /dev/null and b/images/example_5.png differ diff --git a/images/examples.png b/images/examples.png new file mode 100644 index 0000000..567238e Binary files /dev/null and b/images/examples.png differ diff --git a/images/get_examples.png b/images/get_examples.png new file mode 100644 index 0000000..bf6dc7c Binary files /dev/null and b/images/get_examples.png differ diff --git a/images/ide1.png b/images/ide1.png new file mode 100644 index 0000000..7cfb7cd Binary files /dev/null and b/images/ide1.png differ diff --git a/images/install_t4a.png b/images/install_t4a.png new file mode 100644 index 0000000..8299303 Binary files /dev/null and b/images/install_t4a.png differ diff --git a/images/ip_address.png b/images/ip_address.png new file mode 100644 index 0000000..a3c0121 Binary files /dev/null and b/images/ip_address.png differ diff --git a/images/library_manager_1.png b/images/library_manager_1.png new file mode 100644 index 0000000..0cce44b Binary files /dev/null and b/images/library_manager_1.png differ diff --git a/images/library_manager_2.png b/images/library_manager_2.png new file mode 100644 index 0000000..caffb49 Binary files /dev/null and b/images/library_manager_2.png differ diff --git a/images/library_manager_3.png b/images/library_manager_3.png new file mode 100644 index 0000000..26806c6 Binary files /dev/null and b/images/library_manager_3.png differ diff --git a/images/manage_libraries.png b/images/manage_libraries.png new file mode 100644 index 0000000..700fd39 Binary files /dev/null and b/images/manage_libraries.png differ diff --git a/images/no_port.png b/images/no_port.png new file mode 100644 index 0000000..ef20b78 Binary files /dev/null and b/images/no_port.png differ diff --git a/images/pinout.png b/images/pinout.png new file mode 100644 index 0000000..7c7aa6d Binary files /dev/null and b/images/pinout.png differ diff --git a/images/router.png b/images/router.png new file mode 100644 index 0000000..936493d Binary files /dev/null and b/images/router.png differ diff --git a/images/select_board_1.png b/images/select_board_1.png new file mode 100644 index 0000000..f18d134 Binary files /dev/null and b/images/select_board_1.png differ diff --git a/images/select_server.png b/images/select_server.png new file mode 100644 index 0000000..7b8e526 Binary files /dev/null and b/images/select_server.png differ diff --git a/images/serial_ip.png b/images/serial_ip.png new file mode 100644 index 0000000..0ece88c Binary files /dev/null and b/images/serial_ip.png differ diff --git a/images/serial_monitor.png b/images/serial_monitor.png new file mode 100644 index 0000000..1268e0c Binary files /dev/null and b/images/serial_monitor.png differ diff --git a/images/telemetrix4UnoR4.png b/images/telemetrix4UnoR4.png new file mode 100644 index 0000000..7f1959d Binary files /dev/null and b/images/telemetrix4UnoR4.png differ diff --git a/images/telemetrix4arduino2.png b/images/telemetrix4arduino2.png new file mode 100644 index 0000000..54bad6e Binary files /dev/null and b/images/telemetrix4arduino2.png differ diff --git a/images/telemetrixunor4_2.png b/images/telemetrixunor4_2.png new file mode 100644 index 0000000..c100803 Binary files /dev/null and b/images/telemetrixunor4_2.png differ diff --git a/images/tmx.png b/images/tmx.png new file mode 100644 index 0000000..9fbc782 Binary files /dev/null and b/images/tmx.png differ diff --git a/images/tmx10.png b/images/tmx10.png new file mode 100644 index 0000000..59dc005 Binary files /dev/null and b/images/tmx10.png differ diff --git a/images/tmx2.png b/images/tmx2.png new file mode 100644 index 0000000..9fbc782 Binary files /dev/null and b/images/tmx2.png differ diff --git a/images/tmx3.png b/images/tmx3.png new file mode 100644 index 0000000..c00fc32 Binary files /dev/null and b/images/tmx3.png differ diff --git a/images/tmx4.png b/images/tmx4.png new file mode 100644 index 0000000..fc038a6 Binary files /dev/null and b/images/tmx4.png differ diff --git a/images/tmx5.png b/images/tmx5.png new file mode 100644 index 0000000..cea268d Binary files /dev/null and b/images/tmx5.png differ diff --git a/images/tmx6.png b/images/tmx6.png new file mode 100644 index 0000000..0633ed1 Binary files /dev/null and b/images/tmx6.png differ diff --git a/images/tmx7.png b/images/tmx7.png new file mode 100644 index 0000000..68bb123 Binary files /dev/null and b/images/tmx7.png differ diff --git a/images/tmx8.png b/images/tmx8.png new file mode 100644 index 0000000..4dc7a3b Binary files /dev/null and b/images/tmx8.png differ diff --git a/images/usb_ino.png b/images/usb_ino.png new file mode 100644 index 0000000..ef6fc6e Binary files /dev/null and b/images/usb_ino.png differ diff --git a/images/warning.png b/images/warning.png new file mode 100644 index 0000000..06bb709 Binary files /dev/null and b/images/warning.png differ diff --git a/images/warning2.png b/images/warning2.png new file mode 100644 index 0000000..04940dc Binary files /dev/null and b/images/warning2.png differ diff --git a/images/wifi_ino.png b/images/wifi_ino.png new file mode 100644 index 0000000..10653b0 Binary files /dev/null and b/images/wifi_ino.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..2cfaee5 --- /dev/null +++ b/index.html @@ -0,0 +1,1333 @@ + + + + + + + + + + + + + + + + + + + + The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +
Telemetrix User's Guide
+
For The
+
Arduino UNO R4 Minima and WIFI
+ +


+Our logo +

+

Telemetry is a system for collecting data on a remote device and then +automatically transmitting the collected data back to local receiving equipment for +processing.

+

With Telemetrix, you can do things such as establish a GPIO pin as a PWM output pin and +set its value to run a DC motor, communicate with your favorite i2c device, +have the WIFI's LEDs scroll a message, or monitor temperature using a DHT temperature +device, and much more, +all within a Python application.

+

Telemetrix Client-Server Model

+

Telemetrix is implemented using a client-server model. +A "fixed" server is uploaded to the Arduino.

+

The server communicates with a Telemetrix Python client that sends commands to +the Arduino and receives data reports.

+

Application debugging is simplified by using your favorite Python toolset.

+

Telemetrix Client-Server Transports

+

The Arduino UNO R4 Minima uses a USBSerial transport.

+

For the Arduino UNO R4 WIFI, you can choose a WIFI, USBSerial or BLE transport. +There are servers for each of the transport types.

+

Both Threaded And ASYNCIO Client APIs Are Available For Each Board

+

Choose whichever one suits your needs.

+

The transport type is specified for the UNO R4 WIFI when Telemetrix is instantiated.

+

Data Is Reported Using Callback Methods

+

When you set a pin mode as an input type, a user-provided callback method is +registered to provide data change notifications. +Callbacks ensure that data changes +are processed as soon as possible and that no data change events are lost. +Each data change is time-stamped as it is received.

+

You may implement the callback scheme as a single callback to +handle all data change events or multiple individual callbacks to handle +specific pins or input device types, giving you maximum flexibility.

+

Automatic Data Reporting

+

Data is reported automatically without polling for analog inputs, +digital inputs, DHT temperature sensors, and HC-SR04 distance sensors. +Once a pin mode is set, reporting begins immediately.

+


+

Summary Of Major Features

+ +

A Working Example

+

Below is a Telemetrix example for the Arduino UNO R4 Mimima that monitors several +digital input pins. All the pins share a single callback.

+
import sys
+import time
+
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima
+
+"""
+Monitor 4 digital input pins.
+"""
+
+
+# Callback data indices
+# When the callback function is called, the client fills in 
+# the data parameter. Data is a list of values, and the following are 
+# indexes into the list to retrieve report information
+
+CB_PIN_MODE = 0 # The mode of the reporting pin (input, output, PWM, etc.)
+CB_PIN = 1      # The GPIO pin number associated with this report
+CB_VALUE = 2    # The data value reported
+CB_TIME = 3     # A time stamp when the data change occurred
+
+
+def the_callback(data):
+    """
+    A callback function to report data changes.
+    This will print the pin number, its reported value and
+    the date and time when the change occurred
+    :param data: [report type(i.e. analog, pwm, digital), pin number, current reported 
+                 value, timestamp]
+    """
+    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
+    print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '
+          f'Value: {data[CB_VALUE]} Time Stamp: {date}')
+
+# instantiate TelemetrixUnoR4Minima
+board = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()
+
+# Set the pin mode for each pin.
+# A callback must be specified. A single callback is used for this example, but
+# separate callback could be used for each pin.
+board.set_pin_mode_digital_input(5, the_callback)
+board.set_pin_mode_digital_input(6, the_callback)
+board.set_pin_mode_digital_input(7, the_callback)
+board.set_pin_mode_digital_inputp(8, the_callback)
+
+try:
+    while True:
+        time.sleep(.0001)
+except KeyboardInterrupt:
+    board.shutdown()
+    sys.exit(0)
+
+

And here is some sample output:

+
telemetrix_uno_r4_minima:  Version 1.00
+
+Copyright (c) 2023 Alan Yorinks All Rights Reserved.
+
+Opening all potential serial ports...
+    /dev/ttyACM0
+
+Waiting 1 seconds(arduino_wait) for Arduino devices to reset...
+Valid Arduino ID Found.
+Arduino compatible device found and connected to /dev/ttyACM0
+Reset Complete
+
+Retrieving Telemetrix4UnoR4Minima firmware ID...
+Telemetrix4UnoR4Minima firmware version: 1.0.0
+Enter Control-C to quit.
+
+Report Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 6 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 7 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:34:52
+Report Type: 2 Pin: 8 Value: 0 Time Stamp: 2023-07-14 13:35:21
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:22
+Report Type: 2 Pin: 5 Value: 0 Time Stamp: 2023-07-14 13:35:29
+Report Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:35:31
+Report Type: 2 Pin: 6 Value: 0 Time Stamp: 2023-07-14 13:35:33
+Report Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:34
+
+
+
+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+

Last updated 7 August 2023

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/install_telemetrix/index.html b/install_telemetrix/index.html new file mode 100644 index 0000000..0bda0b1 --- /dev/null +++ b/install_telemetrix/index.html @@ -0,0 +1,1205 @@ + + + + + + + + + + + + + + + + + + + + + + Installing The Python Client APIs - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Installing The Client APIs

+

Installing For The First Time

+

To install from PyPI, within your virtual environment type:

+
pip install telemetrix-uno-r4
+
+

Upgrading To A Newer Version

+

To upgrade to a newer version from an existing installation, use the following command:

+
pip install telemetrix-uno-r4 --upgrade
+
+
+

What Is Installed?

+

The telemetrix-uno-r4 package contains four client APIs. You have the choice of using +an API employing a threaded concurrency model or an API using an asyncio concurrency +model. The asyncio API +names end +with _aio.

+

NOTE: BLE is only supported by telemetrix_uno_r4_wifi_aio.

+

Arduino UNO R4 Mimima Clients

+
    +
  • +

    telemetrix_uno_r4_minima

    +
  • +
  • +

    telemetrix_uno_r4_minima_aio

    +
  • +
+

Arduino UNO R4 WIFI Clients

+
    +
  • +

    telemetrix_uno_r4_wifi

    +
  • +
  • +

    telemetrix_uno_r4_wifi_aio

    +
  • +
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/issues/index.html b/issues/index.html new file mode 100644 index 0000000..ff93693 --- /dev/null +++ b/issues/index.html @@ -0,0 +1,1165 @@ + + + + + + + + + + + + + + + + + + + + + + Known Issues - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Known Issues

+ +

Arduino Compiler Warnings

+

Telemetrix4UnoR4 uses the NewPing library for HC-SR04 Sonar distance sensor support. +You may see the following warning when compiling any of the servers. +This warning may be safely ignored.

+

An issue was created but has not yet been addressed.

+
WARNING: library NewPing claims to run on avr, megaavr, esp32 architecture(s)
+and may be incompatible with your current board which runs on 
+renesas architecture(s).
+
+
+

BLE

+

Server Side Issues

+

BLE support for Arduino UNO R4 boards is in a Beta state. Currently, it does not +support the Servo library. An issue has been generated against the ArduinoBLE library.

+

Instructions to install the Beta version of ArduinoBLE may be found here.

+

Client Side Issues

+

BLE is only supported using the asyncio API. The +threaded API does not support BLE.

+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/license/index.html b/license/index.html new file mode 100644 index 0000000..503216b --- /dev/null +++ b/license/index.html @@ -0,0 +1,1943 @@ + + + + + + + + + + + + + + + + + + + + License - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +

License

+ +

GNU AFFERO GENERAL PUBLIC LICENSE

+

Version 3, 19 November 2007

+

Copyright (C) 2007 Free Software Foundation, Inc. +https://fsf.org/

+

Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed.

+

Preamble

+

The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software.

+

The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains +free software for all its users.

+

When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things.

+

Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software.

+

A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public.

+

The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version.

+

An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing +under this license.

+

The precise terms and conditions for copying, distribution and +modification follow.

+

TERMS AND CONDITIONS

+

0. Definitions.

+

"This License" refers to version 3 of the GNU Affero General Public +License.

+

"Copyright" also means copyright-like laws that apply to other kinds +of works, such as semiconductor masks.

+

"The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations.

+

To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of +an exact copy. The resulting work is called a "modified version" of +the earlier work or a work "based on" the earlier work.

+

A "covered work" means either the unmodified Program or a work based +on the Program.

+

To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well.

+

To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user +through a computer network, with no transfer of a copy, is not +conveying.

+

An interactive user interface displays "Appropriate Legal Notices" to +the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion.

+

1. Source Code.

+

The "source code" for a work means the preferred form of the work for +making modifications to it. "Object code" means any non-source form of +a work.

+

A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language.

+

The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it.

+

The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work.

+

The Corresponding Source need not include anything that users can +regenerate automatically from other parts of the Corresponding Source.

+

The Corresponding Source for a work in source code form is that same +work.

+

2. Basic Permissions.

+

All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law.

+

You may make, run and propagate covered works that you do not convey, +without conditions so long as your license otherwise remains in force. +You may convey covered works to others for the sole purpose of having +them make modifications exclusively for you, or provide you with +facilities for running those works, provided that you comply with the +terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for +you must do so exclusively on your behalf, under your direction and +control, on terms that prohibit them from making any copies of your +copyrighted material outside their relationship with you.

+

Conveying under any other circumstances is permitted solely under the +conditions stated below. Sublicensing is not allowed; section 10 makes +it unnecessary.

+ +

No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures.

+

When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such +circumvention is effected by exercising rights under this License with +respect to the covered work, and you disclaim any intention to limit +operation or modification of the work as a means of enforcing, against +the work's users, your or third parties' legal rights to forbid +circumvention of technological measures.

+

4. Conveying Verbatim Copies.

+

You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program.

+

You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee.

+

5. Conveying Modified Source Versions.

+

You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these +conditions:

+
    +
  • a) The work must carry prominent notices stating that you modified + it, and giving a relevant date.
  • +
  • b) The work must carry prominent notices stating that it is + released under this License and any conditions added under + section 7. This requirement modifies the requirement in section 4 + to "keep intact all notices".
  • +
  • c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it.
  • +
  • d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so.
  • +
+

A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate.

+

6. Conveying Non-Source Forms.

+

You may convey a covered work in object code form under the terms of +sections 4 and 5, provided that you also convey the machine-readable +Corresponding Source under the terms of this License, in one of these +ways:

+
    +
  • a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange.
  • +
  • b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the Corresponding + Source from a network server at no charge.
  • +
  • c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b.
  • +
  • d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements.
  • +
  • e) Convey the object code using peer-to-peer transmission, + provided you inform other peers where the object code and + Corresponding Source of the work are being offered to the general + public at no charge under subsection 6d.
  • +
+

A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work.

+

A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, +family, or household purposes, or (2) anything designed or sold for +incorporation into a dwelling. In determining whether a product is a +consumer product, doubtful cases shall be resolved in favor of +coverage. For a particular product received by a particular user, +"normally used" refers to a typical or common use of that class of +product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected +to use, the product. A product is a consumer product regardless of +whether the product has substantial commercial, industrial or +non-consumer uses, unless such uses represent the only significant +mode of use of the product.

+

"Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to +install and execute modified versions of a covered work in that User +Product from a modified version of its Corresponding Source. The +information must suffice to ensure that the continued functioning of +the modified object code is in no case prevented or interfered with +solely because modification has been made.

+

If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM).

+

The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or +updates for a work that has been modified or installed by the +recipient, or for the User Product in which it has been modified or +installed. Access to a network may be denied when the modification +itself materially and adversely affects the operation of the network +or violates the rules and protocols for communication across the +network.

+

Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying.

+

7. Additional Terms.

+

"Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions.

+

When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission.

+

Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders +of that material) supplement the terms of this License with terms:

+
    +
  • a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or
  • +
  • b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or
  • +
  • c) Prohibiting misrepresentation of the origin of that material, + or requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or
  • +
  • d) Limiting the use for publicity purposes of names of licensors + or authors of the material; or
  • +
  • e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or
  • +
  • f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions + of it) with contractual assumptions of liability to the recipient, + for any liability that these contractual assumptions directly + impose on those licensors and authors.
  • +
+

All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying.

+

If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms.

+

Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; the +above requirements apply either way.

+

8. Termination.

+

You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11).

+

However, if you cease all violation of this License, then your license +from a particular copyright holder is reinstated (a) provisionally, +unless and until the copyright holder explicitly and finally +terminates your license, and (b) permanently, if the copyright holder +fails to notify you of the violation by some reasonable means prior to +60 days after the cessation.

+

Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice.

+

Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10.

+

9. Acceptance Not Required for Having Copies.

+

You are not required to accept this License in order to receive or run +a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so.

+

10. Automatic Licensing of Downstream Recipients.

+

Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License.

+

An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts.

+

You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it.

+

11. Patents.

+

A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version".

+

A contributor's "essential patent claims" are all patent claims owned +or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License.

+

Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version.

+

In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party.

+

If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid.

+

If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it.

+

A patent license is "discriminatory" if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on +the non-exercise of one or more of the rights that are specifically +granted under this License. You may not convey a covered work if you +are a party to an arrangement with a third party that is in the +business of distributing software, under which you make payment to the +third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties +who would receive the covered work from you, a discriminatory patent +license (a) in connection with copies of the covered work conveyed by +you (or copies made from those copies), or (b) primarily for and in +connection with specific products or compilations that contain the +covered work, unless you entered into that arrangement, or that patent +license was granted, prior to 28 March 2007.

+

Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law.

+

12. No Surrender of Others' Freedom.

+

If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under +this License and any other pertinent obligations, then as a +consequence you may not convey it at all. For example, if you agree to +terms that obligate you to collect a royalty for further conveying +from those to whom you convey the Program, the only way you could +satisfy both those terms and this License would be to refrain entirely +from conveying the Program.

+

13. Remote Network Interaction; Use with the GNU General Public License.

+

Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your +version supports such interaction) an opportunity to receive the +Corresponding Source of your version by providing access to the +Corresponding Source from a network server at no charge, through some +standard or customary means of facilitating copying of software. This +Corresponding Source shall include the Corresponding Source for any +work covered by version 3 of the GNU General Public License that is +incorporated pursuant to the following paragraph.

+

Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License.

+

14. Revised Versions of this License.

+

The Free Software Foundation may publish revised and/or new versions +of the GNU Affero General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns.

+

Each version is given a distinguishing version number. If the Program +specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever +published by the Free Software Foundation.

+

If the Program specifies that a proxy can decide which future versions +of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program.

+

Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version.

+

15. Disclaimer of Warranty.

+

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION.

+

16. Limitation of Liability.

+

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR +CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT +NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR +LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM +TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+

17. Interpretation of Sections 15 and 16.

+

If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee.

+

END OF TERMS AND CONDITIONS

+

How to Apply These Terms to Your New Programs

+

If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms.

+

To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively state +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found.

+
    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+

Also add information on how to contact you by electronic and paper +mail.

+

If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for +the specific requirements.

+

You should also get your employer (if you work as a programmer) or +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. For more information on this, and how to apply and follow +the GNU AGPL, see https://www.gnu.org/licenses/.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/objects.inv b/objects.inv new file mode 100644 index 0000000..e33a527 Binary files /dev/null and b/objects.inv differ diff --git a/python_3_verify/index.html b/python_3_verify/index.html new file mode 100644 index 0000000..b483b1f --- /dev/null +++ b/python_3_verify/index.html @@ -0,0 +1,1070 @@ + + + + + + + + + + + + + + + + + + + + + + Install Python 3.8+ - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Verifying The Python Version

+

Python 3.8 or greater is required before installing and using the telemetrix-uno-r4 +package.

+

To check that you have the correct version of Python 3 installed, +open a command window and type:

+
python3 -V
+
+

For Windows, you may need to type:

+
python -V
+
+

Executing this command displays the current version of Python 3 installed.

+
Python 3.11.4
+
+

If you need to install Python 3, refer to python.org.

+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json new file mode 100644 index 0000000..33a982a --- /dev/null +++ b/search/search_index.json @@ -0,0 +1 @@ +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Introduction","text":"Telemetrix User's Guide For The Arduino UNO R4 Minima and WIFI

Telemetry is a system for collecting data on a remote device and then automatically transmitting the collected data back to local receiving equipment for processing.

With Telemetrix, you can do things such as establish a GPIO pin as a PWM output pin and set its value to run a DC motor, communicate with your favorite i2c device, have the WIFI's LEDs scroll a message, or monitor temperature using a DHT temperature device, and much more, all within a Python application.

"},{"location":"#telemetrix-client-server-model","title":"Telemetrix Client-Server Model","text":"

Telemetrix is implemented using a client-server model. A \"fixed\" server is uploaded to the Arduino.

The server communicates with a Telemetrix Python client that sends commands to the Arduino and receives data reports.

Application debugging is simplified by using your favorite Python toolset.

"},{"location":"#telemetrix-client-server-transports","title":"Telemetrix Client-Server Transports","text":"

The Arduino UNO R4 Minima uses a USBSerial transport.

For the Arduino UNO R4 WIFI, you can choose a WIFI, USBSerial or BLE transport. There are servers for each of the transport types.

"},{"location":"#both-threaded-and-asyncio-client-apis-are-available-for-each-board","title":"Both Threaded And ASYNCIO Client APIs Are Available For Each Board","text":"

Choose whichever one suits your needs.

The transport type is specified for the UNO R4 WIFI when Telemetrix is instantiated.

"},{"location":"#data-is-reported-using-callback-methods","title":"Data Is Reported Using Callback Methods","text":"

When you set a pin mode as an input type, a user-provided callback method is registered to provide data change notifications. Callbacks ensure that data changes are processed as soon as possible and that no data change events are lost. Each data change is time-stamped as it is received.

You may implement the callback scheme as a single callback to handle all data change events or multiple individual callbacks to handle specific pins or input device types, giving you maximum flexibility.

"},{"location":"#automatic-data-reporting","title":"Automatic Data Reporting","text":"

Data is reported automatically without polling for analog inputs, digital inputs, DHT temperature sensors, and HC-SR04 distance sensors. Once a pin mode is set, reporting begins immediately.

"},{"location":"#summary-of-major-features","title":"Summary Of Major Features","text":"
  • Applications are programmed using Python 3.8 or greater.
  • All Data change events are reported asynchronously via user-registered callback functions.
  • Each data change event is time-stamped.
  • Online API Reference Documentation is provided:
    • For the Arduino UNO R4 Minima Threaded Client
    • For the Arduino UNO R4 Minima Asyncio Client.
    • For the Arduino UNO R4 Wifi Threaded Client
    • For the Arduino UNO R4 Wifi Asyncio Client.
  • A complete set of working Minima examples is provided for the Arduino UNO R4 Minima and the Arduino UNO R4 WIFI
  • Integrated debugging methods are included as part of the Servers.
  • For Arduino UNO R4 WIFI, scrolling transport identifier messages are shown on the display. This feature may be optionally disabled.
"},{"location":"#a-working-example","title":"A Working Example","text":"

Below is a Telemetrix example for the Arduino UNO R4 Mimima that monitors several digital input pins. All the pins share a single callback.

import sys\nimport time\n\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima\n\n\"\"\"\nMonitor 4 digital input pins.\n\"\"\"\n\n\n# Callback data indices\n# When the callback function is called, the client fills in \n# the data parameter. Data is a list of values, and the following are \n# indexes into the list to retrieve report information\n\nCB_PIN_MODE = 0 # The mode of the reporting pin (input, output, PWM, etc.)\nCB_PIN = 1      # The GPIO pin number associated with this report\nCB_VALUE = 2    # The data value reported\nCB_TIME = 3     # A time stamp when the data change occurred\n\n\ndef the_callback(data):\n    \"\"\"\n    A callback function to report data changes.\n    This will print the pin number, its reported value and\n    the date and time when the change occurred\n    :param data: [report type(i.e. analog, pwm, digital), pin number, current reported \n                 value, timestamp]\n    \"\"\"\n    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n    print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '\n          f'Value: {data[CB_VALUE]} Time Stamp: {date}')\n\n# instantiate TelemetrixUnoR4Minima\nboard = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()\n\n# Set the pin mode for each pin.\n# A callback must be specified. A single callback is used for this example, but\n# separate callback could be used for each pin.\nboard.set_pin_mode_digital_input(5, the_callback)\nboard.set_pin_mode_digital_input(6, the_callback)\nboard.set_pin_mode_digital_input(7, the_callback)\nboard.set_pin_mode_digital_inputp(8, the_callback)\n\ntry:\n    while True:\n        time.sleep(.0001)\nexcept KeyboardInterrupt:\n    board.shutdown()\n    sys.exit(0)\n

And here is some sample output:

telemetrix_uno_r4_minima:  Version 1.00\n\nCopyright (c) 2023 Alan Yorinks All Rights Reserved.\n\nOpening all potential serial ports...\n    /dev/ttyACM0\n\nWaiting 1 seconds(arduino_wait) for Arduino devices to reset...\nValid Arduino ID Found.\nArduino compatible device found and connected to /dev/ttyACM0\nReset Complete\n\nRetrieving Telemetrix4UnoR4Minima firmware ID...\nTelemetrix4UnoR4Minima firmware version: 1.0.0\nEnter Control-C to quit.\n\nReport Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 6 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 7 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:34:52\nReport Type: 2 Pin: 8 Value: 0 Time Stamp: 2023-07-14 13:35:21\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:22\nReport Type: 2 Pin: 5 Value: 0 Time Stamp: 2023-07-14 13:35:29\nReport Type: 2 Pin: 5 Value: 1 Time Stamp: 2023-07-14 13:35:31\nReport Type: 2 Pin: 6 Value: 0 Time Stamp: 2023-07-14 13:35:33\nReport Type: 2 Pin: 8 Value: 1 Time Stamp: 2023-07-14 13:35:34\n\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

Last updated 7 August 2023

"},{"location":"about/","title":"REPORTING ISSUES","text":"

If you wish to report an issue with this library, please use this link.

For any of the servers, please use this link.

When filing an issue, please provide:

  1. Any console output.
  2. A description of the issue.
  3. Sample code demonstrating the problem.

For bugs, comments, or questions, please use the links above.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"about_the_apis/","title":"General Principles","text":""},{"location":"about_the_apis/#setting-pin-modes","title":"Setting Pin Modes","text":"

Pin modes must be set before interacting with a pin. All the methods listed below have a consistent API across all API classes.

"},{"location":"about_the_apis/#input-pin-modes","title":"Input Pin Modes","text":""},{"location":"about_the_apis/#requiring-a-callback-to-be-specified","title":"Requiring A Callback To Be Specified","text":"
  • set_pin_mode_analog_input
  • set_pin_mode_dht
  • set_pin_mode_digital_input
  • set_pin_mode_digital_input_pullup
  • set_pin_mode_sonar
"},{"location":"about_the_apis/#callback-specified-in-read-commands","title":"Callback Specified In Read Commands","text":"
  • set_pin_mode_i2c
  • set_pin_mode_spi
"},{"location":"about_the_apis/#output-pin-modes","title":"Output Pin Modes","text":"
  • set_pin_mode_analog_output
  • set_pin_mode_digital_output
  • set_pin_mode_servo

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"app_creation/","title":"Application Creation","text":""},{"location":"app_creation/#a-word-about-the-application-templates","title":"A Word About The Application Templates","text":"

The following section contains a set of application templates for each of the four servers. The templates are based on the included examples.

  • r4_minima_examples - asyncio
  • r4_minima_examples - threaded
  • r4_wifi_examples_asyncio - BLE
  • r4_wifi_examples_asyncio - WIFI
  • r4_wifi_examples_asyncio - usbSerial
  • r4_wifi_examples_threaded - WIFI
  • r4_wifi_examples_threaded - usbSerial

As you will see, your application needs to import the correct API and instantiate the API class. You then use the API method calls in writing your application.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"arduino_ide/","title":"Install The Arduino IDE","text":""},{"location":"arduino_ide/#download-and-install-the-arduino-ide","title":"Download And Install The Arduino IDE","text":"

Arduino IDE version 2.1.X is used to upload a server to the Minima or WIFI. It is also used to modify server source code when configuration is necessary.

To install a copy of the IDE, go to the Arduino Software Download page, and select the version for your operating system. Follow the installation instructions.

"},{"location":"arduino_ide/#a-note-for-linux-users","title":"A Note For Linux Users","text":"

You may need to add your login to the dialout group to upload to the Arduino.

To do so, follow these instructions.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"callbacks/","title":"Callbacks","text":""},{"location":"callbacks/#registering-a-callback","title":"Registering A Callback","text":"

A callback function must be registered when you set a pin to an input mode.

The code below illustrates a typical callback function.

def the_callback(data):\n    \"\"\"\n    A callback function to report data changes.\n    This will print the pin number, its reported value and\n    the date and time when the change occurred\n\n    :param data: [pin mode, pin, current reported value,timestamp]\n    \"\"\"\n    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n    print(f'Report Type: {data[CB_PIN_MODE]} Pin: {data[CB_PIN]} '\n          f'Value: {data[CB_VALUE]} Time Stamp: {date}')\n

And here, the callback is registered when the set_pin_mode is called:

board.set_pin_mode_digital_input_pullup(12, the_callback)\n

If you forget to register a callback, a RunTime exception will be thrown.

Traceback (most recent call last):\n  File \"/home/afy/PycharmProjects/telemetrix-rpi-pico-w/ play/no_callback_registered.py\", line 5, in <module>\n    board.set_pin_mode_digital_input(5)\n  File \"/home/afy/PycharmProjects/telemetrix-rpi-pico-w/telemetrix_rpi_pico_w/telemetrix_rpi_pico_w.py\", line 752, in set_pin_mode_digital_input\n    raise RuntimeError('A callback must be specified')\nRuntimeError: A callback must be specified\n
"},{"location":"callbacks/#callback-function-parameter","title":"Callback Function Parameter","text":"

A callback function or method must accept a single parameter. The client automatically fills in this parameter as a list when receiving an input data change notification. For \"the_callback\" above, this parameter is named data.

The list contents vary from input pin type to input pin type and are described in detail for each set_pin_mode_XXX method in the API documentation. The first element in the list identifies the pin type, and the last element is a timestamp of the data change occurrence. Other elements identify the GPIO pin, the current data value, and additional relevant information.

For example, the list may contain

[DIGITAL_REPORT, pin_number, pin_value, raw_time_stamp]\n\nDIGITAL_REPORT = 2\n

NOTE:

**Telemetrix does not support polling or direct read methods for inputs. Instead, the pin's associated callback is called as soon as a data change is detected, allowing immediate response to data changes and, generally, a more straightforward application design. **

"},{"location":"callbacks/#pin-types","title":"Pin Types","text":"Pin Mode Pin Mode Value Digital Input (including pullup and pulldown) 2 Analog Input (ADC) 3 I2C 10 SONAR Distance 11 DHT 12"},{"location":"callbacks/#converting-the-raw-timestamp","title":"Converting The Raw Timestamp","text":"

To convert the raw timestamp field to a human-readable time, use time.localtime().

date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"examples/","title":"Downloading And Running The Examples","text":"

Once the client and server software have been installed, it would be an excellent time to try the examples.

Examples are provided for all four of the servers.

"},{"location":"examples/#example-naming-conventions","title":"Example Naming Conventions","text":"

The naming convention used for the examples prefixes each example with three letters. The first letter is for the board type:

  • m = Minima
  • w = Wifi

The second letter is for the transport type:

  • b = BLE
  • s = serial
  • w = WIFI

The third is for the concurrency type:

  • a = asyncio
  • t = threaded
"},{"location":"examples/#links-to-the-examples","title":"Links To The Examples","text":"
  • r4_minima_examples - asyncio
  • r4_minima_examples - threaded
  • r4_wifi_examples_asyncio - BLE
  • r4_wifi_examples_asyncio - WIFI
  • r4_wifi_examples_asyncio - usbSerial
  • r4_wifi_examples_threaded - WIFI
  • r4_wifi_examples_threaded - usbSerial

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"install_telemetrix/","title":"Installing The Client APIs","text":""},{"location":"install_telemetrix/#installing-for-the-first-time","title":"Installing For The First Time","text":"

To install from PyPI, within your virtual environment type:

pip install telemetrix-uno-r4\n
"},{"location":"install_telemetrix/#upgrading-to-a-newer-version","title":"Upgrading To A Newer Version","text":"

To upgrade to a newer version from an existing installation, use the following command:

pip install telemetrix-uno-r4 --upgrade\n\n
"},{"location":"install_telemetrix/#what-is-installed","title":"What Is Installed?","text":"

The telemetrix-uno-r4 package contains four client APIs. You have the choice of using an API employing a threaded concurrency model or an API using an asyncio concurrency model. The asyncio API names end with _aio.

NOTE: BLE is only supported by telemetrix_uno_r4_wifi_aio.

"},{"location":"install_telemetrix/#arduino-uno-r4-mimima-clients","title":"Arduino UNO R4 Mimima Clients","text":"
  • telemetrix_uno_r4_minima

  • telemetrix_uno_r4_minima_aio

"},{"location":"install_telemetrix/#arduino-uno-r4-wifi-clients","title":"Arduino UNO R4 WIFI Clients","text":"
  • telemetrix_uno_r4_wifi

  • telemetrix_uno_r4_wifi_aio

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"issues/","title":"Known Issues","text":""},{"location":"issues/#arduino-compiler-warnings","title":"Arduino Compiler Warnings","text":"

Telemetrix4UnoR4 uses the NewPing library for HC-SR04 Sonar distance sensor support. You may see the following warning when compiling any of the servers. This warning may be safely ignored.

An issue was created but has not yet been addressed.

WARNING: library NewPing claims to run on avr, megaavr, esp32 architecture(s)\nand may be incompatible with your current board which runs on \nrenesas architecture(s).\n\n
"},{"location":"issues/#ble","title":"BLE","text":""},{"location":"issues/#server-side-issues","title":"Server Side Issues","text":"

BLE support for Arduino UNO R4 boards is in a Beta state. Currently, it does not support the Servo library. An issue has been generated against the ArduinoBLE library.

Instructions to install the Beta version of ArduinoBLE may be found here.

"},{"location":"issues/#client-side-issues","title":"Client Side Issues","text":"

BLE is only supported using the asyncio API. The threaded API does not support BLE.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"license/","title":"License","text":""},{"location":"license/#gnu-affero-general-public-license","title":"GNU AFFERO GENERAL PUBLIC LICENSE","text":"

Version 3, 19 November 2007

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

"},{"location":"license/#preamble","title":"Preamble","text":"

The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.

The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.

Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.

A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.

The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.

An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.

The precise terms and conditions for copying, distribution and modification follow.

"},{"location":"license/#terms-and-conditions","title":"TERMS AND CONDITIONS","text":""},{"location":"license/#0-definitions","title":"0. Definitions.","text":"

\"This License\" refers to version 3 of the GNU Affero General Public License.

\"Copyright\" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.

\"The Program\" refers to any copyrightable work licensed under this License. Each licensee is addressed as \"you\". \"Licensees\" and \"recipients\" may be individuals or organizations.

To \"modify\" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a \"modified version\" of the earlier work or a work \"based on\" the earlier work.

A \"covered work\" means either the unmodified Program or a work based on the Program.

To \"propagate\" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.

To \"convey\" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.

An interactive user interface displays \"Appropriate Legal Notices\" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.

"},{"location":"license/#1-source-code","title":"1. Source Code.","text":"

The \"source code\" for a work means the preferred form of the work for making modifications to it. \"Object code\" means any non-source form of a work.

A \"Standard Interface\" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.

The \"System Libraries\" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A \"Major Component\", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.

The \"Corresponding Source\" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.

The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.

The Corresponding Source for a work in source code form is that same work.

"},{"location":"license/#2-basic-permissions","title":"2. Basic Permissions.","text":"

All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.

You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.

Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.

"},{"location":"license/#3-protecting-users-legal-rights-from-anti-circumvention-law","title":"3. Protecting Users' Legal Rights From Anti-Circumvention Law.","text":"

No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.

When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.

"},{"location":"license/#4-conveying-verbatim-copies","title":"4. Conveying Verbatim Copies.","text":"

You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.

You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.

"},{"location":"license/#5-conveying-modified-source-versions","title":"5. Conveying Modified Source Versions.","text":"

You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:

  • a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
  • b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to \"keep intact all notices\".
  • c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
  • d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.

A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an \"aggregate\" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.

"},{"location":"license/#6-conveying-non-source-forms","title":"6. Conveying Non-Source Forms.","text":"

You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:

  • a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
  • b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
  • c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
  • d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
  • e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.

A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.

A \"User Product\" is either (1) a \"consumer product\", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, \"normally used\" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.

\"Installation Information\" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.

If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).

The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.

Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.

"},{"location":"license/#7-additional-terms","title":"7. Additional Terms.","text":"

\"Additional permissions\" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.

When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.

Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:

  • a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
  • b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
  • c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
  • d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
  • e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
  • f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.

All other non-permissive additional terms are considered \"further restrictions\" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.

If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.

Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.

"},{"location":"license/#8-termination","title":"8. Termination.","text":"

You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).

However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.

Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.

"},{"location":"license/#9-acceptance-not-required-for-having-copies","title":"9. Acceptance Not Required for Having Copies.","text":"

You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.

"},{"location":"license/#10-automatic-licensing-of-downstream-recipients","title":"10. Automatic Licensing of Downstream Recipients.","text":"

Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.

An \"entity transaction\" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.

You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.

"},{"location":"license/#11-patents","title":"11. Patents.","text":"

A \"contributor\" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's \"contributor version\".

A contributor's \"essential patent claims\" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, \"control\" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.

Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.

In the following three paragraphs, a \"patent license\" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To \"grant\" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.

If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. \"Knowingly relying\" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.

If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.

A patent license is \"discriminatory\" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.

Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.

"},{"location":"license/#12-no-surrender-of-others-freedom","title":"12. No Surrender of Others' Freedom.","text":"

If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.

"},{"location":"license/#13-remote-network-interaction-use-with-the-gnu-general-public-license","title":"13. Remote Network Interaction; Use with the GNU General Public License.","text":"

Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.

Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.

"},{"location":"license/#14-revised-versions-of-this-license","title":"14. Revised Versions of this License.","text":"

The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License \"or any later version\" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.

If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.

Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.

"},{"location":"license/#15-disclaimer-of-warranty","title":"15. Disclaimer of Warranty.","text":"

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

"},{"location":"license/#16-limitation-of-liability","title":"16. Limitation of Liability.","text":"

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

"},{"location":"license/#17-interpretation-of-sections-15-and-16","title":"17. Interpretation of Sections 15 and 16.","text":"

If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.

END OF TERMS AND CONDITIONS

"},{"location":"license/#how-to-apply-these-terms-to-your-new-programs","title":"How to Apply These Terms to Your New Programs","text":"

If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the \"copyright\" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU Affero General Public License as\n    published by the Free Software Foundation, either version 3 of the\n    License, or (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU Affero General Public License for more details.\n\n    You should have received a copy of the GNU Affero General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n

Also add information on how to contact you by electronic and paper mail.

If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a \"Source\" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.

You should also get your employer (if you work as a programmer) or school, if any, to sign a \"copyright disclaimer\" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see https://www.gnu.org/licenses/.

"},{"location":"python_3_verify/","title":"Verifying The Python Version","text":"

Python 3.8 or greater is required before installing and using the telemetrix-uno-r4 package.

To check that you have the correct version of Python 3 installed, open a command window and type:

python3 -V\n

For Windows, you may need to type:

python -V\n

Executing this command displays the current version of Python 3 installed.

Python 3.11.4\n

If you need to install Python 3, refer to python.org.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"server_config/","title":"Server Configuration","text":""},{"location":"server_config/#arduino-uno-r4-minima","title":"Arduino UNO R4 Minima","text":"

The Minima requires no configuration.

"},{"location":"server_config/#arduino-uno-r4-wifi","title":"Arduino UNO R4 WIFI","text":""},{"location":"server_config/#telemetrix4unor4ble","title":"Telemetrix4UnoR4BLE","text":""},{"location":"server_config/#starting-banner-enable","title":"Starting Banner Enable","text":"

By default, when you power up the Arduino, the sketch is identified by the message \"Telemetrix BLE\" scrolling across the display. This message will be extinguished once a client application connects.

You may disable the power on scrolling by commenting out the line that says

#define ENABLE_STARTING_BANNER 1\n

The client API method, enable_scroll_message, which allows you to create and scroll your own message across the display, still functions even if you disable the starting banner.

"},{"location":"server_config/#ble-name","title":"BLE Name","text":"

The ble_name string is the name the BLE client will search for to connect. You may change the default value, but if you do, you must also set the ble_device_name parameter in the __init__ method when you instantiate telemetrix_uno_r4_wifi_aio.

"},{"location":"server_config/#telemetrix4unor4serialusb","title":"Telemetrix4UnoR4SerialUSB","text":""},{"location":"server_config/#starting-banner-enable_1","title":"Starting Banner Enable","text":"

By default, when you power up the Arduino, the sketch is identified by the message \"USBSerial\" scrolling across the display. This message will be extinguished once a client application connects.

You may disable the power on scrolling by commenting out the line that says

#define ENABLE_STARTING_BANNER 1\n

The client API method, enable_scroll_message, allows you to create and scroll your own message across the display, and it still functions even if you disable the starting banner.

"},{"location":"server_config/#telemetrix4unor4wifi","title":"Telemetrix4UnoR4Wifi","text":""},{"location":"server_config/#required-configuration","title":"Required Configuration","text":""},{"location":"server_config/#ssid","title":"SSID","text":"

Edit the sketch and place your router's SSID between the quotes.

"},{"location":"server_config/#password","title":"PASSWORD","text":"

Edit the sketch and place your router's PASSWORD between the quotes.

"},{"location":"server_config/#starting-banner-enable_2","title":"Starting Banner Enable","text":"

If the starting banner is enabled, and you forget to set SSID and PASSWORD in the sketch, a series of question marks will scroll across the screen.

Once you have a valid SSID and PASSWORD configured, the IP address assigned by the router will be displayed.

You may disable the power on scrolling by commenting out the line that says

#define ENABLE_STARTING_BANNER 1\n

The client API method, enable_scroll_message, allows you to create and scroll your own message across the display, and it still functions even if you disable the starting banner.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"server_library_installation/","title":"Install the Telemetrix4Uno Library Into The Arduino IDE","text":""},{"location":"server_library_installation/#add-the-arduino4unor4-library-to-the-ide","title":"Add The Arduino4UnoR4 Library To The IDE","text":"
  1. Open the Arduino IDE and click on the library icon.

  2. In the search box, type Telemetrix4UnoR4, and when the library is found, click INSTALL.

  3. You will be prompted to install all of the dependencies. Select INSTALL ALL.

"},{"location":"server_library_installation/#additional-steps-if-you-wish-to-use-the-ble-server","title":"Additional Steps If You Wish To Use The BLE Server","text":"

Follow the instructions on this link to make sure that you have the correct version of the radio firmware installed and to install the Beta version of the ArduinoBLE library.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"server_selection/","title":"Select A Server From the Arduino IDE Examples Menu","text":""},{"location":"server_selection/#choose-a-server","title":"Choose A Server","text":"

Select File from the Arduino IDE main menu and then select Examples.

Next, select TelemetrixUnoR4 from the example selections.

There are four servers to choose from:

  • Arduino UNO R4 Minima

    • Minima - utilizing a serial transport via the USB port.
  • Arduino UNO R4 WIFI

    • Telemetrix4UnoR4BLE - utilizing a BLE transport.
    • Telemetrix4UnoR4SerialUSB - utilizing serial transport via the USB port.
    • Telemetrix4UnoR4WIFI - utilizing a WIFI transport.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"telemetrix_minima_reference/","title":"telemetrix_uno_r4_minima","text":"

Copyright (c) 2023 Alan Yorinks All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima","title":"TelemetrixUnoR4Minima","text":"

Bases: threading.Thread

This class exposes and implements the telemetrix API. It uses threading to accommodate concurrency. It includes the public API methods as well as a set of private methods.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
class TelemetrixUnoR4Minima(threading.Thread):\n\"\"\"\n    This class exposes and implements the telemetrix API.\n    It uses threading to accommodate concurrency.\n    It includes the public API methods as well as\n    a set of private methods.\n\n    \"\"\"\n\n    # noinspection PyPep8,PyPep8,PyPep8\n    def __init__(self, com_port=None, arduino_instance_id=1,\n                 arduino_wait=1, sleep_tune=0.000001,\n                 shutdown_on_exception=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n\n        :param com_port: e.g. COM3 or /dev/ttyACM0.\n                         Only use if you wish to bypass auto com port\n                         detection.\n\n        :param arduino_instance_id: Match with the value installed on the\n                                    arduino-telemetrix sketch.\n\n        :param arduino_wait: Amount of time to wait for an Arduino to\n                             fully reset itself.\n\n        :param sleep_tune: A tuning parameter (typically not changed by user)\n\n        :param shutdown_on_exception: call shutdown before raising\n                                      a RunTimeError exception, or\n                                      receiving a KeyboardInterrupt exception\n\n        :param hard_reset_on_shutdown: reset the board on shutdown\n\n        \"\"\"\n\n        # initialize threading parent\n        threading.Thread.__init__(self)\n\n        # create the threads and set them as daemons so\n        # that they stop when the program is closed\n\n        # create a thread to interpret received serial data\n        self.the_reporter_thread = threading.Thread(target=self._reporter)\n        self.the_reporter_thread.daemon = True\n\n        self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n\n        self.the_data_receive_thread.daemon = True\n\n        # flag to allow the reporter and receive threads to run.\n        self.run_event = threading.Event()\n\n        # check to make sure that Python interpreter is version 3.7 or greater\n        python_version = sys.version_info\n        if python_version[0] >= 3:\n            if python_version[1] >= 7:\n                pass\n            else:\n                raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                                   \"required for use of this program.\")\n\n        # save input parameters as instance variables\n        self.com_port = com_port\n        self.arduino_instance_id = arduino_instance_id\n        self.arduino_wait = arduino_wait\n        self.sleep_tune = sleep_tune\n        self.shutdown_on_exception = shutdown_on_exception\n        self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n        # create a deque to receive and process data from the arduino\n        self.the_deque = deque()\n\n        # The report_dispatch dictionary is used to process\n        # incoming report messages by looking up the report message\n        # and executing its associated processing method.\n\n        self.report_dispatch = {}\n\n        # To add a command to the command dispatch table, append here.\n        self.report_dispatch.update(\n            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n        self.report_dispatch.update(\n            {PrivateConstants.ANALOG_REPORT: self._analog_message})\n        self.report_dispatch.update(\n            {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n        self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n        self.report_dispatch.update(\n            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n        self.report_dispatch.update(\n            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n        self.report_dispatch.update(\n            {PrivateConstants.SPI_REPORT: self._spi_report})\n        self.report_dispatch.update(\n            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_CURRENT_POSITION:\n                 self._stepper_current_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUNNING_REPORT:\n                 self._stepper_is_running_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n                 self._stepper_run_complete_report})\n\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.FEATURES:\n                 self._features_report})\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        self.cs_pins_enabled = []\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        self.dht_count = 0\n\n        # serial port in use\n        self.serial_port = None\n\n        # flag to indicate we are in shutdown mode\n        self.shutdown_flag = False\n\n        # debug loopback callback method\n        self.loop_back_callback = None\n\n        # flag to indicate the start of a new report\n        # self.new_report_start = True\n\n        # firmware version to be stored here\n        self.firmware_version = []\n\n        # reported arduino instance id\n        self.reported_arduino_id = []\n\n        # reported features\n        self.reported_features = 0\n\n        # flag to indicate if i2c was previously enabled\n        self.i2c_enabled = False\n\n        # flag to indicate if spi is initialized\n        self.spi_enabled = False\n\n        # flag to indicate if onewire is initialized\n        self.onewire_enabled = False\n\n        # # stepper motor variables\n        #\n        # # updated when a new motor is added\n        # self.next_stepper_assigned = 0\n        #\n        # # valid list of stepper motor interface types\n        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n        #\n        # # maximum number of steppers supported\n        # self.max_number_of_steppers = 4\n        #\n        # # number of steppers created - not to exceed the maximum\n        # self.number_of_steppers = 0\n        #\n        # # dictionary to hold stepper motor information\n        # self.stepper_info = {'instance': False, 'is_running': None,\n        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n        #                      'distance_to_go_callback': None,\n        #                      'target_position_callback': None,\n        #                      'current_position_callback': None,\n        #                      'is_running_callback': None,\n        #                      'motion_complete_callback': None,\n        #                      'acceleration_callback': None}\n        #\n        # # build a list of stepper motor info items\n        # self.stepper_info_list = []\n        # # a list of dictionaries to hold stepper information\n        # for motor in range(self.max_number_of_steppers):\n        #     self.stepper_info_list.append(self.stepper_info)\n\n        self.the_reporter_thread.start()\n        self.the_data_receive_thread.start()\n\n        print(f\"telemetrix_uno_r4_minima:  Version\"\n              f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n              f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n        # using the serial link\n        if not self.com_port:\n            # user did not specify a com_port\n            try:\n                self._find_arduino()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n        else:\n            # com_port specified - set com_port and baud rate\n            try:\n                self._manual_open()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n\n        if self.serial_port:\n            print(\n                f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n            self.serial_port.reset_input_buffer()\n            self.serial_port.reset_output_buffer()\n\n        # no com_port found - raise a runtime exception\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('No Arduino Found or User Aborted Program')\n\n        # allow the threads to run\n        self._run_threads()\n        print(f'Reset Complete')\n\n        # get telemetrix firmware version and print it\n        print('\\nRetrieving Telemetrix4UnoR4Minima firmware ID...')\n        self._get_firmware_version()\n        if not self.firmware_version:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')\n\n        else:\n\n            print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'\n                  f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n        command = [PrivateConstants.ENABLE_ALL_REPORTS]\n        self._send_command(command)\n\n        # get the features list\n        command = [PrivateConstants.GET_FEATURES]\n        self._send_command(command)\n        time.sleep(.2)\n\n        # Have the server reset its data structures\n        command = [PrivateConstants.RESET]\n        self._send_command(command)\n\n    def _find_arduino(self):\n\"\"\"\n        This method will search all potential serial ports for an Arduino\n        containing a sketch that has a matching arduino_instance_id as\n        specified in the input parameters of this class.\n\n        This is used explicitly with the Telemetrix4Arduino sketch.\n        \"\"\"\n\n        # a list of serial ports to be checked\n        serial_ports = []\n\n        print('Opening all potential serial ports...')\n        the_ports_list = list_ports.comports()\n        for port in the_ports_list:\n            if port.pid is None:\n                continue\n            try:\n                self.serial_port = serial.Serial(port.device, 115200,\n                                                 timeout=1, writeTimeout=0)\n            except SerialException:\n                continue\n            # create a list of serial ports that we opened\n            serial_ports.append(self.serial_port)\n\n            # display to the user\n            print('\\t' + port.device)\n\n            # clear out any possible data in the input buffer\n        # wait for arduino to reset\n        print(\n            f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n            'reset...')\n        # temporary for testing\n        time.sleep(self.arduino_wait)\n        self._run_threads()\n\n        for serial_port in serial_ports:\n            self.serial_port = serial_port\n\n            self._get_arduino_id()\n            if self.reported_arduino_id != self.arduino_instance_id:\n                continue\n            else:\n                print('Valid Arduino ID Found.')\n                self.serial_port.reset_input_buffer()\n                self.serial_port.reset_output_buffer()\n                return\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n\n    def _manual_open(self):\n\"\"\"\n        Com port was specified by the user - try to open up that port\n\n        \"\"\"\n        # if port is not found, a serial exception will be thrown\n        try:\n            print(f'Opening {self.com_port}...')\n            self.serial_port = serial.Serial(self.com_port, 115200,\n                                             timeout=1, writeTimeout=0)\n\n            print(\n                f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n                'reset...')\n            self._run_threads()\n            time.sleep(self.arduino_wait)\n\n            self._get_arduino_id()\n\n            if self.reported_arduino_id != self.arduino_instance_id:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n            print('Valid Arduino ID Found.')\n            # get arduino firmware version and print it\n            print('\\nRetrieving Telemetrix4Arduino firmware ID...')\n            self._get_firmware_version()\n\n            if not self.firmware_version:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Telemetrix4Arduino Sketch Firmware Version Not Found')\n\n            else:\n                print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'\n                      f'{self.firmware_version[1]}')\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('User Hit Control-C')\n\n    def analog_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (maximum 16 bits)\n\n        \"\"\"\n        value_msb = value >> 8\n        value_lsb = value & 0xff\n        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n        self._send_command(command)\n\n    def digital_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (1 or 0)\n\n        \"\"\"\n\n        command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n        self._send_command(command)\n\n    def disable_all_reporting(self):\n\"\"\"\n        Disable reporting for all digital and analog input pins\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DISABLE_ALL, 0]\n        self._send_command(command)\n\n    def disable_analog_reporting(self, pin):\n\"\"\"\n        Disables analog reporting for a single analog pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n        self._send_command(command)\n\n    def disable_digital_reporting(self, pin):\n\"\"\"\n        Disables digital reporting for a single digital input.\n\n        :param pin: Pin number.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n        self._send_command(command)\n\n    def enable_analog_reporting(self, pin):\n\"\"\"\n        Enables analog reporting for the specified pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n        self._send_command(command)\n\n    def enable_digital_reporting(self, pin):\n\"\"\"\n        Enable reporting on the specified digital pin.\n\n        :param pin: Pin number.\n        \"\"\"\n\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n        self._send_command(command)\n\n    def _get_arduino_id(self):\n\"\"\"\n        Retrieve arduino-telemetrix arduino id\n\n        \"\"\"\n        command = [PrivateConstants.ARE_U_THERE]\n        self._send_command(command)\n        # provide time for the reply\n        time.sleep(.5)\n\n    def _get_firmware_version(self):\n\"\"\"\n        This method retrieves the\n        arduino-telemetrix firmware version\n\n        \"\"\"\n        command = [PrivateConstants.GET_FIRMWARE_VERSION]\n        self._send_command(command)\n        # provide time for the reply\n        time.sleep(.5)\n\n    def i2c_read(self, address, register, number_of_bytes,\n                 callback=None, i2c_port=0,\n                 write_register=True):\n\"\"\"\n        Read the specified number of bytes from the\n        specified register for the i2c device.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                       selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report\n                         i2c data as a result of read command\n\n       :param i2c_port: 0 = default, 1 = secondary\n\n       :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n\n        self._i2c_read_request(address, register, number_of_bytes,\n                               callback=callback, i2c_port=i2c_port,\n                               write_register=write_register)\n\n    def i2c_read_restart_transmission(self, address, register,\n                                      number_of_bytes,\n                                      callback=None, i2c_port=0,\n                                      write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified\n        register for the i2c device. This restarts the transmission\n        after the read. It is required for some i2c devices such as the MMA8452Q\n        accelerometer.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                                    selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c\n                         data as a result of read command\n\n       :param i2c_port: 0 = default 1 = secondary\n\n       :param write_register: If True, the register is written before read\n                              Else, the write is suppressed\n\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n\n        self._i2c_read_request(address, register, number_of_bytes,\n                               stop_transmission=False,\n                               callback=callback, i2c_port=i2c_port,\n                               write_register=write_register)\n\n    def _i2c_read_request(self, address, register, number_of_bytes,\n                          stop_transmission=True, callback=None, i2c_port=0,\n                          write_register=True):\n\"\"\"\n        This method requests the read of an i2c device. Results are retrieved\n        via callback.\n\n        :param address: i2c device address\n\n        :param register: register number (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes expected to be returned\n\n        :param stop_transmission: stop transmission after read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command.\n\n       :param write_register: If True, the register is written before read\n                              Else, the write is suppressed\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('I2C Read: A callback function must be specified.')\n\n        if not i2c_port:\n            self.i2c_callback = callback\n        else:\n            self.i2c_callback2 = callback\n\n        if not register:\n            register = 0\n\n        if write_register:\n            write_register = 1\n        else:\n            write_register = 0\n\n        # message contains:\n        # 1. address\n        # 2. register\n        # 3. number of bytes\n        # 4. restart_transmission - True or False\n        # 5. i2c port\n        # 6. suppress write flag\n\n        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n                   stop_transmission, i2c_port, write_register]\n        self._send_command(command)\n\n    def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n        Write data to an i2c device.\n\n        :param address: i2c device address\n\n        :param i2c_port: 0= port 1, 1 = port 2\n\n        :param args: A variable number of bytes to be sent to the device\n                     passed in as a list\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n        for item in args:\n            command.append(item)\n\n        self._send_command(command)\n\n    def loop_back(self, start_character, callback=None):\n\"\"\"\n        This is a debugging method to send a character to the\n        Arduino device, and have the device loop it back.\n\n        :param start_character: The character to loop back. It should be\n                                an integer.\n\n        :param callback: Looped back character will appear in the callback method\n\n        \"\"\"\n        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n        self.loop_back_callback = callback\n        self._send_command(command)\n\n    def set_analog_scan_interval(self, interval):\n\"\"\"\n        Set the analog scanning interval.\n\n        :param interval: value of 0 - 255 - milliseconds\n        \"\"\"\n\n        if 0 <= interval <= 255:\n            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Analog interval must be between 0 and 255')\n\n    def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n        Set a pin as a pwm (analog output) pin.\n\n        :param pin_number:arduino pin number\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n    def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n        Set a pin as an analog input.\n\n        :param pin_number: arduino pin number\n\n        :param differential: difference in previous to current value before\n                             report will be generated\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for analog input pins = 3\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n                           callback)\n\n    def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n        Set a pin as a digital input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n\n    def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n        Set a pin as a digital input with pullup enabled.\n\n        :param pin_number: arduino pin number\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                           callback=callback)\n\n    def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n        Set a pin as a digital output pin.\n\n        :param pin_number: arduino pin number\n        \"\"\"\n\n        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n    def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n        Establish the standard Arduino i2c pins for i2c utilization.\n\n        :param i2c_port: 0 = i2c1, 1 = i2c2\n\n        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n               2. Callbacks are set within the individual i2c read methods of this\n              API.\n\n              See i2c_read, or i2c_read_restart_transmission.\n\n        \"\"\"\n        # test for i2c port 2\n        if i2c_port:\n            # if not previously activated set it to activated\n            # and the send a begin message for this port\n            if not self.i2c_2_active:\n                self.i2c_2_active = True\n            else:\n                return\n        # port 1\n        else:\n            if not self.i2c_1_active:\n                self.i2c_1_active = True\n            else:\n                return\n\n        command = [PrivateConstants.I2C_BEGIN, i2c_port]\n        self._send_command(command)\n\n    def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n        :param pin: connection pin\n\n        :param callback: callback function\n\n        :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n        Temperature,\n        Time]\n\n        DHT_REPORT_TYPE = 12\n        \"\"\"\n        if self.reported_features & PrivateConstants.DHT_FEATURE:\n            if not callback:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n            if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n                self.dht_callbacks[pin] = callback\n                self.dht_count += 1\n\n                if dht_type != 22 and dht_type != 11:\n                    dht_type = 22\n\n                command = [PrivateConstants.DHT_NEW, pin, dht_type]\n                self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n    # noinspection PyRedundantParentheses\n    def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n        Attach a pin to a servo motor\n\n        :param pin_number: pin\n\n        :param min_pulse: minimum pulse width\n\n        :param max_pulse: maximum pulse width\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n            minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n            maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n            command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                       minv[0], minv[1], maxv[0], maxv[1]]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n    def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                           callback=None):\n\"\"\"\n\n        :param trigger_pin:\n\n        :param echo_pin:\n\n        :param callback: callback\n\n        callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n                self.sonar_callbacks[trigger_pin] = callback\n                self.sonar_count += 1\n\n                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n                self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n    def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n        Specify the list of chip select pins.\n\n        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n        Chip Select is any digital output capable pin.\n\n        :param chip_select_list: this is a list of pins to be used for chip select.\n                           The pins will be configured as output, and set to high\n                           ready to be used for chip select.\n                           NOTE: You must specify the chips select pins here!\n\n\n        command message: [command, [cs pins...]]\n        \"\"\"\n\n        if self.reported_features & PrivateConstants.SPI_FEATURE:\n            if type(chip_select_list) != list:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('chip_select_list must be in the form of a list')\n            if not chip_select_list:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('Chip select pins were not specified')\n\n            self.spi_enabled = True\n\n            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n            for pin in chip_select_list:\n                command.append(pin)\n                self.cs_pins_enabled.append(pin)\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n    # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n    #                          pin4=5, enable=True):\n    #     \"\"\"\n    #     Stepper motor support is implemented as a proxy for the\n    #     the AccelStepper library for the Arduino.\n    #\n    #     This feature is compatible with the TB6600 Motor Driver\n    #\n    #     Note: It may not work for other driver types!\n    #\n    #     https://github.com/waspinator/AccelStepper\n    #\n    #     Instantiate a stepper motor.\n    #\n    #     Initialize the interface and pins for a stepper motor.\n    #\n    #     :param interface: Motor Interface Type:\n    #\n    #             1 = Stepper Driver, 2 driver pins required\n    #\n    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required\n    #\n    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n    #                 required\n    #\n    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n    #\n    #     :param pin1: Arduino digital pin number for motor pin 1\n    #\n    #     :param pin2: Arduino digital pin number for motor pin 2\n    #\n    #     :param pin3: Arduino digital pin number for motor pin 3\n    #\n    #     :param pin4: Arduino digital pin number for motor pin 4\n    #\n    #     :param enable: If this is true, the output pins at construction time.\n    #\n    #     :return: Motor Reference number\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n    #\n    #         if self.number_of_steppers == self.max_number_of_steppers:\n    #             if self.shutdown_on_exception:\n    #                 self.shutdown()\n    #             raise RuntimeError('Maximum number of steppers has already been assigned')\n    #\n    #         if interface not in self.valid_stepper_interfaces:\n    #             if self.shutdown_on_exception:\n    #                 self.shutdown()\n    #             raise RuntimeError('Invalid stepper interface')\n    #\n    #         self.number_of_steppers += 1\n    #\n    #         motor_id = self.next_stepper_assigned\n    #         self.next_stepper_assigned += 1\n    #         self.stepper_info_list[motor_id]['instance'] = True\n    #\n    #         # build message and send message to server\n    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n    #                    pin2, pin3, pin4, enable]\n    #         self._send_command(command)\n    #\n    #         # return motor id\n    #         return motor_id\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n    def servo_write(self, pin_number, angle):\n\"\"\"\n\n        Set a servo attached to a pin to a given angle.\n\n        :param pin_number: pin\n\n        :param angle: angle (0-180)\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n        self._send_command(command)\n\n    def servo_detach(self, pin_number):\n\"\"\"\n        Detach a servo for reuse\n\n        :param pin_number: attached pin\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_DETACH, pin_number]\n        self._send_command(command)\n\n    # def stepper_move_to(self, motor_id, position):\n    #     \"\"\"\n    #     Set an absolution target position. If position is positive, the movement is\n    #     clockwise, else it is counter-clockwise.\n    #\n    #     The run() function (below) will try to move the motor (at most one step per call)\n    #     from the current position to the target position set by the most\n    #     recent call to this function. Caution: moveTo() also recalculates the\n    #     speed for the next step.\n    #     If you are trying to use constant speed movements, you should call setSpeed()\n    #     after calling moveTo().\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param position: target position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(position)\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     self._send_command(command)\n    #\n    # def stepper_move(self, motor_id, relative_position):\n    #     \"\"\"\n    #     Set the target position relative to the current position.\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param relative_position: The desired position relative to the current\n    #                               position. Negative is anticlockwise from\n    #                               the current position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if relative_position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #\n    #     relative_position = abs(relative_position)\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_move: Invalid motor_id.')\n    #\n    #     position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     self._send_command(command)\n    #\n    # def stepper_run(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     This method steps the selected motor based on the current speed.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run: A motion complete callback must be '\n    #                            'specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_run_speed(self, motor_id):\n    #     \"\"\"\n    #     This method steps the selected motor based at a constant speed as set by the most\n    #     recent call to stepper_set_max_speed(). The motor will run continuously.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_max_speed(self, motor_id, max_speed):\n    #     \"\"\"\n    #     Sets the maximum permitted speed. The stepper_run() function will accelerate\n    #     up to the speed set by this function.\n    #\n    #     Caution: the maximum speed achievable depends on your processor and clock speed.\n    #     The default maxSpeed is 1 step per second.\n    #\n    #      Caution: Speeds that exceed the maximum speed supported by the processor may\n    #               result in non-linear accelerations and decelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param max_speed: 1 - 1000\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n    #\n    #     if not 1 < max_speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n    #\n    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed\n    #     max_speed_msb = (max_speed & 0xff00) >> 8\n    #     max_speed_lsb = max_speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n    #                max_speed_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_get_max_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the maximum speed configured for this stepper\n    #     that was previously set by stepper_set_max_speed()\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :return: The currently configured maximum speed.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['max_speed']\n    #\n    # def stepper_set_acceleration(self, motor_id, acceleration):\n    #     \"\"\"\n    #     Sets the acceleration/deceleration rate.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param acceleration: The desired acceleration in steps per second\n    #                          per second. Must be > 0.0. This is an\n    #                          expensive call since it requires a square\n    #                          root to be calculated on the server.\n    #                          Dont call more often than needed.\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n    #\n    #     if not 1 < acceleration <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration\n    #\n    #     max_accel_msb = acceleration >> 8\n    #     max_accel_lsb = acceleration & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n    #                max_accel_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_set_speed(self, motor_id, speed):\n    #     \"\"\"\n    #     Sets the desired constant speed for use with stepper_run_speed().\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param speed: 0 - 1000 The desired constant speed in steps per\n    #                   second. Positive is clockwise. Speeds of more than 1000 steps per\n    #                   second are unreliable. Speed accuracy depends on the Arduino\n    #                   crystal. Jitter depends on how frequently you call the\n    #                   stepper_run_speed() method.\n    #                   The speed will be limited by the current value of\n    #                   stepper_set_max_speed().\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n    #\n    #     if not 0 < speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['speed'] = speed\n    #\n    #     speed_msb = speed >> 8\n    #     speed_lsb = speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_get_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the  most recently set speed.\n    #     that was previously set by stepper_set_speed();\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['speed']\n    #\n    # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n    #     \"\"\"\n    #     Request the distance from the current position to the target position\n    #     from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param distance_to_go_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n    #\n    #     A positive distance is clockwise from the current position.\n    #\n    #     \"\"\"\n    #     if not distance_to_go_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n    #     self.stepper_info_list[motor_id][\n    #         'distance_to_go_callback'] = distance_to_go_callback\n    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_get_target_position(self, motor_id, target_callback):\n    #     \"\"\"\n    #     Request the most recently set target position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param target_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #\n    #     \"\"\"\n    #     if not target_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_target_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id][\n    #         'target_position_callback'] = target_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_get_current_position(self, motor_id, current_position_callback):\n    #     \"\"\"\n    #     Request the current motor position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param current_position_callback: required callback function to receive report\n    #\n    #     :return: The current motor position returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #     \"\"\"\n    #     if not current_position_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_current_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_current_position(self, motor_id, position):\n    #     \"\"\"\n    #     Resets the current position of the motor, so that wherever the motor\n    #     happens to be right now is considered to be the new 0 position. Useful\n    #     for setting a zero position on a stepper after an initial hardware\n    #     positioning move.\n    #\n    #     Has the side effect of setting the current motor speed to 0.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     :param position: Position in steps. This is a 32 bit value\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     self._send_command(command)\n    #\n    # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     Runs the motor at the currently selected speed until the target position is\n    #     reached.\n    #\n    #     Does not implement accelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n    #                            'callback must be '\n    #                            'specified.')\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_stop(self, motor_id):\n    #     \"\"\"\n    #     Sets a new target position that causes the stepper\n    #     to stop as quickly as possible, using the current speed and\n    #     acceleration parameters.\n    #\n    #     :param motor_id:  0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_stop: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_STOP, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_disable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Disable motor pin outputs by setting them all LOW.\n    #\n    #     Depending on the design of your electronics this may turn off\n    #     the power to the motor coils, saving power.\n    #\n    #     This is useful to support Arduino low power modes: disable the outputs\n    #     during sleep and then re-enable with enableOutputs() before stepping\n    #     again.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and clears\n    #     the pin to disabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_enable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Enable motor pin outputs by setting the motor pins to OUTPUT\n    #     mode.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and sets\n    #     the pin to enabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n    #     \"\"\"\n    #     Sets the minimum pulse width allowed by the stepper driver.\n    #\n    #     The minimum practical pulse width is approximately 20 microseconds.\n    #\n    #     Times less than 20 microseconds will usually result in 20 microseconds or so.\n    #\n    #     :param motor_id: 0 -3\n    #\n    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n    #\n    #     if not 0 < minimum_width <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n    #                            '0-0xffff.')\n    #\n    #     width_msb = minimum_width >> 8\n    #     width_lsb = minimum_width & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n    #                width_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_set_enable_pin(self, motor_id, pin=0xff):\n    #     \"\"\"\n    #     Sets the enable pin number for stepper drivers.\n    #     0xFF indicates unused (default).\n    #\n    #     Otherwise, if a pin is set, the pin will be turned on when\n    #     enableOutputs() is called and switched off when disableOutputs()\n    #     is called.\n    #\n    #     :param motor_id: 0 - 4\n    #     :param pin: 0-0xff\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n    #\n    #     if not 0 < pin <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n    #                            '0-0xff.')\n    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n    #                                 enable=False):\n    #     \"\"\"\n    #     Sets the inversion for stepper driver pins.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param direction: True=inverted or False\n    #\n    #     :param step: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n    #                step, enable]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,\n    #                                 pin3_invert=False, pin4_invert=False, enable=False):\n    #     \"\"\"\n    #     Sets the inversion for 2, 3 and 4 wire stepper pins\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param pin1_invert: True=inverted or False\n    #\n    #     :param pin2_invert: True=inverted or False\n    #\n    #     :param pin3_invert: True=inverted or False\n    #\n    #     :param pin4_invert: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n    #                pin2_invert, pin3_invert, pin4_invert, enable]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_is_running(self, motor_id, callback):\n    #     \"\"\"\n    #     Checks to see if the motor is currently running to a target.\n    #\n    #     Callback return True if the speed is not zero or not at the target position.\n    #\n    #     :param motor_id: 0-4\n    #\n    #     :param callback: required callback function to receive report\n    #\n    #     :return: The current running state returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n    #     \"\"\"\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_is_running: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback\n    #\n    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n    #     self._send_command(command)\n\n    def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):\n\"\"\"\n        A private method to set the various pin modes.\n\n        :param pin_number: arduino pin number\n\n        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP\n                         For SERVO use: set_pin_mode_servo\n                         For DHT   use: set_pin_mode_dht\n\n        :param differential: for analog inputs - threshold\n                             value to be achieved for report to\n                             be generated\n\n        :param callback: A reference to a call back function to be\n                         called when pin data value changes\n\n        \"\"\"\n        if callback:\n            if pin_state == PrivateConstants.AT_INPUT:\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_ANALOG:\n                self.analog_callbacks[pin_number] = callback\n            else:\n                print('{} {}'.format('set_pin_mode: callback ignored for '\n                                     'pin state:', pin_state))\n\n        if pin_state == PrivateConstants.AT_INPUT:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_INPUT, 1]\n\n        elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_INPUT_PULLUP, 1]\n\n        elif pin_state == PrivateConstants.AT_OUTPUT:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_OUTPUT]\n\n        elif pin_state == PrivateConstants.AT_ANALOG:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_ANALOG,\n                       differential >> 8, differential & 0xff, 1]\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Unknown pin state')\n\n        if command:\n            self._send_command(command)\n\n    def shutdown(self):\n\"\"\"\n        This method attempts an orderly shutdown\n        If any exceptions are thrown, they are ignored.\n        \"\"\"\n        self.shutdown_flag = True\n\n        self._stop_threads()\n\n        try:\n            command = [PrivateConstants.STOP_ALL_REPORTS]\n            self._send_command(command)\n            time.sleep(.5)\n\n            if self.hard_reset_on_shutdown:\n                self.r4_hard_reset()\n            else:\n                try:\n                    self.serial_port.reset_input_buffer()\n                    self.serial_port.reset_output_buffer()\n\n                    self.serial_port.close()\n\n                except (RuntimeError, SerialException, OSError):\n                    # ignore error on shutdown\n                    pass\n        except Exception:\n            # raise RuntimeError('Shutdown failed - could not send stop streaming\n            # message')\n            pass\n\n    def sonar_disable(self):\n\"\"\"\n        Disable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_DISABLE]\n        self._send_command(command)\n\n    def sonar_enable(self):\n\"\"\"\n        Enable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_ENABLE]\n        self._send_command(command)\n\n    def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n        Control an SPI chip select line\n        :param chip_select_pin: pin connected to CS\n\n        :param select: 0=select, 1=deselect\n        \"\"\"\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n        if chip_select_pin not in self.cs_pins_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n        self._send_command(command)\n\n    def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n                          call_back=None):\n\"\"\"\n        Read the specified number of bytes from the specified SPI port and\n        call the callback function with the reported data.\n\n        :param chip_select: chip select pin\n\n        :param register_selection: Register to be selected for read.\n\n        :param number_of_bytes_to_read: Number of bytes to read\n\n        :param call_back: Required callback function to report spi data as a\n                   result of read command\n\n\n        callback returns a data list:\n        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n        data bytes, time-stamp]\n\n        SPI_READ_REPORT = 13\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n        if not call_back:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n        self.spi_callback = call_back\n\n        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n                   number_of_bytes_to_read,\n                   register_selection]\n\n        self._send_command(command)\n\n    def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n        Configure how the SPI serializes and de-serializes data on the wire.\n\n        See Arduino SPI reference materials for details.\n\n        :param clock_divisor: 1 - 255\n\n        :param bit_order:\n\n                            LSBFIRST = 0\n\n                            MSBFIRST = 1 (default)\n\n        :param data_mode:\n\n                            SPI_MODE0 = 0x00 (default)\n\n                            SPI_MODE1  = 1\n\n                            SPI_MODE2 = 2\n\n                            SPI_MODE3 = 3\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n        if not 0 < clock_divisor <= 255:\n            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n        if bit_order not in [0, 1]:\n            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n        if data_mode not in [0, 1, 2, 3]:\n            raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n                   data_mode]\n        self._send_command(command)\n\n    def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n        Write a list of bytes to the SPI device.\n\n        :param chip_select: chip select pin\n\n        :param bytes_to_write: A list of bytes to write. This must\n                                be in the form of a list.\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n        if type(bytes_to_write) is not list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n        for data in bytes_to_write:\n            command.append(data)\n\n        self._send_command(command)\n\n    # def set_pin_mode_one_wire(self, pin):\n    #     \"\"\"\n    #     Initialize the one wire serial bus.\n    #\n    #     :param pin: Data pin connected to the OneWire device\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:\n    #         self.onewire_enabled = True\n    #         command = [PrivateConstants.ONE_WIRE_INIT, pin]\n    #         self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'The OneWire feature is disabled in the server.')\n    #\n    # def onewire_reset(self, callback=None):\n    #     \"\"\"\n    #     Reset the onewire device\n    #\n    #     :param callback: required  function to report reset result\n    #\n    #     callback returns a list:\n    #     [ReportType = 14, Report Subtype = 25, reset result byte,\n    #                     timestamp]\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_reset: A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_RESET]\n    #     self._send_command(command)\n    #\n    # def onewire_select(self, device_address):\n    #     \"\"\"\n    #     Select a device based on its address\n    #     :param device_address: A bytearray of 8 bytes\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n    #\n    #     if type(device_address) is not list:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #\n    #     if len(device_address) != 8:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #     command = [PrivateConstants.ONE_WIRE_SELECT]\n    #     for data in device_address:\n    #         command.append(data)\n    #     self._send_command(command)\n    #\n    # def onewire_skip(self):\n    #     \"\"\"\n    #     Skip the device selection. This only works if you have a\n    #     single device, but you can avoid searching and use this to\n    #     immediately access your device.\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SKIP]\n    #     self._send_command(command)\n    #\n    # def onewire_write(self, data, power=0):\n    #     \"\"\"\n    #     Write a byte to the onewire device. If 'power' is one\n    #     then the wire is held high at the end for\n    #     parasitically powered devices. You\n    #     are responsible for eventually de-powering it by calling\n    #     another read or write.\n    #\n    #     :param data: byte to write.\n    #     :param power: power control (see above)\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n    #     if 0 < data < 255:\n    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n    #         self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_write: Data must be no larger than 255')\n    #\n    # def onewire_read(self, callback=None):\n    #     \"\"\"\n    #     Read a byte from the onewire device\n    #     :param callback: required  function to report onewire data as a\n    #                result of read command\n    #\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_READ]\n    #     self._send_command(command)\n    #\n    # def onewire_reset_search(self):\n    #     \"\"\"\n    #     Begin a new search. The next use of search will begin at the first device\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n    #                            f'enabled.')\n    #     else:\n    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n    #         self._send_command(command)\n    #\n    # def onewire_search(self, callback=None):\n    #     \"\"\"\n    #     Search for the next device. The device address will returned in the callback.\n    #     If a device is found, the 8 byte address is contained in the callback.\n    #     If no more devices are found, the address returned contains all elements set\n    #     to 0xff.\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SEARCH]\n    #     self._send_command(command)\n    #\n    # def onewire_crc8(self, address_list, callback=None):\n    #     \"\"\"\n    #     Compute a CRC check on an array of data.\n    #     :param address_list:\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_crc8 A Callback must be specified')\n    #\n    #     if type(address_list) is not list:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_crc8: address list must be a list.')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     address_length = len(address_list)\n    #\n    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n    #\n    #     for data in address_list:\n    #         command.append(data)\n    #\n    #     self._send_command(command)\n\n    def r4_hard_reset(self):\n\"\"\"\n        Place the r4 into hard reset\n        \"\"\"\n        command = [PrivateConstants.RESET, 1]\n        self._send_command(command)\n        time.sleep(.5)\n        command = [PrivateConstants.BOARD_HARD_RESET, 1]\n        self._send_command(command)\n'''\n    report message handlers\n    '''\n\n    def _analog_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for analog messages.\n\n        :param data: message data\n\n        \"\"\"\n        pin = data[0]\n        value = (data[1] << 8) + data[2]\n        # set the current value in the pin structure\n        time_stamp = time.time()\n        # self.digital_pins[pin].event_time = time_stamp\n        if self.analog_callbacks[pin]:\n            message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]\n            try:\n                self.analog_callbacks[pin](message)\n            except KeyError:\n                pass\n\n    def _dht_report(self, data):\n\"\"\"\n        This is the dht report handler method.\n\n        :param data:            data[0] = report error return\n                                    No Errors = 0\n\n                                    Checksum Error = 1\n\n                                    Timeout Error = 2\n\n                                    Invalid Value = 999\n\n                                data[1] = pin number\n\n                                data[2] = dht type 11 or 22\n\n                                data[3] = humidity positivity flag\n\n                                data[4] = temperature positivity value\n\n                                data[5] = humidity integer\n\n                                data[6] = humidity fractional value\n\n                                data[7] = temperature integer\n\n                                data[8] = temperature fractional value\n\n\n        \"\"\"\n        if data[0]:  # DHT_ERROR\n            # error report\n            # data[0] = report sub type, data[1] = pin, data[2] = error message\n            if self.dht_callbacks[data[1]]:\n                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                           time.time()]\n                try:\n                    self.dht_callbacks[data[1]](message)\n                except KeyError:\n                    pass\n        else:\n            # got valid data DHT_DATA\n            f_humidity = float(data[5] + data[6] / 100)\n            if data[3]:\n                f_humidity *= -1.0\n            f_temperature = float(data[7] + data[8] / 100)\n            if data[4]:\n                f_temperature *= -1.0\n            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                       f_humidity, f_temperature, time.time()]\n\n            try:\n                self.dht_callbacks[data[1]](message)\n            except KeyError:\n                pass\n\n    def _digital_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for Digital Messages.\n\n        :param data: digital message\n\n        \"\"\"\n        pin = data[0]\n        value = data[1]\n\n        time_stamp = time.time()\n        if self.digital_callbacks[pin]:\n            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n            self.digital_callbacks[pin](message)\n\n    def _firmware_message(self, data):\n\"\"\"\n        Telemetrix4Arduino firmware version message\n\n        :param data: data[0] = major number, data[1] = minor number.\n\n                               data[2] = patch number\n        \"\"\"\n\n        self.firmware_version = [data[0], data[1], data[2]]\n\n    def _i2c_read_report(self, data):\n\"\"\"\n        Execute callback for i2c reads.\n\n        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n        \"\"\"\n\n        # we receive [# data bytes, address, register, data bytes]\n        # number of bytes of data returned\n\n        # data[0] = number of bytes\n        # data[1] = i2c_port\n        # data[2] = number of bytes returned\n        # data[3] = address\n        # data[4] = register\n        # data[5] ... all the data bytes\n\n        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n        cb_list.append(time.time())\n\n        if cb_list[1]:\n            self.i2c_callback2(cb_list)\n        else:\n            self.i2c_callback(cb_list)\n\n    def _i2c_too_few(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    def _i2c_too_many(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    def _i_am_here(self, data):\n\"\"\"\n        Reply to are_u_there message\n        :param data: arduino id\n        \"\"\"\n        self.reported_arduino_id = data[0]\n\n    def _spi_report(self, report):\n\n        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n        cb_list.append(time.time())\n\n        self.spi_callback(cb_list)\n\n    def _onewire_report(self, report):\n        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n        cb_list.append(time.time())\n        self.onewire_callback(cb_list)\n\n    def _report_debug_data(self, data):\n\"\"\"\n        Print debug data sent from Arduino\n        :param data: data[0] is a byte followed by 2\n                     bytes that comprise an integer\n        :return:\n        \"\"\"\n        value = (data[1] << 8) + data[2]\n        print(f'DEBUG ID: {data[0]} Value: {value}')\n\n    def _report_loop_data(self, data):\n\"\"\"\n        Print data that was looped back\n        :param data: byte of loop back data\n        :return:\n        \"\"\"\n        if self.loop_back_callback:\n            self.loop_back_callback(data)\n\n    def _send_command(self, command):\n\"\"\"\n        This is a private utility method.\n\n\n        :param command:  command data in the form of a list\n\n        \"\"\"\n        # the length of the list is added at the head\n        command.insert(0, len(command))\n        send_message = bytes(command)\n\n        if self.serial_port:\n            try:\n                self.serial_port.write(send_message)\n            except SerialException:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('write fail in _send_command')\n        else:\n            raise RuntimeError('No serial port set.')\n\n    def _servo_unavailable(self, report):\n\"\"\"\n        Message if no servos are available for use.\n        :param report: pin number\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n    def _sonar_distance_report(self, report):\n\"\"\"\n\n        :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n        \"\"\"\n\n        # get callback from pin number\n        cb = self.sonar_callbacks[report[0]]\n\n        # build report data\n        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n                   ((report[1] << 8) + report[2]), time.time()]\n\n        cb(cb_list)\n\n    def _stepper_distance_to_go_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper distance to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n    #                              data[3] = steps bytes 2, data[4] = steps LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n    #                              steps, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     steps = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n\n    def _stepper_target_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper target position to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = target position MSB,\n    #                    data[2] = target position byte MSB+1\n    #                    data[3] = target position byte MSB+2\n    #                    data[4] = target position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n    #                              target_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['target_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     target = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     target_position = int.from_bytes(target, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n\n    def _stepper_current_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper current position.\n    #\n    #     :param report: data[0] = motor_id, data[1] = current position MSB,\n    #                    data[2] = current position byte MSB+1\n    #                    data[3] = current position byte MSB+2\n    #                    data[4] = current position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n    #                              current_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['current_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     position = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     current_position = int.from_bytes(position, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n\n    def _stepper_is_running_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report if the motor is currently running\n    #\n    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.\n    #\n    #     callback report format: [18, motor_id,\n    #                              running_state, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['is_running_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n    #\n    #     cb(cb_list)\n    #\n\n    def _stepper_run_complete_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     The motor completed it motion\n    #\n    #     :param report: data[0] = motor_id\n    #\n    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n    #                              time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n    #                time.time()]\n    #\n    #     cb(cb_list)\n\n    def _features_report(self, report):\n        self.reported_features = report[0]\n\n    def _run_threads(self):\n        self.run_event.set()\n\n    def _is_running(self):\n        return self.run_event.is_set()\n\n    def _stop_threads(self):\n        self.run_event.clear()\n\n    def _reporter(self):\n\"\"\"\n        This is the reporter thread. It continuously pulls data from\n        the deque. When a full message is detected, that message is\n        processed.\n        \"\"\"\n        self.run_event.wait()\n\n        while self._is_running() and not self.shutdown_flag:\n            if len(self.the_deque):\n                # response_data will be populated with the received data for the report\n                response_data = []\n                packet_length = self.the_deque.popleft()\n                if packet_length:\n                    # get all the data for the report and place it into response_data\n                    for i in range(packet_length):\n                        while not len(self.the_deque):\n                            time.sleep(self.sleep_tune)\n                        data = self.the_deque.popleft()\n                        response_data.append(data)\n\n                    # print(f'response_data {response_data}')\n\n                    # get the report type and look up its dispatch method\n                    # here we pop the report type off of response_data\n                    report_type = response_data.pop(0)\n                    # print(f' reported type {report_type}')\n\n                    # retrieve the report handler from the dispatch table\n                    dispatch_entry = self.report_dispatch.get(report_type)\n\n                    # if there is additional data for the report,\n                    # it will be contained in response_data\n                    # noinspection PyArgumentList\n                    dispatch_entry(response_data)\n                    continue\n                else:\n                    if self.shutdown_on_exception:\n                        self.shutdown()\n                    raise RuntimeError(\n                        'A report with a packet length of zero was received.')\n            else:\n                time.sleep(self.sleep_tune)\n\n    def _serial_receiver(self):\n\"\"\"\n        Thread to continuously check for incoming data.\n        When a byte comes in, place it onto the deque.\n        \"\"\"\n        self.run_event.wait()\n\n        # Don't start this thread if using a tcp/ip transport\n\n        while self._is_running() and not self.shutdown_flag:\n            # we can get an OSError: [Errno9] Bad file descriptor when shutting down\n            # just ignore it\n            try:\n                if self.serial_port.inWaiting():\n                    c = self.serial_port.read()\n                    self.the_deque.append(ord(c))\n                    # print(ord(c))\n                else:\n                    time.sleep(self.sleep_tune)\n                    # continue\n            except OSError:\n                pass\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True)","text":"

:param com_port: e.g. COM3 or /dev/ttyACM0. Only use if you wish to bypass auto com port detection.

:param arduino_instance_id: Match with the value installed on the arduino-telemetrix sketch.

:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.

:param sleep_tune: A tuning parameter (typically not changed by user)

:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception

:param hard_reset_on_shutdown: reset the board on shutdown

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def __init__(self, com_port=None, arduino_instance_id=1,\n             arduino_wait=1, sleep_tune=0.000001,\n             shutdown_on_exception=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n\n    :param com_port: e.g. COM3 or /dev/ttyACM0.\n                     Only use if you wish to bypass auto com port\n                     detection.\n\n    :param arduino_instance_id: Match with the value installed on the\n                                arduino-telemetrix sketch.\n\n    :param arduino_wait: Amount of time to wait for an Arduino to\n                         fully reset itself.\n\n    :param sleep_tune: A tuning parameter (typically not changed by user)\n\n    :param shutdown_on_exception: call shutdown before raising\n                                  a RunTimeError exception, or\n                                  receiving a KeyboardInterrupt exception\n\n    :param hard_reset_on_shutdown: reset the board on shutdown\n\n    \"\"\"\n\n    # initialize threading parent\n    threading.Thread.__init__(self)\n\n    # create the threads and set them as daemons so\n    # that they stop when the program is closed\n\n    # create a thread to interpret received serial data\n    self.the_reporter_thread = threading.Thread(target=self._reporter)\n    self.the_reporter_thread.daemon = True\n\n    self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n\n    self.the_data_receive_thread.daemon = True\n\n    # flag to allow the reporter and receive threads to run.\n    self.run_event = threading.Event()\n\n    # check to make sure that Python interpreter is version 3.7 or greater\n    python_version = sys.version_info\n    if python_version[0] >= 3:\n        if python_version[1] >= 7:\n            pass\n        else:\n            raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                               \"required for use of this program.\")\n\n    # save input parameters as instance variables\n    self.com_port = com_port\n    self.arduino_instance_id = arduino_instance_id\n    self.arduino_wait = arduino_wait\n    self.sleep_tune = sleep_tune\n    self.shutdown_on_exception = shutdown_on_exception\n    self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n    # create a deque to receive and process data from the arduino\n    self.the_deque = deque()\n\n    # The report_dispatch dictionary is used to process\n    # incoming report messages by looking up the report message\n    # and executing its associated processing method.\n\n    self.report_dispatch = {}\n\n    # To add a command to the command dispatch table, append here.\n    self.report_dispatch.update(\n        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n    self.report_dispatch.update(\n        {PrivateConstants.ANALOG_REPORT: self._analog_message})\n    self.report_dispatch.update(\n        {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n    self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n    self.report_dispatch.update(\n        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n    self.report_dispatch.update(\n        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n    self.report_dispatch.update(\n        {PrivateConstants.SPI_REPORT: self._spi_report})\n    self.report_dispatch.update(\n        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_CURRENT_POSITION:\n             self._stepper_current_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUNNING_REPORT:\n             self._stepper_is_running_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n             self._stepper_run_complete_report})\n\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.FEATURES:\n             self._features_report})\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    self.cs_pins_enabled = []\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    self.dht_count = 0\n\n    # serial port in use\n    self.serial_port = None\n\n    # flag to indicate we are in shutdown mode\n    self.shutdown_flag = False\n\n    # debug loopback callback method\n    self.loop_back_callback = None\n\n    # flag to indicate the start of a new report\n    # self.new_report_start = True\n\n    # firmware version to be stored here\n    self.firmware_version = []\n\n    # reported arduino instance id\n    self.reported_arduino_id = []\n\n    # reported features\n    self.reported_features = 0\n\n    # flag to indicate if i2c was previously enabled\n    self.i2c_enabled = False\n\n    # flag to indicate if spi is initialized\n    self.spi_enabled = False\n\n    # flag to indicate if onewire is initialized\n    self.onewire_enabled = False\n\n    # # stepper motor variables\n    #\n    # # updated when a new motor is added\n    # self.next_stepper_assigned = 0\n    #\n    # # valid list of stepper motor interface types\n    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n    #\n    # # maximum number of steppers supported\n    # self.max_number_of_steppers = 4\n    #\n    # # number of steppers created - not to exceed the maximum\n    # self.number_of_steppers = 0\n    #\n    # # dictionary to hold stepper motor information\n    # self.stepper_info = {'instance': False, 'is_running': None,\n    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n    #                      'distance_to_go_callback': None,\n    #                      'target_position_callback': None,\n    #                      'current_position_callback': None,\n    #                      'is_running_callback': None,\n    #                      'motion_complete_callback': None,\n    #                      'acceleration_callback': None}\n    #\n    # # build a list of stepper motor info items\n    # self.stepper_info_list = []\n    # # a list of dictionaries to hold stepper information\n    # for motor in range(self.max_number_of_steppers):\n    #     self.stepper_info_list.append(self.stepper_info)\n\n    self.the_reporter_thread.start()\n    self.the_data_receive_thread.start()\n\n    print(f\"telemetrix_uno_r4_minima:  Version\"\n          f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n          f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n    # using the serial link\n    if not self.com_port:\n        # user did not specify a com_port\n        try:\n            self._find_arduino()\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                self.shutdown()\n    else:\n        # com_port specified - set com_port and baud rate\n        try:\n            self._manual_open()\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                self.shutdown()\n\n    if self.serial_port:\n        print(\n            f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n        self.serial_port.reset_input_buffer()\n        self.serial_port.reset_output_buffer()\n\n    # no com_port found - raise a runtime exception\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('No Arduino Found or User Aborted Program')\n\n    # allow the threads to run\n    self._run_threads()\n    print(f'Reset Complete')\n\n    # get telemetrix firmware version and print it\n    print('\\nRetrieving Telemetrix4UnoR4Minima firmware ID...')\n    self._get_firmware_version()\n    if not self.firmware_version:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')\n\n    else:\n\n        print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'\n              f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n    command = [PrivateConstants.ENABLE_ALL_REPORTS]\n    self._send_command(command)\n\n    # get the features list\n    command = [PrivateConstants.GET_FEATURES]\n    self._send_command(command)\n    time.sleep(.2)\n\n    # Have the server reset its data structures\n    command = [PrivateConstants.RESET]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.analog_write","title":"analog_write(pin, value)","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (maximum 16 bits)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def analog_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (maximum 16 bits)\n\n    \"\"\"\n    value_msb = value >> 8\n    value_lsb = value & 0xff\n    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.digital_write","title":"digital_write(pin, value)","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (1 or 0)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def digital_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (1 or 0)\n\n    \"\"\"\n\n    command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_all_reporting","title":"disable_all_reporting()","text":"

Disable reporting for all digital and analog input pins

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_all_reporting(self):\n\"\"\"\n    Disable reporting for all digital and analog input pins\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DISABLE_ALL, 0]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_analog_reporting","title":"disable_analog_reporting(pin)","text":"

Disables analog reporting for a single analog pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_analog_reporting(self, pin):\n\"\"\"\n    Disables analog reporting for a single analog pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.disable_digital_reporting","title":"disable_digital_reporting(pin)","text":"

Disables digital reporting for a single digital input.

:param pin: Pin number.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def disable_digital_reporting(self, pin):\n\"\"\"\n    Disables digital reporting for a single digital input.\n\n    :param pin: Pin number.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.enable_analog_reporting","title":"enable_analog_reporting(pin)","text":"

Enables analog reporting for the specified pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def enable_analog_reporting(self, pin):\n\"\"\"\n    Enables analog reporting for the specified pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.enable_digital_reporting","title":"enable_digital_reporting(pin)","text":"

Enable reporting on the specified digital pin.

:param pin: Pin number.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def enable_digital_reporting(self, pin):\n\"\"\"\n    Enable reporting on the specified digital pin.\n\n    :param pin: Pin number.\n    \"\"\"\n\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)","text":"

Read the specified number of bytes from the specified register for the i2c device.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: 0 = default, 1 = secondary

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_read(self, address, register, number_of_bytes,\n             callback=None, i2c_port=0,\n             write_register=True):\n\"\"\"\n    Read the specified number of bytes from the\n    specified register for the i2c device.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                   selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report\n                     i2c data as a result of read command\n\n   :param i2c_port: 0 = default, 1 = secondary\n\n   :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n\n    self._i2c_read_request(address, register, number_of_bytes,\n                           callback=callback, i2c_port=i2c_port,\n                           write_register=write_register)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)","text":"

Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: 0 = default 1 = secondary

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_read_restart_transmission(self, address, register,\n                                  number_of_bytes,\n                                  callback=None, i2c_port=0,\n                                  write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified\n    register for the i2c device. This restarts the transmission\n    after the read. It is required for some i2c devices such as the MMA8452Q\n    accelerometer.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                                selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c\n                     data as a result of read command\n\n   :param i2c_port: 0 = default 1 = secondary\n\n   :param write_register: If True, the register is written before read\n                          Else, the write is suppressed\n\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n\n    self._i2c_read_request(address, register, number_of_bytes,\n                           stop_transmission=False,\n                           callback=callback, i2c_port=i2c_port,\n                           write_register=write_register)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.i2c_write","title":"i2c_write(address, args, i2c_port=0)","text":"

Write data to an i2c device.

:param address: i2c device address

:param i2c_port: 0= port 1, 1 = port 2

:param args: A variable number of bytes to be sent to the device passed in as a list

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n    Write data to an i2c device.\n\n    :param address: i2c device address\n\n    :param i2c_port: 0= port 1, 1 = port 2\n\n    :param args: A variable number of bytes to be sent to the device\n                 passed in as a list\n\n    \"\"\"\n    if not i2c_port:\n        if not self.i2c_1_active:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n    if i2c_port:\n        if not self.i2c_2_active:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n    for item in args:\n        command.append(item)\n\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.loop_back","title":"loop_back(start_character, callback=None)","text":"

This is a debugging method to send a character to the Arduino device, and have the device loop it back.

:param start_character: The character to loop back. It should be an integer.

:param callback: Looped back character will appear in the callback method

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def loop_back(self, start_character, callback=None):\n\"\"\"\n    This is a debugging method to send a character to the\n    Arduino device, and have the device loop it back.\n\n    :param start_character: The character to loop back. It should be\n                            an integer.\n\n    :param callback: Looped back character will appear in the callback method\n\n    \"\"\"\n    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n    self.loop_back_callback = callback\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.r4_hard_reset","title":"r4_hard_reset()","text":"

Place the r4 into hard reset

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def r4_hard_reset(self):\n\"\"\"\n    Place the r4 into hard reset\n    \"\"\"\n    command = [PrivateConstants.RESET, 1]\n    self._send_command(command)\n    time.sleep(.5)\n    command = [PrivateConstants.BOARD_HARD_RESET, 1]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.servo_detach","title":"servo_detach(pin_number)","text":"

Detach a servo for reuse

:param pin_number: attached pin

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def servo_detach(self, pin_number):\n\"\"\"\n    Detach a servo for reuse\n\n    :param pin_number: attached pin\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_DETACH, pin_number]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.servo_write","title":"servo_write(pin_number, angle)","text":"

Set a servo attached to a pin to a given angle.

:param pin_number: pin

:param angle: angle (0-180)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def servo_write(self, pin_number, angle):\n\"\"\"\n\n    Set a servo attached to a pin to a given angle.\n\n    :param pin_number: pin\n\n    :param angle: angle (0-180)\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_analog_scan_interval","title":"set_analog_scan_interval(interval)","text":"

Set the analog scanning interval.

:param interval: value of 0 - 255 - milliseconds

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_analog_scan_interval(self, interval):\n\"\"\"\n    Set the analog scanning interval.\n\n    :param interval: value of 0 - 255 - milliseconds\n    \"\"\"\n\n    if 0 <= interval <= 255:\n        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)","text":"

Set a pin as an analog input.

:param pin_number: arduino pin number

:param differential: difference in previous to current value before report will be generated

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for analog input pins = 3

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n    Set a pin as an analog input.\n\n    :param pin_number: arduino pin number\n\n    :param differential: difference in previous to current value before\n                         report will be generated\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for analog input pins = 3\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n                       callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)","text":"

Set a pin as a pwm (analog output) pin.

:param pin_number:arduino pin number

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n    Set a pin as a pwm (analog output) pin.\n\n    :param pin_number:arduino pin number\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)","text":"

:param pin: connection pin

:param callback: callback function

:param dht_type: either 22 for DHT22 or 11 for DHT11

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]

DHT_REPORT_TYPE = 12

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n    :param pin: connection pin\n\n    :param callback: callback function\n\n    :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n    Temperature,\n    Time]\n\n    DHT_REPORT_TYPE = 12\n    \"\"\"\n    if self.reported_features & PrivateConstants.DHT_FEATURE:\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n        if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n            self.dht_callbacks[pin] = callback\n            self.dht_count += 1\n\n            if dht_type != 22 and dht_type != 11:\n                dht_type = 22\n\n            command = [PrivateConstants.DHT_NEW, pin, dht_type]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback=None)","text":"

Set a pin as a digital input.

:param pin_number: arduino pin number

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n    Set a pin as a digital input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback=None)","text":"

Set a pin as a digital input with pullup enabled.

:param pin_number: arduino pin number

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n    Set a pin as a digital input with pullup enabled.\n\n    :param pin_number: arduino pin number\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                       callback=callback)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)","text":"

Set a pin as a digital output pin.

:param pin_number: arduino pin number

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n    Set a pin as a digital output pin.\n\n    :param pin_number: arduino pin number\n    \"\"\"\n\n    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)","text":"

Establish the standard Arduino i2c pins for i2c utilization.

:param i2c_port: 0 = i2c1, 1 = i2c2

  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  1. Callbacks are set within the individual i2c read methods of this
  API.\n\n  See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n    Establish the standard Arduino i2c pins for i2c utilization.\n\n    :param i2c_port: 0 = i2c1, 1 = i2c2\n\n    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n           2. Callbacks are set within the individual i2c read methods of this\n          API.\n\n          See i2c_read, or i2c_read_restart_transmission.\n\n    \"\"\"\n    # test for i2c port 2\n    if i2c_port:\n        # if not previously activated set it to activated\n        # and the send a begin message for this port\n        if not self.i2c_2_active:\n            self.i2c_2_active = True\n        else:\n            return\n    # port 1\n    else:\n        if not self.i2c_1_active:\n            self.i2c_1_active = True\n        else:\n            return\n\n    command = [PrivateConstants.I2C_BEGIN, i2c_port]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)","text":"

Attach a pin to a servo motor

:param pin_number: pin

:param min_pulse: minimum pulse width

:param max_pulse: maximum pulse width

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n    Attach a pin to a servo motor\n\n    :param pin_number: pin\n\n    :param min_pulse: minimum pulse width\n\n    :param max_pulse: maximum pulse width\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n        minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n        maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n        command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                   minv[0], minv[1], maxv[0], maxv[1]]\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)","text":"

:param trigger_pin:

:param echo_pin:

:param callback: callback

callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                       callback=None):\n\"\"\"\n\n    :param trigger_pin:\n\n    :param echo_pin:\n\n    :param callback: callback\n\n    callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n            self.sonar_callbacks[trigger_pin] = callback\n            self.sonar_count += 1\n\n            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)","text":"

Specify the list of chip select pins.

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

Chip Select is any digital output capable pin.

:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!

command message: [command, [cs pins...]]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n    Specify the list of chip select pins.\n\n    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n    Chip Select is any digital output capable pin.\n\n    :param chip_select_list: this is a list of pins to be used for chip select.\n                       The pins will be configured as output, and set to high\n                       ready to be used for chip select.\n                       NOTE: You must specify the chips select pins here!\n\n\n    command message: [command, [cs pins...]]\n    \"\"\"\n\n    if self.reported_features & PrivateConstants.SPI_FEATURE:\n        if type(chip_select_list) != list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('chip_select_list must be in the form of a list')\n        if not chip_select_list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Chip select pins were not specified')\n\n        self.spi_enabled = True\n\n        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n        for pin in chip_select_list:\n            command.append(pin)\n            self.cs_pins_enabled.append(pin)\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.shutdown","title":"shutdown()","text":"

This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def shutdown(self):\n\"\"\"\n    This method attempts an orderly shutdown\n    If any exceptions are thrown, they are ignored.\n    \"\"\"\n    self.shutdown_flag = True\n\n    self._stop_threads()\n\n    try:\n        command = [PrivateConstants.STOP_ALL_REPORTS]\n        self._send_command(command)\n        time.sleep(.5)\n\n        if self.hard_reset_on_shutdown:\n            self.r4_hard_reset()\n        else:\n            try:\n                self.serial_port.reset_input_buffer()\n                self.serial_port.reset_output_buffer()\n\n                self.serial_port.close()\n\n            except (RuntimeError, SerialException, OSError):\n                # ignore error on shutdown\n                pass\n    except Exception:\n        # raise RuntimeError('Shutdown failed - could not send stop streaming\n        # message')\n        pass\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.sonar_disable","title":"sonar_disable()","text":"

Disable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def sonar_disable(self):\n\"\"\"\n    Disable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_DISABLE]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.sonar_enable","title":"sonar_enable()","text":"

Enable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def sonar_enable(self):\n\"\"\"\n    Enable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_ENABLE]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)","text":"

Control an SPI chip select line :param chip_select_pin: pin connected to CS

:param select: 0=select, 1=deselect

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n    Control an SPI chip select line\n    :param chip_select_pin: pin connected to CS\n\n    :param select: 0=select, 1=deselect\n    \"\"\"\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n    if chip_select_pin not in self.cs_pins_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)","text":"

Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.

:param chip_select: chip select pin

:param register_selection: Register to be selected for read.

:param number_of_bytes_to_read: Number of bytes to read

:param call_back: Required callback function to report spi data as a result of read command

callback returns a data list: [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]

SPI_READ_REPORT = 13

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n                      call_back=None):\n\"\"\"\n    Read the specified number of bytes from the specified SPI port and\n    call the callback function with the reported data.\n\n    :param chip_select: chip select pin\n\n    :param register_selection: Register to be selected for read.\n\n    :param number_of_bytes_to_read: Number of bytes to read\n\n    :param call_back: Required callback function to report spi data as a\n               result of read command\n\n\n    callback returns a data list:\n    [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n    data bytes, time-stamp]\n\n    SPI_READ_REPORT = 13\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n    if not call_back:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n    self.spi_callback = call_back\n\n    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n               number_of_bytes_to_read,\n               register_selection]\n\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)","text":"

Configure how the SPI serializes and de-serializes data on the wire.

See Arduino SPI reference materials for details.

:param clock_divisor: 1 - 255

:param bit_order:

                LSBFIRST = 0\n\n                MSBFIRST = 1 (default)\n

:param data_mode:

                SPI_MODE0 = 0x00 (default)\n\n                SPI_MODE1  = 1\n\n                SPI_MODE2 = 2\n\n                SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n    Configure how the SPI serializes and de-serializes data on the wire.\n\n    See Arduino SPI reference materials for details.\n\n    :param clock_divisor: 1 - 255\n\n    :param bit_order:\n\n                        LSBFIRST = 0\n\n                        MSBFIRST = 1 (default)\n\n    :param data_mode:\n\n                        SPI_MODE0 = 0x00 (default)\n\n                        SPI_MODE1  = 1\n\n                        SPI_MODE2 = 2\n\n                        SPI_MODE3 = 3\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n    if not 0 < clock_divisor <= 255:\n        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n    if bit_order not in [0, 1]:\n        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n    if data_mode not in [0, 1, 2, 3]:\n        raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n               data_mode]\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference/#telemetrix_uno_r4_minima.TelemetrixUnoR4Minima.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)","text":"

Write a list of bytes to the SPI device.

:param chip_select: chip select pin

:param bytes_to_write: A list of bytes to write. This must be in the form of a list.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py
def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n    Write a list of bytes to the SPI device.\n\n    :param chip_select: chip select pin\n\n    :param bytes_to_write: A list of bytes to write. This must\n                            be in the form of a list.\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n    if type(bytes_to_write) is not list:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n    for data in bytes_to_write:\n        command.append(data)\n\n    self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/","title":"telemetrix_uno_r4_minima_aio","text":"

Copyright (c) 2023 Alan Yorinks All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio","title":"TelemetrixUnoR4MinimaAio","text":"

This class exposes and implements the TelemetrixAIO API. It includes the public API methods as well as a set of private methods. This is an asyncio API.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
class TelemetrixUnoR4MinimaAio:\n\"\"\"\n    This class exposes and implements the TelemetrixAIO API.\n    It includes the public API methods as well as\n    a set of private methods. This is an asyncio API.\n\n    \"\"\"\n\n    # noinspection PyPep8,PyPep8\n    def __init__(self, com_port=None,\n                 arduino_instance_id=1, arduino_wait=1,\n                 sleep_tune=0.0001, autostart=True,\n                 loop=None, shutdown_on_exception=True,\n                 close_loop_on_shutdown=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n        If you have a single Arduino connected to your computer,\n        then you may accept all the default values.\n\n        Otherwise, specify a unique arduino_instance id for each board in use.\n\n        :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n        :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n        :param arduino_wait: Amount of time to wait for an Arduino to\n                             fully reset itself.\n\n        :param sleep_tune: A tuning parameter (typically not changed by user)\n\n        :param autostart: If you wish to call the start method within\n                          your application, then set this to False.\n\n        :param loop: optional user provided event loop\n\n        :param shutdown_on_exception: call shutdown before raising\n                                      a RunTimeError exception, or\n                                      receiving a KeyboardInterrupt exception\n\n        :param close_loop_on_shutdown: stop and close the event loop loop\n                                       when a shutdown is called or a serial\n                                       error occurs\n\n       :param hard_reset_on_shutdown: reset the board on shutdown\n\n        \"\"\"\n        # check to make sure that Python interpreter is version 3.8.3 or greater\n        python_version = sys.version_info\n        if python_version[0] >= 3:\n            if python_version[1] >= 8:\n                if python_version[2] >= 3:\n                    pass\n            else:\n                raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                                   \"required for use of this program.\")\n\n        # save input parameters\n        self.com_port = com_port\n        self.arduino_instance_id = arduino_instance_id\n        self.arduino_wait = arduino_wait\n        self.sleep_tune = sleep_tune\n        self.autostart = autostart\n        self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n        # set the event loop\n        if loop is None:\n            self.loop = asyncio.get_event_loop()\n        else:\n            self.loop = loop\n\n        self.shutdown_on_exception = shutdown_on_exception\n        self.close_loop_on_shutdown = close_loop_on_shutdown\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        # debug loopback callback method\n        self.loop_back_callback = None\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        self.dht_count = 0\n\n        # serial port in use\n        self.serial_port = None\n\n        # generic asyncio task holder\n        self.the_task = None\n\n        # flag to indicate we are in shutdown mode\n        self.shutdown_flag = False\n\n        self.report_dispatch = {}\n\n        # reported features\n        self.reported_features = 0\n\n        # To add a command to the command dispatch table, append here.\n        self.report_dispatch.update(\n            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n        self.report_dispatch.update(\n            {PrivateConstants.ANALOG_REPORT: self._analog_message})\n        self.report_dispatch.update(\n            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n        self.report_dispatch.update(\n            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n        self.report_dispatch.update(\n            {PrivateConstants.SPI_REPORT: self._spi_report})\n        self.report_dispatch.update(\n            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_CURRENT_POSITION:\n                 self._stepper_current_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUNNING_REPORT:\n                 self._stepper_is_running_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n                 self._stepper_run_complete_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.FEATURES:\n                 self._features_report})\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        self.cs_pins_enabled = []\n\n        # flag to indicate if spi is initialized\n        self.spi_enabled = False\n\n        # flag to indicate if onewire is initialized\n        self.onewire_enabled = False\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        # # stepper motor variables\n        #\n        # # updated when a new motor is added\n        # self.next_stepper_assigned = 0\n        #\n        # # valid list of stepper motor interface types\n        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n        #\n        # # maximum number of steppers supported\n        # self.max_number_of_steppers = 4\n        #\n        # # number of steppers created - not to exceed the maximum\n        # self.number_of_steppers = 0\n        #\n        # # dictionary to hold stepper motor information\n        # self.stepper_info = {'instance': False, 'is_running': None,\n        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n        #                      'distance_to_go_callback': None,\n        #                      'target_position_callback': None,\n        #                      'current_position_callback': None,\n        #                      'is_running_callback': None,\n        #                      'motion_complete_callback': None,\n        #                      'acceleration_callback': None}\n        #\n        # # build a list of stepper motor info items\n        # self.stepper_info_list = []\n        # # a list of dictionaries to hold stepper information\n        # for motor in range(self.max_number_of_steppers):\n        #     self.stepper_info_list.append(self.stepper_info)\n\n        print(f'telemetrix_uno_r4_minima_aio Version:'\n              f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')\n        print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n        if autostart:\n            self.loop.run_until_complete(self.start_aio())\n\n    async def start_aio(self):\n\"\"\"\n        This method may be called directly, if the autostart\n        parameter in __init__ is set to false.\n\n        This method instantiates the serial interface and then performs auto pin\n        discovery if using a serial interface, or creates and connects to\n        a TCP/IP enabled device running StandardFirmataWiFi.\n\n        Use this method if you wish to start TelemetrixAIO manually from\n        an asyncio function.\n         \"\"\"\n\n        if not self.com_port:\n            # user did not specify a com_port\n            try:\n                await self._find_arduino()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n        else:\n            # com_port specified - set com_port and baud rate\n            try:\n                await self._manual_open()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n\n        if self.com_port:\n            print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')\n\n            # no com_port found - raise a runtime exception\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('No Arduino Found or User Aborted Program')\n\n        # get arduino firmware version and print it\n        firmware_version = await self._get_firmware_version()\n        if not firmware_version:\n            print('*** Firmware Version retrieval timed out. ***')\n            print('\\nDo you have Arduino connectivity and do you have the ')\n            print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n            print('to the correct serial port.\\n')\n            print('To see a list of serial ports, type: '\n                  '\"list_serial_ports\" in your console.')\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError\n        else:\n\n            print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n                  f'{firmware_version[3]}.{firmware_version[4]}')\n            # start the command dispatcher loop\n            command = [PrivateConstants.ENABLE_ALL_REPORTS]\n            await self._send_command(command)\n            if not self.loop:\n                self.loop = asyncio.get_event_loop()\n            self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n            # get the features list\n            command = [PrivateConstants.GET_FEATURES]\n            await self._send_command(command)\n            await asyncio.sleep(.5)\n\n            # Have the server reset its data structures\n            command = [PrivateConstants.RESET]\n            await self._send_command(command)\n\n    async def get_event_loop(self):\n\"\"\"\n        Return the currently active asyncio event loop\n\n        :return: Active event loop\n\n        \"\"\"\n        return self.loop\n\n    async def _find_arduino(self):\n\"\"\"\n        This method will search all potential serial ports for an Arduino\n        containing a sketch that has a matching arduino_instance_id as\n        specified in the input parameters of this class.\n\n        This is used explicitly with the FirmataExpress sketch.\n        \"\"\"\n\n        # a list of serial ports to be checked\n        serial_ports = []\n\n        print('Opening all potential serial ports...')\n        the_ports_list = list_ports.comports()\n        for port in the_ports_list:\n            if port.pid is None:\n                continue\n            print('\\nChecking {}'.format(port.device))\n            try:\n                self.serial_port = TelemetrixAioSerial(port.device, 115200,\n                                                       telemetrix_aio_instance=self,\n                                                       close_loop_on_error=self.close_loop_on_shutdown)\n            except SerialException:\n                continue\n            # create a list of serial ports that we opened\n            serial_ports.append(self.serial_port)\n\n            # display to the user\n            print('\\t' + port.device)\n\n            # clear out any possible data in the input buffer\n            await self.serial_port.reset_input_buffer()\n\n        # wait for arduino to reset\n        print('\\nWaiting {} seconds(arduino_wait) for Arduino devices to '\n              'reset...'.format(self.arduino_wait))\n        await asyncio.sleep(self.arduino_wait)\n\n        print('\\nSearching for an Arduino configured with an arduino_instance = ',\n              self.arduino_instance_id)\n\n        for serial_port in serial_ports:\n            self.serial_port = serial_port\n\n            command = [PrivateConstants.ARE_U_THERE]\n            await self._send_command(command)\n            # provide time for the reply\n            await asyncio.sleep(.1)\n\n            i_am_here = await self.serial_port.read(3)\n\n            if not i_am_here:\n                continue\n\n            # got an I am here message - is it the correct ID?\n            if i_am_here[2] == self.arduino_instance_id:\n                self.com_port = serial_port.com_port\n                return\n\n    async def _manual_open(self):\n\"\"\"\n        Com port was specified by the user - try to open up that port\n\n        \"\"\"\n        # if port is not found, a serial exception will be thrown\n        print('Opening {} ...'.format(self.com_port))\n        self.serial_port = TelemetrixAioSerial(self.com_port, 115200,\n                                               telemetrix_aio_instance=self,\n                                               close_loop_on_error=self.close_loop_on_shutdown)\n\n        print('Waiting {} seconds for the Arduino To Reset.'\n              .format(self.arduino_wait))\n        await asyncio.sleep(self.arduino_wait)\n        command = [PrivateConstants.ARE_U_THERE]\n        await self._send_command(command)\n        # provide time for the reply\n        await asyncio.sleep(.1)\n\n        print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')\n        i_am_here = await self.serial_port.read(3)\n\n        if not i_am_here:\n            print(f'ERROR: correct arduino_instance_id not found')\n\n        print('Correct arduino_instance_id found')\n\n    async def _get_firmware_version(self):\n\"\"\"\n        This method retrieves the Arduino4Telemetrix firmware version\n\n        :returns: Firmata firmware version\n        \"\"\"\n        command = [PrivateConstants.GET_FIRMWARE_VERSION]\n        await self._send_command(command)\n        # provide time for the reply\n        await asyncio.sleep(.1)\n        firmware_version = await self.serial_port.read(5)\n\n        return firmware_version\n\n    async def analog_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (maximum 16 bits)\n\n        \"\"\"\n        value_msb = value >> 8\n        value_lsb = value & 0xff\n        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n        await self._send_command(command)\n\n    async def digital_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (1 or 0)\n\n        \"\"\"\n        command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n        await self._send_command(command)\n\n    async def i2c_read(self, address, register, number_of_bytes,\n                       callback, i2c_port=0,\n                       write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified register for\n        the i2c device.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command\n\n        :param i2c_port: select the default port (0) or secondary port (1)\n\n        :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('i2c_read: A Callback must be specified')\n\n        await self._i2c_read_request(address, register, number_of_bytes,\n                                     callback=callback, i2c_port=i2c_port,\n                                     write_register=write_register)\n\n    async def i2c_read_restart_transmission(self, address, register,\n                                            number_of_bytes,\n                                            callback, i2c_port=0,\n                                            write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified register for\n        the i2c device. This restarts the transmission after the read. It is\n        required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                                    selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command\n\n        :param i2c_port: select the default port (0) or secondary port (1)\n\n        :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'i2c_read_restart_transmission: A Callback must be specified')\n\n        await self._i2c_read_request(address, register, number_of_bytes,\n                                     stop_transmission=False,\n                                     callback=callback, i2c_port=i2c_port,\n                                     write_register=write_register)\n\n    async def _i2c_read_request(self, address, register, number_of_bytes,\n                                stop_transmission=True, callback=None,\n                                i2c_port=0, write_register=True):\n\"\"\"\n        This method requests the read of an i2c device. Results are retrieved\n        via callback.\n\n        :param address: i2c device address\n\n        :param register: register number (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes expected to be returned\n\n        :param stop_transmission: stop transmission after read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command.\n\n       :param i2c_port: select the default port (0) or secondary port (1)\n\n       :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('I2C Read: A callback function must be specified.')\n\n        if not i2c_port:\n            self.i2c_callback = callback\n        else:\n            self.i2c_callback2 = callback\n\n        if not register:\n            register = 0\n\n        if write_register:\n            write_register = 1\n        else:\n            write_register = 0\n\n        # message contains:\n        # 1. address\n        # 2. register\n        # 3. number of bytes\n        # 4. restart_transmission - True or False\n        # 5. i2c port\n        # 6. suppress write flag\n\n        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n                   stop_transmission, i2c_port, write_register]\n        await self._send_command(command)\n\n    async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n        Write data to an i2c device.\n\n        :param address: i2c device address\n\n        :param i2c_port: 0= port 1, 1 = port 2\n\n        :param args: A variable number of bytes to be sent to the device\n                     passed in as a list\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n        for item in args:\n            command.append(item)\n\n        await self._send_command(command)\n\n    async def loop_back(self, start_character, callback):\n\"\"\"\n        This is a debugging method to send a character to the\n        Arduino device, and have the device loop it back.\n\n        :param start_character: The character to loop back. It should be\n                                an integer.\n\n        :param callback: Looped back character will appear in the callback method\n\n        \"\"\"\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('loop_back: A callback function must be specified.')\n        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n        self.loop_back_callback = callback\n        await self._send_command(command)\n\n    async def set_analog_scan_interval(self, interval):\n\"\"\"\n        Set the analog scanning interval.\n\n        :param interval: value of 0 - 255 - milliseconds\n        \"\"\"\n\n        if 0 <= interval <= 255:\n            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('Analog interval must be between 0 and 255')\n\n    async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n        Set a pin as an analog input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        :param differential: difference in previous to current value before\n                             report will be generated\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for analog input pins = 3\n\n        \"\"\"\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'set_pin_mode_analog_input: A callback function must be specified.')\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n                                 differential, callback=callback)\n\n    async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n        Set a pin as a pwm (analog output) pin.\n\n        :param pin_number:arduino pin number\n\n        \"\"\"\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                                 callback=None)\n\n    async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n        Set a pin as a digital input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n                                 callback=callback)\n\n    async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n        Set a pin as a digital input with pullup enabled.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                                 differential=0, callback=callback)\n\n    async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n        Set a pin as a digital output pin.\n\n        :param pin_number: arduino pin number\n        \"\"\"\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                                 callback=None)\n\n    # noinspection PyIncorrectDocstring\n    async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n        Establish the standard Arduino i2c pins for i2c utilization.\n\n        :param i2c_port: 0 = i2c1, 1 = i2c2\n\n        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n               2. Callbacks are set within the individual i2c read methods of this\n              API.\n\n              See i2c_read, or i2c_read_restart_transmission.\n\n        \"\"\"\n        # test for i2c port 2\n        if i2c_port:\n            # if not previously activated set it to activated\n            # and the send a begin message for this port\n            if not self.i2c_2_active:\n                self.i2c_2_active = True\n            else:\n                return\n        # port 1\n        else:\n            if not self.i2c_1_active:\n                self.i2c_1_active = True\n            else:\n                return\n\n        command = [PrivateConstants.I2C_BEGIN, i2c_port]\n        await self._send_command(command)\n\n    async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n        :param pin: connection pin\n\n        :param callback: callback function\n\n        :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n        Temperature,\n        Time]\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n            if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n                self.dht_callbacks[pin] = callback\n                self.dht_count += 1\n\n                if dht_type != 22 and dht_type != 11:\n                    dht_type = 22\n\n                command = [PrivateConstants.DHT_NEW, pin, dht_type]\n                await self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n    async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n        Attach a pin to a servo motor\n\n        :param pin_number: pin\n\n        :param min_pulse: minimum pulse width\n\n        :param max_pulse: maximum pulse width\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n            minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n            maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n            command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                       minv[0], minv[1], maxv[0], maxv[1]]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n    async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                                 callback):\n\"\"\"\n\n        :param trigger_pin:\n\n        :param echo_pin:\n\n        :param callback:  callback\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n                self.sonar_callbacks[trigger_pin] = callback\n                self.sonar_count += 1\n\n                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n                await self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n    async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n        Specify the list of chip select pins.\n\n        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n        Chip Select is any digital output capable pin.\n\n        :param chip_select_list: this is a list of pins to be used for chip select.\n                           The pins will be configured as output, and set to high\n                           ready to be used for chip select.\n                           NOTE: You must specify the chips select pins here!\n\n\n        command message: [command, number of cs pins, [cs pins...]]\n        \"\"\"\n        if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n            if type(chip_select_list) != list:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('chip_select_list must be in the form of a list')\n            if not chip_select_list:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('Chip select pins were not specified')\n\n            self.spi_enabled = True\n\n            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n            for pin in chip_select_list:\n                command.append(pin)\n                self.cs_pins_enabled.append(pin)\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n    # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n    #                          pin4=5, enable=True):\n    #     \"\"\"\n    #     Stepper motor support is implemented as a proxy for the\n    #     the AccelStepper library for the Arduino.\n    #\n    #     This feature is compatible with the TB6600 Motor Driver\n    #\n    #     Note: It may not work for other driver types!\n    #\n    #     https://github.com/waspinator/AccelStepper\n    #\n    #     Instantiate a stepper motor.\n    #\n    #     Initialize the interface and pins for a stepper motor.\n    #\n    #     :param interface: Motor Interface Type:\n    #\n    #             1 = Stepper Driver, 2 driver pins required\n    #\n    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required\n    #\n    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n    #                 required\n    #\n    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n    #\n    #     :param pin1: Arduino digital pin number for motor pin 1\n    #\n    #     :param pin2: Arduino digital pin number for motor pin 2\n    #\n    #     :param pin3: Arduino digital pin number for motor pin 3\n    #\n    #     :param pin4: Arduino digital pin number for motor pin 4\n    #\n    #     :param enable: If this is true, the output pins at construction time.\n    #\n    #     :return: Motor Reference number\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n    #\n    #         if self.number_of_steppers == self.max_number_of_steppers:\n    #             if self.shutdown_on_exception:\n    #                 await self.shutdown()\n    #             raise RuntimeError('Maximum number of steppers has already been assigned')\n    #\n    #         if interface not in self.valid_stepper_interfaces:\n    #             if self.shutdown_on_exception:\n    #                 await self.shutdown()\n    #             raise RuntimeError('Invalid stepper interface')\n    #\n    #         self.number_of_steppers += 1\n    #\n    #         motor_id = self.next_stepper_assigned\n    #         self.next_stepper_assigned += 1\n    #         self.stepper_info_list[motor_id]['instance'] = True\n    #\n    #         # build message and send message to server\n    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n    #                    pin2, pin3, pin4, enable]\n    #         await self._send_command(command)\n    #\n    #         # return motor id\n    #         return motor_id\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n    async def sonar_disable(self):\n\"\"\"\n        Disable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_DISABLE]\n        await self._send_command(command)\n\n    async def sonar_enable(self):\n\"\"\"\n        Enable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_ENABLE]\n        await self._send_command(command)\n\n    async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n        Control an SPI chip select line\n        :param chip_select_pin: pin connected to CS\n\n        :param select: 0=select, 1=deselect\n        \"\"\"\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n        if chip_select_pin not in self.cs_pins_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n        await self._send_command(command)\n\n    async def spi_read_blocking(self, chip_select, register_selection,\n                                number_of_bytes_to_read,\n                          call_back=None):\n\"\"\"\n        Read the specified number of bytes from the specified SPI port and\n        call the callback function with the reported data.\n\n        :param chip_select: chip select pin\n\n        :param register_selection: Register to be selected for read.\n\n        :param number_of_bytes_to_read: Number of bytes to read\n\n        :param call_back: Required callback function to report spi data as a\n                   result of read command\n\n\n        callback returns a data list:\n            [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n             data bytes, time-stamp]\n        SPI_READ_REPORT = 13\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n        if not call_back:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n        self.spi_callback = call_back\n\n        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n                   number_of_bytes_to_read,\n                   register_selection]\n\n        await self._send_command(command)\n\n    async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n        Configure how the SPI serializes and de-serializes data on the wire.\n\n        See Arduino SPI reference materials for details.\n\n        :param clock_divisor: 1 - 255\n\n        :param bit_order:\n\n                            LSBFIRST = 0\n\n                            MSBFIRST = 1 (default)\n\n        :param data_mode:\n\n                            SPI_MODE0 = 0x00 (default)\n\n                            SPI_MODE1  = 1\n\n                            SPI_MODE2 = 2\n\n                            SPI_MODE3 = 3\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n        if not 0 < clock_divisor <= 255:\n            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n        if bit_order not in [0, 1]:\n            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n        if data_mode not in [0, 1, 2, 3]:\n            raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n                   data_mode]\n        await self._send_command(command)\n\n    async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n        Write a list of bytes to the SPI device.\n\n        :param chip_select: chip select pin\n\n        :param bytes_to_write: A list of bytes to write. This must\n                                be in the form of a list.\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n        if type(bytes_to_write) is not list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n        for data in bytes_to_write:\n            command.append(data)\n\n        await self._send_command(command)\n\n    # async def set_pin_mode_one_wire(self, pin):\n    #     \"\"\"\n    #     Initialize the one wire serial bus.\n    #\n    #     :param pin: Data pin connected to the OneWire device\n    #     \"\"\"\n    #     self.onewire_enabled = True\n    #     command = [PrivateConstants.ONE_WIRE_INIT, pin]\n    #     await self._send_command(command)\n    #\n    # async def onewire_reset(self, callback=None):\n    #     \"\"\"\n    #     Reset the onewire device\n    #\n    #     :param callback: required  function to report reset result\n    #\n    #     callback returns a list:\n    #     [ReportType = 14, Report Subtype = 25, reset result byte,\n    #                     timestamp]\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_reset: A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_RESET]\n    #     await self._send_command(command)\n    #\n    # async def onewire_select(self, device_address):\n    #     \"\"\"\n    #     Select a device based on its address\n    #     :param device_address: A bytearray of 8 bytes\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n    #\n    #     if type(device_address) is not list:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #\n    #     if len(device_address) != 8:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #     command = [PrivateConstants.ONE_WIRE_SELECT]\n    #     for data in device_address:\n    #         command.append(data)\n    #     await self._send_command(command)\n    #\n    # async def onewire_skip(self):\n    #     \"\"\"\n    #     Skip the device selection. This only works if you have a\n    #     single device, but you can avoid searching and use this to\n    #     immediately access your device.\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SKIP]\n    #     await self._send_command(command)\n    #\n    # async def onewire_write(self, data, power=0):\n    #     \"\"\"\n    #     Write a byte to the onewire device. If 'power' is one\n    #     then the wire is held high at the end for\n    #     parasitically powered devices. You\n    #     are responsible for eventually de-powering it by calling\n    #     another read or write.\n    #\n    #     :param data: byte to write.\n    #     :param power: power control (see above)\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n    #     if 0 < data < 255:\n    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n    #         await self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_write: Data must be no larger than 255')\n    #\n    # async def onewire_read(self, callback=None):\n    #     \"\"\"\n    #     Read a byte from the onewire device\n    #     :param callback: required  function to report onewire data as a\n    #                result of read command\n    #\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_READ]\n    #     await self._send_command(command)\n    #\n    # async def onewire_reset_search(self):\n    #     \"\"\"\n    #     Begin a new search. The next use of search will begin at the first device\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n    #                            f'enabled.')\n    #     else:\n    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n    #         await self._send_command(command)\n    #\n    # async def onewire_search(self, callback=None):\n    #     \"\"\"\n    #     Search for the next device. The device address will returned in the callback.\n    #     If a device is found, the 8 byte address is contained in the callback.\n    #     If no more devices are found, the address returned contains all elements set\n    #     to 0xff.\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SEARCH]\n    #     await self._send_command(command)\n    #\n    # async def onewire_crc8(self, address_list, callback=None):\n    #     \"\"\"\n    #     Compute a CRC check on an array of data.\n    #     :param address_list:\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_crc8 A Callback must be specified')\n    #\n    #     if type(address_list) is not list:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_crc8: address list must be a list.')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     address_length = len(address_list)\n    #\n    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n    #\n    #     for data in address_list:\n    #         command.append(data)\n    #\n    #     await self._send_command(command)\n\n    async def _set_pin_mode(self, pin_number, pin_state, differential, callback):\n\"\"\"\n        A private method to set the various pin modes.\n\n        :param pin_number: arduino pin number\n\n        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use\n                          servo_config()\n                          For DHT   use: set_pin_mode_dht\n\n        :param differential: for analog inputs - threshold\n                             value to be achieved for report to\n                             be generated\n\n        :param callback: A reference to an async call back function to be\n                         called when pin data value changes\n\n        \"\"\"\n        if not callback and pin_state != PrivateConstants.AT_OUTPUT:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('_set_pin_mode: A Callback must be specified')\n        else:\n            if pin_state == PrivateConstants.AT_INPUT:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_INPUT, 1]\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_INPUT_PULLUP, 1]\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_ANALOG:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_ANALOG,\n                           differential >> 8, differential & 0xff, 1]\n                self.analog_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_OUTPUT:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_OUTPUT, 1]\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('Unknown pin state')\n\n        if command:\n            await self._send_command(command)\n\n        await asyncio.sleep(.05)\n\n    async def servo_detach(self, pin_number):\n\"\"\"\n        Detach a servo for reuse\n        :param pin_number: attached pin\n        \"\"\"\n        command = [PrivateConstants.SERVO_DETACH, pin_number]\n        await self._send_command(command)\n\n    async def servo_write(self, pin_number, angle):\n\"\"\"\n\n        Set a servo attached to a pin to a given angle.\n\n        :param pin_number: pin\n\n        :param angle: angle (0-180)\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n        await self._send_command(command)\n\n    # async def stepper_move_to(self, motor_id, position):\n    #     \"\"\"\n    #     Set an absolution target position. If position is positive, the movement is\n    #     clockwise, else it is counter-clockwise.\n    #\n    #     The run() function (below) will try to move the motor (at most one step per call)\n    #     from the current position to the target position set by the most\n    #     recent call to this function. Caution: moveTo() also recalculates the\n    #     speed for the next step.\n    #     If you are trying to use constant speed movements, you should call setSpeed()\n    #     after calling moveTo().\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param position: target position. Maximum value is 32 bits.\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')\n    #\n    #     if position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(position)\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_move(self, motor_id, relative_position):\n    #     \"\"\"\n    #     Set the target position relative to the current position.\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param relative_position: The desired position relative to the current\n    #                               position. Negative is anticlockwise from\n    #                               the current position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_move: Invalid motor_id.')\n    #\n    #     if relative_position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(relative_position)\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     await self._send_command(command)\n    #\n    # async def stepper_run(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     This method steps the selected motor based on the current speed.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run: A motion complete callback must be '\n    #                            'specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_run_speed(self, motor_id):\n    #     \"\"\"\n    #     This method steps the selected motor based at a constant speed as set by the most\n    #     recent call to stepper_set_max_speed(). The motor will run continuously.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_max_speed(self, motor_id, max_speed):\n    #     \"\"\"\n    #     Sets the maximum permitted speed. The stepper_run() function will accelerate\n    #     up to the speed set by this function.\n    #\n    #     Caution: the maximum speed achievable depends on your processor and clock speed.\n    #     The default maxSpeed is 1 step per second.\n    #\n    #      Caution: Speeds that exceed the maximum speed supported by the processor may\n    #               result in non-linear accelerations and decelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param max_speed: 1 - 1000\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n    #\n    #     if not 1 < max_speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n    #\n    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed\n    #     max_speed_msb = (max_speed & 0xff00) >> 8\n    #     max_speed_lsb = max_speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n    #                max_speed_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_max_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the maximum speed configured for this stepper\n    #     that was previously set by stepper_set_max_speed()\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :return: The currently configured maximum speed.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['max_speed']\n    #\n    # async def stepper_set_acceleration(self, motor_id, acceleration):\n    #     \"\"\"\n    #     Sets the acceleration/deceleration rate.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param acceleration: The desired acceleration in steps per second\n    #                          per second. Must be > 0.0. This is an\n    #                          expensive call since it requires a square\n    #                          root to be calculated on the server.\n    #                          Dont call more often than needed.\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n    #\n    #     if not 1 < acceleration <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration\n    #\n    #     max_accel_msb = acceleration >> 8\n    #     max_accel_lsb = acceleration & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n    #                max_accel_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_speed(self, motor_id, speed):\n    #     \"\"\"\n    #     Sets the desired constant speed for use with stepper_run_speed().\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param speed: 0 - 1000 The desired constant speed in steps per\n    #                   second. Positive is clockwise. Speeds of more than 1000 steps per\n    #                   second are unreliable. Speed accuracy depends on the Arduino\n    #                   crystal. Jitter depends on how frequently you call the\n    #                   stepper_run_speed() method.\n    #                   The speed will be limited by the current value of\n    #                   stepper_set_max_speed().\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n    #\n    #     if not 0 < speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['speed'] = speed\n    #\n    #     speed_msb = speed >> 8\n    #     speed_lsb = speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the  most recently set speed.\n    #     that was previously set by stepper_set_speed();\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['speed']\n    #\n    # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n    #     \"\"\"\n    #     Request the distance from the current position to the target position\n    #     from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param distance_to_go_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n    #\n    #     A positive distance is clockwise from the current position.\n    #\n    #     \"\"\"\n    #     if not distance_to_go_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n    #     self.stepper_info_list[motor_id][\n    #         'distance_to_go_callback'] = distance_to_go_callback\n    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_target_position(self, motor_id, target_callback):\n    #     \"\"\"\n    #     Request the most recently set target position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param target_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #\n    #     \"\"\"\n    #     if not target_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_target_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id][\n    #         'target_position_callback'] = target_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_current_position(self, motor_id, current_position_callback):\n    #     \"\"\"\n    #     Request the current motor position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param current_position_callback: required callback function to receive report\n    #\n    #     :return: The current motor position returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #     \"\"\"\n    #     if not current_position_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_current_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_current_position(self, motor_id, position):\n    #     \"\"\"\n    #     Resets the current position of the motor, so that wherever the motor\n    #     happens to be right now is considered to be the new 0 position. Useful\n    #     for setting a zero position on a stepper after an initial hardware\n    #     positioning move.\n    #\n    #     Has the side effect of setting the current motor speed to 0.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     :param position: Position in steps. This is a 32 bit value\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     await self._send_command(command)\n    #\n    # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     Runs the motor at the currently selected speed until the target position is\n    #     reached.\n    #\n    #     Does not implement accelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n    #                            'callback must be '\n    #                            'specified.')\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_stop(self, motor_id):\n    #     \"\"\"\n    #     Sets a new target position that causes the stepper\n    #     to stop as quickly as possible, using the current speed and\n    #     acceleration parameters.\n    #\n    #     :param motor_id:  0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_stop: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_STOP, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_disable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Disable motor pin outputs by setting them all LOW.\n    #\n    #     Depending on the design of your electronics this may turn off\n    #     the power to the motor coils, saving power.\n    #\n    #     This is useful to support Arduino low power modes: disable the outputs\n    #     during sleep and then re-enable with enableOutputs() before stepping\n    #     again.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and clears\n    #     the pin to disabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_enable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Enable motor pin outputs by setting the motor pins to OUTPUT\n    #     mode.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and sets\n    #     the pin to enabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n    #     \"\"\"\n    #     Sets the minimum pulse width allowed by the stepper driver.\n    #\n    #     The minimum practical pulse width is approximately 20 microseconds.\n    #\n    #     Times less than 20 microseconds will usually result in 20 microseconds or so.\n    #\n    #     :param motor_id: 0 -3\n    #\n    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n    #\n    #     if not 0 < minimum_width <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n    #                            '0-0xffff.')\n    #\n    #     width_msb = minimum_width >> 8\n    #     width_lsb = minimum_width & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n    #                width_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_enable_pin(self, motor_id, pin=0xff):\n    #     \"\"\"\n    #     Sets the enable pin number for stepper drivers.\n    #     0xFF indicates unused (default).\n    #\n    #     Otherwise, if a pin is set, the pin will be turned on when\n    #     enableOutputs() is called and switched off when disableOutputs()\n    #     is called.\n    #\n    #     :param motor_id: 0 - 4\n    #     :param pin: 0-0xff\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n    #\n    #     if not 0 < pin <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n    #                            '0-0xff.')\n    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n    #                                 enable=False):\n    #     \"\"\"\n    #     Sets the inversion for stepper driver pins.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param direction: True=inverted or False\n    #\n    #     :param step: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n    #                step, enable]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,\n    #                                   pin2_invert=False,\n    #                                 pin3_invert=False, pin4_invert=False, enable=False):\n    #     \"\"\"\n    #     Sets the inversion for 2, 3 and 4 wire stepper pins\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param pin1_invert: True=inverted or False\n    #\n    #     :param pin2_invert: True=inverted or False\n    #\n    #     :param pin3_invert: True=inverted or False\n    #\n    #     :param pin4_invert: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n    #                pin2_invert, pin3_invert, pin4_invert, enable]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_is_running(self, motor_id, callback):\n    #     \"\"\"\n    #     Checks to see if the motor is currently running to a target.\n    #\n    #     Callback return True if the speed is not zero or not at the target position.\n    #\n    #     :param motor_id: 0-4\n    #\n    #     :param callback: required callback function to receive report\n    #\n    #     :return: The current running state returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n    #     \"\"\"\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_is_running: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback\n    #\n    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n    #     await self._send_command(command)\n\n    async def shutdown(self):\n\"\"\"\n        This method attempts an orderly shutdown\n        If any exceptions are thrown, they are ignored.\n\n        \"\"\"\n        self.shutdown_flag = True\n\n        if self.hard_reset_on_shutdown:\n            await self.r4_hard_reset()\n        # stop all reporting - both analog and digital\n        else:\n            try:\n                command = [PrivateConstants.STOP_ALL_REPORTS]\n                await self._send_command(command)\n\n                await asyncio.sleep(.5)\n                await self.serial_port.reset_input_buffer()\n                await self.serial_port.close()\n                if self.close_loop_on_shutdown:\n                    self.loop.stop()\n            except (RuntimeError, SerialException):\n                pass\n\n    async def r4_hard_reset(self):\n\"\"\"\n        Place the r4 into hard reset\n        \"\"\"\n        command = [PrivateConstants.BOARD_HARD_RESET, 1]\n        await self._send_command(command)\n\n    async def disable_all_reporting(self):\n\"\"\"\n        Disable reporting for all digital and analog input pins\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DISABLE_ALL, 0]\n        await self._send_command(command)\n\n    async def disable_analog_reporting(self, pin):\n\"\"\"\n        Disables analog reporting for a single analog pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n        await self._send_command(command)\n\n    async def disable_digital_reporting(self, pin):\n\"\"\"\n        Disables digital reporting for a single digital pin\n\n\n        :param pin: pin number\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n        await self._send_command(command)\n\n    async def enable_analog_reporting(self, pin):\n\"\"\"\n        Enables analog reporting for the specified pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n        await self._send_command(command)\n\n    async def enable_digital_reporting(self, pin):\n\"\"\"\n        Enable reporting on the specified digital pin.\n\n        :param pin: Pin number.\n        \"\"\"\n\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n        await self._send_command(command)\n\n    async def _arduino_report_dispatcher(self):\n\"\"\"\n        This is a private method.\n        It continually accepts and interprets data coming from Telemetrix4Arduino,and then\n        dispatches the correct handler to process the data.\n\n        It first receives the length of the packet, and then reads in the rest of the\n        packet. A packet consists of a length, report identifier and then the report data.\n        Using the report identifier, the report handler is fetched from report_dispatch.\n\n        :returns: This method never returns\n        \"\"\"\n\n        while True:\n            if self.shutdown_flag:\n                break\n            try:\n                packet_length = await self.serial_port.read()\n            except TypeError:\n                continue\n\n            # get the rest of the packet\n            packet = await self.serial_port.read(packet_length)\n\n            report = packet[0]\n            # print(report)\n            # handle all other messages by looking them up in the\n            # command dictionary\n\n            await self.report_dispatch[report](packet[1:])\n            await asyncio.sleep(self.sleep_tune)\n\n'''\n    Report message handlers\n    '''\n\n    async def _report_loop_data(self, data):\n\"\"\"\n        Print data that was looped back\n\n        :param data: byte of loop back data\n        \"\"\"\n        if self.loop_back_callback:\n            await self.loop_back_callback(data)\n\n    async def _spi_report(self, report):\n\n        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n        cb_list.append(time.time())\n\n        await self.spi_callback(cb_list)\n\n    async def _onewire_report(self, report):\n        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n        cb_list.append(time.time())\n        await self.onewire_callback(cb_list)\n\n    async def _report_debug_data(self, data):\n\"\"\"\n        Print debug data sent from Arduino\n\n        :param data: data[0] is a byte followed by 2\n                     bytes that comprise an integer\n        \"\"\"\n        value = (data[1] << 8) + data[2]\n        print(f'DEBUG ID: {data[0]} Value: {value}')\n\n    async def _analog_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for analog messages.\n\n        :param data: message data\n\n        \"\"\"\n        pin = data[0]\n        value = (data[1] << 8) + data[2]\n\n        time_stamp = time.time()\n\n        # append pin number, pin value, and pin type to return value and return as a list\n        message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]\n\n        await self.analog_callbacks[pin](message)\n\n    async def _dht_report(self, data):\n\"\"\"\n        This is a private message handler for dht reports\n\n        :param data:            data[0] = report error return\n                                    No Errors = 0\n\n                                    Checksum Error = 1\n\n                                    Timeout Error = 2\n\n                                    Invalid Value = 999\n\n                                data[1] = pin number\n\n                                data[2] = dht type 11 or 22\n\n                                data[3] = humidity positivity flag\n\n                                data[4] = temperature positivity value\n\n                                data[5] = humidity integer\n\n                                data[6] = humidity fractional value\n\n                                data[7] = temperature integer\n\n                                data[8] = temperature fractional value\n        \"\"\"\n        if data[0]:  # DHT_ERROR\n            # error report\n            # data[0] = report sub type, data[1] = pin, data[2] = error message\n            if self.dht_callbacks[data[1]]:\n                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                           time.time()]\n                await self.dht_callbacks[data[1]](message)\n        else:\n            # got valid data DHT_DATA\n            f_humidity = float(data[5] + data[6] / 100)\n            if data[3]:\n                f_humidity *= -1.0\n            f_temperature = float(data[7] + data[8] / 100)\n            if data[4]:\n                f_temperature *= -1.0\n            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                       f_humidity, f_temperature, time.time()]\n\n            await self.dht_callbacks[data[1]](message)\n\n    async def _digital_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for Digital Messages.\n\n        :param data: digital message\n\n        \"\"\"\n        pin = data[0]\n        value = data[1]\n\n        time_stamp = time.time()\n        if self.digital_callbacks[pin]:\n            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n            await self.digital_callbacks[pin](message)\n\n    async def _servo_unavailable(self, report):\n\"\"\"\n        Message if no servos are available for use.\n\n        :param report: pin number\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n    async def _i2c_read_report(self, data):\n\"\"\"\n        Execute callback for i2c reads.\n\n        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n        \"\"\"\n\n        # we receive [# data bytes, address, register, data bytes]\n        # number of bytes of data returned\n\n        # data[0] = number of bytes\n        # data[1] = i2c_port\n        # data[2] = number of bytes returned\n        # data[3] = address\n        # data[4] = register\n        # data[5] ... all the data bytes\n\n        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n        cb_list.append(time.time())\n\n        if cb_list[1]:\n            await self.i2c_callback2(cb_list)\n        else:\n            await self.i2c_callback(cb_list)\n\n    async def _i2c_too_few(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    async def _i2c_too_many(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    async def _sonar_distance_report(self, report):\n\"\"\"\n\n        :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n        \"\"\"\n\n        # get callback from pin number\n        cb = self.sonar_callbacks[report[0]]\n\n        # build report data\n        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n                   ((report[1] << 8) + report[2]), time.time()]\n\n        await cb(cb_list)\n\n    async def _stepper_distance_to_go_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper distance to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n    #                              data[3] = steps bytes 2, data[4] = steps LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n    #                              steps, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     steps = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n\n    async def _stepper_target_position_report(self, report):\n        return  # for now\n\n    #     \"\"\"\n    #     Report stepper target position to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = target position MSB,\n    #                    data[2] = target position byte MSB+1\n    #                    data[3] = target position byte MSB+2\n    #                    data[4] = target position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n    #                              target_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['target_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     target = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     target_position = int.from_bytes(target, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n    async def _stepper_current_position_report(self, report):\n        return  # for now\n\n    #     \"\"\"\n    #     Report stepper current position.\n    #\n    #     :param report: data[0] = motor_id, data[1] = current position MSB,\n    #                    data[2] = current position byte MSB+1\n    #                    data[3] = current position byte MSB+2\n    #                    data[4] = current position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n    #                              current_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['current_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     position = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     current_position = int.from_bytes(position, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n    async def _stepper_is_running_report(self, report):\n        return  # for now\n\n    #     \"\"\"\n    #     Report if the motor is currently running\n    #\n    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.\n    #\n    #     callback report format: [18, motor_id,\n    #                              running_state, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['is_running_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n    #\n    #     await cb(cb_list)\n    #\n    async def _stepper_run_complete_report(self, report):\n        return  # for now\n\n    #     \"\"\"\n    #     The motor completed it motion\n    #\n    #     :param report: data[0] = motor_id\n    #\n    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n    #                              time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n\n    async def _features_report(self, report):\n        self.reported_features = report[0]\n\n    async def _send_command(self, command):\n\"\"\"\n        This is a private utility method.\n\n\n        :param command:  command data in the form of a list\n\n        :returns: number of bytes sent\n        \"\"\"\n        # the length of the list is added at the head\n        command.insert(0, len(command))\n        # print(command)\n        send_message = bytes(command)\n\n        await self.serial_port.write(send_message)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True)","text":"

If you have a single Arduino connected to your computer, then you may accept all the default values.

Otherwise, specify a unique arduino_instance id for each board in use.

:param com_port: e.g. COM3 or /dev/ttyACM0.

:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch

:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.

:param sleep_tune: A tuning parameter (typically not changed by user)

:param autostart: If you wish to call the start method within your application, then set this to False.

:param loop: optional user provided event loop

:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception

:param close_loop_on_shutdown: stop and close the event loop loop when a shutdown is called or a serial error occurs

:param hard_reset_on_shutdown: reset the board on shutdown

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
def __init__(self, com_port=None,\n             arduino_instance_id=1, arduino_wait=1,\n             sleep_tune=0.0001, autostart=True,\n             loop=None, shutdown_on_exception=True,\n             close_loop_on_shutdown=True, hard_reset_on_shutdown=True):\n\n\"\"\"\n    If you have a single Arduino connected to your computer,\n    then you may accept all the default values.\n\n    Otherwise, specify a unique arduino_instance id for each board in use.\n\n    :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n    :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n    :param arduino_wait: Amount of time to wait for an Arduino to\n                         fully reset itself.\n\n    :param sleep_tune: A tuning parameter (typically not changed by user)\n\n    :param autostart: If you wish to call the start method within\n                      your application, then set this to False.\n\n    :param loop: optional user provided event loop\n\n    :param shutdown_on_exception: call shutdown before raising\n                                  a RunTimeError exception, or\n                                  receiving a KeyboardInterrupt exception\n\n    :param close_loop_on_shutdown: stop and close the event loop loop\n                                   when a shutdown is called or a serial\n                                   error occurs\n\n   :param hard_reset_on_shutdown: reset the board on shutdown\n\n    \"\"\"\n    # check to make sure that Python interpreter is version 3.8.3 or greater\n    python_version = sys.version_info\n    if python_version[0] >= 3:\n        if python_version[1] >= 8:\n            if python_version[2] >= 3:\n                pass\n        else:\n            raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                               \"required for use of this program.\")\n\n    # save input parameters\n    self.com_port = com_port\n    self.arduino_instance_id = arduino_instance_id\n    self.arduino_wait = arduino_wait\n    self.sleep_tune = sleep_tune\n    self.autostart = autostart\n    self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n    # set the event loop\n    if loop is None:\n        self.loop = asyncio.get_event_loop()\n    else:\n        self.loop = loop\n\n    self.shutdown_on_exception = shutdown_on_exception\n    self.close_loop_on_shutdown = close_loop_on_shutdown\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    # debug loopback callback method\n    self.loop_back_callback = None\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    self.dht_count = 0\n\n    # serial port in use\n    self.serial_port = None\n\n    # generic asyncio task holder\n    self.the_task = None\n\n    # flag to indicate we are in shutdown mode\n    self.shutdown_flag = False\n\n    self.report_dispatch = {}\n\n    # reported features\n    self.reported_features = 0\n\n    # To add a command to the command dispatch table, append here.\n    self.report_dispatch.update(\n        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n    self.report_dispatch.update(\n        {PrivateConstants.ANALOG_REPORT: self._analog_message})\n    self.report_dispatch.update(\n        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n    self.report_dispatch.update(\n        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n    self.report_dispatch.update(\n        {PrivateConstants.SPI_REPORT: self._spi_report})\n    self.report_dispatch.update(\n        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_CURRENT_POSITION:\n             self._stepper_current_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUNNING_REPORT:\n             self._stepper_is_running_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n             self._stepper_run_complete_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.FEATURES:\n             self._features_report})\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    self.cs_pins_enabled = []\n\n    # flag to indicate if spi is initialized\n    self.spi_enabled = False\n\n    # flag to indicate if onewire is initialized\n    self.onewire_enabled = False\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    # # stepper motor variables\n    #\n    # # updated when a new motor is added\n    # self.next_stepper_assigned = 0\n    #\n    # # valid list of stepper motor interface types\n    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n    #\n    # # maximum number of steppers supported\n    # self.max_number_of_steppers = 4\n    #\n    # # number of steppers created - not to exceed the maximum\n    # self.number_of_steppers = 0\n    #\n    # # dictionary to hold stepper motor information\n    # self.stepper_info = {'instance': False, 'is_running': None,\n    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n    #                      'distance_to_go_callback': None,\n    #                      'target_position_callback': None,\n    #                      'current_position_callback': None,\n    #                      'is_running_callback': None,\n    #                      'motion_complete_callback': None,\n    #                      'acceleration_callback': None}\n    #\n    # # build a list of stepper motor info items\n    # self.stepper_info_list = []\n    # # a list of dictionaries to hold stepper information\n    # for motor in range(self.max_number_of_steppers):\n    #     self.stepper_info_list.append(self.stepper_info)\n\n    print(f'telemetrix_uno_r4_minima_aio Version:'\n          f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')\n    print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n    if autostart:\n        self.loop.run_until_complete(self.start_aio())\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.analog_write","title":"analog_write(pin, value) async","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (maximum 16 bits)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def analog_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (maximum 16 bits)\n\n    \"\"\"\n    value_msb = value >> 8\n    value_lsb = value & 0xff\n    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.digital_write","title":"digital_write(pin, value) async","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (1 or 0)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def digital_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (1 or 0)\n\n    \"\"\"\n    command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_all_reporting","title":"disable_all_reporting() async","text":"

Disable reporting for all digital and analog input pins

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_all_reporting(self):\n\"\"\"\n    Disable reporting for all digital and analog input pins\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DISABLE_ALL, 0]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_analog_reporting","title":"disable_analog_reporting(pin) async","text":"

Disables analog reporting for a single analog pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_analog_reporting(self, pin):\n\"\"\"\n    Disables analog reporting for a single analog pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.disable_digital_reporting","title":"disable_digital_reporting(pin) async","text":"

Disables digital reporting for a single digital pin

:param pin: pin number

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def disable_digital_reporting(self, pin):\n\"\"\"\n    Disables digital reporting for a single digital pin\n\n\n    :param pin: pin number\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.enable_analog_reporting","title":"enable_analog_reporting(pin) async","text":"

Enables analog reporting for the specified pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def enable_analog_reporting(self, pin):\n\"\"\"\n    Enables analog reporting for the specified pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.enable_digital_reporting","title":"enable_digital_reporting(pin) async","text":"

Enable reporting on the specified digital pin.

:param pin: Pin number.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def enable_digital_reporting(self, pin):\n\"\"\"\n    Enable reporting on the specified digital pin.\n\n    :param pin: Pin number.\n    \"\"\"\n\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.get_event_loop","title":"get_event_loop() async","text":"

Return the currently active asyncio event loop

:return: Active event loop

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def get_event_loop(self):\n\"\"\"\n    Return the currently active asyncio event loop\n\n    :return: Active event loop\n\n    \"\"\"\n    return self.loop\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) async","text":"

Read the specified number of bytes from the specified register for the i2c device.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: select the default port (0) or secondary port (1)

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_read(self, address, register, number_of_bytes,\n                   callback, i2c_port=0,\n                   write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified register for\n    the i2c device.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c data as a\n               result of read command\n\n    :param i2c_port: select the default port (0) or secondary port (1)\n\n    :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('i2c_read: A Callback must be specified')\n\n    await self._i2c_read_request(address, register, number_of_bytes,\n                                 callback=callback, i2c_port=i2c_port,\n                                 write_register=write_register)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) async","text":"

Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: select the default port (0) or secondary port (1)

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_read_restart_transmission(self, address, register,\n                                        number_of_bytes,\n                                        callback, i2c_port=0,\n                                        write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified register for\n    the i2c device. This restarts the transmission after the read. It is\n    required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                                selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c data as a\n               result of read command\n\n    :param i2c_port: select the default port (0) or secondary port (1)\n\n    :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'i2c_read_restart_transmission: A Callback must be specified')\n\n    await self._i2c_read_request(address, register, number_of_bytes,\n                                 stop_transmission=False,\n                                 callback=callback, i2c_port=i2c_port,\n                                 write_register=write_register)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.i2c_write","title":"i2c_write(address, args, i2c_port=0) async","text":"

Write data to an i2c device.

:param address: i2c device address

:param i2c_port: 0= port 1, 1 = port 2

:param args: A variable number of bytes to be sent to the device passed in as a list

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n    Write data to an i2c device.\n\n    :param address: i2c device address\n\n    :param i2c_port: 0= port 1, 1 = port 2\n\n    :param args: A variable number of bytes to be sent to the device\n                 passed in as a list\n\n    \"\"\"\n    if not i2c_port:\n        if not self.i2c_1_active:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n    if i2c_port:\n        if not self.i2c_2_active:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n    for item in args:\n        command.append(item)\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.loop_back","title":"loop_back(start_character, callback) async","text":"

This is a debugging method to send a character to the Arduino device, and have the device loop it back.

:param start_character: The character to loop back. It should be an integer.

:param callback: Looped back character will appear in the callback method

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def loop_back(self, start_character, callback):\n\"\"\"\n    This is a debugging method to send a character to the\n    Arduino device, and have the device loop it back.\n\n    :param start_character: The character to loop back. It should be\n                            an integer.\n\n    :param callback: Looped back character will appear in the callback method\n\n    \"\"\"\n\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('loop_back: A callback function must be specified.')\n    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n    self.loop_back_callback = callback\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.r4_hard_reset","title":"r4_hard_reset() async","text":"

Place the r4 into hard reset

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def r4_hard_reset(self):\n\"\"\"\n    Place the r4 into hard reset\n    \"\"\"\n    command = [PrivateConstants.BOARD_HARD_RESET, 1]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.servo_detach","title":"servo_detach(pin_number) async","text":"

Detach a servo for reuse :param pin_number: attached pin

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def servo_detach(self, pin_number):\n\"\"\"\n    Detach a servo for reuse\n    :param pin_number: attached pin\n    \"\"\"\n    command = [PrivateConstants.SERVO_DETACH, pin_number]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.servo_write","title":"servo_write(pin_number, angle) async","text":"

Set a servo attached to a pin to a given angle.

:param pin_number: pin

:param angle: angle (0-180)

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def servo_write(self, pin_number, angle):\n\"\"\"\n\n    Set a servo attached to a pin to a given angle.\n\n    :param pin_number: pin\n\n    :param angle: angle (0-180)\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_analog_scan_interval","title":"set_analog_scan_interval(interval) async","text":"

Set the analog scanning interval.

:param interval: value of 0 - 255 - milliseconds

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_analog_scan_interval(self, interval):\n\"\"\"\n    Set the analog scanning interval.\n\n    :param interval: value of 0 - 255 - milliseconds\n    \"\"\"\n\n    if 0 <= interval <= 255:\n        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None) async","text":"

Set a pin as an analog input.

:param pin_number: arduino pin number

:param callback: async callback function

:param differential: difference in previous to current value before report will be generated

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for analog input pins = 3

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n    Set a pin as an analog input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    :param differential: difference in previous to current value before\n                         report will be generated\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for analog input pins = 3\n\n    \"\"\"\n\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'set_pin_mode_analog_input: A callback function must be specified.')\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n                             differential, callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number) async","text":"

Set a pin as a pwm (analog output) pin.

:param pin_number:arduino pin number

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n    Set a pin as a pwm (analog output) pin.\n\n    :param pin_number:arduino pin number\n\n    \"\"\"\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                             callback=None)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22) async","text":"

:param pin: connection pin

:param callback: callback function

:param dht_type: either 22 for DHT22 or 11 for DHT11

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n    :param pin: connection pin\n\n    :param callback: callback function\n\n    :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n    Temperature,\n    Time]\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n        if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n            self.dht_callbacks[pin] = callback\n            self.dht_count += 1\n\n            if dht_type != 22 and dht_type != 11:\n                dht_type = 22\n\n            command = [PrivateConstants.DHT_NEW, pin, dht_type]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback) async","text":"

Set a pin as a digital input.

:param pin_number: arduino pin number

:param callback: async callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n    Set a pin as a digital input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n                             callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback) async","text":"

Set a pin as a digital input with pullup enabled.

:param pin_number: arduino pin number

:param callback: async callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n    Set a pin as a digital input with pullup enabled.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                             differential=0, callback=callback)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number) async","text":"

Set a pin as a digital output pin.

:param pin_number: arduino pin number

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n    Set a pin as a digital output pin.\n\n    :param pin_number: arduino pin number\n    \"\"\"\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                             callback=None)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0) async","text":"

Establish the standard Arduino i2c pins for i2c utilization.

:param i2c_port: 0 = i2c1, 1 = i2c2

  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  1. Callbacks are set within the individual i2c read methods of this
  API.\n\n  See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n    Establish the standard Arduino i2c pins for i2c utilization.\n\n    :param i2c_port: 0 = i2c1, 1 = i2c2\n\n    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n           2. Callbacks are set within the individual i2c read methods of this\n          API.\n\n          See i2c_read, or i2c_read_restart_transmission.\n\n    \"\"\"\n    # test for i2c port 2\n    if i2c_port:\n        # if not previously activated set it to activated\n        # and the send a begin message for this port\n        if not self.i2c_2_active:\n            self.i2c_2_active = True\n        else:\n            return\n    # port 1\n    else:\n        if not self.i2c_1_active:\n            self.i2c_1_active = True\n        else:\n            return\n\n    command = [PrivateConstants.I2C_BEGIN, i2c_port]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) async","text":"

Attach a pin to a servo motor

:param pin_number: pin

:param min_pulse: minimum pulse width

:param max_pulse: maximum pulse width

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n    Attach a pin to a servo motor\n\n    :param pin_number: pin\n\n    :param min_pulse: minimum pulse width\n\n    :param max_pulse: maximum pulse width\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n        minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n        maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n        command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                   minv[0], minv[1], maxv[0], maxv[1]]\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback) async","text":"

:param trigger_pin:

:param echo_pin:

:param callback: callback

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                             callback):\n\"\"\"\n\n    :param trigger_pin:\n\n    :param echo_pin:\n\n    :param callback:  callback\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n            self.sonar_callbacks[trigger_pin] = callback\n            self.sonar_count += 1\n\n            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None) async","text":"

Specify the list of chip select pins.

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

Chip Select is any digital output capable pin.

:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!

command message: [command, number of cs pins, [cs pins...]]

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n    Specify the list of chip select pins.\n\n    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n    Chip Select is any digital output capable pin.\n\n    :param chip_select_list: this is a list of pins to be used for chip select.\n                       The pins will be configured as output, and set to high\n                       ready to be used for chip select.\n                       NOTE: You must specify the chips select pins here!\n\n\n    command message: [command, number of cs pins, [cs pins...]]\n    \"\"\"\n    if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n        if type(chip_select_list) != list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('chip_select_list must be in the form of a list')\n        if not chip_select_list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('Chip select pins were not specified')\n\n        self.spi_enabled = True\n\n        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n        for pin in chip_select_list:\n            command.append(pin)\n            self.cs_pins_enabled.append(pin)\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.shutdown","title":"shutdown() async","text":"

This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def shutdown(self):\n\"\"\"\n    This method attempts an orderly shutdown\n    If any exceptions are thrown, they are ignored.\n\n    \"\"\"\n    self.shutdown_flag = True\n\n    if self.hard_reset_on_shutdown:\n        await self.r4_hard_reset()\n    # stop all reporting - both analog and digital\n    else:\n        try:\n            command = [PrivateConstants.STOP_ALL_REPORTS]\n            await self._send_command(command)\n\n            await asyncio.sleep(.5)\n            await self.serial_port.reset_input_buffer()\n            await self.serial_port.close()\n            if self.close_loop_on_shutdown:\n                self.loop.stop()\n        except (RuntimeError, SerialException):\n            pass\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.sonar_disable","title":"sonar_disable() async","text":"

Disable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def sonar_disable(self):\n\"\"\"\n    Disable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_DISABLE]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.sonar_enable","title":"sonar_enable() async","text":"

Enable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def sonar_enable(self):\n\"\"\"\n    Enable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_ENABLE]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_cs_control","title":"spi_cs_control(chip_select_pin, select) async","text":"

Control an SPI chip select line :param chip_select_pin: pin connected to CS

:param select: 0=select, 1=deselect

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n    Control an SPI chip select line\n    :param chip_select_pin: pin connected to CS\n\n    :param select: 0=select, 1=deselect\n    \"\"\"\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n    if chip_select_pin not in self.cs_pins_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) async","text":"

Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.

:param chip_select: chip select pin

:param register_selection: Register to be selected for read.

:param number_of_bytes_to_read: Number of bytes to read

:param call_back: Required callback function to report spi data as a result of read command

callback returns a data list

[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]

SPI_READ_REPORT = 13

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_read_blocking(self, chip_select, register_selection,\n                            number_of_bytes_to_read,\n                      call_back=None):\n\"\"\"\n    Read the specified number of bytes from the specified SPI port and\n    call the callback function with the reported data.\n\n    :param chip_select: chip select pin\n\n    :param register_selection: Register to be selected for read.\n\n    :param number_of_bytes_to_read: Number of bytes to read\n\n    :param call_back: Required callback function to report spi data as a\n               result of read command\n\n\n    callback returns a data list:\n        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n         data bytes, time-stamp]\n    SPI_READ_REPORT = 13\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n    if not call_back:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n    self.spi_callback = call_back\n\n    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n               number_of_bytes_to_read,\n               register_selection]\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode) async","text":"

Configure how the SPI serializes and de-serializes data on the wire.

See Arduino SPI reference materials for details.

:param clock_divisor: 1 - 255

:param bit_order:

                LSBFIRST = 0\n\n                MSBFIRST = 1 (default)\n

:param data_mode:

                SPI_MODE0 = 0x00 (default)\n\n                SPI_MODE1  = 1\n\n                SPI_MODE2 = 2\n\n                SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n    Configure how the SPI serializes and de-serializes data on the wire.\n\n    See Arduino SPI reference materials for details.\n\n    :param clock_divisor: 1 - 255\n\n    :param bit_order:\n\n                        LSBFIRST = 0\n\n                        MSBFIRST = 1 (default)\n\n    :param data_mode:\n\n                        SPI_MODE0 = 0x00 (default)\n\n                        SPI_MODE1  = 1\n\n                        SPI_MODE2 = 2\n\n                        SPI_MODE3 = 3\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n    if not 0 < clock_divisor <= 255:\n        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n    if bit_order not in [0, 1]:\n        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n    if data_mode not in [0, 1, 2, 3]:\n        raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n               data_mode]\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write) async","text":"

Write a list of bytes to the SPI device.

:param chip_select: chip select pin

:param bytes_to_write: A list of bytes to write. This must be in the form of a list.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n    Write a list of bytes to the SPI device.\n\n    :param chip_select: chip select pin\n\n    :param bytes_to_write: A list of bytes to write. This must\n                            be in the form of a list.\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n    if type(bytes_to_write) is not list:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n    for data in bytes_to_write:\n        command.append(data)\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_minima_reference_aio/#telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio.start_aio","title":"start_aio() async","text":"

This method may be called directly, if the autostart parameter in init is set to false.

This method instantiates the serial interface and then performs auto pin discovery if using a serial interface, or creates and connects to a TCP/IP enabled device running StandardFirmataWiFi.

Use this method if you wish to start TelemetrixAIO manually from an asyncio function.

Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py
async def start_aio(self):\n\"\"\"\n    This method may be called directly, if the autostart\n    parameter in __init__ is set to false.\n\n    This method instantiates the serial interface and then performs auto pin\n    discovery if using a serial interface, or creates and connects to\n    a TCP/IP enabled device running StandardFirmataWiFi.\n\n    Use this method if you wish to start TelemetrixAIO manually from\n    an asyncio function.\n     \"\"\"\n\n    if not self.com_port:\n        # user did not specify a com_port\n        try:\n            await self._find_arduino()\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n    else:\n        # com_port specified - set com_port and baud rate\n        try:\n            await self._manual_open()\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n\n    if self.com_port:\n        print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')\n\n        # no com_port found - raise a runtime exception\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('No Arduino Found or User Aborted Program')\n\n    # get arduino firmware version and print it\n    firmware_version = await self._get_firmware_version()\n    if not firmware_version:\n        print('*** Firmware Version retrieval timed out. ***')\n        print('\\nDo you have Arduino connectivity and do you have the ')\n        print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n        print('to the correct serial port.\\n')\n        print('To see a list of serial ports, type: '\n              '\"list_serial_ports\" in your console.')\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError\n    else:\n\n        print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n              f'{firmware_version[3]}.{firmware_version[4]}')\n        # start the command dispatcher loop\n        command = [PrivateConstants.ENABLE_ALL_REPORTS]\n        await self._send_command(command)\n        if not self.loop:\n            self.loop = asyncio.get_event_loop()\n        self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n        # get the features list\n        command = [PrivateConstants.GET_FEATURES]\n        await self._send_command(command)\n        await asyncio.sleep(.5)\n\n        # Have the server reset its data structures\n        command = [PrivateConstants.RESET]\n        await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/","title":"telemetrix_uno_r4_wifi","text":"

Copyright (c) 2023 Alan Yorinks All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi","title":"TelemetrixUnoR4WiFi","text":"

Bases: threading.Thread

This class exposes and implements the telemetrix API. It uses threading to accommodate concurrency. It includes the public API methods as well as a set of private methods.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
class TelemetrixUnoR4WiFi(threading.Thread):\n\"\"\"\n    This class exposes and implements the telemetrix API.\n    It uses threading to accommodate concurrency.\n    It includes the public API methods as well as\n    a set of private methods.\n\n    \"\"\"\n\n    # noinspection PyPep8,PyPep8,PyPep8\n    def __init__(self, com_port=None, arduino_instance_id=1,\n                 arduino_wait=1, sleep_tune=0.000001,\n                 shutdown_on_exception=True, hard_reset_on_shutdown=True,\n                 transport_address=None, ip_port=31336, transport_type=0):\n\n\"\"\"\n\n        :param com_port: e.g. COM3 or /dev/ttyACM0.\n                         Only use if you wish to bypass auto com port\n                         detection.\n\n        :param arduino_instance_id: Match with the value installed on the\n                                    arduino-telemetrix sketch.\n\n        :param arduino_wait: Amount of time to wait for an Arduino to\n                             fully reset itself.\n\n        :param sleep_tune: A tuning parameter (typically not changed by user)\n\n        :param shutdown_on_exception: call shutdown before raising\n                                      a RunTimeError exception, or\n                                      receiving a KeyboardInterrupt exception\n\n        :param hard_reset_on_shutdown: reset the board on shutdown\n\n        :param transport_address: ip address of tcp/ip connected device.\n\n        :param ip_port: ip port of tcp/ip connected device\n\n        :param transport_type: 0 = WiFI\n                               1 = USBSerial\n                               2 = BLE\n\n\n        \"\"\"\n\n        # initialize threading parent\n        threading.Thread.__init__(self)\n\n        # create the threads and set them as daemons so\n        # that they stop when the program is closed\n\n        # create a thread to interpret received serial data\n        self.the_reporter_thread = threading.Thread(target=self._reporter)\n        self.the_reporter_thread.daemon = True\n\n        self.transport_address = transport_address\n        self.ip_port = ip_port\n\n        if transport_type not in [0, 1, 2]:\n            raise RuntimeError(\"Valid transport_type value is 0, 1, or 2\")\n\n        self.transport_type = transport_type\n\n        if transport_type == 0:\n            if not transport_address:\n                raise RuntimeError(\"An IP address must be specified.\")\n\n        if not self.transport_address:\n            self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n        else:\n            self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)\n\n        self.the_data_receive_thread.daemon = True\n\n        # flag to allow the reporter and receive threads to run.\n        self.run_event = threading.Event()\n\n        # check to make sure that Python interpreter is version 3.7 or greater\n        python_version = sys.version_info\n        if python_version[0] >= 3:\n            if python_version[1] >= 7:\n                pass\n            else:\n                raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                                   \"required for use of this program.\")\n\n        # save input parameters as instance variables\n        self.com_port = com_port\n        self.arduino_instance_id = arduino_instance_id\n        self.arduino_wait = arduino_wait\n        self.sleep_tune = sleep_tune\n        self.shutdown_on_exception = shutdown_on_exception\n        self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n        # create a deque to receive and process data from the arduino\n        self.the_deque = deque()\n\n        # The report_dispatch dictionary is used to process\n        # incoming report messages by looking up the report message\n        # and executing its associated processing method.\n\n        self.report_dispatch = {}\n\n        # To add a command to the command dispatch table, append here.\n        self.report_dispatch.update(\n            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n        self.report_dispatch.update(\n            {PrivateConstants.ANALOG_REPORT: self._analog_message})\n        self.report_dispatch.update(\n            {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n        self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n        self.report_dispatch.update(\n            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n        self.report_dispatch.update(\n            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n        self.report_dispatch.update(\n            {PrivateConstants.SPI_REPORT: self._spi_report})\n        self.report_dispatch.update(\n            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_CURRENT_POSITION:\n                 self._stepper_current_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUNNING_REPORT:\n                 self._stepper_is_running_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n                 self._stepper_run_complete_report})\n\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.FEATURES:\n                 self._features_report})\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        self.cs_pins_enabled = []\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        self.dht_count = 0\n\n        # serial port in use\n        self.serial_port = None\n\n        # socket for tcp/ip communications\n        self.sock = None\n\n        # flag to indicate we are in shutdown mode\n        self.shutdown_flag = False\n\n        # debug loopback callback method\n        self.loop_back_callback = None\n\n        # flag to indicate the start of a new report\n        # self.new_report_start = True\n\n        # firmware version to be stored here\n        self.firmware_version = []\n\n        # reported arduino instance id\n        self.reported_arduino_id = []\n\n        # reported features\n        self.reported_features = 0\n\n        # flag to indicate if i2c was previously enabled\n        self.i2c_enabled = False\n\n        # flag to indicate if spi is initialized\n        self.spi_enabled = False\n\n        # flag to indicate if onewire is initialized\n        self.onewire_enabled = False\n\n        # stepper motor variables\n\n        # updated when a new motor is added\n        # self.next_stepper_assigned = 0\n        #\n        # # valid list of stepper motor interface types\n        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n        #\n        # # maximum number of steppers supported\n        # self.max_number_of_steppers = 4\n        #\n        # # number of steppers created - not to exceed the maximum\n        # self.number_of_steppers = 0\n        #\n        # # dictionary to hold stepper motor information\n        # self.stepper_info = {'instance': False, 'is_running': None,\n        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n        #                      'distance_to_go_callback': None,\n        #                      'target_position_callback': None,\n        #                      'current_position_callback': None,\n        #                      'is_running_callback': None,\n        #                      'motion_complete_callback': None,\n        #                      'acceleration_callback': None}\n        #\n        # # build a list of stepper motor info items\n        # self.stepper_info_list = []\n        # # a list of dictionaries to hold stepper information\n        # for motor in range(self.max_number_of_steppers):\n        #     self.stepper_info_list.append(self.stepper_info)\n\n        self.the_reporter_thread.start()\n        self.the_data_receive_thread.start()\n\n        print(f\"telemetrix_uno_r4_wifi:  Version\"\n              f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n              f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n        # using the serial link\n        if not self.transport_address:\n            if not self.com_port:\n                # user did not specify a com_port\n                try:\n                    self._find_arduino()\n                except KeyboardInterrupt:\n                    if self.shutdown_on_exception:\n                        self.shutdown()\n            else:\n                # com_port specified - set com_port and baud rate\n                try:\n                    self._manual_open()\n                except KeyboardInterrupt:\n                    if self.shutdown_on_exception:\n                        self.shutdown()\n\n            if self.serial_port:\n                print(\n                    f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n                self.serial_port.reset_input_buffer()\n                self.serial_port.reset_output_buffer()\n                self.disable_scroll_message()\n\n            # no com_port found - raise a runtime exception\n            else:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('No Arduino Found or User Aborted Program')\n        else:\n            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n            self.sock.connect((self.transport_address, self.ip_port))\n            print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')\n\n        # allow the threads to run\n        self._run_threads()\n        print(f'Waiting for Arduino to reset')\n        print(f'Reset Complete')\n\n        # get telemetrix firmware version and print it\n        print('\\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')\n        self._get_firmware_version()\n        if not self.firmware_version:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')\n\n        else:\n\n            print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'\n                  f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n        command = [PrivateConstants.ENABLE_ALL_REPORTS]\n        self._send_command(command)\n\n        # get the features list\n        command = [PrivateConstants.GET_FEATURES]\n        self._send_command(command)\n        time.sleep(.2)\n\n        # Have the server reset its data structures\n        command = [PrivateConstants.RESET]\n        self._send_command(command)\n        time.sleep(.2)\n\n    def _find_arduino(self):\n\"\"\"\n        This method will search all potential serial ports for an Arduino\n        containing a sketch that has a matching arduino_instance_id as\n        specified in the input parameters of this class.\n\n        This is used explicitly with the Telemetrix4Arduino sketch.\n        \"\"\"\n\n        # a list of serial ports to be checked\n        serial_ports = []\n\n        print('Opening all potential serial ports...')\n        the_ports_list = list_ports.comports()\n        for port in the_ports_list:\n            if port.pid is None:\n                continue\n            try:\n                self.serial_port = serial.Serial(port.device, 115200,\n                                                 timeout=1, writeTimeout=0)\n            except SerialException:\n                continue\n            # create a list of serial ports that we opened\n            serial_ports.append(self.serial_port)\n\n            # display to the user\n            print('\\t' + port.device)\n\n            # clear out any possible data in the input buffer\n        # wait for arduino to reset\n        print(\n            f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n            'reset...')\n        # temporary for testing\n        time.sleep(self.arduino_wait)\n        self._run_threads()\n\n        for serial_port in serial_ports:\n            self.serial_port = serial_port\n\n            self._get_arduino_id()\n            if self.reported_arduino_id != self.arduino_instance_id:\n                continue\n            else:\n                print('Valid Arduino ID Found.')\n                self.serial_port.reset_input_buffer()\n                self.serial_port.reset_output_buffer()\n                return\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n\n    def _manual_open(self):\n\"\"\"\n        Com port was specified by the user - try to open up that port\n\n        \"\"\"\n        # if port is not found, a serial exception will be thrown\n        try:\n            print(f'Opening {self.com_port}...')\n            self.serial_port = serial.Serial(self.com_port, 115200,\n                                             timeout=1, writeTimeout=0)\n\n            print(\n                f'\\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '\n                'reset...')\n            self._run_threads()\n            time.sleep(self.arduino_wait)\n\n            self._get_arduino_id()\n\n            if self.reported_arduino_id != self.arduino_instance_id:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')\n            print('Valid Arduino ID Found.')\n            # get arduino firmware version and print it\n            print('\\nRetrieving Telemetrix4Arduino firmware ID...')\n            self._get_firmware_version()\n\n            if not self.firmware_version:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Telemetrix4Arduino Sketch Firmware Version Not Found')\n\n            else:\n                print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'\n                      f'{self.firmware_version[1]}')\n        except KeyboardInterrupt:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('User Hit Control-C')\n\n    def analog_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (maximum 16 bits)\n\n        \"\"\"\n        value_msb = value >> 8\n        value_lsb = value & 0xff\n        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n        self._send_command(command)\n\n    def digital_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (1 or 0)\n\n        \"\"\"\n\n        command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n        self._send_command(command)\n\n    def disable_all_reporting(self):\n\"\"\"\n        Disable reporting for all digital and analog input pins\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DISABLE_ALL, 0]\n        self._send_command(command)\n\n    def disable_analog_reporting(self, pin):\n\"\"\"\n        Disables analog reporting for a single analog pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n        self._send_command(command)\n\n    def disable_digital_reporting(self, pin):\n\"\"\"\n        Disables digital reporting for a single digital input.\n\n        :param pin: Pin number.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n        self._send_command(command)\n\n    def enable_analog_reporting(self, pin):\n\"\"\"\n        Enables analog reporting for the specified pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n        self._send_command(command)\n\n    def enable_digital_reporting(self, pin):\n\"\"\"\n        Enable reporting on the specified digital pin.\n\n        :param pin: Pin number.\n        \"\"\"\n\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n        self._send_command(command)\n\n    def _get_arduino_id(self):\n\"\"\"\n        Retrieve arduino-telemetrix arduino id\n\n        \"\"\"\n        command = [PrivateConstants.ARE_U_THERE]\n        self._send_command(command)\n        # provide time for the reply\n        time.sleep(.5)\n\n    def _get_firmware_version(self):\n\"\"\"\n        This method retrieves the\n        arduino-telemetrix firmware version\n\n        \"\"\"\n        command = [PrivateConstants.GET_FIRMWARE_VERSION]\n        self._send_command(command)\n        # provide time for the reply\n        time.sleep(.5)\n\n    def i2c_read(self, address, register, number_of_bytes,\n                 callback=None, i2c_port=0,\n                 write_register=True):\n\"\"\"\n        Read the specified number of bytes from the\n        specified register for the i2c device.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                       selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report\n                         i2c data as a result of read command\n\n       :param i2c_port: 0 = default, 1 = secondary\n\n       :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n\n        self._i2c_read_request(address, register, number_of_bytes,\n                               callback=callback, i2c_port=i2c_port,\n                               write_register=write_register)\n\n    def i2c_read_restart_transmission(self, address, register,\n                                      number_of_bytes,\n                                      callback=None, i2c_port=0,\n                                      write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified\n        register for the i2c device. This restarts the transmission\n        after the read. It is required for some i2c devices such as the MMA8452Q\n        accelerometer.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                                    selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c\n                         data as a result of read command\n\n       :param i2c_port: 0 = default 1 = secondary\n\n       :param write_register: If True, the register is written before read\n                              Else, the write is suppressed\n\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n\n        self._i2c_read_request(address, register, number_of_bytes,\n                               stop_transmission=False,\n                               callback=callback, i2c_port=i2c_port,\n                               write_register=write_register)\n\n    def _i2c_read_request(self, address, register, number_of_bytes,\n                          stop_transmission=True, callback=None, i2c_port=0,\n                          write_register=True):\n\"\"\"\n        This method requests the read of an i2c device. Results are retrieved\n        via callback.\n\n        :param address: i2c device address\n\n        :param register: register number (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes expected to be returned\n\n        :param stop_transmission: stop transmission after read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command.\n\n       :param write_register: If True, the register is written before read\n                              Else, the write is suppressed\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('I2C Read: A callback function must be specified.')\n\n        if not i2c_port:\n            self.i2c_callback = callback\n        else:\n            self.i2c_callback2 = callback\n\n        if not register:\n            register = 0\n\n        if write_register:\n            write_register = 1\n        else:\n            write_register = 0\n\n        # message contains:\n        # 1. address\n        # 2. register\n        # 3. number of bytes\n        # 4. restart_transmission - True or False\n        # 5. i2c port\n        # 6. suppress write flag\n\n        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n                   stop_transmission, i2c_port, write_register]\n        self._send_command(command)\n\n    def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n        Write data to an i2c device.\n\n        :param address: i2c device address\n\n        :param i2c_port: 0= port 1, 1 = port 2\n\n        :param args: A variable number of bytes to be sent to the device\n                     passed in as a list\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n        for item in args:\n            command.append(item)\n\n        self._send_command(command)\n\n    def loop_back(self, start_character, callback=None):\n\"\"\"\n        This is a debugging method to send a character to the\n        Arduino device, and have the device loop it back.\n\n        :param start_character: The character to loop back. It should be\n                                an integer.\n\n        :param callback: Looped back character will appear in the callback method\n\n        \"\"\"\n        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n        self.loop_back_callback = callback\n        self._send_command(command)\n\n    def set_analog_scan_interval(self, interval):\n\"\"\"\n        Set the analog scanning interval.\n\n        :param interval: value of 0 - 255 - milliseconds\n        \"\"\"\n\n        if 0 <= interval <= 255:\n            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Analog interval must be between 0 and 255')\n\n    def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n        Set a pin as a pwm (analog output) pin.\n\n        :param pin_number:arduino pin number\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n    def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n        Set a pin as an analog input.\n\n        :param pin_number: arduino pin number\n\n        :param differential: difference in previous to current value before\n                             report will be generated\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for analog input pins = 3\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n                           callback)\n\n    def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n        Set a pin as a digital input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n\n    def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n        Set a pin as a digital input with pullup enabled.\n\n        :param pin_number: arduino pin number\n\n        :param callback: callback function\n\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n        \"\"\"\n        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                           callback=callback)\n\n    def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n        Set a pin as a digital output pin.\n\n        :param pin_number: arduino pin number\n        \"\"\"\n\n        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n\n    def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n        Establish the standard Arduino i2c pins for i2c utilization.\n\n        :param i2c_port: 0 = i2c1, 1 = i2c2\n\n        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n               2. Callbacks are set within the individual i2c read methods of this\n              API.\n\n              See i2c_read, or i2c_read_restart_transmission.\n\n        \"\"\"\n        # test for i2c port 2\n        if i2c_port:\n            # if not previously activated set it to activated\n            # and the send a begin message for this port\n            if not self.i2c_2_active:\n                self.i2c_2_active = True\n            else:\n                return\n        # port 1\n        else:\n            if not self.i2c_1_active:\n                self.i2c_1_active = True\n            else:\n                return\n\n        command = [PrivateConstants.I2C_BEGIN, i2c_port]\n        self._send_command(command)\n\n    def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n        :param pin: connection pin\n\n        :param callback: callback function\n\n        :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n        Temperature,\n        Time]\n\n        DHT_REPORT_TYPE = 12\n        \"\"\"\n        if self.reported_features & PrivateConstants.DHT_FEATURE:\n            if not callback:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n            if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n                self.dht_callbacks[pin] = callback\n                self.dht_count += 1\n\n                if dht_type != 22 and dht_type != 11:\n                    dht_type = 22\n\n                command = [PrivateConstants.DHT_NEW, pin, dht_type]\n                self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n    # noinspection PyRedundantParentheses\n    def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n        Attach a pin to a servo motor\n\n        :param pin_number: pin\n\n        :param min_pulse: minimum pulse width\n\n        :param max_pulse: maximum pulse width\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n            minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n            maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n            command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                       minv[0], minv[1], maxv[0], maxv[1]]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n    def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                           callback=None):\n\"\"\"\n\n        :param trigger_pin:\n\n        :param echo_pin:\n\n        :param callback: callback\n\n        callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n                self.sonar_callbacks[trigger_pin] = callback\n                self.sonar_count += 1\n\n                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n                self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n    def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n        Specify the list of chip select pins.\n\n        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n        Chip Select is any digital output capable pin.\n\n        :param chip_select_list: this is a list of pins to be used for chip select.\n                           The pins will be configured as output, and set to high\n                           ready to be used for chip select.\n                           NOTE: You must specify the chips select pins here!\n\n\n        command message: [command, [cs pins...]]\n        \"\"\"\n\n        if self.reported_features & PrivateConstants.SPI_FEATURE:\n            if type(chip_select_list) != list:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('chip_select_list must be in the form of a list')\n            if not chip_select_list:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('Chip select pins were not specified')\n\n            self.spi_enabled = True\n\n            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n            for pin in chip_select_list:\n                command.append(pin)\n                self.cs_pins_enabled.append(pin)\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n    # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n    #                          pin4=5, enable=True):\n    #     \"\"\"\n    #     Stepper motor support is implemented as a proxy for the\n    #     the AccelStepper library for the Arduino.\n    #\n    #     This feature is compatible with the TB6600 Motor Driver\n    #\n    #     Note: It may not work for other driver types!\n    #\n    #     https://github.com/waspinator/AccelStepper\n    #\n    #     Instantiate a stepper motor.\n    #\n    #     Initialize the interface and pins for a stepper motor.\n    #\n    #     :param interface: Motor Interface Type:\n    #\n    #             1 = Stepper Driver, 2 driver pins required\n    #\n    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required\n    #\n    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n    #                 required\n    #\n    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n    #\n    #     :param pin1: Arduino digital pin number for motor pin 1\n    #\n    #     :param pin2: Arduino digital pin number for motor pin 2\n    #\n    #     :param pin3: Arduino digital pin number for motor pin 3\n    #\n    #     :param pin4: Arduino digital pin number for motor pin 4\n    #\n    #     :param enable: If this is true, the output pins at construction time.\n    #\n    #     :return: Motor Reference number\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n    #\n    #         if self.number_of_steppers == self.max_number_of_steppers:\n    #             if self.shutdown_on_exception:\n    #                 self.shutdown()\n    #             raise RuntimeError('Maximum number of steppers has already been assigned')\n    #\n    #         if interface not in self.valid_stepper_interfaces:\n    #             if self.shutdown_on_exception:\n    #                 self.shutdown()\n    #             raise RuntimeError('Invalid stepper interface')\n    #\n    #         self.number_of_steppers += 1\n    #\n    #         motor_id = self.next_stepper_assigned\n    #         self.next_stepper_assigned += 1\n    #         self.stepper_info_list[motor_id]['instance'] = True\n    #\n    #         # build message and send message to server\n    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n    #                    pin2, pin3, pin4, enable]\n    #         self._send_command(command)\n    #\n    #         # return motor id\n    #         return motor_id\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n    def servo_write(self, pin_number, angle):\n\"\"\"\n\n        Set a servo attached to a pin to a given angle.\n\n        :param pin_number: pin\n\n        :param angle: angle (0-180)\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n        self._send_command(command)\n\n    def servo_detach(self, pin_number):\n\"\"\"\n        Detach a servo for reuse\n\n        :param pin_number: attached pin\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_DETACH, pin_number]\n        self._send_command(command)\n\n    # def stepper_move_to(self, motor_id, position):\n    #     \"\"\"\n    #     Set an absolution target position. If position is positive, the movement is\n    #     clockwise, else it is counter-clockwise.\n    #\n    #     The run() function (below) will try to move the motor (at most one step per call)\n    #     from the current position to the target position set by the most\n    #     recent call to this function. Caution: moveTo() also recalculates the\n    #     speed for the next step.\n    #     If you are trying to use constant speed movements, you should call setSpeed()\n    #     after calling moveTo().\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param position: target position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(position)\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     self._send_command(command)\n    #\n    # def stepper_move(self, motor_id, relative_position):\n    #     \"\"\"\n    #     Set the target position relative to the current position.\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param relative_position: The desired position relative to the current\n    #                               position. Negative is anticlockwise from\n    #                               the current position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if relative_position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #\n    #     relative_position = abs(relative_position)\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_move: Invalid motor_id.')\n    #\n    #     position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     self._send_command(command)\n    #\n    # def stepper_run(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     This method steps the selected motor based on the current speed.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run: A motion complete callback must be '\n    #                            'specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_run_speed(self, motor_id):\n    #     \"\"\"\n    #     This method steps the selected motor based at a constant speed as set by the most\n    #     recent call to stepper_set_max_speed(). The motor will run continuously.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_max_speed(self, motor_id, max_speed):\n    #     \"\"\"\n    #     Sets the maximum permitted speed. The stepper_run() function will accelerate\n    #     up to the speed set by this function.\n    #\n    #     Caution: the maximum speed achievable depends on your processor and clock speed.\n    #     The default maxSpeed is 1 step per second.\n    #\n    #      Caution: Speeds that exceed the maximum speed supported by the processor may\n    #               result in non-linear accelerations and decelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param max_speed: 1 - 1000\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n    #\n    #     if not 1 < max_speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n    #\n    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed\n    #     max_speed_msb = (max_speed & 0xff00) >> 8\n    #     max_speed_lsb = max_speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n    #                max_speed_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_get_max_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the maximum speed configured for this stepper\n    #     that was previously set by stepper_set_max_speed()\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :return: The currently configured maximum speed.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['max_speed']\n    #\n    # def stepper_set_acceleration(self, motor_id, acceleration):\n    #     \"\"\"\n    #     Sets the acceleration/deceleration rate.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param acceleration: The desired acceleration in steps per second\n    #                          per second. Must be > 0.0. This is an\n    #                          expensive call since it requires a square\n    #                          root to be calculated on the server.\n    #                          Dont call more often than needed.\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n    #\n    #     if not 1 < acceleration <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration\n    #\n    #     max_accel_msb = acceleration >> 8\n    #     max_accel_lsb = acceleration & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n    #                max_accel_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_set_speed(self, motor_id, speed):\n    #     \"\"\"\n    #     Sets the desired constant speed for use with stepper_run_speed().\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param speed: 0 - 1000 The desired constant speed in steps per\n    #                   second. Positive is clockwise. Speeds of more than 1000 steps per\n    #                   second are unreliable. Speed accuracy depends on the Arduino\n    #                   crystal. Jitter depends on how frequently you call the\n    #                   stepper_run_speed() method.\n    #                   The speed will be limited by the current value of\n    #                   stepper_set_max_speed().\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n    #\n    #     if not 0 < speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['speed'] = speed\n    #\n    #     speed_msb = speed >> 8\n    #     speed_lsb = speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_get_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the  most recently set speed.\n    #     that was previously set by stepper_set_speed();\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['speed']\n    #\n    # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n    #     \"\"\"\n    #     Request the distance from the current position to the target position\n    #     from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param distance_to_go_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n    #\n    #     A positive distance is clockwise from the current position.\n    #\n    #     \"\"\"\n    #     if not distance_to_go_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n    #     self.stepper_info_list[motor_id][\n    #         'distance_to_go_callback'] = distance_to_go_callback\n    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_get_target_position(self, motor_id, target_callback):\n    #     \"\"\"\n    #     Request the most recently set target position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param target_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #\n    #     \"\"\"\n    #     if not target_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_target_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id][\n    #         'target_position_callback'] = target_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_get_current_position(self, motor_id, current_position_callback):\n    #     \"\"\"\n    #     Request the current motor position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param current_position_callback: required callback function to receive report\n    #\n    #     :return: The current motor position returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #     \"\"\"\n    #     if not current_position_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_current_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_current_position(self, motor_id, position):\n    #     \"\"\"\n    #     Resets the current position of the motor, so that wherever the motor\n    #     happens to be right now is considered to be the new 0 position. Useful\n    #     for setting a zero position on a stepper after an initial hardware\n    #     positioning move.\n    #\n    #     Has the side effect of setting the current motor speed to 0.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     :param position: Position in steps. This is a 32 bit value\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     self._send_command(command)\n    #\n    # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     Runs the motor at the currently selected speed until the target position is\n    #     reached.\n    #\n    #     Does not implement accelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n    #                            'callback must be '\n    #                            'specified.')\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_stop(self, motor_id):\n    #     \"\"\"\n    #     Sets a new target position that causes the stepper\n    #     to stop as quickly as possible, using the current speed and\n    #     acceleration parameters.\n    #\n    #     :param motor_id:  0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_stop: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_STOP, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_disable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Disable motor pin outputs by setting them all LOW.\n    #\n    #     Depending on the design of your electronics this may turn off\n    #     the power to the motor coils, saving power.\n    #\n    #     This is useful to support Arduino low power modes: disable the outputs\n    #     during sleep and then re-enable with enableOutputs() before stepping\n    #     again.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and clears\n    #     the pin to disabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_enable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Enable motor pin outputs by setting the motor pins to OUTPUT\n    #     mode.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and sets\n    #     the pin to enabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n    #     self._send_command(command)\n    #\n    # def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n    #     \"\"\"\n    #     Sets the minimum pulse width allowed by the stepper driver.\n    #\n    #     The minimum practical pulse width is approximately 20 microseconds.\n    #\n    #     Times less than 20 microseconds will usually result in 20 microseconds or so.\n    #\n    #     :param motor_id: 0 -3\n    #\n    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n    #\n    #     if not 0 < minimum_width <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n    #                            '0-0xffff.')\n    #\n    #     width_msb = minimum_width >> 8\n    #     width_lsb = minimum_width & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n    #                width_lsb]\n    #     self._send_command(command)\n    #\n    # def stepper_set_enable_pin(self, motor_id, pin=0xff):\n    #     \"\"\"\n    #     Sets the enable pin number for stepper drivers.\n    #     0xFF indicates unused (default).\n    #\n    #     Otherwise, if a pin is set, the pin will be turned on when\n    #     enableOutputs() is called and switched off when disableOutputs()\n    #     is called.\n    #\n    #     :param motor_id: 0 - 4\n    #     :param pin: 0-0xff\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n    #\n    #     if not 0 < pin <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n    #                            '0-0xff.')\n    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n    #                                 enable=False):\n    #     \"\"\"\n    #     Sets the inversion for stepper driver pins.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param direction: True=inverted or False\n    #\n    #     :param step: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n    #                step, enable]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,\n    #                                 pin3_invert=False, pin4_invert=False, enable=False):\n    #     \"\"\"\n    #     Sets the inversion for 2, 3 and 4 wire stepper pins\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param pin1_invert: True=inverted or False\n    #\n    #     :param pin2_invert: True=inverted or False\n    #\n    #     :param pin3_invert: True=inverted or False\n    #\n    #     :param pin4_invert: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n    #                pin2_invert, pin3_invert, pin4_invert, enable]\n    #\n    #     self._send_command(command)\n    #\n    # def stepper_is_running(self, motor_id, callback):\n    #     \"\"\"\n    #     Checks to see if the motor is currently running to a target.\n    #\n    #     Callback return True if the speed is not zero or not at the target position.\n    #\n    #     :param motor_id: 0-4\n    #\n    #     :param callback: required callback function to receive report\n    #\n    #     :return: The current running state returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n    #     \"\"\"\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_is_running: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback\n    #\n    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n    #     self._send_command(command)\n\n    def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):\n\"\"\"\n        A private method to set the various pin modes.\n\n        :param pin_number: arduino pin number\n\n        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP\n                         For SERVO use: set_pin_mode_servo\n                         For DHT   use: set_pin_mode_dht\n\n        :param differential: for analog inputs - threshold\n                             value to be achieved for report to\n                             be generated\n\n        :param callback: A reference to a call back function to be\n                         called when pin data value changes\n\n        \"\"\"\n        if callback:\n            if pin_state == PrivateConstants.AT_INPUT:\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_ANALOG:\n                self.analog_callbacks[pin_number] = callback\n            else:\n                print('{} {}'.format('set_pin_mode: callback ignored for '\n                                     'pin state:', pin_state))\n\n        if pin_state == PrivateConstants.AT_INPUT:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_INPUT, 1]\n\n        elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_INPUT_PULLUP, 1]\n\n        elif pin_state == PrivateConstants.AT_OUTPUT:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_OUTPUT]\n\n        elif pin_state == PrivateConstants.AT_ANALOG:\n            command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                       PrivateConstants.AT_ANALOG,\n                       differential >> 8, differential & 0xff, 1]\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Unknown pin state')\n\n        if command:\n            self._send_command(command)\n\n    def shutdown(self):\n\"\"\"\n        This method attempts an orderly shutdown\n        If any exceptions are thrown, they are ignored.\n        \"\"\"\n        self.shutdown_flag = True\n\n        self._stop_threads()\n\n        try:\n            command = [PrivateConstants.STOP_ALL_REPORTS]\n            self._send_command(command)\n            time.sleep(.5)\n\n            if self.hard_reset_on_shutdown:\n                self.r4_hard_reset()\n\n            if self.transport_address:\n                try:\n                    self.sock.shutdown(socket.SHUT_RDWR)\n                    self.sock.close()\n                except Exception:\n                    pass\n            else:\n                try:\n                    self.serial_port.reset_input_buffer()\n                    self.serial_port.reset_output_buffer()\n\n                    self.serial_port.close()\n\n                except (RuntimeError, SerialException, OSError):\n                    # ignore error on shutdown\n                    pass\n        except Exception:\n            # raise RuntimeError('Shutdown failed - could not send stop streaming\n            # message')\n            pass\n\n    def sonar_disable(self):\n\"\"\"\n        Disable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_DISABLE]\n        self._send_command(command)\n\n    def sonar_enable(self):\n\"\"\"\n        Enable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_ENABLE]\n        self._send_command(command)\n\n    def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n        Control an SPI chip select line\n        :param chip_select_pin: pin connected to CS\n\n        :param select: 0=select, 1=deselect\n        \"\"\"\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n        if chip_select_pin not in self.cs_pins_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n        self._send_command(command)\n\n    def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n                          call_back=None):\n\"\"\"\n        Read the specified number of bytes from the specified SPI port and\n        call the callback function with the reported data.\n\n        :param chip_select: chip select pin\n\n        :param register_selection: Register to be selected for read.\n\n        :param number_of_bytes_to_read: Number of bytes to read\n\n        :param call_back: Required callback function to report spi data as a\n                   result of read command\n\n\n        callback returns a data list:\n        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n        data bytes, time-stamp]\n\n        SPI_READ_REPORT = 13\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n        if not call_back:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n        self.spi_callback = call_back\n\n        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n                   number_of_bytes_to_read,\n                   register_selection]\n\n        self._send_command(command)\n\n    def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n        Configure how the SPI serializes and de-serializes data on the wire.\n\n        See Arduino SPI reference materials for details.\n\n        :param clock_divisor: 1 - 255\n\n        :param bit_order:\n\n                            LSBFIRST = 0\n\n                            MSBFIRST = 1 (default)\n\n        :param data_mode:\n\n                            SPI_MODE0 = 0x00 (default)\n\n                            SPI_MODE1  = 1\n\n                            SPI_MODE2 = 2\n\n                            SPI_MODE3 = 3\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n        if not 0 < clock_divisor <= 255:\n            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n        if bit_order not in [0, 1]:\n            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n        if data_mode not in [0, 1, 2, 3]:\n            raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n                   data_mode]\n        self._send_command(command)\n\n    def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n        Write a list of bytes to the SPI device.\n\n        :param chip_select: chip select pin\n\n        :param bytes_to_write: A list of bytes to write. This must\n                                be in the form of a list.\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n        if type(bytes_to_write) is not list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n        for data in bytes_to_write:\n            command.append(data)\n\n        self._send_command(command)\n\n    # def set_pin_mode_one_wire(self, pin):\n    #     \"\"\"\n    #     Initialize the one wire serial bus.\n    #\n    #     :param pin: Data pin connected to the OneWire device\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:\n    #         self.onewire_enabled = True\n    #         command = [PrivateConstants.ONE_WIRE_INIT, pin]\n    #         self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'The OneWire feature is disabled in the server.')\n    #\n    # def onewire_reset(self, callback=None):\n    #     \"\"\"\n    #     Reset the onewire device\n    #\n    #     :param callback: required  function to report reset result\n    #\n    #     callback returns a list:\n    #     [ReportType = 14, Report Subtype = 25, reset result byte,\n    #                     timestamp]\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_reset: A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_RESET]\n    #     self._send_command(command)\n    #\n    # def onewire_select(self, device_address):\n    #     \"\"\"\n    #     Select a device based on its address\n    #     :param device_address: A bytearray of 8 bytes\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n    #\n    #     if type(device_address) is not list:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #\n    #     if len(device_address) != 8:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #     command = [PrivateConstants.ONE_WIRE_SELECT]\n    #     for data in device_address:\n    #         command.append(data)\n    #     self._send_command(command)\n    #\n    # def onewire_skip(self):\n    #     \"\"\"\n    #     Skip the device selection. This only works if you have a\n    #     single device, but you can avoid searching and use this to\n    #     immediately access your device.\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SKIP]\n    #     self._send_command(command)\n    #\n    # def onewire_write(self, data, power=0):\n    #     \"\"\"\n    #     Write a byte to the onewire device. If 'power' is one\n    #     then the wire is held high at the end for\n    #     parasitically powered devices. You\n    #     are responsible for eventually de-powering it by calling\n    #     another read or write.\n    #\n    #     :param data: byte to write.\n    #     :param power: power control (see above)\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n    #     if 0 < data < 255:\n    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n    #         self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_write: Data must be no larger than 255')\n    #\n    # def onewire_read(self, callback=None):\n    #     \"\"\"\n    #     Read a byte from the onewire device\n    #     :param callback: required  function to report onewire data as a\n    #                result of read command\n    #\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_READ]\n    #     self._send_command(command)\n    #     time.sleep(.2)\n    #\n    # def onewire_reset_search(self):\n    #     \"\"\"\n    #     Begin a new search. The next use of search will begin at the first device\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n    #                            f'enabled.')\n    #     else:\n    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n    #         self._send_command(command)\n    #\n    # def onewire_search(self, callback=None):\n    #     \"\"\"\n    #     Search for the next device. The device address will returned in the callback.\n    #     If a device is found, the 8 byte address is contained in the callback.\n    #     If no more devices are found, the address returned contains all elements set\n    #     to 0xff.\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SEARCH]\n    #     self._send_command(command)\n    #\n    # def onewire_crc8(self, address_list, callback=None):\n    #     \"\"\"\n    #     Compute a CRC check on an array of data.\n    #     :param address_list:\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_crc8 A Callback must be specified')\n    #\n    #     if type(address_list) is not list:\n    #         if self.shutdown_on_exception:\n    #             self.shutdown()\n    #         raise RuntimeError('onewire_crc8: address list must be a list.')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     address_length = len(address_list)\n    #\n    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n    #\n    #     for data in address_list:\n    #         command.append(data)\n    #\n    #     self._send_command(command)\n\n    def r4_hard_reset(self):\n\"\"\"\n        Place the r4 into hard reset\n        \"\"\"\n        command = [PrivateConstants.RESET, 1]\n        self._send_command(command)\n        time.sleep(.5)\n        command = [PrivateConstants.BOARD_HARD_RESET, 1]\n        self._send_command(command)\n\n    def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n        :param message: Message with maximum length of 25\n        :param scroll_speed: in milliseconds (maximum of 255)\n        \"\"\"\n        if len(message) > 25:\n            raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n        if scroll_speed > 255:\n            raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n        message = message.encode()\n        command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n        for x in message:\n            command.append(x)\n        self._send_command(command)\n\n    def disable_scroll_message(self):\n\"\"\"\n        Turn off a scrolling message\n        \"\"\"\n\n        command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n        self._send_command(command)\n\n'''\n    report message handlers\n    '''\n\n    def _analog_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for analog messages.\n\n        :param data: message data\n\n        \"\"\"\n        pin = data[0]\n        value = (data[1] << 8) + data[2]\n        # set the current value in the pin structure\n        time_stamp = time.time()\n        # self.digital_pins[pin].event_time = time_stamp\n        if self.analog_callbacks[pin]:\n            message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]\n            try:\n                self.analog_callbacks[pin](message)\n            except KeyError:\n                pass\n\n    def _dht_report(self, data):\n\"\"\"\n        This is the dht report handler method.\n\n        :param data:            data[0] = report error return\n                                    No Errors = 0\n\n                                    Checksum Error = 1\n\n                                    Timeout Error = 2\n\n                                    Invalid Value = 999\n\n                                data[1] = pin number\n\n                                data[2] = dht type 11 or 22\n\n                                data[3] = humidity positivity flag\n\n                                data[4] = temperature positivity value\n\n                                data[5] = humidity integer\n\n                                data[6] = humidity fractional value\n\n                                data[7] = temperature integer\n\n                                data[8] = temperature fractional value\n\n\n        \"\"\"\n        if data[0]:  # DHT_ERROR\n            # error report\n            # data[0] = report sub type, data[1] = pin, data[2] = error message\n            if self.dht_callbacks[data[1]]:\n                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                           time.time()]\n                try:\n                    self.dht_callbacks[data[1]](message)\n                except KeyError:\n                    pass\n        else:\n            # got valid data DHT_DATA\n            f_humidity = float(data[5] + data[6] / 100)\n            if data[3]:\n                f_humidity *= -1.0\n            f_temperature = float(data[7] + data[8] / 100)\n            if data[4]:\n                f_temperature *= -1.0\n            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                       f_humidity, f_temperature, time.time()]\n\n            try:\n                self.dht_callbacks[data[1]](message)\n            except KeyError:\n                pass\n\n    def _digital_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for Digital Messages.\n\n        :param data: digital message\n\n        \"\"\"\n        pin = data[0]\n        value = data[1]\n\n        time_stamp = time.time()\n        if self.digital_callbacks[pin]:\n            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n            self.digital_callbacks[pin](message)\n\n    def _firmware_message(self, data):\n\"\"\"\n        Telemetrix4Arduino firmware version message\n\n        :param data: data[0] = major number, data[1] = minor number.\n\n                               data[2] = patch number\n        \"\"\"\n\n        self.firmware_version = [data[0], data[1], data[2]]\n\n    def _i2c_read_report(self, data):\n\"\"\"\n        Execute callback for i2c reads.\n\n        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n        \"\"\"\n\n        # we receive [# data bytes, address, register, data bytes]\n        # number of bytes of data returned\n\n        # data[0] = number of bytes\n        # data[1] = i2c_port\n        # data[2] = number of bytes returned\n        # data[3] = address\n        # data[4] = register\n        # data[5] ... all the data bytes\n\n        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n        cb_list.append(time.time())\n\n        if cb_list[1]:\n            self.i2c_callback2(cb_list)\n        else:\n            self.i2c_callback(cb_list)\n\n    def _i2c_too_few(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    def _i2c_too_many(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    def _i_am_here(self, data):\n\"\"\"\n        Reply to are_u_there message\n        :param data: arduino id\n        \"\"\"\n        self.reported_arduino_id = data[0]\n\n    def _spi_report(self, report):\n\n        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n        cb_list.append(time.time())\n\n        self.spi_callback(cb_list)\n\n    def _onewire_report(self, report):\n        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n        cb_list.append(time.time())\n        self.onewire_callback(cb_list)\n\n    def _report_debug_data(self, data):\n\"\"\"\n        Print debug data sent from Arduino\n        :param data: data[0] is a byte followed by 2\n                     bytes that comprise an integer\n        :return:\n        \"\"\"\n        value = (data[1] << 8) + data[2]\n        print(f'DEBUG ID: {data[0]} Value: {value}')\n\n    def _report_loop_data(self, data):\n\"\"\"\n        Print data that was looped back\n        :param data: byte of loop back data\n        :return:\n        \"\"\"\n        if self.loop_back_callback:\n            self.loop_back_callback(data)\n\n    def _send_command(self, command):\n\"\"\"\n        This is a private utility method.\n\n\n        :param command:  command data in the form of a list\n\n        \"\"\"\n        # the length of the list is added at the head\n        command.insert(0, len(command))\n        send_message = bytes(command)\n\n        if self.serial_port:\n            try:\n                self.serial_port.write(send_message)\n            except SerialException:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n                raise RuntimeError('write fail in _send_command')\n        elif self.transport_address:\n            self.sock.sendall(send_message)\n        else:\n            raise RuntimeError('No serial port or ip address set.')\n\n    def _servo_unavailable(self, report):\n\"\"\"\n        Message if no servos are available for use.\n        :param report: pin number\n        \"\"\"\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(\n            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n    def _sonar_distance_report(self, report):\n\"\"\"\n\n        :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n        \"\"\"\n\n        # get callback from pin number\n        cb = self.sonar_callbacks[report[0]]\n\n        # build report data\n        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n                   ((report[1] << 8) + report[2]), time.time()]\n\n        cb(cb_list)\n\n    def _stepper_distance_to_go_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper distance to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n    #                              data[3] = steps bytes 2, data[4] = steps LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n    #                              steps, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     steps = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n    def _stepper_target_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper target position to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = target position MSB,\n    #                    data[2] = target position byte MSB+1\n    #                    data[3] = target position byte MSB+2\n    #                    data[4] = target position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n    #                              target_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['target_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     target = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     target_position = int.from_bytes(target, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n    def _stepper_current_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper current position.\n    #\n    #     :param report: data[0] = motor_id, data[1] = current position MSB,\n    #                    data[2] = current position byte MSB+1\n    #                    data[3] = current position byte MSB+2\n    #                    data[4] = current position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n    #                              current_position, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['current_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     position = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     current_position = int.from_bytes(position, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n    #                time.time()]\n    #\n    #     cb(cb_list)\n    #\n    def _stepper_is_running_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report if the motor is currently running\n    #\n    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.\n    #\n    #     callback report format: [18, motor_id,\n    #                              running_state, time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['is_running_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n    #\n    #     cb(cb_list)\n    #\n    def _stepper_run_complete_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     The motor completed it motion\n    #\n    #     :param report: data[0] = motor_id\n    #\n    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n    #                              time_stamp]\n    #     \"\"\"\n    #\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n    #                time.time()]\n    #\n    #     cb(cb_list)\n\n    def _features_report(self, report):\n        self.reported_features = report[0]\n\n    def _run_threads(self):\n        self.run_event.set()\n\n    def _is_running(self):\n        return self.run_event.is_set()\n\n    def _stop_threads(self):\n        self.run_event.clear()\n\n    def _reporter(self):\n\"\"\"\n        This is the reporter thread. It continuously pulls data from\n        the deque. When a full message is detected, that message is\n        processed.\n        \"\"\"\n        self.run_event.wait()\n\n        while self._is_running() and not self.shutdown_flag:\n            if len(self.the_deque):\n                # response_data will be populated with the received data for the report\n                response_data = []\n                packet_length = self.the_deque.popleft()\n                # print(f'packet_length {packet_length}')\n                if packet_length:\n                    # get all the data for the report and place it into response_data\n                    for i in range(packet_length):\n                        while not len(self.the_deque):\n                            time.sleep(self.sleep_tune)\n                        data = self.the_deque.popleft()\n                        response_data.append(data)\n\n                    # print(f'response_data {response_data}')\n\n                    # get the report type and look up its dispatch method\n                    # here we pop the report type off of response_data\n                    report_type = response_data.pop(0)\n                    # print(f' reported type {report_type}')\n\n                    # retrieve the report handler from the dispatch table\n                    dispatch_entry = self.report_dispatch.get(report_type)\n\n                    # if there is additional data for the report,\n                    # it will be contained in response_data\n                    # noinspection PyArgumentList\n                    dispatch_entry(response_data)\n                    continue\n                else:\n                    if self.shutdown_on_exception:\n                        self.shutdown()\n                    raise RuntimeError(\n                        'A report with a packet length of zero was received.')\n            else:\n                time.sleep(self.sleep_tune)\n\n    def _serial_receiver(self):\n\"\"\"\n        Thread to continuously check for incoming data.\n        When a byte comes in, place it onto the deque.\n        \"\"\"\n        self.run_event.wait()\n\n        # Don't start this thread if using a tcp/ip transport\n        if self.transport_address:\n            return\n\n        while self._is_running() and not self.shutdown_flag:\n            # we can get an OSError: [Errno9] Bad file descriptor when shutting down\n            # just ignore it\n            try:\n                if self.serial_port.inWaiting():\n                    c = self.serial_port.read()\n                    self.the_deque.append(ord(c))\n                    # print(ord(c))\n                else:\n                    time.sleep(self.sleep_tune)\n                    # continue\n            except OSError:\n                pass\n\n    def _tcp_receiver(self):\n\"\"\"\n        Thread to continuously check for incoming data.\n        When a byte comes in, place it onto the deque.\n        \"\"\"\n        self.run_event.wait()\n\n        # Start this thread only if transport_address is set\n\n        if self.transport_address:\n\n            while self._is_running() and not self.shutdown_flag:\n                try:\n                    payload = self.sock.recv(1)\n                    self.the_deque.append(ord(payload))\n                except Exception:\n                    pass\n        else:\n            return\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0)","text":"

:param com_port: e.g. COM3 or /dev/ttyACM0. Only use if you wish to bypass auto com port detection.

:param arduino_instance_id: Match with the value installed on the arduino-telemetrix sketch.

:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.

:param sleep_tune: A tuning parameter (typically not changed by user)

:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception

:param hard_reset_on_shutdown: reset the board on shutdown

:param transport_address: ip address of tcp/ip connected device.

:param ip_port: ip port of tcp/ip connected device

:param transport_type: 0 = WiFI 1 = USBSerial 2 = BLE

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def __init__(self, com_port=None, arduino_instance_id=1,\n             arduino_wait=1, sleep_tune=0.000001,\n             shutdown_on_exception=True, hard_reset_on_shutdown=True,\n             transport_address=None, ip_port=31336, transport_type=0):\n\n\"\"\"\n\n    :param com_port: e.g. COM3 or /dev/ttyACM0.\n                     Only use if you wish to bypass auto com port\n                     detection.\n\n    :param arduino_instance_id: Match with the value installed on the\n                                arduino-telemetrix sketch.\n\n    :param arduino_wait: Amount of time to wait for an Arduino to\n                         fully reset itself.\n\n    :param sleep_tune: A tuning parameter (typically not changed by user)\n\n    :param shutdown_on_exception: call shutdown before raising\n                                  a RunTimeError exception, or\n                                  receiving a KeyboardInterrupt exception\n\n    :param hard_reset_on_shutdown: reset the board on shutdown\n\n    :param transport_address: ip address of tcp/ip connected device.\n\n    :param ip_port: ip port of tcp/ip connected device\n\n    :param transport_type: 0 = WiFI\n                           1 = USBSerial\n                           2 = BLE\n\n\n    \"\"\"\n\n    # initialize threading parent\n    threading.Thread.__init__(self)\n\n    # create the threads and set them as daemons so\n    # that they stop when the program is closed\n\n    # create a thread to interpret received serial data\n    self.the_reporter_thread = threading.Thread(target=self._reporter)\n    self.the_reporter_thread.daemon = True\n\n    self.transport_address = transport_address\n    self.ip_port = ip_port\n\n    if transport_type not in [0, 1, 2]:\n        raise RuntimeError(\"Valid transport_type value is 0, 1, or 2\")\n\n    self.transport_type = transport_type\n\n    if transport_type == 0:\n        if not transport_address:\n            raise RuntimeError(\"An IP address must be specified.\")\n\n    if not self.transport_address:\n        self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)\n    else:\n        self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)\n\n    self.the_data_receive_thread.daemon = True\n\n    # flag to allow the reporter and receive threads to run.\n    self.run_event = threading.Event()\n\n    # check to make sure that Python interpreter is version 3.7 or greater\n    python_version = sys.version_info\n    if python_version[0] >= 3:\n        if python_version[1] >= 7:\n            pass\n        else:\n            raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                               \"required for use of this program.\")\n\n    # save input parameters as instance variables\n    self.com_port = com_port\n    self.arduino_instance_id = arduino_instance_id\n    self.arduino_wait = arduino_wait\n    self.sleep_tune = sleep_tune\n    self.shutdown_on_exception = shutdown_on_exception\n    self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n    # create a deque to receive and process data from the arduino\n    self.the_deque = deque()\n\n    # The report_dispatch dictionary is used to process\n    # incoming report messages by looking up the report message\n    # and executing its associated processing method.\n\n    self.report_dispatch = {}\n\n    # To add a command to the command dispatch table, append here.\n    self.report_dispatch.update(\n        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n    self.report_dispatch.update(\n        {PrivateConstants.ANALOG_REPORT: self._analog_message})\n    self.report_dispatch.update(\n        {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})\n    self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})\n    self.report_dispatch.update(\n        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n    self.report_dispatch.update(\n        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n    self.report_dispatch.update(\n        {PrivateConstants.SPI_REPORT: self._spi_report})\n    self.report_dispatch.update(\n        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_CURRENT_POSITION:\n             self._stepper_current_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUNNING_REPORT:\n             self._stepper_is_running_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n             self._stepper_run_complete_report})\n\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.FEATURES:\n             self._features_report})\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    self.cs_pins_enabled = []\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    self.dht_count = 0\n\n    # serial port in use\n    self.serial_port = None\n\n    # socket for tcp/ip communications\n    self.sock = None\n\n    # flag to indicate we are in shutdown mode\n    self.shutdown_flag = False\n\n    # debug loopback callback method\n    self.loop_back_callback = None\n\n    # flag to indicate the start of a new report\n    # self.new_report_start = True\n\n    # firmware version to be stored here\n    self.firmware_version = []\n\n    # reported arduino instance id\n    self.reported_arduino_id = []\n\n    # reported features\n    self.reported_features = 0\n\n    # flag to indicate if i2c was previously enabled\n    self.i2c_enabled = False\n\n    # flag to indicate if spi is initialized\n    self.spi_enabled = False\n\n    # flag to indicate if onewire is initialized\n    self.onewire_enabled = False\n\n    # stepper motor variables\n\n    # updated when a new motor is added\n    # self.next_stepper_assigned = 0\n    #\n    # # valid list of stepper motor interface types\n    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n    #\n    # # maximum number of steppers supported\n    # self.max_number_of_steppers = 4\n    #\n    # # number of steppers created - not to exceed the maximum\n    # self.number_of_steppers = 0\n    #\n    # # dictionary to hold stepper motor information\n    # self.stepper_info = {'instance': False, 'is_running': None,\n    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n    #                      'distance_to_go_callback': None,\n    #                      'target_position_callback': None,\n    #                      'current_position_callback': None,\n    #                      'is_running_callback': None,\n    #                      'motion_complete_callback': None,\n    #                      'acceleration_callback': None}\n    #\n    # # build a list of stepper motor info items\n    # self.stepper_info_list = []\n    # # a list of dictionaries to hold stepper information\n    # for motor in range(self.max_number_of_steppers):\n    #     self.stepper_info_list.append(self.stepper_info)\n\n    self.the_reporter_thread.start()\n    self.the_data_receive_thread.start()\n\n    print(f\"telemetrix_uno_r4_wifi:  Version\"\n          f\" {PrivateConstants.TELEMETRIX_VERSION}\\n\\n\"\n          f\"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\\n\")\n\n    # using the serial link\n    if not self.transport_address:\n        if not self.com_port:\n            # user did not specify a com_port\n            try:\n                self._find_arduino()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n        else:\n            # com_port specified - set com_port and baud rate\n            try:\n                self._manual_open()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    self.shutdown()\n\n        if self.serial_port:\n            print(\n                f\"Arduino compatible device found and connected to {self.serial_port.port}\")\n\n            self.serial_port.reset_input_buffer()\n            self.serial_port.reset_output_buffer()\n            self.disable_scroll_message()\n\n        # no com_port found - raise a runtime exception\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('No Arduino Found or User Aborted Program')\n    else:\n        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        self.sock.connect((self.transport_address, self.ip_port))\n        print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')\n\n    # allow the threads to run\n    self._run_threads()\n    print(f'Waiting for Arduino to reset')\n    print(f'Reset Complete')\n\n    # get telemetrix firmware version and print it\n    print('\\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')\n    self._get_firmware_version()\n    if not self.firmware_version:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')\n\n    else:\n\n        print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'\n              f'{self.firmware_version[1]}.{self.firmware_version[2]}')\n    command = [PrivateConstants.ENABLE_ALL_REPORTS]\n    self._send_command(command)\n\n    # get the features list\n    command = [PrivateConstants.GET_FEATURES]\n    self._send_command(command)\n    time.sleep(.2)\n\n    # Have the server reset its data structures\n    command = [PrivateConstants.RESET]\n    self._send_command(command)\n    time.sleep(.2)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.analog_write","title":"analog_write(pin, value)","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (maximum 16 bits)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def analog_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (maximum 16 bits)\n\n    \"\"\"\n    value_msb = value >> 8\n    value_lsb = value & 0xff\n    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.digital_write","title":"digital_write(pin, value)","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (1 or 0)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def digital_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (1 or 0)\n\n    \"\"\"\n\n    command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_all_reporting","title":"disable_all_reporting()","text":"

Disable reporting for all digital and analog input pins

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_all_reporting(self):\n\"\"\"\n    Disable reporting for all digital and analog input pins\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DISABLE_ALL, 0]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_analog_reporting","title":"disable_analog_reporting(pin)","text":"

Disables analog reporting for a single analog pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_analog_reporting(self, pin):\n\"\"\"\n    Disables analog reporting for a single analog pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_digital_reporting","title":"disable_digital_reporting(pin)","text":"

Disables digital reporting for a single digital input.

:param pin: Pin number.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_digital_reporting(self, pin):\n\"\"\"\n    Disables digital reporting for a single digital input.\n\n    :param pin: Pin number.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.disable_scroll_message","title":"disable_scroll_message()","text":"

Turn off a scrolling message

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def disable_scroll_message(self):\n\"\"\"\n    Turn off a scrolling message\n    \"\"\"\n\n    command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_analog_reporting","title":"enable_analog_reporting(pin)","text":"

Enables analog reporting for the specified pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_analog_reporting(self, pin):\n\"\"\"\n    Enables analog reporting for the specified pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_digital_reporting","title":"enable_digital_reporting(pin)","text":"

Enable reporting on the specified digital pin.

:param pin: Pin number.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_digital_reporting(self, pin):\n\"\"\"\n    Enable reporting on the specified digital pin.\n\n    :param pin: Pin number.\n    \"\"\"\n\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.enable_scroll_message","title":"enable_scroll_message(message, scroll_speed=50)","text":"

:param message: Message with maximum length of 25 :param scroll_speed: in milliseconds (maximum of 255)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n    :param message: Message with maximum length of 25\n    :param scroll_speed: in milliseconds (maximum of 255)\n    \"\"\"\n    if len(message) > 25:\n        raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n    if scroll_speed > 255:\n        raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n    message = message.encode()\n    command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n    for x in message:\n        command.append(x)\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)","text":"

Read the specified number of bytes from the specified register for the i2c device.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: 0 = default, 1 = secondary

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_read(self, address, register, number_of_bytes,\n             callback=None, i2c_port=0,\n             write_register=True):\n\"\"\"\n    Read the specified number of bytes from the\n    specified register for the i2c device.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                   selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report\n                     i2c data as a result of read command\n\n   :param i2c_port: 0 = default, 1 = secondary\n\n   :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n\n    self._i2c_read_request(address, register, number_of_bytes,\n                           callback=callback, i2c_port=i2c_port,\n                           write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)","text":"

Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: 0 = default 1 = secondary

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_read_restart_transmission(self, address, register,\n                                  number_of_bytes,\n                                  callback=None, i2c_port=0,\n                                  write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified\n    register for the i2c device. This restarts the transmission\n    after the read. It is required for some i2c devices such as the MMA8452Q\n    accelerometer.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                                selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c\n                     data as a result of read command\n\n   :param i2c_port: 0 = default 1 = secondary\n\n   :param write_register: If True, the register is written before read\n                          Else, the write is suppressed\n\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n\n    self._i2c_read_request(address, register, number_of_bytes,\n                           stop_transmission=False,\n                           callback=callback, i2c_port=i2c_port,\n                           write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.i2c_write","title":"i2c_write(address, args, i2c_port=0)","text":"

Write data to an i2c device.

:param address: i2c device address

:param i2c_port: 0= port 1, 1 = port 2

:param args: A variable number of bytes to be sent to the device passed in as a list

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n    Write data to an i2c device.\n\n    :param address: i2c device address\n\n    :param i2c_port: 0= port 1, 1 = port 2\n\n    :param args: A variable number of bytes to be sent to the device\n                 passed in as a list\n\n    \"\"\"\n    if not i2c_port:\n        if not self.i2c_1_active:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n    if i2c_port:\n        if not self.i2c_2_active:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n    for item in args:\n        command.append(item)\n\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.loop_back","title":"loop_back(start_character, callback=None)","text":"

This is a debugging method to send a character to the Arduino device, and have the device loop it back.

:param start_character: The character to loop back. It should be an integer.

:param callback: Looped back character will appear in the callback method

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def loop_back(self, start_character, callback=None):\n\"\"\"\n    This is a debugging method to send a character to the\n    Arduino device, and have the device loop it back.\n\n    :param start_character: The character to loop back. It should be\n                            an integer.\n\n    :param callback: Looped back character will appear in the callback method\n\n    \"\"\"\n    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n    self.loop_back_callback = callback\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.r4_hard_reset","title":"r4_hard_reset()","text":"

Place the r4 into hard reset

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def r4_hard_reset(self):\n\"\"\"\n    Place the r4 into hard reset\n    \"\"\"\n    command = [PrivateConstants.RESET, 1]\n    self._send_command(command)\n    time.sleep(.5)\n    command = [PrivateConstants.BOARD_HARD_RESET, 1]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.servo_detach","title":"servo_detach(pin_number)","text":"

Detach a servo for reuse

:param pin_number: attached pin

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def servo_detach(self, pin_number):\n\"\"\"\n    Detach a servo for reuse\n\n    :param pin_number: attached pin\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_DETACH, pin_number]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.servo_write","title":"servo_write(pin_number, angle)","text":"

Set a servo attached to a pin to a given angle.

:param pin_number: pin

:param angle: angle (0-180)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def servo_write(self, pin_number, angle):\n\"\"\"\n\n    Set a servo attached to a pin to a given angle.\n\n    :param pin_number: pin\n\n    :param angle: angle (0-180)\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_analog_scan_interval","title":"set_analog_scan_interval(interval)","text":"

Set the analog scanning interval.

:param interval: value of 0 - 255 - milliseconds

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_analog_scan_interval(self, interval):\n\"\"\"\n    Set the analog scanning interval.\n\n    :param interval: value of 0 - 255 - milliseconds\n    \"\"\"\n\n    if 0 <= interval <= 255:\n        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None)","text":"

Set a pin as an analog input.

:param pin_number: arduino pin number

:param differential: difference in previous to current value before report will be generated

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for analog input pins = 3

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n    Set a pin as an analog input.\n\n    :param pin_number: arduino pin number\n\n    :param differential: difference in previous to current value before\n                         report will be generated\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for analog input pins = 3\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,\n                       callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number)","text":"

Set a pin as a pwm (analog output) pin.

:param pin_number:arduino pin number

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n    Set a pin as a pwm (analog output) pin.\n\n    :param pin_number:arduino pin number\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22)","text":"

:param pin: connection pin

:param callback: callback function

:param dht_type: either 22 for DHT22 or 11 for DHT11

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]

DHT_REPORT_TYPE = 12

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n    :param pin: connection pin\n\n    :param callback: callback function\n\n    :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n    Temperature,\n    Time]\n\n    DHT_REPORT_TYPE = 12\n    \"\"\"\n    if self.reported_features & PrivateConstants.DHT_FEATURE:\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n        if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n            self.dht_callbacks[pin] = callback\n            self.dht_count += 1\n\n            if dht_type != 22 and dht_type != 11:\n                dht_type = 22\n\n            command = [PrivateConstants.DHT_NEW, pin, dht_type]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback=None)","text":"

Set a pin as a digital input.

:param pin_number: arduino pin number

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_input(self, pin_number, callback=None):\n\"\"\"\n    Set a pin as a digital input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback=None)","text":"

Set a pin as a digital input with pullup enabled.

:param pin_number: arduino pin number

:param callback: callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):\n\"\"\"\n    Set a pin as a digital input with pullup enabled.\n\n    :param pin_number: arduino pin number\n\n    :param callback: callback function\n\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n    \"\"\"\n    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                       callback=callback)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number)","text":"

Set a pin as a digital output pin.

:param pin_number: arduino pin number

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n    Set a pin as a digital output pin.\n\n    :param pin_number: arduino pin number\n    \"\"\"\n\n    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0)","text":"

Establish the standard Arduino i2c pins for i2c utilization.

:param i2c_port: 0 = i2c1, 1 = i2c2

  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  1. Callbacks are set within the individual i2c read methods of this
  API.\n\n  See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n    Establish the standard Arduino i2c pins for i2c utilization.\n\n    :param i2c_port: 0 = i2c1, 1 = i2c2\n\n    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n           2. Callbacks are set within the individual i2c read methods of this\n          API.\n\n          See i2c_read, or i2c_read_restart_transmission.\n\n    \"\"\"\n    # test for i2c port 2\n    if i2c_port:\n        # if not previously activated set it to activated\n        # and the send a begin message for this port\n        if not self.i2c_2_active:\n            self.i2c_2_active = True\n        else:\n            return\n    # port 1\n    else:\n        if not self.i2c_1_active:\n            self.i2c_1_active = True\n        else:\n            return\n\n    command = [PrivateConstants.I2C_BEGIN, i2c_port]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400)","text":"

Attach a pin to a servo motor

:param pin_number: pin

:param min_pulse: minimum pulse width

:param max_pulse: maximum pulse width

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n    Attach a pin to a servo motor\n\n    :param pin_number: pin\n\n    :param min_pulse: minimum pulse width\n\n    :param max_pulse: maximum pulse width\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n        minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n        maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n        command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                   minv[0], minv[1], maxv[0], maxv[1]]\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback=None)","text":"

:param trigger_pin:

:param echo_pin:

:param callback: callback

callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                       callback=None):\n\"\"\"\n\n    :param trigger_pin:\n\n    :param echo_pin:\n\n    :param callback: callback\n\n    callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n            self.sonar_callbacks[trigger_pin] = callback\n            self.sonar_count += 1\n\n            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n            self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None)","text":"

Specify the list of chip select pins.

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

Chip Select is any digital output capable pin.

:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!

command message: [command, [cs pins...]]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n    Specify the list of chip select pins.\n\n    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n    Chip Select is any digital output capable pin.\n\n    :param chip_select_list: this is a list of pins to be used for chip select.\n                       The pins will be configured as output, and set to high\n                       ready to be used for chip select.\n                       NOTE: You must specify the chips select pins here!\n\n\n    command message: [command, [cs pins...]]\n    \"\"\"\n\n    if self.reported_features & PrivateConstants.SPI_FEATURE:\n        if type(chip_select_list) != list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('chip_select_list must be in the form of a list')\n        if not chip_select_list:\n            if self.shutdown_on_exception:\n                self.shutdown()\n            raise RuntimeError('Chip select pins were not specified')\n\n        self.spi_enabled = True\n\n        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n        for pin in chip_select_list:\n            command.append(pin)\n            self.cs_pins_enabled.append(pin)\n        self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.shutdown","title":"shutdown()","text":"

This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def shutdown(self):\n\"\"\"\n    This method attempts an orderly shutdown\n    If any exceptions are thrown, they are ignored.\n    \"\"\"\n    self.shutdown_flag = True\n\n    self._stop_threads()\n\n    try:\n        command = [PrivateConstants.STOP_ALL_REPORTS]\n        self._send_command(command)\n        time.sleep(.5)\n\n        if self.hard_reset_on_shutdown:\n            self.r4_hard_reset()\n\n        if self.transport_address:\n            try:\n                self.sock.shutdown(socket.SHUT_RDWR)\n                self.sock.close()\n            except Exception:\n                pass\n        else:\n            try:\n                self.serial_port.reset_input_buffer()\n                self.serial_port.reset_output_buffer()\n\n                self.serial_port.close()\n\n            except (RuntimeError, SerialException, OSError):\n                # ignore error on shutdown\n                pass\n    except Exception:\n        # raise RuntimeError('Shutdown failed - could not send stop streaming\n        # message')\n        pass\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.sonar_disable","title":"sonar_disable()","text":"

Disable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def sonar_disable(self):\n\"\"\"\n    Disable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_DISABLE]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.sonar_enable","title":"sonar_enable()","text":"

Enable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def sonar_enable(self):\n\"\"\"\n    Enable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_ENABLE]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_cs_control","title":"spi_cs_control(chip_select_pin, select)","text":"

Control an SPI chip select line :param chip_select_pin: pin connected to CS

:param select: 0=select, 1=deselect

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n    Control an SPI chip select line\n    :param chip_select_pin: pin connected to CS\n\n    :param select: 0=select, 1=deselect\n    \"\"\"\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n    if chip_select_pin not in self.cs_pins_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None)","text":"

Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.

:param chip_select: chip select pin

:param register_selection: Register to be selected for read.

:param number_of_bytes_to_read: Number of bytes to read

:param call_back: Required callback function to report spi data as a result of read command

callback returns a data list: [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]

SPI_READ_REPORT = 13

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,\n                      call_back=None):\n\"\"\"\n    Read the specified number of bytes from the specified SPI port and\n    call the callback function with the reported data.\n\n    :param chip_select: chip select pin\n\n    :param register_selection: Register to be selected for read.\n\n    :param number_of_bytes_to_read: Number of bytes to read\n\n    :param call_back: Required callback function to report spi data as a\n               result of read command\n\n\n    callback returns a data list:\n    [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n    data bytes, time-stamp]\n\n    SPI_READ_REPORT = 13\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n    if not call_back:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n    self.spi_callback = call_back\n\n    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n               number_of_bytes_to_read,\n               register_selection]\n\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode)","text":"

Configure how the SPI serializes and de-serializes data on the wire.

See Arduino SPI reference materials for details.

:param clock_divisor: 1 - 255

:param bit_order:

                LSBFIRST = 0\n\n                MSBFIRST = 1 (default)\n

:param data_mode:

                SPI_MODE0 = 0x00 (default)\n\n                SPI_MODE1  = 1\n\n                SPI_MODE2 = 2\n\n                SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n    Configure how the SPI serializes and de-serializes data on the wire.\n\n    See Arduino SPI reference materials for details.\n\n    :param clock_divisor: 1 - 255\n\n    :param bit_order:\n\n                        LSBFIRST = 0\n\n                        MSBFIRST = 1 (default)\n\n    :param data_mode:\n\n                        SPI_MODE0 = 0x00 (default)\n\n                        SPI_MODE1  = 1\n\n                        SPI_MODE2 = 2\n\n                        SPI_MODE3 = 3\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n    if not 0 < clock_divisor <= 255:\n        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n    if bit_order not in [0, 1]:\n        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n    if data_mode not in [0, 1, 2, 3]:\n        raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n               data_mode]\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference/#telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write)","text":"

Write a list of bytes to the SPI device.

:param chip_select: chip select pin

:param bytes_to_write: A list of bytes to write. This must be in the form of a list.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py
def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n    Write a list of bytes to the SPI device.\n\n    :param chip_select: chip select pin\n\n    :param bytes_to_write: A list of bytes to write. This must\n                            be in the form of a list.\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n    if type(bytes_to_write) is not list:\n        if self.shutdown_on_exception:\n            self.shutdown()\n        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n    for data in bytes_to_write:\n        command.append(data)\n\n    self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/","title":"telemetrix_uno_r4_wifi_aio","text":"

Copyright (c) 2023 Alan Yorinks All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 as published by the Free Software Foundation; either or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio","title":"TelemetrixUnoR4WiFiAio","text":"

This class exposes and implements the TelemetrixUnoR4WifiAio API. It includes the public API methods as well as a set of private methods. This is an asyncio API.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
class TelemetrixUnoR4WiFiAio:\n\"\"\"\n    This class exposes and implements the TelemetrixUnoR4WifiAio API.\n    It includes the public API methods as well as\n    a set of private methods. This is an asyncio API.\n\n    \"\"\"\n\n    # noinspection PyPep8,PyPep8\n    def __init__(self, com_port=None,\n                 arduino_instance_id=1, arduino_wait=1,\n                 sleep_tune=0.0001, autostart=True,\n                 loop=None, shutdown_on_exception=True,\n                 close_loop_on_shutdown=True, hard_reset_on_shutdown=True,\n                 transport_address=None, ip_port=31336, transport_type=0,\n                 ble_device_name='Telemetrix4UnoR4 BLE'):\n\n\"\"\"\n        If you have a single Arduino connected to your computer,\n        then you may accept all the default values.\n\n        Otherwise, specify a unique arduino_instance id for each board in use.\n\n        :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n        :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n        :param arduino_wait: Amount of time to wait for an Arduino to\n                             fully reset itself.\n\n        :param sleep_tune: A tuning parameter (typically not changed by user)\n\n        :param autostart: If you wish to call the start method within\n                          your application, then set this to False.\n\n        :param loop: optional user provided event loop\n\n        :param shutdown_on_exception: call shutdown before raising\n                                      a RunTimeError exception, or\n                                      receiving a KeyboardInterrupt exception\n\n        :param close_loop_on_shutdown: stop and close the event loop loop\n                                       when a shutdown is called or a serial\n                                       error occurs\n\n       :param hard_reset_on_shutdown: reset the board on shutdown\n\n       :param transport_address: ip address of tcp/ip connected device.\n\n        :param ip_port: ip port of tcp/ip connected device\n\n        :param transport_type: 0 = WiFi\n                               1 = SerialUSB\n                               2 = BLE\n\n       :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.\n                               It must match that of Telemetrix4UnoR4BLE.ino\n\n        \"\"\"\n        # check to make sure that Python interpreter is version 3.8.3 or greater\n        python_version = sys.version_info\n        if python_version[0] >= 3:\n            if python_version[1] >= 8:\n                if python_version[2] >= 3:\n                    pass\n            else:\n                raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                                   \"required for use of this program.\")\n\n        # save input parameters\n        self.com_port = com_port\n        self.arduino_instance_id = arduino_instance_id\n        self.arduino_wait = arduino_wait\n        self.sleep_tune = sleep_tune\n        self.autostart = autostart\n        self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n        self.transport_address = transport_address\n        self.ip_port = ip_port\n        if transport_type not in [0, 1, 2]:\n            raise RuntimeError('Invalid transport type')\n        self.transport_type = transport_type\n        self.firmware_version = None\n        # if tcp, this variable is set to the connected socket\n        self.sock = None\n\n        self.ble_device_name = ble_device_name\n\n        # instance of telemetrix_aio_ble\n        self.ble_instance = None\n\n        # set the event loop\n        if loop is None:\n            self.loop = asyncio.get_event_loop()\n        else:\n            self.loop = loop\n\n        self.shutdown_on_exception = shutdown_on_exception\n        self.close_loop_on_shutdown = close_loop_on_shutdown\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        # debug loopback callback method\n        self.loop_back_callback = None\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        self.dht_count = 0\n\n        # serial port in use\n        self.serial_port = None\n\n        # generic asyncio task holder\n        self.the_task = None\n\n        # flag to indicate we are in shutdown mode\n        self.shutdown_flag = False\n\n        self.report_dispatch = {}\n\n        # reported features\n        self.reported_features = 0\n\n        # To add a command to the command dispatch table, append here.\n        self.report_dispatch.update(\n            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n        self.report_dispatch.update(\n            {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n        self.report_dispatch.update(\n            {PrivateConstants.ANALOG_REPORT: self._analog_message})\n        self.report_dispatch.update(\n            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n        self.report_dispatch.update(\n            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n        self.report_dispatch.update(\n            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n        self.report_dispatch.update(\n            {PrivateConstants.SPI_REPORT: self._spi_report})\n        self.report_dispatch.update(\n            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_CURRENT_POSITION:\n                 self._stepper_current_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUNNING_REPORT:\n                 self._stepper_is_running_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n                 self._stepper_run_complete_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n                 self._stepper_distance_to_go_report})\n        self.report_dispatch.update(\n            {PrivateConstants.STEPPER_TARGET_POSITION:\n                 self._stepper_target_position_report})\n        self.report_dispatch.update(\n            {PrivateConstants.FEATURES:\n                 self._features_report})\n\n        # dictionaries to store the callbacks for each pin\n        self.analog_callbacks = {}\n\n        self.digital_callbacks = {}\n\n        self.i2c_callback = None\n        self.i2c_callback2 = None\n\n        self.i2c_1_active = False\n        self.i2c_2_active = False\n\n        self.spi_callback = None\n\n        self.onewire_callback = None\n\n        self.cs_pins_enabled = []\n\n        # flag to indicate if spi is initialized\n        self.spi_enabled = False\n\n        # flag to indicate if onewire is initialized\n        self.onewire_enabled = False\n\n        # the trigger pin will be the key to retrieve\n        # the callback for a specific HC-SR04\n        self.sonar_callbacks = {}\n\n        self.sonar_count = 0\n\n        self.dht_callbacks = {}\n\n        # # stepper motor variables\n        #\n        # # updated when a new motor is added\n        # self.next_stepper_assigned = 0\n        #\n        # # valid list of stepper motor interface types\n        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n        #\n        # # maximum number of steppers supported\n        # self.max_number_of_steppers = 4\n        #\n        # # number of steppers created - not to exceed the maximum\n        # self.number_of_steppers = 0\n        #\n        # # dictionary to hold stepper motor information\n        # self.stepper_info = {'instance': False, 'is_running': None,\n        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n        #                      'distance_to_go_callback': None,\n        #                      'target_position_callback': None,\n        #                      'current_position_callback': None,\n        #                      'is_running_callback': None,\n        #                      'motion_complete_callback': None,\n        #                      'acceleration_callback': None}\n        #\n        # # build a list of stepper motor info items\n        # self.stepper_info_list = []\n        # # a list of dictionaries to hold stepper information\n        # for motor in range(self.max_number_of_steppers):\n        #     self.stepper_info_list.append(self.stepper_info)\n\n        print(f'telemetrix_uno_r4_wifi_aio Version:'\n              f' {PrivateConstants.TELEMETRIX_VERSION}')\n        print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n        if autostart:\n            self.loop.run_until_complete(self.start_aio())\n\n    async def start_aio(self):\n\"\"\"\n        This method may be called directly, if the autostart\n        parameter in __init__ is set to false.\n\n        This method instantiates the serial interface and then performs auto pin\n        discovery if using a serial interface, or creates and connects to\n        a TCP/IP enabled device running StandardFirmataWiFi.\n\n        Use this method if you wish to start TelemetrixAIO manually from\n        an asyncio function.\n         \"\"\"\n\n        if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n            if not self.com_port:\n                # user did not specify a com_port\n                try:\n                    await self._find_arduino()\n                except KeyboardInterrupt:\n                    if self.shutdown_on_exception:\n                        await self.shutdown()\n            else:\n                # com_port specified - set com_port and baud rate\n                try:\n                    await self._manual_open()\n                except KeyboardInterrupt:\n                    if self.shutdown_on_exception:\n                        await self.shutdown()\n\n            if self.com_port:\n                print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')\n\n                # no com_port found - raise a runtime exception\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('No Arduino Found or User Aborted Program')\n            await self.disable_scroll_message()\n            # using tcp/ip\n        elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n            self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)\n            await self.sock.start()\n        else:  # ble\n            self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)\n            await self.ble_instance.connect()\n\n        # get arduino firmware version and print it\n        firmware_version = await self._get_firmware_version()\n        if not firmware_version:\n            print('*** Firmware Version retrieval timed out. ***')\n            print('\\nDo you have Arduino connectivity and do you have the ')\n            print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n            print('to the correct serial port.\\n')\n            print('To see a list of serial ports, type: '\n                  '\"list_serial_ports\" in your console.')\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError\n        else:\n\n            print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n                  f'{firmware_version[3]}.{firmware_version[4]}')\n            # start the command dispatcher loop\n            command = [PrivateConstants.ENABLE_ALL_REPORTS]\n            await self._send_command(command)\n            if not self.loop:\n                self.loop = asyncio.get_event_loop()\n            self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n            # get the features list\n            command = [PrivateConstants.GET_FEATURES]\n            await self._send_command(command)\n            await asyncio.sleep(.5)\n\n            # Have the server reset its data structures\n            command = [PrivateConstants.RESET]\n            await self._send_command(command)\n            await asyncio.sleep(.1)\n\n    async def get_event_loop(self):\n\"\"\"\n        Return the currently active asyncio event loop\n\n        :return: Active event loop\n\n        \"\"\"\n        return self.loop\n\n    async def _find_arduino(self):\n\"\"\"\n        This method will search all potential serial ports for an Arduino\n        containing a sketch that has a matching arduino_instance_id as\n        specified in the input parameters of this class.\n\n        This is used explicitly with the FirmataExpress sketch.\n        \"\"\"\n\n        # a list of serial ports to be checked\n        serial_ports = []\n\n        print('Opening all potential serial ports...')\n        the_ports_list = list_ports.comports()\n        for port in the_ports_list:\n            if port.pid is None:\n                continue\n            print('\\nChecking {}'.format(port.device))\n            try:\n                self.serial_port = TelemetrixAioSerial(port.device, 115200,\n                                                       telemetrix_aio_instance=self,\n                                                       close_loop_on_error=self.close_loop_on_shutdown)\n            except SerialException:\n                continue\n            # create a list of serial ports that we opened\n            serial_ports.append(self.serial_port)\n\n            # display to the user\n            print('\\t' + port.device)\n\n            # clear out any possible data in the input buffer\n            await self.serial_port.reset_input_buffer()\n\n        # wait for arduino to reset\n        print('\\nWaiting {} seconds(arduino_wait) for Arduino devices to '\n              'reset...'.format(self.arduino_wait))\n        await asyncio.sleep(self.arduino_wait)\n\n        print('\\nSearching for an Arduino configured with an arduino_instance = ',\n              self.arduino_instance_id)\n\n        for serial_port in serial_ports:\n            self.serial_port = serial_port\n\n            command = [PrivateConstants.ARE_U_THERE]\n            await self._send_command(command)\n            # provide time for the reply\n            await asyncio.sleep(.1)\n\n            i_am_here = await self.serial_port.read(3)\n\n            if not i_am_here:\n                continue\n\n            # got an I am here message - is it the correct ID?\n            if i_am_here[2] == self.arduino_instance_id:\n                self.com_port = serial_port.com_port\n                return\n\n    async def _manual_open(self):\n\"\"\"\n        Com port was specified by the user - try to open up that port\n\n        \"\"\"\n        # if port is not found, a serial exception will be thrown\n        print('Opening {} ...'.format(self.com_port))\n        self.serial_port = TelemetrixAioSerial(self.com_port, 115200,\n                                               telemetrix_aio_instance=self,\n                                               close_loop_on_error=self.close_loop_on_shutdown)\n\n        print('Waiting {} seconds for the Arduino To Reset.'\n              .format(self.arduino_wait))\n        await asyncio.sleep(self.arduino_wait)\n        command = [PrivateConstants.ARE_U_THERE]\n        await self._send_command(command)\n        # provide time for the reply\n        await asyncio.sleep(.1)\n\n        print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')\n        i_am_here = await self.serial_port.read(3)\n\n        if not i_am_here:\n            print(f'ERROR: correct arduino_instance_id not found')\n\n        print('Correct arduino_instance_id found')\n\n    async def _get_firmware_version(self):\n\"\"\"\n        This method retrieves the Arduino4Telemetrix firmware version\n\n        :returns: Firmata firmware version\n        \"\"\"\n        self.firmware_version = None\n        command = [PrivateConstants.GET_FIRMWARE_VERSION]\n        await self._send_command(command)\n        # provide time for the reply\n        await asyncio.sleep(.3)\n        if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n            self.firmware_version = await self.serial_port.read(5)\n        elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n            self.firmware_version = list(await self.sock.read(5))\n        else:\n            pass\n        return self.firmware_version\n\n    async def analog_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (maximum 16 bits)\n\n        \"\"\"\n        value_msb = value >> 8\n        value_lsb = value & 0xff\n        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n        await self._send_command(command)\n\n    async def digital_write(self, pin, value):\n\"\"\"\n        Set the specified pin to the specified value.\n\n        :param pin: arduino pin number\n\n        :param value: pin value (1 or 0)\n\n        \"\"\"\n        command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n        await self._send_command(command)\n\n    async def i2c_read(self, address, register, number_of_bytes,\n                       callback, i2c_port=0,\n                       write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified register for\n        the i2c device.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command\n\n        :param i2c_port: select the default port (0) or secondary port (1)\n\n        :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('i2c_read: A Callback must be specified')\n\n        await self._i2c_read_request(address, register, number_of_bytes,\n                                     callback=callback, i2c_port=i2c_port,\n                                     write_register=write_register)\n\n    async def i2c_read_restart_transmission(self, address, register,\n                                            number_of_bytes,\n                                            callback, i2c_port=0,\n                                            write_register=True):\n\"\"\"\n        Read the specified number of bytes from the specified register for\n        the i2c device. This restarts the transmission after the read. It is\n        required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n        :param address: i2c device address\n\n        :param register: i2c register (or None if no register\n                                                    selection is needed)\n\n        :param number_of_bytes: number of bytes to be read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command\n\n        :param i2c_port: select the default port (0) or secondary port (1)\n\n        :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n        callback returns a data list:\n\n        [I2C_READ_REPORT, address, register, count of data bytes,\n         data bytes, time-stamp]\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'i2c_read_restart_transmission: A Callback must be specified')\n\n        await self._i2c_read_request(address, register, number_of_bytes,\n                                     stop_transmission=False,\n                                     callback=callback, i2c_port=i2c_port,\n                                     write_register=write_register)\n\n    async def _i2c_read_request(self, address, register, number_of_bytes,\n                                stop_transmission=True, callback=None,\n                                i2c_port=0, write_register=True):\n\"\"\"\n        This method requests the read of an i2c device. Results are retrieved\n        via callback.\n\n        :param address: i2c device address\n\n        :param register: register number (or None if no register selection is needed)\n\n        :param number_of_bytes: number of bytes expected to be returned\n\n        :param stop_transmission: stop transmission after read\n\n        :param callback: Required callback function to report i2c data as a\n                   result of read command.\n\n       :param i2c_port: select the default port (0) or secondary port (1)\n\n       :param write_register: If True, the register is written\n                                       before read\n                              Else, the write is suppressed\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('I2C Read: A callback function must be specified.')\n\n        if not i2c_port:\n            self.i2c_callback = callback\n        else:\n            self.i2c_callback2 = callback\n\n        if not register:\n            register = 0\n\n        if write_register:\n            write_register = 1\n        else:\n            write_register = 0\n\n        # message contains:\n        # 1. address\n        # 2. register\n        # 3. number of bytes\n        # 4. restart_transmission - True or False\n        # 5. i2c port\n        # 6. suppress write flag\n\n        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,\n                   stop_transmission, i2c_port, write_register]\n        await self._send_command(command)\n\n    async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n        Write data to an i2c device.\n\n        :param address: i2c device address\n\n        :param i2c_port: 0= port 1, 1 = port 2\n\n        :param args: A variable number of bytes to be sent to the device\n                     passed in as a list\n\n        \"\"\"\n        if not i2c_port:\n            if not self.i2c_1_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n        if i2c_port:\n            if not self.i2c_2_active:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n        for item in args:\n            command.append(item)\n\n        await self._send_command(command)\n\n    async def loop_back(self, start_character, callback):\n\"\"\"\n        This is a debugging method to send a character to the\n        Arduino device, and have the device loop it back.\n\n        :param start_character: The character to loop back. It should be\n                                an integer.\n\n        :param callback: Looped back character will appear in the callback method\n\n        \"\"\"\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('loop_back: A callback function must be specified.')\n        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n        self.loop_back_callback = callback\n        await self._send_command(command)\n\n    async def set_analog_scan_interval(self, interval):\n\"\"\"\n        Set the analog scanning interval.\n\n        :param interval: value of 0 - 255 - milliseconds\n        \"\"\"\n\n        if 0 <= interval <= 255:\n            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('Analog interval must be between 0 and 255')\n\n    async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n        Set a pin as an analog input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        :param differential: difference in previous to current value before\n                             report will be generated\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for analog input pins = 3\n\n        \"\"\"\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'set_pin_mode_analog_input: A callback function must be specified.')\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n                                 differential, callback=callback)\n\n    async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n        Set a pin as a pwm (analog output) pin.\n\n        :param pin_number:arduino pin number\n\n        \"\"\"\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                                 callback=None)\n\n    async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n        Set a pin as a digital input.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n                                 callback=callback)\n\n    async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n        Set a pin as a digital input with pullup enabled.\n\n        :param pin_number: arduino pin number\n\n        :param callback: async callback function\n\n        callback returns a data list:\n\n        [pin_type, pin_number, pin_value, raw_time_stamp]\n\n        The pin_type for all digital input pins = 2\n\n        \"\"\"\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                                 differential=0, callback=callback)\n\n    async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n        Set a pin as a digital output pin.\n\n        :param pin_number: arduino pin number\n        \"\"\"\n\n        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                                 callback=None)\n\n    # noinspection PyIncorrectDocstring\n    async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n        Establish the standard Arduino i2c pins for i2c utilization.\n\n        :param i2c_port: 0 = i2c1, 1 = i2c2\n\n        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n               2. Callbacks are set within the individual i2c read methods of this\n              API.\n\n              See i2c_read, or i2c_read_restart_transmission.\n\n        \"\"\"\n        # test for i2c port 2\n        if i2c_port:\n            # if not previously activated set it to activated\n            # and the send a begin message for this port\n            if not self.i2c_2_active:\n                self.i2c_2_active = True\n            else:\n                return\n        # port 1\n        else:\n            if not self.i2c_1_active:\n                self.i2c_1_active = True\n            else:\n                return\n\n        command = [PrivateConstants.I2C_BEGIN, i2c_port]\n        await self._send_command(command)\n\n    async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n        :param pin: connection pin\n\n        :param callback: callback function\n\n        :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n        Temperature,\n        Time]\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n            if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n                self.dht_callbacks[pin] = callback\n                self.dht_count += 1\n\n                if dht_type != 22 and dht_type != 11:\n                    dht_type = 22\n\n                command = [PrivateConstants.DHT_NEW, pin, dht_type]\n                await self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The DHT feature is disabled in the server.')\n\n    async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n        Attach a pin to a servo motor\n\n        :param pin_number: pin\n\n        :param min_pulse: minimum pulse width\n\n        :param max_pulse: maximum pulse width\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n            minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n            maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n            command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                       minv[0], minv[1], maxv[0], maxv[1]]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SERVO feature is disabled in the server.')\n\n    async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                                 callback):\n\"\"\"\n\n        :param trigger_pin:\n\n        :param echo_pin:\n\n        :param callback:  callback\n\n        \"\"\"\n        if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n            if not callback:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n                self.sonar_callbacks[trigger_pin] = callback\n                self.sonar_count += 1\n\n                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n                await self._send_command(command)\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError(\n                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SONAR feature is disabled in the server.')\n\n    async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n        Specify the list of chip select pins.\n\n        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n        Chip Select is any digital output capable pin.\n\n        :param chip_select_list: this is a list of pins to be used for chip select.\n                           The pins will be configured as output, and set to high\n                           ready to be used for chip select.\n                           NOTE: You must specify the chips select pins here!\n\n\n        command message: [command, number of cs pins, [cs pins...]]\n        \"\"\"\n        if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n            if type(chip_select_list) != list:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('chip_select_list must be in the form of a list')\n            if not chip_select_list:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('Chip select pins were not specified')\n\n            self.spi_enabled = True\n\n            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n            for pin in chip_select_list:\n                command.append(pin)\n                self.cs_pins_enabled.append(pin)\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'The SPI feature is disabled in the server.')\n\n    # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,\n    #                          pin4=5, enable=True):\n    #     \"\"\"\n    #     Stepper motor support is implemented as a proxy for the\n    #     the AccelStepper library for the Arduino.\n    #\n    #     This feature is compatible with the TB6600 Motor Driver\n    #\n    #     Note: It may not work for other driver types!\n    #\n    #     https://github.com/waspinator/AccelStepper\n    #\n    #     Instantiate a stepper motor.\n    #\n    #     Initialize the interface and pins for a stepper motor.\n    #\n    #     :param interface: Motor Interface Type:\n    #\n    #             1 = Stepper Driver, 2 driver pins required\n    #\n    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required\n    #\n    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins\n    #                 required\n    #\n    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,\n    #                 3 motor pins required\n    #\n    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required\n    #\n    #     :param pin1: Arduino digital pin number for motor pin 1\n    #\n    #     :param pin2: Arduino digital pin number for motor pin 2\n    #\n    #     :param pin3: Arduino digital pin number for motor pin 3\n    #\n    #     :param pin4: Arduino digital pin number for motor pin 4\n    #\n    #     :param enable: If this is true, the output pins at construction time.\n    #\n    #     :return: Motor Reference number\n    #     \"\"\"\n    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:\n    #\n    #         if self.number_of_steppers == self.max_number_of_steppers:\n    #             if self.shutdown_on_exception:\n    #                 await self.shutdown()\n    #             raise RuntimeError('Maximum number of steppers has already been assigned')\n    #\n    #         if interface not in self.valid_stepper_interfaces:\n    #             if self.shutdown_on_exception:\n    #                 await self.shutdown()\n    #             raise RuntimeError('Invalid stepper interface')\n    #\n    #         self.number_of_steppers += 1\n    #\n    #         motor_id = self.next_stepper_assigned\n    #         self.next_stepper_assigned += 1\n    #         self.stepper_info_list[motor_id]['instance'] = True\n    #\n    #         # build message and send message to server\n    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,\n    #                    pin2, pin3, pin4, enable]\n    #         await self._send_command(command)\n    #\n    #         # return motor id\n    #         return motor_id\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')\n\n    async def sonar_disable(self):\n\"\"\"\n        Disable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_DISABLE]\n        await self._send_command(command)\n\n    async def sonar_enable(self):\n\"\"\"\n        Enable sonar scanning for all sonar sensors\n        \"\"\"\n        command = [PrivateConstants.SONAR_ENABLE]\n        await self._send_command(command)\n\n    async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n        Control an SPI chip select line\n        :param chip_select_pin: pin connected to CS\n\n        :param select: 0=select, 1=deselect\n        \"\"\"\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n        if chip_select_pin not in self.cs_pins_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n        await self._send_command(command)\n\n    async def spi_read_blocking(self, chip_select, register_selection,\n                                number_of_bytes_to_read,\n                          call_back=None):\n\"\"\"\n        Read the specified number of bytes from the specified SPI port and\n        call the callback function with the reported data.\n\n        :param chip_select: chip select pin\n\n        :param register_selection: Register to be selected for read.\n\n        :param number_of_bytes_to_read: Number of bytes to read\n\n        :param call_back: Required callback function to report spi data as a\n                   result of read command\n\n\n        callback returns a data list:\n            [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n             data bytes, time-stamp]\n        SPI_READ_REPORT = 13\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n        if not call_back:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n        self.spi_callback = call_back\n\n        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n                   number_of_bytes_to_read,\n                   register_selection]\n\n        await self._send_command(command)\n\n    async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n        Configure how the SPI serializes and de-serializes data on the wire.\n\n        See Arduino SPI reference materials for details.\n\n        :param clock_divisor: 1 - 255\n\n        :param bit_order:\n\n                            LSBFIRST = 0\n\n                            MSBFIRST = 1 (default)\n\n        :param data_mode:\n\n                            SPI_MODE0 = 0x00 (default)\n\n                            SPI_MODE1  = 1\n\n                            SPI_MODE2 = 2\n\n                            SPI_MODE3 = 3\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n        if not 0 < clock_divisor <= 255:\n            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n        if bit_order not in [0, 1]:\n            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n        if data_mode not in [0, 1, 2, 3]:\n            raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n                   data_mode]\n        await self._send_command(command)\n\n    async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n        Write a list of bytes to the SPI device.\n\n        :param chip_select: chip select pin\n\n        :param bytes_to_write: A list of bytes to write. This must\n                                be in the form of a list.\n\n        \"\"\"\n\n        if not self.spi_enabled:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n        if type(bytes_to_write) is not list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n        for data in bytes_to_write:\n            command.append(data)\n\n        await self._send_command(command)\n\n    # async def set_pin_mode_one_wire(self, pin):\n    #     \"\"\"\n    #     Initialize the one wire serial bus.\n    #\n    #     :param pin: Data pin connected to the OneWire device\n    #     \"\"\"\n    #     self.onewire_enabled = True\n    #     command = [PrivateConstants.ONE_WIRE_INIT, pin]\n    #     await self._send_command(command)\n    #\n    # async def onewire_reset(self, callback=None):\n    #     \"\"\"\n    #     Reset the onewire device\n    #\n    #     :param callback: required  function to report reset result\n    #\n    #     callback returns a list:\n    #     [ReportType = 14, Report Subtype = 25, reset result byte,\n    #                     timestamp]\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_reset: A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_RESET]\n    #     await self._send_command(command)\n    #\n    # async def onewire_select(self, device_address):\n    #     \"\"\"\n    #     Select a device based on its address\n    #     :param device_address: A bytearray of 8 bytes\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')\n    #\n    #     if type(device_address) is not list:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #\n    #     if len(device_address) != 8:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_select: device address must be an array of 8 '\n    #                            'bytes.')\n    #     command = [PrivateConstants.ONE_WIRE_SELECT]\n    #     for data in device_address:\n    #         command.append(data)\n    #     await self._send_command(command)\n    #\n    # async def onewire_skip(self):\n    #     \"\"\"\n    #     Skip the device selection. This only works if you have a\n    #     single device, but you can avoid searching and use this to\n    #     immediately access your device.\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SKIP]\n    #     await self._send_command(command)\n    #\n    # async def onewire_write(self, data, power=0):\n    #     \"\"\"\n    #     Write a byte to the onewire device. If 'power' is one\n    #     then the wire is held high at the end for\n    #     parasitically powered devices. You\n    #     are responsible for eventually de-powering it by calling\n    #     another read or write.\n    #\n    #     :param data: byte to write.\n    #     :param power: power control (see above)\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')\n    #     if 0 < data < 255:\n    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]\n    #         await self._send_command(command)\n    #     else:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_write: Data must be no larger than 255')\n    #\n    # async def onewire_read(self, callback=None):\n    #     \"\"\"\n    #     Read a byte from the onewire device\n    #     :param callback: required  function to report onewire data as a\n    #                result of read command\n    #\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_READ]\n    #     await self._send_command(command)\n    #     await asynio.sleep(.2)\n    #\n    # async def onewire_reset_search(self):\n    #     \"\"\"\n    #     Begin a new search. The next use of search will begin at the first device\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '\n    #                            f'enabled.')\n    #     else:\n    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]\n    #         await self._send_command(command)\n    #\n    # async def onewire_search(self, callback=None):\n    #     \"\"\"\n    #     Search for the next device. The device address will returned in the callback.\n    #     If a device is found, the 8 byte address is contained in the callback.\n    #     If no more devices are found, the address returned contains all elements set\n    #     to 0xff.\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #     \"\"\"\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_read A Callback must be specified')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     command = [PrivateConstants.ONE_WIRE_SEARCH]\n    #     await self._send_command(command)\n    #\n    # async def onewire_crc8(self, address_list, callback=None):\n    #     \"\"\"\n    #     Compute a CRC check on an array of data.\n    #     :param address_list:\n    #\n    #     :param callback: required  function to report a onewire device address\n    #\n    #     callback returns a data list:\n    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]\n    #\n    #     ONEWIRE_REPORT = 14\n    #\n    #     \"\"\"\n    #\n    #     if not self.onewire_enabled:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')\n    #\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_crc8 A Callback must be specified')\n    #\n    #     if type(address_list) is not list:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('onewire_crc8: address list must be a list.')\n    #\n    #     self.onewire_callback = callback\n    #\n    #     address_length = len(address_list)\n    #\n    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]\n    #\n    #     for data in address_list:\n    #         command.append(data)\n    #\n    #     await self._send_command(command)\n\n    async def _set_pin_mode(self, pin_number, pin_state, differential, callback):\n\"\"\"\n        A private method to set the various pin modes.\n\n        :param pin_number: arduino pin number\n\n        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use\n                          servo_config()\n                          For DHT   use: set_pin_mode_dht\n\n        :param differential: for analog inputs - threshold\n                             value to be achieved for report to\n                             be generated\n\n        :param callback: A reference to an async call back function to be\n                         called when pin data value changes\n\n        \"\"\"\n        if not callback and pin_state != PrivateConstants.AT_OUTPUT:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('_set_pin_mode: A Callback must be specified')\n        else:\n            if pin_state == PrivateConstants.AT_INPUT:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_INPUT, 1]\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_INPUT_PULLUP, 1]\n                self.digital_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_ANALOG:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_ANALOG,\n                           differential >> 8, differential & 0xff, 1]\n                self.analog_callbacks[pin_number] = callback\n            elif pin_state == PrivateConstants.AT_OUTPUT:\n                command = [PrivateConstants.SET_PIN_MODE, pin_number,\n                           PrivateConstants.AT_OUTPUT, 1]\n            else:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('Unknown pin state')\n\n        if command:\n            await self._send_command(command)\n\n        await asyncio.sleep(.05)\n\n    async def servo_detach(self, pin_number):\n\"\"\"\n        Detach a servo for reuse\n        :param pin_number: attached pin\n        \"\"\"\n        command = [PrivateConstants.SERVO_DETACH, pin_number]\n        await self._send_command(command)\n\n    async def servo_write(self, pin_number, angle):\n\"\"\"\n\n        Set a servo attached to a pin to a given angle.\n\n        :param pin_number: pin\n\n        :param angle: angle (0-180)\n\n        \"\"\"\n        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n        await self._send_command(command)\n\n    # async def stepper_move_to(self, motor_id, position):\n    #     \"\"\"\n    #     Set an absolution target position. If position is positive, the movement is\n    #     clockwise, else it is counter-clockwise.\n    #\n    #     The run() function (below) will try to move the motor (at most one step per call)\n    #     from the current position to the target position set by the most\n    #     recent call to this function. Caution: moveTo() also recalculates the\n    #     speed for the next step.\n    #     If you are trying to use constant speed movements, you should call setSpeed()\n    #     after calling moveTo().\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param position: target position. Maximum value is 32 bits.\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')\n    #\n    #     if position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(position)\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_move(self, motor_id, relative_position):\n    #     \"\"\"\n    #     Set the target position relative to the current position.\n    #\n    #     :param motor_id: motor id: 0 - 3\n    #\n    #     :param relative_position: The desired position relative to the current\n    #                               position. Negative is anticlockwise from\n    #                               the current position. Maximum value is 32 bits.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_move: Invalid motor_id.')\n    #\n    #     if relative_position < 0:\n    #         polarity = 1\n    #     else:\n    #         polarity = 0\n    #     position = abs(relative_position)\n    #\n    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     command.append(polarity)\n    #     await self._send_command(command)\n    #\n    # async def stepper_run(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     This method steps the selected motor based on the current speed.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run: A motion complete callback must be '\n    #                            'specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_run_speed(self, motor_id):\n    #     \"\"\"\n    #     This method steps the selected motor based at a constant speed as set by the most\n    #     recent call to stepper_set_max_speed(). The motor will run continuously.\n    #\n    #     Once called, the server will continuously attempt to step the motor.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_max_speed(self, motor_id, max_speed):\n    #     \"\"\"\n    #     Sets the maximum permitted speed. The stepper_run() function will accelerate\n    #     up to the speed set by this function.\n    #\n    #     Caution: the maximum speed achievable depends on your processor and clock speed.\n    #     The default maxSpeed is 1 step per second.\n    #\n    #      Caution: Speeds that exceed the maximum speed supported by the processor may\n    #               result in non-linear accelerations and decelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param max_speed: 1 - 1000\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')\n    #\n    #     if not 1 < max_speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')\n    #\n    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed\n    #     max_speed_msb = (max_speed & 0xff00) >> 8\n    #     max_speed_lsb = max_speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,\n    #                max_speed_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_max_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the maximum speed configured for this stepper\n    #     that was previously set by stepper_set_max_speed()\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :return: The currently configured maximum speed.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['max_speed']\n    #\n    # async def stepper_set_acceleration(self, motor_id, acceleration):\n    #     \"\"\"\n    #     Sets the acceleration/deceleration rate.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param acceleration: The desired acceleration in steps per second\n    #                          per second. Must be > 0.0. This is an\n    #                          expensive call since it requires a square\n    #                          root to be calculated on the server.\n    #                          Dont call more often than needed.\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')\n    #\n    #     if not 1 < acceleration <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration\n    #\n    #     max_accel_msb = acceleration >> 8\n    #     max_accel_lsb = acceleration & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,\n    #                max_accel_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_speed(self, motor_id, speed):\n    #     \"\"\"\n    #     Sets the desired constant speed for use with stepper_run_speed().\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param speed: 0 - 1000 The desired constant speed in steps per\n    #                   second. Positive is clockwise. Speeds of more than 1000 steps per\n    #                   second are unreliable. Speed accuracy depends on the Arduino\n    #                   crystal. Jitter depends on how frequently you call the\n    #                   stepper_run_speed() method.\n    #                   The speed will be limited by the current value of\n    #                   stepper_set_max_speed().\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')\n    #\n    #     if not 0 < speed <= 1000:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '\n    #                            '1000.')\n    #\n    #     self.stepper_info_list[motor_id]['speed'] = speed\n    #\n    #     speed_msb = speed >> 8\n    #     speed_lsb = speed & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_speed(self, motor_id):\n    #     \"\"\"\n    #     Returns the  most recently set speed.\n    #     that was previously set by stepper_set_speed();\n    #\n    #     Value is stored in the client, so no callback is required.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')\n    #\n    #     return self.stepper_info_list[motor_id]['speed']\n    #\n    # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):\n    #     \"\"\"\n    #     Request the distance from the current position to the target position\n    #     from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param distance_to_go_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]\n    #\n    #     A positive distance is clockwise from the current position.\n    #\n    #     \"\"\"\n    #     if not distance_to_go_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')\n    #     self.stepper_info_list[motor_id][\n    #         'distance_to_go_callback'] = distance_to_go_callback\n    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_target_position(self, motor_id, target_callback):\n    #     \"\"\"\n    #     Request the most recently set target position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param target_callback: required callback function to receive report\n    #\n    #     :return: The distance to go is returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #\n    #     \"\"\"\n    #     if not target_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_target_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id][\n    #         'target_position_callback'] = target_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_get_current_position(self, motor_id, current_position_callback):\n    #     \"\"\"\n    #     Request the current motor position from the server.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param current_position_callback: required callback function to receive report\n    #\n    #     :return: The current motor position returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]\n    #\n    #     Positive is clockwise from the 0 position.\n    #     \"\"\"\n    #     if not current_position_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_get_current_position Read: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback\n    #\n    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_current_position(self, motor_id, position):\n    #     \"\"\"\n    #     Resets the current position of the motor, so that wherever the motor\n    #     happens to be right now is considered to be the new 0 position. Useful\n    #     for setting a zero position on a stepper after an initial hardware\n    #     positioning move.\n    #\n    #     Has the side effect of setting the current motor speed to 0.\n    #\n    #     :param motor_id:  0 - 3\n    #\n    #     :param position: Position in steps. This is a 32 bit value\n    #     \"\"\"\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')\n    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))\n    #\n    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]\n    #     for value in position_bytes:\n    #         command.append(value)\n    #     await self._send_command(command)\n    #\n    # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):\n    #     \"\"\"\n    #     Runs the motor at the currently selected speed until the target position is\n    #     reached.\n    #\n    #     Does not implement accelerations.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param completion_callback: call back function to receive motion complete\n    #                                 notification\n    #\n    #     callback returns a data list:\n    #\n    #     [report_type, motor_id, raw_time_stamp]\n    #\n    #     The report_type = 19\n    #     \"\"\"\n    #     if not completion_callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '\n    #                            'callback must be '\n    #                            'specified.')\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback\n    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_stop(self, motor_id):\n    #     \"\"\"\n    #     Sets a new target position that causes the stepper\n    #     to stop as quickly as possible, using the current speed and\n    #     acceleration parameters.\n    #\n    #     :param motor_id:  0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_stop: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_STOP, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_disable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Disable motor pin outputs by setting them all LOW.\n    #\n    #     Depending on the design of your electronics this may turn off\n    #     the power to the motor coils, saving power.\n    #\n    #     This is useful to support Arduino low power modes: disable the outputs\n    #     during sleep and then re-enable with enableOutputs() before stepping\n    #     again.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and clears\n    #     the pin to disabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_enable_outputs(self, motor_id):\n    #     \"\"\"\n    #     Enable motor pin outputs by setting the motor pins to OUTPUT\n    #     mode.\n    #\n    #     If the enable Pin is defined, sets it to OUTPUT mode and sets\n    #     the pin to enabled.\n    #\n    #     :param motor_id: 0 - 3\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):\n    #     \"\"\"\n    #     Sets the minimum pulse width allowed by the stepper driver.\n    #\n    #     The minimum practical pulse width is approximately 20 microseconds.\n    #\n    #     Times less than 20 microseconds will usually result in 20 microseconds or so.\n    #\n    #     :param motor_id: 0 -3\n    #\n    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')\n    #\n    #     if not 0 < minimum_width <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '\n    #                            '0-0xffff.')\n    #\n    #     width_msb = minimum_width >> 8\n    #     width_lsb = minimum_width & 0xff\n    #\n    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,\n    #                width_lsb]\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_enable_pin(self, motor_id, pin=0xff):\n    #     \"\"\"\n    #     Sets the enable pin number for stepper drivers.\n    #     0xFF indicates unused (default).\n    #\n    #     Otherwise, if a pin is set, the pin will be turned on when\n    #     enableOutputs() is called and switched off when disableOutputs()\n    #     is called.\n    #\n    #     :param motor_id: 0 - 4\n    #     :param pin: 0-0xff\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')\n    #\n    #     if not 0 < pin <= 0xff:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '\n    #                            '0-0xff.')\n    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,\n    #                                 enable=False):\n    #     \"\"\"\n    #     Sets the inversion for stepper driver pins.\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param direction: True=inverted or False\n    #\n    #     :param step: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,\n    #                step, enable]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,\n    #                                   pin2_invert=False,\n    #                                 pin3_invert=False, pin4_invert=False, enable=False):\n    #     \"\"\"\n    #     Sets the inversion for 2, 3 and 4 wire stepper pins\n    #\n    #     :param motor_id: 0 - 3\n    #\n    #     :param pin1_invert: True=inverted or False\n    #\n    #     :param pin2_invert: True=inverted or False\n    #\n    #     :param pin3_invert: True=inverted or False\n    #\n    #     :param pin4_invert: True=inverted or False\n    #\n    #     :param enable: True=inverted or False\n    #     \"\"\"\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')\n    #\n    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,\n    #                pin2_invert, pin3_invert, pin4_invert, enable]\n    #\n    #     await self._send_command(command)\n    #\n    # async def stepper_is_running(self, motor_id, callback):\n    #     \"\"\"\n    #     Checks to see if the motor is currently running to a target.\n    #\n    #     Callback return True if the speed is not zero or not at the target position.\n    #\n    #     :param motor_id: 0-4\n    #\n    #     :param callback: required callback function to receive report\n    #\n    #     :return: The current running state returned via the callback as a list:\n    #\n    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]\n    #     \"\"\"\n    #     if not callback:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError(\n    #             'stepper_is_running: A callback function must be specified.')\n    #\n    #     if not self.stepper_info_list[motor_id]['instance']:\n    #         if self.shutdown_on_exception:\n    #             await self.shutdown()\n    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')\n    #\n    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback\n    #\n    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]\n    #     await self._send_command(command)\n\n    async def shutdown(self):\n\"\"\"\n        This method attempts an orderly shutdown\n        If any exceptions are thrown, they are ignored.\n\n        \"\"\"\n        self.shutdown_flag = True\n\n        if self.hard_reset_on_shutdown:\n            await self.r4_hard_reset()\n        # stop all reporting - both analog and digital\n        try:\n            if self.serial_port:\n                command = [PrivateConstants.STOP_ALL_REPORTS]\n                await self._send_command(command)\n\n                await asyncio.sleep(.5)\n\n                await self.serial_port.reset_input_buffer()\n                await self.serial_port.close()\n                if self.close_loop_on_shutdown:\n                    self.loop.stop()\n            elif self.sock:\n                command = [PrivateConstants.STOP_ALL_REPORTS]\n                await self._send_command(command)\n                self.the_task.cancel()\n                await asyncio.sleep(.5)\n                if self.close_loop_on_shutdown:\n                    self.loop.stop()\n        except (RuntimeError, SerialException):\n            pass\n\n    async def r4_hard_reset(self):\n\"\"\"\n        Place the r4 into hard reset\n        \"\"\"\n        command = [PrivateConstants.BOARD_HARD_RESET, 1]\n        await self._send_command(command)\n\n    async def disable_all_reporting(self):\n\"\"\"\n        Disable reporting for all digital and analog input pins\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DISABLE_ALL, 0]\n        await self._send_command(command)\n\n    async def disable_analog_reporting(self, pin):\n\"\"\"\n        Disables analog reporting for a single analog pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n        await self._send_command(command)\n\n    async def disable_digital_reporting(self, pin):\n\"\"\"\n        Disables digital reporting for a single digital pin\n\n\n        :param pin: pin number\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n        await self._send_command(command)\n\n    async def enable_analog_reporting(self, pin):\n\"\"\"\n        Enables analog reporting for the specified pin.\n\n        :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n        \"\"\"\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n        await self._send_command(command)\n\n    async def enable_digital_reporting(self, pin):\n\"\"\"\n        Enable reporting on the specified digital pin.\n\n        :param pin: Pin number.\n        \"\"\"\n\n        command = [PrivateConstants.MODIFY_REPORTING,\n                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n        await self._send_command(command)\n\n    async def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n        :param message: Message with maximum length of 25\n        :param scroll_speed: in milliseconds (maximum of 255)\n        \"\"\"\n        if len(message) > 25:\n            raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n        if scroll_speed > 255:\n            raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n        message = message.encode()\n        command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n        for x in message:\n            command.append(x)\n        await self._send_command(command)\n\n    async def disable_scroll_message(self):\n\"\"\"\n        Turn off a scrolling message\n        \"\"\"\n\n        command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n        await self._send_command(command)\n\n    async def _arduino_report_dispatcher(self):\n\"\"\"\n        This is a private method.\n        It continually accepts and interprets data coming from Telemetrix4Arduino,and then\n        dispatches the correct handler to process the data.\n\n        It first receives the length of the packet, and then reads in the rest of the\n        packet. A packet consists of a length, report identifier and then the report data.\n        Using the report identifier, the report handler is fetched from report_dispatch.\n\n        :returns: This method never returns\n        \"\"\"\n\n        while True:\n            if self.shutdown_flag:\n                break\n            try:\n                if not self.transport_address:\n                    packet_length = await self.serial_port.read()\n                else:\n\n                    packet_length = ord(await self.sock.read())\n            except TypeError:\n                continue\n\n            # get the rest of the packet\n            if not self.transport_address:\n                packet = await self.serial_port.read(packet_length)\n            else:\n                packet = list(await self.sock.read(packet_length))\n                if len(packet) != packet_length:\n                    continue\n                # print(f'packet.len() {}')\n                # await asyncio.sleep(.1)\n\n            report = packet[0]\n            # print(report)\n            # handle all other messages by looking them up in the\n            # command dictionary\n\n            await self.report_dispatch[report](packet[1:])\n            await asyncio.sleep(self.sleep_tune)\n\n    async def _ble_report_dispatcher(self, sender=None, data=None):\n\"\"\"\n        This is a private method called by the incoming data notifier\n\n        Using the report identifier, the report handler is fetched from report_dispatch.\n\n        :param sender: BLE sender ID\n        :param data: data received over the ble link\n\n        \"\"\"\n        self.the_sender = sender\n        data = list(data)\n        report = data[1]\n\n        if report == 5:  # get firmware data reply\n            self.firmware_version = list(data)\n            print()\n        # noinspection PyArgumentList\n        else:\n            await self.report_dispatch[report](data[2:])\n\n'''\n    Report message handlers\n    '''\n\n    async def _report_loop_data(self, data):\n\"\"\"\n        Print data that was looped back\n\n        :param data: byte of loop back data\n        \"\"\"\n        if self.loop_back_callback:\n            await self.loop_back_callback(data)\n\n    async def _spi_report(self, report):\n        report = list(report)\n        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]\n\n        cb_list.append(time.time())\n\n        await self.spi_callback(cb_list)\n\n    async def _onewire_report(self, report):\n        report = list(report)\n\n        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]\n        cb_list.append(time.time())\n        await self.onewire_callback(cb_list)\n\n    async def _report_debug_data(self, data):\n\"\"\"\n        Print debug data sent from Arduino\n\n        :param data: data[0] is a byte followed by 2\n                     bytes that comprise an integer\n        \"\"\"\n        value = (data[1] << 8) + data[2]\n        print(f'DEBUG ID: {data[0]} Value: {value}')\n\n    async def _analog_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for analog messages.\n\n        :param data: message data\n\n        \"\"\"\n        pin = data[0]\n        value = (data[1] << 8) + data[2]\n\n        time_stamp = time.time()\n\n        # append pin number, pin value, and pin type to return value and return as a list\n        message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]\n\n        await self.analog_callbacks[pin](message)\n\n    async def _dht_report(self, data):\n\"\"\"\n        This is a private message handler for dht reports\n\n        :param data:            data[0] = report error return\n                                    No Errors = 0\n\n                                    Checksum Error = 1\n\n                                    Timeout Error = 2\n\n                                    Invalid Value = 999\n\n                                data[1] = pin number\n\n                                data[2] = dht type 11 or 22\n\n                                data[3] = humidity positivity flag\n\n                                data[4] = temperature positivity value\n\n                                data[5] = humidity integer\n\n                                data[6] = humidity fractional value\n\n                                data[7] = temperature integer\n\n                                data[8] = temperature fractional value\n        \"\"\"\n        data = list(data)\n        if data[0]:  # DHT_ERROR\n            # error report\n            # data[0] = report sub type, data[1] = pin, data[2] = error message\n            if self.dht_callbacks[data[1]]:\n                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time\n                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                           time.time()]\n                await self.dht_callbacks[data[1]](message)\n        else:\n            # got valid data DHT_DATA\n            f_humidity = float(data[5] + data[6] / 100)\n            if data[3]:\n                f_humidity *= -1.0\n            f_temperature = float(data[7] + data[8] / 100)\n            if data[4]:\n                f_temperature *= -1.0\n            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],\n                       f_humidity, f_temperature, time.time()]\n\n            await self.dht_callbacks[data[1]](message)\n\n    async def _digital_message(self, data):\n\"\"\"\n        This is a private message handler method.\n        It is a message handler for Digital Messages.\n\n        :param data: digital message\n\n        \"\"\"\n        pin = data[0]\n        value = data[1]\n\n        time_stamp = time.time()\n        if self.digital_callbacks[pin]:\n            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]\n            await self.digital_callbacks[pin](message)\n\n    async def _servo_unavailable(self, report):\n\"\"\"\n        Message if no servos are available for use.\n\n        :param report: pin number\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')\n\n    async def _i2c_read_report(self, data):\n\"\"\"\n        Execute callback for i2c reads.\n\n        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]\n        \"\"\"\n\n        # we receive [# data bytes, address, register, data bytes]\n        # number of bytes of data returned\n\n        # data[0] = number of bytes\n        # data[1] = i2c_port\n        # data[2] = number of bytes returned\n        # data[3] = address\n        # data[4] = register\n        # data[5] ... all the data bytes\n        data = list(data)\n        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]\n        cb_list.append(time.time())\n\n        if cb_list[1]:\n            await self.i2c_callback2(cb_list)\n        else:\n            await self.i2c_callback(cb_list)\n\n    async def _i2c_too_few(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    async def _i2c_too_many(self, data):\n\"\"\"\n        I2c reports too few bytes received\n\n        :param data: data[0] = device address\n        \"\"\"\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')\n\n    async def _sonar_distance_report(self, report):\n\"\"\"\n\n        :param report: data[0] = trigger pin, data[1] and data[2] = distance\n\n        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]\n        \"\"\"\n        report = list(report)\n        # get callback from pin number\n        cb = self.sonar_callbacks[report[0]]\n\n        # build report data\n        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],\n                   ((report[1] << 8) + report[2]), time.time()]\n\n        await cb(cb_list)\n\n    async def _stepper_distance_to_go_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper distance to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,\n    #                              data[3] = steps bytes 2, data[4] = steps LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id\n    #                              steps, time_stamp]\n    #     \"\"\"\n    #     report = list(report)\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     steps = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n\n    async def _stepper_target_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper target position to go.\n    #\n    #     :param report: data[0] = motor_id, data[1] = target position MSB,\n    #                    data[2] = target position byte MSB+1\n    #                    data[3] = target position byte MSB+2\n    #                    data[4] = target position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id\n    #                              target_position, time_stamp]\n    #     \"\"\"\n    #     report = list(report)\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['target_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     target = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     target_position = int.from_bytes(target, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n\n    async def _stepper_current_position_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report stepper current position.\n    #\n    #     :param report: data[0] = motor_id, data[1] = current position MSB,\n    #                    data[2] = current position byte MSB+1\n    #                    data[3] = current position byte MSB+2\n    #                    data[4] = current position LSB\n    #\n    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id\n    #                              current_position, time_stamp]\n    #     \"\"\"\n    #     report = list(report)\n\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['current_position_callback']\n    #\n    #     # isolate the steps bytes and covert list to bytes\n    #     position = bytes(report[1:])\n    #\n    #     # get value from steps\n    #     current_position = int.from_bytes(position, byteorder='big', signed=True)\n    #\n    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n    #\n\n    async def _stepper_is_running_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     Report if the motor is currently running\n    #\n    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.\n    #\n    #     callback report format: [18, motor_id,\n    #                              running_state, time_stamp]\n    #     \"\"\"\n    #     report = list(report)\n\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['is_running_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]\n    #\n    #     await cb(cb_list)\n    #\n\n    async def _stepper_run_complete_report(self, report):\n        return  # for now\n    #     \"\"\"\n    #     The motor completed it motion\n    #\n    #     :param report: data[0] = motor_id\n    #\n    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,\n    #                              time_stamp]\n    #     \"\"\"\n    #     report = list(report)\n    #     # get callback\n    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']\n    #\n    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],\n    #                time.time()]\n    #\n    #     await cb(cb_list)\n\n    async def _features_report(self, report):\n        self.reported_features = report[0]\n\n    async def _send_command(self, command):\n\"\"\"\n        This is a private utility method.\n\n\n        :param command:  command data in the form of a list\n\n        :returns: number of bytes sent\n        \"\"\"\n        # the length of the list is added at the head\n        # the length of the list is added at the head\n        command.insert(0, len(command))\n        send_message = bytes(command)\n\n        if self.transport_type == 1:\n            try:\n                await self.serial_port.write(send_message)\n            except SerialException:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n                raise RuntimeError('write fail in _send_command')\n        elif self.transport_type == 0:\n            await self.sock.write(send_message)\n        else:\n            await self.ble_instance.write(send_message)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.__init__","title":"__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0, ble_device_name='Telemetrix4UnoR4 BLE')","text":"

If you have a single Arduino connected to your computer, then you may accept all the default values.

Otherwise, specify a unique arduino_instance id for each board in use.

:param com_port: e.g. COM3 or /dev/ttyACM0.

:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch

:param arduino_wait: Amount of time to wait for an Arduino to fully reset itself.

:param sleep_tune: A tuning parameter (typically not changed by user)

:param autostart: If you wish to call the start method within your application, then set this to False.

:param loop: optional user provided event loop

:param shutdown_on_exception: call shutdown before raising a RunTimeError exception, or receiving a KeyboardInterrupt exception

:param close_loop_on_shutdown: stop and close the event loop loop when a shutdown is called or a serial error occurs

:param hard_reset_on_shutdown: reset the board on shutdown

:param transport_address: ip address of tcp/ip connected device.

:param ip_port: ip port of tcp/ip connected device

:param transport_type: 0 = WiFi 1 = SerialUSB 2 = BLE

:param ble_device_name: name of Arduino UNO R4 WIFI BLE device. It must match that of Telemetrix4UnoR4BLE.ino

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
def __init__(self, com_port=None,\n             arduino_instance_id=1, arduino_wait=1,\n             sleep_tune=0.0001, autostart=True,\n             loop=None, shutdown_on_exception=True,\n             close_loop_on_shutdown=True, hard_reset_on_shutdown=True,\n             transport_address=None, ip_port=31336, transport_type=0,\n             ble_device_name='Telemetrix4UnoR4 BLE'):\n\n\"\"\"\n    If you have a single Arduino connected to your computer,\n    then you may accept all the default values.\n\n    Otherwise, specify a unique arduino_instance id for each board in use.\n\n    :param com_port: e.g. COM3 or /dev/ttyACM0.\n\n    :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch\n\n    :param arduino_wait: Amount of time to wait for an Arduino to\n                         fully reset itself.\n\n    :param sleep_tune: A tuning parameter (typically not changed by user)\n\n    :param autostart: If you wish to call the start method within\n                      your application, then set this to False.\n\n    :param loop: optional user provided event loop\n\n    :param shutdown_on_exception: call shutdown before raising\n                                  a RunTimeError exception, or\n                                  receiving a KeyboardInterrupt exception\n\n    :param close_loop_on_shutdown: stop and close the event loop loop\n                                   when a shutdown is called or a serial\n                                   error occurs\n\n   :param hard_reset_on_shutdown: reset the board on shutdown\n\n   :param transport_address: ip address of tcp/ip connected device.\n\n    :param ip_port: ip port of tcp/ip connected device\n\n    :param transport_type: 0 = WiFi\n                           1 = SerialUSB\n                           2 = BLE\n\n   :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.\n                           It must match that of Telemetrix4UnoR4BLE.ino\n\n    \"\"\"\n    # check to make sure that Python interpreter is version 3.8.3 or greater\n    python_version = sys.version_info\n    if python_version[0] >= 3:\n        if python_version[1] >= 8:\n            if python_version[2] >= 3:\n                pass\n        else:\n            raise RuntimeError(\"ERROR: Python 3.7 or greater is \"\n                               \"required for use of this program.\")\n\n    # save input parameters\n    self.com_port = com_port\n    self.arduino_instance_id = arduino_instance_id\n    self.arduino_wait = arduino_wait\n    self.sleep_tune = sleep_tune\n    self.autostart = autostart\n    self.hard_reset_on_shutdown = hard_reset_on_shutdown\n\n    self.transport_address = transport_address\n    self.ip_port = ip_port\n    if transport_type not in [0, 1, 2]:\n        raise RuntimeError('Invalid transport type')\n    self.transport_type = transport_type\n    self.firmware_version = None\n    # if tcp, this variable is set to the connected socket\n    self.sock = None\n\n    self.ble_device_name = ble_device_name\n\n    # instance of telemetrix_aio_ble\n    self.ble_instance = None\n\n    # set the event loop\n    if loop is None:\n        self.loop = asyncio.get_event_loop()\n    else:\n        self.loop = loop\n\n    self.shutdown_on_exception = shutdown_on_exception\n    self.close_loop_on_shutdown = close_loop_on_shutdown\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    # debug loopback callback method\n    self.loop_back_callback = None\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    self.dht_count = 0\n\n    # serial port in use\n    self.serial_port = None\n\n    # generic asyncio task holder\n    self.the_task = None\n\n    # flag to indicate we are in shutdown mode\n    self.shutdown_flag = False\n\n    self.report_dispatch = {}\n\n    # reported features\n    self.reported_features = 0\n\n    # To add a command to the command dispatch table, append here.\n    self.report_dispatch.update(\n        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})\n    self.report_dispatch.update(\n        {PrivateConstants.DIGITAL_REPORT: self._digital_message})\n    self.report_dispatch.update(\n        {PrivateConstants.ANALOG_REPORT: self._analog_message})\n    self.report_dispatch.update(\n        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})\n    self.report_dispatch.update(\n        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})\n    self.report_dispatch.update(\n        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})\n    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})\n    self.report_dispatch.update(\n        {PrivateConstants.SPI_REPORT: self._spi_report})\n    self.report_dispatch.update(\n        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_CURRENT_POSITION:\n             self._stepper_current_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUNNING_REPORT:\n             self._stepper_is_running_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:\n             self._stepper_run_complete_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_DISTANCE_TO_GO:\n             self._stepper_distance_to_go_report})\n    self.report_dispatch.update(\n        {PrivateConstants.STEPPER_TARGET_POSITION:\n             self._stepper_target_position_report})\n    self.report_dispatch.update(\n        {PrivateConstants.FEATURES:\n             self._features_report})\n\n    # dictionaries to store the callbacks for each pin\n    self.analog_callbacks = {}\n\n    self.digital_callbacks = {}\n\n    self.i2c_callback = None\n    self.i2c_callback2 = None\n\n    self.i2c_1_active = False\n    self.i2c_2_active = False\n\n    self.spi_callback = None\n\n    self.onewire_callback = None\n\n    self.cs_pins_enabled = []\n\n    # flag to indicate if spi is initialized\n    self.spi_enabled = False\n\n    # flag to indicate if onewire is initialized\n    self.onewire_enabled = False\n\n    # the trigger pin will be the key to retrieve\n    # the callback for a specific HC-SR04\n    self.sonar_callbacks = {}\n\n    self.sonar_count = 0\n\n    self.dht_callbacks = {}\n\n    # # stepper motor variables\n    #\n    # # updated when a new motor is added\n    # self.next_stepper_assigned = 0\n    #\n    # # valid list of stepper motor interface types\n    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]\n    #\n    # # maximum number of steppers supported\n    # self.max_number_of_steppers = 4\n    #\n    # # number of steppers created - not to exceed the maximum\n    # self.number_of_steppers = 0\n    #\n    # # dictionary to hold stepper motor information\n    # self.stepper_info = {'instance': False, 'is_running': None,\n    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,\n    #                      'distance_to_go_callback': None,\n    #                      'target_position_callback': None,\n    #                      'current_position_callback': None,\n    #                      'is_running_callback': None,\n    #                      'motion_complete_callback': None,\n    #                      'acceleration_callback': None}\n    #\n    # # build a list of stepper motor info items\n    # self.stepper_info_list = []\n    # # a list of dictionaries to hold stepper information\n    # for motor in range(self.max_number_of_steppers):\n    #     self.stepper_info_list.append(self.stepper_info)\n\n    print(f'telemetrix_uno_r4_wifi_aio Version:'\n          f' {PrivateConstants.TELEMETRIX_VERSION}')\n    print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\\n')\n\n    if autostart:\n        self.loop.run_until_complete(self.start_aio())\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.analog_write","title":"analog_write(pin, value) async","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (maximum 16 bits)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def analog_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (maximum 16 bits)\n\n    \"\"\"\n    value_msb = value >> 8\n    value_lsb = value & 0xff\n    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.digital_write","title":"digital_write(pin, value) async","text":"

Set the specified pin to the specified value.

:param pin: arduino pin number

:param value: pin value (1 or 0)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def digital_write(self, pin, value):\n\"\"\"\n    Set the specified pin to the specified value.\n\n    :param pin: arduino pin number\n\n    :param value: pin value (1 or 0)\n\n    \"\"\"\n    command = [PrivateConstants.DIGITAL_WRITE, pin, value]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_all_reporting","title":"disable_all_reporting() async","text":"

Disable reporting for all digital and analog input pins

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_all_reporting(self):\n\"\"\"\n    Disable reporting for all digital and analog input pins\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DISABLE_ALL, 0]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_analog_reporting","title":"disable_analog_reporting(pin) async","text":"

Disables analog reporting for a single analog pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_analog_reporting(self, pin):\n\"\"\"\n    Disables analog reporting for a single analog pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_digital_reporting","title":"disable_digital_reporting(pin) async","text":"

Disables digital reporting for a single digital pin

:param pin: pin number

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_digital_reporting(self, pin):\n\"\"\"\n    Disables digital reporting for a single digital pin\n\n\n    :param pin: pin number\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.disable_scroll_message","title":"disable_scroll_message() async","text":"

Turn off a scrolling message

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def disable_scroll_message(self):\n\"\"\"\n    Turn off a scrolling message\n    \"\"\"\n\n    command = [PrivateConstants.SCROLL_MESSAGE_OFF]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_analog_reporting","title":"enable_analog_reporting(pin) async","text":"

Enables analog reporting for the specified pin.

:param pin: Analog pin number. For example for A0, the number is 0.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_analog_reporting(self, pin):\n\"\"\"\n    Enables analog reporting for the specified pin.\n\n    :param pin: Analog pin number. For example for A0, the number is 0.\n\n\n    \"\"\"\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_digital_reporting","title":"enable_digital_reporting(pin) async","text":"

Enable reporting on the specified digital pin.

:param pin: Pin number.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_digital_reporting(self, pin):\n\"\"\"\n    Enable reporting on the specified digital pin.\n\n    :param pin: Pin number.\n    \"\"\"\n\n    command = [PrivateConstants.MODIFY_REPORTING,\n               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.enable_scroll_message","title":"enable_scroll_message(message, scroll_speed=50) async","text":"

:param message: Message with maximum length of 25 :param scroll_speed: in milliseconds (maximum of 255)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def enable_scroll_message(self, message, scroll_speed=50):\n\"\"\"\n\n    :param message: Message with maximum length of 25\n    :param scroll_speed: in milliseconds (maximum of 255)\n    \"\"\"\n    if len(message) > 25:\n        raise RuntimeError(\"Scroll message size is maximum of 25 characters.\")\n\n    if scroll_speed > 255:\n        raise RuntimeError(\"Scroll speed maximum of 255 milliseconds.\")\n\n    message = message.encode()\n    command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]\n    for x in message:\n        command.append(x)\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.get_event_loop","title":"get_event_loop() async","text":"

Return the currently active asyncio event loop

:return: Active event loop

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def get_event_loop(self):\n\"\"\"\n    Return the currently active asyncio event loop\n\n    :return: Active event loop\n\n    \"\"\"\n    return self.loop\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_read","title":"i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) async","text":"

Read the specified number of bytes from the specified register for the i2c device.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: select the default port (0) or secondary port (1)

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_read(self, address, register, number_of_bytes,\n                   callback, i2c_port=0,\n                   write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified register for\n    the i2c device.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c data as a\n               result of read command\n\n    :param i2c_port: select the default port (0) or secondary port (1)\n\n    :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('i2c_read: A Callback must be specified')\n\n    await self._i2c_read_request(address, register, number_of_bytes,\n                                 callback=callback, i2c_port=i2c_port,\n                                 write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_read_restart_transmission","title":"i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) async","text":"

Read the specified number of bytes from the specified register for the i2c device. This restarts the transmission after the read. It is required for some i2c devices such as the MMA8452Q accelerometer.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

:param callback: Required callback function to report i2c data as a result of read command

:param i2c_port: select the default port (0) or secondary port (1)

:param write_register: If True, the register is written before read Else, the write is suppressed

callback returns a data list:

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_read_restart_transmission(self, address, register,\n                                        number_of_bytes,\n                                        callback, i2c_port=0,\n                                        write_register=True):\n\"\"\"\n    Read the specified number of bytes from the specified register for\n    the i2c device. This restarts the transmission after the read. It is\n    required for some i2c devices such as the MMA8452Q accelerometer.\n\n\n    :param address: i2c device address\n\n    :param register: i2c register (or None if no register\n                                                selection is needed)\n\n    :param number_of_bytes: number of bytes to be read\n\n    :param callback: Required callback function to report i2c data as a\n               result of read command\n\n    :param i2c_port: select the default port (0) or secondary port (1)\n\n    :param write_register: If True, the register is written\n                                   before read\n                          Else, the write is suppressed\n\n    callback returns a data list:\n\n    [I2C_READ_REPORT, address, register, count of data bytes,\n     data bytes, time-stamp]\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'i2c_read_restart_transmission: A Callback must be specified')\n\n    await self._i2c_read_request(address, register, number_of_bytes,\n                                 stop_transmission=False,\n                                 callback=callback, i2c_port=i2c_port,\n                                 write_register=write_register)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.i2c_write","title":"i2c_write(address, args, i2c_port=0) async","text":"

Write data to an i2c device.

:param address: i2c device address

:param i2c_port: 0= port 1, 1 = port 2

:param args: A variable number of bytes to be sent to the device passed in as a list

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def i2c_write(self, address, args, i2c_port=0):\n\"\"\"\n    Write data to an i2c device.\n\n    :param address: i2c device address\n\n    :param i2c_port: 0= port 1, 1 = port 2\n\n    :param args: A variable number of bytes to be sent to the device\n                 passed in as a list\n\n    \"\"\"\n    if not i2c_port:\n        if not self.i2c_1_active:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 1.')\n\n    if i2c_port:\n        if not self.i2c_2_active:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                'I2C Write: set_pin_mode i2c never called for i2c port 2.')\n\n    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]\n\n    for item in args:\n        command.append(item)\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.loop_back","title":"loop_back(start_character, callback) async","text":"

This is a debugging method to send a character to the Arduino device, and have the device loop it back.

:param start_character: The character to loop back. It should be an integer.

:param callback: Looped back character will appear in the callback method

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def loop_back(self, start_character, callback):\n\"\"\"\n    This is a debugging method to send a character to the\n    Arduino device, and have the device loop it back.\n\n    :param start_character: The character to loop back. It should be\n                            an integer.\n\n    :param callback: Looped back character will appear in the callback method\n\n    \"\"\"\n\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('loop_back: A callback function must be specified.')\n    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]\n    self.loop_back_callback = callback\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.r4_hard_reset","title":"r4_hard_reset() async","text":"

Place the r4 into hard reset

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def r4_hard_reset(self):\n\"\"\"\n    Place the r4 into hard reset\n    \"\"\"\n    command = [PrivateConstants.BOARD_HARD_RESET, 1]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.servo_detach","title":"servo_detach(pin_number) async","text":"

Detach a servo for reuse :param pin_number: attached pin

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def servo_detach(self, pin_number):\n\"\"\"\n    Detach a servo for reuse\n    :param pin_number: attached pin\n    \"\"\"\n    command = [PrivateConstants.SERVO_DETACH, pin_number]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.servo_write","title":"servo_write(pin_number, angle) async","text":"

Set a servo attached to a pin to a given angle.

:param pin_number: pin

:param angle: angle (0-180)

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def servo_write(self, pin_number, angle):\n\"\"\"\n\n    Set a servo attached to a pin to a given angle.\n\n    :param pin_number: pin\n\n    :param angle: angle (0-180)\n\n    \"\"\"\n    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_analog_scan_interval","title":"set_analog_scan_interval(interval) async","text":"

Set the analog scanning interval.

:param interval: value of 0 - 255 - milliseconds

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_analog_scan_interval(self, interval):\n\"\"\"\n    Set the analog scanning interval.\n\n    :param interval: value of 0 - 255 - milliseconds\n    \"\"\"\n\n    if 0 <= interval <= 255:\n        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('Analog interval must be between 0 and 255')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_analog_input","title":"set_pin_mode_analog_input(pin_number, differential=0, callback=None) async","text":"

Set a pin as an analog input.

:param pin_number: arduino pin number

:param callback: async callback function

:param differential: difference in previous to current value before report will be generated

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for analog input pins = 3

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):\n\"\"\"\n    Set a pin as an analog input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    :param differential: difference in previous to current value before\n                         report will be generated\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for analog input pins = 3\n\n    \"\"\"\n\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'set_pin_mode_analog_input: A callback function must be specified.')\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,\n                             differential, callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_analog_output","title":"set_pin_mode_analog_output(pin_number) async","text":"

Set a pin as a pwm (analog output) pin.

:param pin_number:arduino pin number

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_analog_output(self, pin_number):\n\"\"\"\n\n    Set a pin as a pwm (analog output) pin.\n\n    :param pin_number:arduino pin number\n\n    \"\"\"\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                             callback=None)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_dht","title":"set_pin_mode_dht(pin, callback=None, dht_type=22) async","text":"

:param pin: connection pin

:param callback: callback function

:param dht_type: either 22 for DHT22 or 11 for DHT11

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, Temperature, Time]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):\n\"\"\"\n\n    :param pin: connection pin\n\n    :param callback: callback function\n\n    :param dht_type: either 22 for DHT22 or 11 for DHT11\n\n    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]\n\n    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,\n    Temperature,\n    Time]\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.DHT_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')\n\n        if self.dht_count < PrivateConstants.MAX_DHTS - 1:\n            self.dht_callbacks[pin] = callback\n            self.dht_count += 1\n\n            if dht_type != 22 and dht_type != 11:\n                dht_type = 22\n\n            command = [PrivateConstants.DHT_NEW, pin, dht_type]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')\n\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The DHT feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_input","title":"set_pin_mode_digital_input(pin_number, callback) async","text":"

Set a pin as a digital input.

:param pin_number: arduino pin number

:param callback: async callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_input(self, pin_number, callback):\n\"\"\"\n    Set a pin as a digital input.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,\n                             callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_input_pullup","title":"set_pin_mode_digital_input_pullup(pin_number, callback) async","text":"

Set a pin as a digital input with pullup enabled.

:param pin_number: arduino pin number

:param callback: async callback function

callback returns a data list:

[pin_type, pin_number, pin_value, raw_time_stamp]

The pin_type for all digital input pins = 2

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):\n\"\"\"\n    Set a pin as a digital input with pullup enabled.\n\n    :param pin_number: arduino pin number\n\n    :param callback: async callback function\n\n    callback returns a data list:\n\n    [pin_type, pin_number, pin_value, raw_time_stamp]\n\n    The pin_type for all digital input pins = 2\n\n    \"\"\"\n    if not callback:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(\n            'set_pin_mode_digital_input_pullup: A callback function must be specified.')\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,\n                             differential=0, callback=callback)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_digital_output","title":"set_pin_mode_digital_output(pin_number) async","text":"

Set a pin as a digital output pin.

:param pin_number: arduino pin number

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_digital_output(self, pin_number):\n\"\"\"\n    Set a pin as a digital output pin.\n\n    :param pin_number: arduino pin number\n    \"\"\"\n\n    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,\n                             callback=None)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_i2c","title":"set_pin_mode_i2c(i2c_port=0) async","text":"

Establish the standard Arduino i2c pins for i2c utilization.

:param i2c_port: 0 = i2c1, 1 = i2c2

  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  1. Callbacks are set within the individual i2c read methods of this
  API.\n\n  See i2c_read, or i2c_read_restart_transmission.\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_i2c(self, i2c_port=0):\n\"\"\"\n    Establish the standard Arduino i2c pins for i2c utilization.\n\n    :param i2c_port: 0 = i2c1, 1 = i2c2\n\n    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE\n           2. Callbacks are set within the individual i2c read methods of this\n          API.\n\n          See i2c_read, or i2c_read_restart_transmission.\n\n    \"\"\"\n    # test for i2c port 2\n    if i2c_port:\n        # if not previously activated set it to activated\n        # and the send a begin message for this port\n        if not self.i2c_2_active:\n            self.i2c_2_active = True\n        else:\n            return\n    # port 1\n    else:\n        if not self.i2c_1_active:\n            self.i2c_1_active = True\n        else:\n            return\n\n    command = [PrivateConstants.I2C_BEGIN, i2c_port]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_servo","title":"set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) async","text":"

Attach a pin to a servo motor

:param pin_number: pin

:param min_pulse: minimum pulse width

:param max_pulse: maximum pulse width

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):\n\"\"\"\n\n    Attach a pin to a servo motor\n\n    :param pin_number: pin\n\n    :param min_pulse: minimum pulse width\n\n    :param max_pulse: maximum pulse width\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SERVO_FEATURE:\n\n        minv = (min_pulse).to_bytes(2, byteorder=\"big\")\n        maxv = (max_pulse).to_bytes(2, byteorder=\"big\")\n\n        command = [PrivateConstants.SERVO_ATTACH, pin_number,\n                   minv[0], minv[1], maxv[0], maxv[1]]\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SERVO feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_sonar","title":"set_pin_mode_sonar(trigger_pin, echo_pin, callback) async","text":"

:param trigger_pin:

:param echo_pin:

:param callback: callback

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,\n                             callback):\n\"\"\"\n\n    :param trigger_pin:\n\n    :param echo_pin:\n\n    :param callback:  callback\n\n    \"\"\"\n    if self.reported_features & PrivateConstants.SONAR_FEATURE:\n\n        if not callback:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')\n\n        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:\n            self.sonar_callbacks[trigger_pin] = callback\n            self.sonar_count += 1\n\n            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]\n            await self._send_command(command)\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError(\n                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SONAR feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.set_pin_mode_spi","title":"set_pin_mode_spi(chip_select_list=None) async","text":"

Specify the list of chip select pins.

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

Chip Select is any digital output capable pin.

:param chip_select_list: this is a list of pins to be used for chip select. The pins will be configured as output, and set to high ready to be used for chip select. NOTE: You must specify the chips select pins here!

command message: [command, number of cs pins, [cs pins...]]

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def set_pin_mode_spi(self, chip_select_list=None):\n\"\"\"\n    Specify the list of chip select pins.\n\n    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.\n\n    Chip Select is any digital output capable pin.\n\n    :param chip_select_list: this is a list of pins to be used for chip select.\n                       The pins will be configured as output, and set to high\n                       ready to be used for chip select.\n                       NOTE: You must specify the chips select pins here!\n\n\n    command message: [command, number of cs pins, [cs pins...]]\n    \"\"\"\n    if self.reported_features & PrivateConstants.SPI_FEATURE:\n\n        if type(chip_select_list) != list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('chip_select_list must be in the form of a list')\n        if not chip_select_list:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('Chip select pins were not specified')\n\n        self.spi_enabled = True\n\n        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]\n\n        for pin in chip_select_list:\n            command.append(pin)\n            self.cs_pins_enabled.append(pin)\n        await self._send_command(command)\n    else:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'The SPI feature is disabled in the server.')\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.shutdown","title":"shutdown() async","text":"

This method attempts an orderly shutdown If any exceptions are thrown, they are ignored.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def shutdown(self):\n\"\"\"\n    This method attempts an orderly shutdown\n    If any exceptions are thrown, they are ignored.\n\n    \"\"\"\n    self.shutdown_flag = True\n\n    if self.hard_reset_on_shutdown:\n        await self.r4_hard_reset()\n    # stop all reporting - both analog and digital\n    try:\n        if self.serial_port:\n            command = [PrivateConstants.STOP_ALL_REPORTS]\n            await self._send_command(command)\n\n            await asyncio.sleep(.5)\n\n            await self.serial_port.reset_input_buffer()\n            await self.serial_port.close()\n            if self.close_loop_on_shutdown:\n                self.loop.stop()\n        elif self.sock:\n            command = [PrivateConstants.STOP_ALL_REPORTS]\n            await self._send_command(command)\n            self.the_task.cancel()\n            await asyncio.sleep(.5)\n            if self.close_loop_on_shutdown:\n                self.loop.stop()\n    except (RuntimeError, SerialException):\n        pass\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.sonar_disable","title":"sonar_disable() async","text":"

Disable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def sonar_disable(self):\n\"\"\"\n    Disable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_DISABLE]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.sonar_enable","title":"sonar_enable() async","text":"

Enable sonar scanning for all sonar sensors

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def sonar_enable(self):\n\"\"\"\n    Enable sonar scanning for all sonar sensors\n    \"\"\"\n    command = [PrivateConstants.SONAR_ENABLE]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_cs_control","title":"spi_cs_control(chip_select_pin, select) async","text":"

Control an SPI chip select line :param chip_select_pin: pin connected to CS

:param select: 0=select, 1=deselect

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_cs_control(self, chip_select_pin, select):\n\"\"\"\n    Control an SPI chip select line\n    :param chip_select_pin: pin connected to CS\n\n    :param select: 0=select, 1=deselect\n    \"\"\"\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')\n\n    if chip_select_pin not in self.cs_pins_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')\n    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_read_blocking","title":"spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) async","text":"

Read the specified number of bytes from the specified SPI port and call the callback function with the reported data.

:param chip_select: chip select pin

:param register_selection: Register to be selected for read.

:param number_of_bytes_to_read: Number of bytes to read

:param call_back: Required callback function to report spi data as a result of read command

callback returns a data list

[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, data bytes, time-stamp]

SPI_READ_REPORT = 13

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_read_blocking(self, chip_select, register_selection,\n                            number_of_bytes_to_read,\n                      call_back=None):\n\"\"\"\n    Read the specified number of bytes from the specified SPI port and\n    call the callback function with the reported data.\n\n    :param chip_select: chip select pin\n\n    :param register_selection: Register to be selected for read.\n\n    :param number_of_bytes_to_read: Number of bytes to read\n\n    :param call_back: Required callback function to report spi data as a\n               result of read command\n\n\n    callback returns a data list:\n        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,\n         data bytes, time-stamp]\n    SPI_READ_REPORT = 13\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')\n\n    if not call_back:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('spi_read_blocking: A Callback must be specified')\n\n    self.spi_callback = call_back\n\n    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,\n               number_of_bytes_to_read,\n               register_selection]\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_set_format","title":"spi_set_format(clock_divisor, bit_order, data_mode) async","text":"

Configure how the SPI serializes and de-serializes data on the wire.

See Arduino SPI reference materials for details.

:param clock_divisor: 1 - 255

:param bit_order:

                LSBFIRST = 0\n\n                MSBFIRST = 1 (default)\n

:param data_mode:

                SPI_MODE0 = 0x00 (default)\n\n                SPI_MODE1  = 1\n\n                SPI_MODE2 = 2\n\n                SPI_MODE3 = 3\n
Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_set_format(self, clock_divisor, bit_order, data_mode):\n\"\"\"\n    Configure how the SPI serializes and de-serializes data on the wire.\n\n    See Arduino SPI reference materials for details.\n\n    :param clock_divisor: 1 - 255\n\n    :param bit_order:\n\n                        LSBFIRST = 0\n\n                        MSBFIRST = 1 (default)\n\n    :param data_mode:\n\n                        SPI_MODE0 = 0x00 (default)\n\n                        SPI_MODE1  = 1\n\n                        SPI_MODE2 = 2\n\n                        SPI_MODE3 = 3\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')\n\n    if not 0 < clock_divisor <= 255:\n        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')\n    if bit_order not in [0, 1]:\n        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')\n    if data_mode not in [0, 1, 2, 3]:\n        raise RuntimeError(f'spi_set_format: illegal data_order selected.')\n\n    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,\n               data_mode]\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.spi_write_blocking","title":"spi_write_blocking(chip_select, bytes_to_write) async","text":"

Write a list of bytes to the SPI device.

:param chip_select: chip select pin

:param bytes_to_write: A list of bytes to write. This must be in the form of a list.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def spi_write_blocking(self, chip_select, bytes_to_write):\n\"\"\"\n    Write a list of bytes to the SPI device.\n\n    :param chip_select: chip select pin\n\n    :param bytes_to_write: A list of bytes to write. This must\n                            be in the form of a list.\n\n    \"\"\"\n\n    if not self.spi_enabled:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')\n\n    if type(bytes_to_write) is not list:\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')\n\n    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]\n\n    for data in bytes_to_write:\n        command.append(data)\n\n    await self._send_command(command)\n
"},{"location":"telemetrix_wifi_reference_aio/#telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio.start_aio","title":"start_aio() async","text":"

This method may be called directly, if the autostart parameter in init is set to false.

This method instantiates the serial interface and then performs auto pin discovery if using a serial interface, or creates and connects to a TCP/IP enabled device running StandardFirmataWiFi.

Use this method if you wish to start TelemetrixAIO manually from an asyncio function.

Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py
async def start_aio(self):\n\"\"\"\n    This method may be called directly, if the autostart\n    parameter in __init__ is set to false.\n\n    This method instantiates the serial interface and then performs auto pin\n    discovery if using a serial interface, or creates and connects to\n    a TCP/IP enabled device running StandardFirmataWiFi.\n\n    Use this method if you wish to start TelemetrixAIO manually from\n    an asyncio function.\n     \"\"\"\n\n    if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:\n        if not self.com_port:\n            # user did not specify a com_port\n            try:\n                await self._find_arduino()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n        else:\n            # com_port specified - set com_port and baud rate\n            try:\n                await self._manual_open()\n            except KeyboardInterrupt:\n                if self.shutdown_on_exception:\n                    await self.shutdown()\n\n        if self.com_port:\n            print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')\n\n            # no com_port found - raise a runtime exception\n        else:\n            if self.shutdown_on_exception:\n                await self.shutdown()\n            raise RuntimeError('No Arduino Found or User Aborted Program')\n        await self.disable_scroll_message()\n        # using tcp/ip\n    elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:\n        self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)\n        await self.sock.start()\n    else:  # ble\n        self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)\n        await self.ble_instance.connect()\n\n    # get arduino firmware version and print it\n    firmware_version = await self._get_firmware_version()\n    if not firmware_version:\n        print('*** Firmware Version retrieval timed out. ***')\n        print('\\nDo you have Arduino connectivity and do you have the ')\n        print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')\n        print('to the correct serial port.\\n')\n        print('To see a list of serial ports, type: '\n              '\"list_serial_ports\" in your console.')\n        if self.shutdown_on_exception:\n            await self.shutdown()\n        raise RuntimeError\n    else:\n\n        print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'\n              f'{firmware_version[3]}.{firmware_version[4]}')\n        # start the command dispatcher loop\n        command = [PrivateConstants.ENABLE_ALL_REPORTS]\n        await self._send_command(command)\n        if not self.loop:\n            self.loop = asyncio.get_event_loop()\n        self.the_task = self.loop.create_task(self._arduino_report_dispatcher())\n\n        # get the features list\n        command = [PrivateConstants.GET_FEATURES]\n        await self._send_command(command)\n        await asyncio.sleep(.5)\n\n        # Have the server reset its data structures\n        command = [PrivateConstants.RESET]\n        await self._send_command(command)\n        await asyncio.sleep(.1)\n
"},{"location":"template_ble/","title":"BLE AIO","text":"

Here, we need to instantiate the class passing in two parameters. We need to pass in auto_start=False. This is because we are using the Bleak BLE library, and this allows for a clean shutdown. We also need to pass in transport_type=2, which enables the BLE transport.

Lastly, we need to manually start the asyncio portion of the API by calling board.start_aio() in our main function.

\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(my_board):\n    # THIS NEXT LINE MUST BE ADDED HERE\n    await my_board.start_aio()\n\n    # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\n\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(autostart=False,\n                                                          transport_type=2)\n\ntry:\n    # start the main function\n    loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n    try:\n        loop.run_until_complete(board.shutdown())\n    except:\n        pass\n    sys.exit(0)\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"template_minima_aio/","title":"Minima AIO","text":"
\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima_aio import telemetrix_uno_r4_minima_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n    # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\nboard = telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio()\n\ntry:\n    # start the main function\n    loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n    try:\n        loop.run_until_complete(board.shutdown())\n    except:\n        pass\n    sys.exit(0)\n\n
"},{"location":"template_minima_threaded/","title":"Minima Threaded","text":"
import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima\n\"\"\"\n\n# INSTANTIATE THE API CLASS\nboard = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()\n\ntry:\n    # WRITE YOUR APPLICATION HERE\nexcept:\n    board.shutdown()\n\n\n\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"template_usb_serial_aio/","title":"USBSerial AIO","text":"

Here, we need to instantiate the class passing in a transport_type of 1. This parameter value enables the serial transport.

\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n    # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(transport_type=1)\n\ntry:\n    # start the main function\n    loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n    try:\n        loop.run_until_complete(board.shutdown())\n    except:\n        pass\n    sys.exit(0)\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"template_usb_serial_threaded/","title":"USBSerial Threaded","text":"

Here, we need to instantiate the class passing in a transport_type of 1. This enables the serial transport.

import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi\n\n# INSTANTIATE THE API CLASS\nboard = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_type=1)\ntry:\n    # WRITE YOUR APPLICATION HERE\nexcept:\n    board.shutdown()\n\n\n\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"template_wifi_aio/","title":"WIFI AIO","text":"

Here, we need to instantiate the class passing in the IP address assigned by your router. This parameter enables the WIFI transport.

\nimport sys\nimport asyncio\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio\n\n# An async method for running your application.\n# We pass in the instance of the API created below .\nasync def my_app(the_board):\n    # Your Application code\n\n# get the event loop\nloop = asyncio.new_event_loop()\nasyncio.set_event_loop(loop)\n\n# instantiate telemetrix_aio\n# Make sure to edit the transport address assigned by your router.\nboard = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(\n    transport_address='192.168.2.118')\n\ntry:\n    # start the main function\n    loop.run_until_complete(my_app(board))\nexcept KeyboardInterrupt:\n    try:\n        loop.run_until_complete(board.shutdown())\n    except:\n        pass\n    sys.exit(0)\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"template_wifi_threaded/","title":"WIFI Threaded","text":"

Here, we need to instantiate the class passing in the IP address assigned by your router. This parameter enables the WIFI transport.

import sys\nimport time\n\n# IMPORT THE API\nfrom telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi\n\n# INSTANTIATE THE API CLASS\n# Make sure to edit the transport address assigned by your router.\n\nboard = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_address='192.168.2.118')\ntry:\n    # WRITE YOUR APPLICATION HERE\nexcept:\n    board.shutdown()\n\n\n\n\n

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"},{"location":"venv/","title":"Create A Python Virtual Environment","text":"

When using Telemetrix, it is highly recommended that you work within a Python virtual environment.

A virtual environment isolates your project from other projects. Packages installed into a virtual environment are confined to your current project and will not affect or change packages used by other projects. Please refer to this article or the Python documentation.

If you are using the latest version of Ubuntu and Debian Linux, you are required to use a virtual environment.

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

"}]} \ No newline at end of file diff --git a/server_config/index.html b/server_config/index.html new file mode 100644 index 0000000..a2c2e6f --- /dev/null +++ b/server_config/index.html @@ -0,0 +1,1361 @@ + + + + + + + + + + + + + + + + + + + + + + Server Configuration - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Server Configuration

+ +

Arduino UNO R4 Minima

+

The Minima requires no configuration.

+

Arduino UNO R4 WIFI

+

Telemetrix4UnoR4BLE

+

+

Starting Banner Enable

+

By default, when you power up the Arduino, the sketch is identified by the message +"Telemetrix BLE" scrolling across the display. This message will be extinguished once a +client application connects.

+

You may disable the power on scrolling by commenting out the line that says

+
#define ENABLE_STARTING_BANNER 1
+
+

The client API method, enable_scroll_message, which allows you to create and scroll your +own message +across the display, still functions even if you disable the starting banner.

+

BLE Name

+

The ble_name string is the name the BLE client will search for to connect. You may +change the default value, but if you do, you must also set the +ble_device_name parameter in the __init__ method when you +instantiate telemetrix_uno_r4_wifi_aio.

+

Telemetrix4UnoR4SerialUSB

+

+

Starting Banner Enable

+

By default, when you power up the Arduino, the sketch is identified by the message +"USBSerial" scrolling across the display. This message will be extinguished once a +client application connects.

+

You may disable the power on scrolling by commenting out the line that says

+
#define ENABLE_STARTING_BANNER 1
+
+

The client API method, enable_scroll_message, allows you to create and scroll your +own message +across the display, and it still functions even if you disable the starting banner.

+

Telemetrix4UnoR4Wifi

+

+

Required Configuration

+
SSID
+

Edit the sketch and place your router's SSID between the quotes.

+
PASSWORD
+

Edit the sketch and place your router's PASSWORD between the quotes.

+

Starting Banner Enable

+

If the starting banner is enabled, and you forget to set SSID and PASSWORD in the sketch, +a series of question marks will scroll across the screen.

+

Once you have a valid SSID and PASSWORD configured, the IP address assigned by the +router will be displayed.

+

You may disable the power on scrolling by commenting out the line that says

+
#define ENABLE_STARTING_BANNER 1
+
+

The client API method, enable_scroll_message, allows you to create and scroll your +own message +across the display, and it still functions even if you disable the starting banner.

+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/server_library_installation/index.html b/server_library_installation/index.html new file mode 100644 index 0000000..d4ece80 --- /dev/null +++ b/server_library_installation/index.html @@ -0,0 +1,1130 @@ + + + + + + + + + + + + + + + + + + + + + + Install the Telemetrix4Uno Library Into The Arduino IDE - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Install the Telemetrix4Uno Library Into The Arduino IDE

+ +

Add The Arduino4UnoR4 Library To The IDE

+
    +
  1. +

    Open the Arduino IDE and click on the library icon.

    +

    +
  2. +
  3. +

    In the search box, type Telemetrix4UnoR4, and when the library is found, click INSTALL.

    +

    +
  4. +
  5. +

    You will be prompted to install all of the dependencies. Select INSTALL ALL.

    +

    +
  6. +
+

Additional Steps If You Wish To Use The BLE Server

+

Follow the instructions on this link +to make sure that you have the correct version of +the radio firmware installed and to install the Beta version of the ArduinoBLE library.

+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/server_selection/index.html b/server_selection/index.html new file mode 100644 index 0000000..cf2fad3 --- /dev/null +++ b/server_selection/index.html @@ -0,0 +1,1118 @@ + + + + + + + + + + + + + + + + + + + + + + Select A Server From the Arduino IDE Examples Menu - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Select A Server From the Arduino IDE Examples Menu

+ +

Choose A Server

+

Select File from the Arduino IDE main menu and then select Examples.

+

Next, select TelemetrixUnoR4 from the example selections.

+

+

There are four servers to choose from:

+
    +
  • +

    Arduino UNO R4 Minima

    +
      +
    • Minima - utilizing a serial transport via the USB port.
    • +
    +
  • +
  • +

    Arduino UNO R4 WIFI

    +
      +
    • Telemetrix4UnoR4BLE - utilizing a BLE transport.
    • +
    • Telemetrix4UnoR4SerialUSB - utilizing serial transport via the USB port.
    • +
    • Telemetrix4UnoR4WIFI - utilizing a WIFI transport.
    • +
    +
  • +
+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..0f8724e --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz new file mode 100644 index 0000000..8606549 Binary files /dev/null and b/sitemap.xml.gz differ diff --git a/telemetrix_minima_reference/index.html b/telemetrix_minima_reference/index.html new file mode 100644 index 0000000..10d9753 --- /dev/null +++ b/telemetrix_minima_reference/index.html @@ -0,0 +1,9410 @@ + + + + + + + + + + + + + + + + + + + + + + telemetrix_uno_r4_minima - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +

telemetrix_uno_r4_minima

+ +
+ + + +
+ +

Copyright (c) 2023 Alan Yorinks All rights reserved.

+

This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.

+

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

+ + + +
+ + + + + + + + +
+ + + +

+ TelemetrixUnoR4Minima + + +

+ + +
+

+ Bases: threading.Thread

+ + +

This class exposes and implements the telemetrix API. +It uses threading to accommodate concurrency. +It includes the public API methods as well as +a set of private methods.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
  35
+  36
+  37
+  38
+  39
+  40
+  41
+  42
+  43
+  44
+  45
+  46
+  47
+  48
+  49
+  50
+  51
+  52
+  53
+  54
+  55
+  56
+  57
+  58
+  59
+  60
+  61
+  62
+  63
+  64
+  65
+  66
+  67
+  68
+  69
+  70
+  71
+  72
+  73
+  74
+  75
+  76
+  77
+  78
+  79
+  80
+  81
+  82
+  83
+  84
+  85
+  86
+  87
+  88
+  89
+  90
+  91
+  92
+  93
+  94
+  95
+  96
+  97
+  98
+  99
+ 100
+ 101
+ 102
+ 103
+ 104
+ 105
+ 106
+ 107
+ 108
+ 109
+ 110
+ 111
+ 112
+ 113
+ 114
+ 115
+ 116
+ 117
+ 118
+ 119
+ 120
+ 121
+ 122
+ 123
+ 124
+ 125
+ 126
+ 127
+ 128
+ 129
+ 130
+ 131
+ 132
+ 133
+ 134
+ 135
+ 136
+ 137
+ 138
+ 139
+ 140
+ 141
+ 142
+ 143
+ 144
+ 145
+ 146
+ 147
+ 148
+ 149
+ 150
+ 151
+ 152
+ 153
+ 154
+ 155
+ 156
+ 157
+ 158
+ 159
+ 160
+ 161
+ 162
+ 163
+ 164
+ 165
+ 166
+ 167
+ 168
+ 169
+ 170
+ 171
+ 172
+ 173
+ 174
+ 175
+ 176
+ 177
+ 178
+ 179
+ 180
+ 181
+ 182
+ 183
+ 184
+ 185
+ 186
+ 187
+ 188
+ 189
+ 190
+ 191
+ 192
+ 193
+ 194
+ 195
+ 196
+ 197
+ 198
+ 199
+ 200
+ 201
+ 202
+ 203
+ 204
+ 205
+ 206
+ 207
+ 208
+ 209
+ 210
+ 211
+ 212
+ 213
+ 214
+ 215
+ 216
+ 217
+ 218
+ 219
+ 220
+ 221
+ 222
+ 223
+ 224
+ 225
+ 226
+ 227
+ 228
+ 229
+ 230
+ 231
+ 232
+ 233
+ 234
+ 235
+ 236
+ 237
+ 238
+ 239
+ 240
+ 241
+ 242
+ 243
+ 244
+ 245
+ 246
+ 247
+ 248
+ 249
+ 250
+ 251
+ 252
+ 253
+ 254
+ 255
+ 256
+ 257
+ 258
+ 259
+ 260
+ 261
+ 262
+ 263
+ 264
+ 265
+ 266
+ 267
+ 268
+ 269
+ 270
+ 271
+ 272
+ 273
+ 274
+ 275
+ 276
+ 277
+ 278
+ 279
+ 280
+ 281
+ 282
+ 283
+ 284
+ 285
+ 286
+ 287
+ 288
+ 289
+ 290
+ 291
+ 292
+ 293
+ 294
+ 295
+ 296
+ 297
+ 298
+ 299
+ 300
+ 301
+ 302
+ 303
+ 304
+ 305
+ 306
+ 307
+ 308
+ 309
+ 310
+ 311
+ 312
+ 313
+ 314
+ 315
+ 316
+ 317
+ 318
+ 319
+ 320
+ 321
+ 322
+ 323
+ 324
+ 325
+ 326
+ 327
+ 328
+ 329
+ 330
+ 331
+ 332
+ 333
+ 334
+ 335
+ 336
+ 337
+ 338
+ 339
+ 340
+ 341
+ 342
+ 343
+ 344
+ 345
+ 346
+ 347
+ 348
+ 349
+ 350
+ 351
+ 352
+ 353
+ 354
+ 355
+ 356
+ 357
+ 358
+ 359
+ 360
+ 361
+ 362
+ 363
+ 364
+ 365
+ 366
+ 367
+ 368
+ 369
+ 370
+ 371
+ 372
+ 373
+ 374
+ 375
+ 376
+ 377
+ 378
+ 379
+ 380
+ 381
+ 382
+ 383
+ 384
+ 385
+ 386
+ 387
+ 388
+ 389
+ 390
+ 391
+ 392
+ 393
+ 394
+ 395
+ 396
+ 397
+ 398
+ 399
+ 400
+ 401
+ 402
+ 403
+ 404
+ 405
+ 406
+ 407
+ 408
+ 409
+ 410
+ 411
+ 412
+ 413
+ 414
+ 415
+ 416
+ 417
+ 418
+ 419
+ 420
+ 421
+ 422
+ 423
+ 424
+ 425
+ 426
+ 427
+ 428
+ 429
+ 430
+ 431
+ 432
+ 433
+ 434
+ 435
+ 436
+ 437
+ 438
+ 439
+ 440
+ 441
+ 442
+ 443
+ 444
+ 445
+ 446
+ 447
+ 448
+ 449
+ 450
+ 451
+ 452
+ 453
+ 454
+ 455
+ 456
+ 457
+ 458
+ 459
+ 460
+ 461
+ 462
+ 463
+ 464
+ 465
+ 466
+ 467
+ 468
+ 469
+ 470
+ 471
+ 472
+ 473
+ 474
+ 475
+ 476
+ 477
+ 478
+ 479
+ 480
+ 481
+ 482
+ 483
+ 484
+ 485
+ 486
+ 487
+ 488
+ 489
+ 490
+ 491
+ 492
+ 493
+ 494
+ 495
+ 496
+ 497
+ 498
+ 499
+ 500
+ 501
+ 502
+ 503
+ 504
+ 505
+ 506
+ 507
+ 508
+ 509
+ 510
+ 511
+ 512
+ 513
+ 514
+ 515
+ 516
+ 517
+ 518
+ 519
+ 520
+ 521
+ 522
+ 523
+ 524
+ 525
+ 526
+ 527
+ 528
+ 529
+ 530
+ 531
+ 532
+ 533
+ 534
+ 535
+ 536
+ 537
+ 538
+ 539
+ 540
+ 541
+ 542
+ 543
+ 544
+ 545
+ 546
+ 547
+ 548
+ 549
+ 550
+ 551
+ 552
+ 553
+ 554
+ 555
+ 556
+ 557
+ 558
+ 559
+ 560
+ 561
+ 562
+ 563
+ 564
+ 565
+ 566
+ 567
+ 568
+ 569
+ 570
+ 571
+ 572
+ 573
+ 574
+ 575
+ 576
+ 577
+ 578
+ 579
+ 580
+ 581
+ 582
+ 583
+ 584
+ 585
+ 586
+ 587
+ 588
+ 589
+ 590
+ 591
+ 592
+ 593
+ 594
+ 595
+ 596
+ 597
+ 598
+ 599
+ 600
+ 601
+ 602
+ 603
+ 604
+ 605
+ 606
+ 607
+ 608
+ 609
+ 610
+ 611
+ 612
+ 613
+ 614
+ 615
+ 616
+ 617
+ 618
+ 619
+ 620
+ 621
+ 622
+ 623
+ 624
+ 625
+ 626
+ 627
+ 628
+ 629
+ 630
+ 631
+ 632
+ 633
+ 634
+ 635
+ 636
+ 637
+ 638
+ 639
+ 640
+ 641
+ 642
+ 643
+ 644
+ 645
+ 646
+ 647
+ 648
+ 649
+ 650
+ 651
+ 652
+ 653
+ 654
+ 655
+ 656
+ 657
+ 658
+ 659
+ 660
+ 661
+ 662
+ 663
+ 664
+ 665
+ 666
+ 667
+ 668
+ 669
+ 670
+ 671
+ 672
+ 673
+ 674
+ 675
+ 676
+ 677
+ 678
+ 679
+ 680
+ 681
+ 682
+ 683
+ 684
+ 685
+ 686
+ 687
+ 688
+ 689
+ 690
+ 691
+ 692
+ 693
+ 694
+ 695
+ 696
+ 697
+ 698
+ 699
+ 700
+ 701
+ 702
+ 703
+ 704
+ 705
+ 706
+ 707
+ 708
+ 709
+ 710
+ 711
+ 712
+ 713
+ 714
+ 715
+ 716
+ 717
+ 718
+ 719
+ 720
+ 721
+ 722
+ 723
+ 724
+ 725
+ 726
+ 727
+ 728
+ 729
+ 730
+ 731
+ 732
+ 733
+ 734
+ 735
+ 736
+ 737
+ 738
+ 739
+ 740
+ 741
+ 742
+ 743
+ 744
+ 745
+ 746
+ 747
+ 748
+ 749
+ 750
+ 751
+ 752
+ 753
+ 754
+ 755
+ 756
+ 757
+ 758
+ 759
+ 760
+ 761
+ 762
+ 763
+ 764
+ 765
+ 766
+ 767
+ 768
+ 769
+ 770
+ 771
+ 772
+ 773
+ 774
+ 775
+ 776
+ 777
+ 778
+ 779
+ 780
+ 781
+ 782
+ 783
+ 784
+ 785
+ 786
+ 787
+ 788
+ 789
+ 790
+ 791
+ 792
+ 793
+ 794
+ 795
+ 796
+ 797
+ 798
+ 799
+ 800
+ 801
+ 802
+ 803
+ 804
+ 805
+ 806
+ 807
+ 808
+ 809
+ 810
+ 811
+ 812
+ 813
+ 814
+ 815
+ 816
+ 817
+ 818
+ 819
+ 820
+ 821
+ 822
+ 823
+ 824
+ 825
+ 826
+ 827
+ 828
+ 829
+ 830
+ 831
+ 832
+ 833
+ 834
+ 835
+ 836
+ 837
+ 838
+ 839
+ 840
+ 841
+ 842
+ 843
+ 844
+ 845
+ 846
+ 847
+ 848
+ 849
+ 850
+ 851
+ 852
+ 853
+ 854
+ 855
+ 856
+ 857
+ 858
+ 859
+ 860
+ 861
+ 862
+ 863
+ 864
+ 865
+ 866
+ 867
+ 868
+ 869
+ 870
+ 871
+ 872
+ 873
+ 874
+ 875
+ 876
+ 877
+ 878
+ 879
+ 880
+ 881
+ 882
+ 883
+ 884
+ 885
+ 886
+ 887
+ 888
+ 889
+ 890
+ 891
+ 892
+ 893
+ 894
+ 895
+ 896
+ 897
+ 898
+ 899
+ 900
+ 901
+ 902
+ 903
+ 904
+ 905
+ 906
+ 907
+ 908
+ 909
+ 910
+ 911
+ 912
+ 913
+ 914
+ 915
+ 916
+ 917
+ 918
+ 919
+ 920
+ 921
+ 922
+ 923
+ 924
+ 925
+ 926
+ 927
+ 928
+ 929
+ 930
+ 931
+ 932
+ 933
+ 934
+ 935
+ 936
+ 937
+ 938
+ 939
+ 940
+ 941
+ 942
+ 943
+ 944
+ 945
+ 946
+ 947
+ 948
+ 949
+ 950
+ 951
+ 952
+ 953
+ 954
+ 955
+ 956
+ 957
+ 958
+ 959
+ 960
+ 961
+ 962
+ 963
+ 964
+ 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031
+1032
+1033
+1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
+1193
+1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
+1221
+1222
+1223
+1224
+1225
+1226
+1227
+1228
+1229
+1230
+1231
+1232
+1233
+1234
+1235
+1236
+1237
+1238
+1239
+1240
+1241
+1242
+1243
+1244
+1245
+1246
+1247
+1248
+1249
+1250
+1251
+1252
+1253
+1254
+1255
+1256
+1257
+1258
+1259
+1260
+1261
+1262
+1263
+1264
+1265
+1266
+1267
+1268
+1269
+1270
+1271
+1272
+1273
+1274
+1275
+1276
+1277
+1278
+1279
+1280
+1281
+1282
+1283
+1284
+1285
+1286
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1294
+1295
+1296
+1297
+1298
+1299
+1300
+1301
+1302
+1303
+1304
+1305
+1306
+1307
+1308
+1309
+1310
+1311
+1312
+1313
+1314
+1315
+1316
+1317
+1318
+1319
+1320
+1321
+1322
+1323
+1324
+1325
+1326
+1327
+1328
+1329
+1330
+1331
+1332
+1333
+1334
+1335
+1336
+1337
+1338
+1339
+1340
+1341
+1342
+1343
+1344
+1345
+1346
+1347
+1348
+1349
+1350
+1351
+1352
+1353
+1354
+1355
+1356
+1357
+1358
+1359
+1360
+1361
+1362
+1363
+1364
+1365
+1366
+1367
+1368
+1369
+1370
+1371
+1372
+1373
+1374
+1375
+1376
+1377
+1378
+1379
+1380
+1381
+1382
+1383
+1384
+1385
+1386
+1387
+1388
+1389
+1390
+1391
+1392
+1393
+1394
+1395
+1396
+1397
+1398
+1399
+1400
+1401
+1402
+1403
+1404
+1405
+1406
+1407
+1408
+1409
+1410
+1411
+1412
+1413
+1414
+1415
+1416
+1417
+1418
+1419
+1420
+1421
+1422
+1423
+1424
+1425
+1426
+1427
+1428
+1429
+1430
+1431
+1432
+1433
+1434
+1435
+1436
+1437
+1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
+1450
+1451
+1452
+1453
+1454
+1455
+1456
+1457
+1458
+1459
+1460
+1461
+1462
+1463
+1464
+1465
+1466
+1467
+1468
+1469
+1470
+1471
+1472
+1473
+1474
+1475
+1476
+1477
+1478
+1479
+1480
+1481
+1482
+1483
+1484
+1485
+1486
+1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
+1499
+1500
+1501
+1502
+1503
+1504
+1505
+1506
+1507
+1508
+1509
+1510
+1511
+1512
+1513
+1514
+1515
+1516
+1517
+1518
+1519
+1520
+1521
+1522
+1523
+1524
+1525
+1526
+1527
+1528
+1529
+1530
+1531
+1532
+1533
+1534
+1535
+1536
+1537
+1538
+1539
+1540
+1541
+1542
+1543
+1544
+1545
+1546
+1547
+1548
+1549
+1550
+1551
+1552
+1553
+1554
+1555
+1556
+1557
+1558
+1559
+1560
+1561
+1562
+1563
+1564
+1565
+1566
+1567
+1568
+1569
+1570
+1571
+1572
+1573
+1574
+1575
+1576
+1577
+1578
+1579
+1580
+1581
+1582
+1583
+1584
+1585
+1586
+1587
+1588
+1589
+1590
+1591
+1592
+1593
+1594
+1595
+1596
+1597
+1598
+1599
+1600
+1601
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
+1614
+1615
+1616
+1617
+1618
+1619
+1620
+1621
+1622
+1623
+1624
+1625
+1626
+1627
+1628
+1629
+1630
+1631
+1632
+1633
+1634
+1635
+1636
+1637
+1638
+1639
+1640
+1641
+1642
+1643
+1644
+1645
+1646
+1647
+1648
+1649
+1650
+1651
+1652
+1653
+1654
+1655
+1656
+1657
+1658
+1659
+1660
+1661
+1662
+1663
+1664
+1665
+1666
+1667
+1668
+1669
+1670
+1671
+1672
+1673
+1674
+1675
+1676
+1677
+1678
+1679
+1680
+1681
+1682
+1683
+1684
+1685
+1686
+1687
+1688
+1689
+1690
+1691
+1692
+1693
+1694
+1695
+1696
+1697
+1698
+1699
+1700
+1701
+1702
+1703
+1704
+1705
+1706
+1707
+1708
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
+1742
+1743
+1744
+1745
+1746
+1747
+1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
+1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
+1930
+1931
+1932
+1933
+1934
+1935
+1936
+1937
+1938
+1939
+1940
+1941
+1942
+1943
+1944
+1945
+1946
+1947
+1948
+1949
+1950
+1951
+1952
+1953
+1954
+1955
+1956
+1957
+1958
+1959
+1960
+1961
+1962
+1963
+1964
+1965
+1966
+1967
+1968
+1969
+1970
+1971
+1972
+1973
+1974
+1975
+1976
+1977
+1978
+1979
+1980
+1981
+1982
+1983
+1984
+1985
+1986
+1987
+1988
+1989
+1990
+1991
+1992
+1993
+1994
+1995
+1996
+1997
+1998
+1999
+2000
+2001
+2002
+2003
+2004
+2005
+2006
+2007
+2008
+2009
+2010
+2011
+2012
+2013
+2014
+2015
+2016
+2017
+2018
+2019
+2020
+2021
+2022
+2023
+2024
+2025
+2026
+2027
+2028
+2029
+2030
+2031
+2032
+2033
+2034
+2035
+2036
+2037
+2038
+2039
+2040
+2041
+2042
+2043
+2044
+2045
+2046
+2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
+2070
+2071
+2072
+2073
+2074
+2075
+2076
+2077
+2078
+2079
+2080
+2081
+2082
+2083
+2084
+2085
+2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
+2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
+2131
+2132
+2133
+2134
+2135
+2136
+2137
+2138
+2139
+2140
+2141
+2142
+2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
+2153
+2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
+2177
+2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
+2188
+2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
+2206
+2207
+2208
+2209
+2210
+2211
+2212
+2213
+2214
+2215
+2216
+2217
+2218
+2219
+2220
+2221
+2222
+2223
+2224
+2225
+2226
+2227
+2228
+2229
+2230
+2231
+2232
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
+2244
+2245
+2246
+2247
+2248
+2249
+2250
+2251
+2252
+2253
+2254
+2255
+2256
+2257
+2258
+2259
+2260
+2261
+2262
+2263
+2264
+2265
+2266
+2267
+2268
+2269
+2270
+2271
+2272
+2273
+2274
+2275
+2276
+2277
+2278
+2279
+2280
+2281
+2282
+2283
+2284
+2285
+2286
+2287
+2288
+2289
+2290
+2291
+2292
+2293
+2294
+2295
+2296
+2297
+2298
+2299
+2300
+2301
+2302
+2303
+2304
+2305
+2306
+2307
+2308
+2309
+2310
+2311
+2312
+2313
+2314
+2315
+2316
+2317
+2318
+2319
+2320
+2321
+2322
+2323
+2324
+2325
+2326
+2327
+2328
+2329
+2330
+2331
+2332
+2333
+2334
+2335
+2336
+2337
+2338
+2339
+2340
+2341
+2342
+2343
+2344
+2345
+2346
+2347
+2348
+2349
+2350
+2351
+2352
+2353
+2354
+2355
+2356
+2357
+2358
+2359
+2360
+2361
+2362
+2363
+2364
+2365
+2366
+2367
+2368
+2369
+2370
+2371
+2372
+2373
+2374
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+2396
+2397
+2398
+2399
+2400
+2401
+2402
+2403
+2404
+2405
+2406
+2407
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+2417
+2418
+2419
+2420
+2421
+2422
+2423
+2424
+2425
+2426
+2427
+2428
+2429
+2430
+2431
+2432
+2433
+2434
+2435
+2436
+2437
+2438
+2439
+2440
+2441
+2442
+2443
+2444
+2445
+2446
+2447
+2448
+2449
+2450
+2451
+2452
+2453
+2454
+2455
+2456
+2457
+2458
+2459
+2460
+2461
+2462
+2463
+2464
+2465
+2466
+2467
+2468
+2469
+2470
+2471
+2472
+2473
+2474
+2475
+2476
+2477
+2478
+2479
+2480
+2481
+2482
+2483
+2484
+2485
+2486
+2487
+2488
+2489
+2490
+2491
+2492
+2493
+2494
+2495
+2496
+2497
+2498
+2499
+2500
+2501
+2502
+2503
+2504
+2505
+2506
+2507
+2508
+2509
+2510
+2511
+2512
+2513
+2514
+2515
+2516
+2517
+2518
+2519
+2520
+2521
+2522
+2523
+2524
+2525
+2526
+2527
+2528
+2529
+2530
+2531
+2532
+2533
+2534
+2535
+2536
+2537
+2538
+2539
+2540
+2541
+2542
+2543
+2544
+2545
+2546
+2547
+2548
+2549
+2550
+2551
+2552
+2553
class TelemetrixUnoR4Minima(threading.Thread):
+    """
+    This class exposes and implements the telemetrix API.
+    It uses threading to accommodate concurrency.
+    It includes the public API methods as well as
+    a set of private methods.
+
+    """
+
+    # noinspection PyPep8,PyPep8,PyPep8
+    def __init__(self, com_port=None, arduino_instance_id=1,
+                 arduino_wait=1, sleep_tune=0.000001,
+                 shutdown_on_exception=True, hard_reset_on_shutdown=True):
+
+        """
+
+        :param com_port: e.g. COM3 or /dev/ttyACM0.
+                         Only use if you wish to bypass auto com port
+                         detection.
+
+        :param arduino_instance_id: Match with the value installed on the
+                                    arduino-telemetrix sketch.
+
+        :param arduino_wait: Amount of time to wait for an Arduino to
+                             fully reset itself.
+
+        :param sleep_tune: A tuning parameter (typically not changed by user)
+
+        :param shutdown_on_exception: call shutdown before raising
+                                      a RunTimeError exception, or
+                                      receiving a KeyboardInterrupt exception
+
+        :param hard_reset_on_shutdown: reset the board on shutdown
+
+        """
+
+        # initialize threading parent
+        threading.Thread.__init__(self)
+
+        # create the threads and set them as daemons so
+        # that they stop when the program is closed
+
+        # create a thread to interpret received serial data
+        self.the_reporter_thread = threading.Thread(target=self._reporter)
+        self.the_reporter_thread.daemon = True
+
+        self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)
+
+        self.the_data_receive_thread.daemon = True
+
+        # flag to allow the reporter and receive threads to run.
+        self.run_event = threading.Event()
+
+        # check to make sure that Python interpreter is version 3.7 or greater
+        python_version = sys.version_info
+        if python_version[0] >= 3:
+            if python_version[1] >= 7:
+                pass
+            else:
+                raise RuntimeError("ERROR: Python 3.7 or greater is "
+                                   "required for use of this program.")
+
+        # save input parameters as instance variables
+        self.com_port = com_port
+        self.arduino_instance_id = arduino_instance_id
+        self.arduino_wait = arduino_wait
+        self.sleep_tune = sleep_tune
+        self.shutdown_on_exception = shutdown_on_exception
+        self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+        # create a deque to receive and process data from the arduino
+        self.the_deque = deque()
+
+        # The report_dispatch dictionary is used to process
+        # incoming report messages by looking up the report message
+        # and executing its associated processing method.
+
+        self.report_dispatch = {}
+
+        # To add a command to the command dispatch table, append here.
+        self.report_dispatch.update(
+            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+        self.report_dispatch.update(
+            {PrivateConstants.ANALOG_REPORT: self._analog_message})
+        self.report_dispatch.update(
+            {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})
+        self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})
+        self.report_dispatch.update(
+            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+        self.report_dispatch.update(
+            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+        self.report_dispatch.update(
+            {PrivateConstants.SPI_REPORT: self._spi_report})
+        self.report_dispatch.update(
+            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_CURRENT_POSITION:
+                 self._stepper_current_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUNNING_REPORT:
+                 self._stepper_is_running_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+                 self._stepper_run_complete_report})
+
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.FEATURES:
+                 self._features_report})
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        self.cs_pins_enabled = []
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        self.dht_count = 0
+
+        # serial port in use
+        self.serial_port = None
+
+        # flag to indicate we are in shutdown mode
+        self.shutdown_flag = False
+
+        # debug loopback callback method
+        self.loop_back_callback = None
+
+        # flag to indicate the start of a new report
+        # self.new_report_start = True
+
+        # firmware version to be stored here
+        self.firmware_version = []
+
+        # reported arduino instance id
+        self.reported_arduino_id = []
+
+        # reported features
+        self.reported_features = 0
+
+        # flag to indicate if i2c was previously enabled
+        self.i2c_enabled = False
+
+        # flag to indicate if spi is initialized
+        self.spi_enabled = False
+
+        # flag to indicate if onewire is initialized
+        self.onewire_enabled = False
+
+        # # stepper motor variables
+        #
+        # # updated when a new motor is added
+        # self.next_stepper_assigned = 0
+        #
+        # # valid list of stepper motor interface types
+        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+        #
+        # # maximum number of steppers supported
+        # self.max_number_of_steppers = 4
+        #
+        # # number of steppers created - not to exceed the maximum
+        # self.number_of_steppers = 0
+        #
+        # # dictionary to hold stepper motor information
+        # self.stepper_info = {'instance': False, 'is_running': None,
+        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+        #                      'distance_to_go_callback': None,
+        #                      'target_position_callback': None,
+        #                      'current_position_callback': None,
+        #                      'is_running_callback': None,
+        #                      'motion_complete_callback': None,
+        #                      'acceleration_callback': None}
+        #
+        # # build a list of stepper motor info items
+        # self.stepper_info_list = []
+        # # a list of dictionaries to hold stepper information
+        # for motor in range(self.max_number_of_steppers):
+        #     self.stepper_info_list.append(self.stepper_info)
+
+        self.the_reporter_thread.start()
+        self.the_data_receive_thread.start()
+
+        print(f"telemetrix_uno_r4_minima:  Version"
+              f" {PrivateConstants.TELEMETRIX_VERSION}\n\n"
+              f"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\n")
+
+        # using the serial link
+        if not self.com_port:
+            # user did not specify a com_port
+            try:
+                self._find_arduino()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+        else:
+            # com_port specified - set com_port and baud rate
+            try:
+                self._manual_open()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+
+        if self.serial_port:
+            print(
+                f"Arduino compatible device found and connected to {self.serial_port.port}")
+
+            self.serial_port.reset_input_buffer()
+            self.serial_port.reset_output_buffer()
+
+        # no com_port found - raise a runtime exception
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('No Arduino Found or User Aborted Program')
+
+        # allow the threads to run
+        self._run_threads()
+        print(f'Reset Complete')
+
+        # get telemetrix firmware version and print it
+        print('\nRetrieving Telemetrix4UnoR4Minima firmware ID...')
+        self._get_firmware_version()
+        if not self.firmware_version:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')
+
+        else:
+
+            print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'
+                  f'{self.firmware_version[1]}.{self.firmware_version[2]}')
+        command = [PrivateConstants.ENABLE_ALL_REPORTS]
+        self._send_command(command)
+
+        # get the features list
+        command = [PrivateConstants.GET_FEATURES]
+        self._send_command(command)
+        time.sleep(.2)
+
+        # Have the server reset its data structures
+        command = [PrivateConstants.RESET]
+        self._send_command(command)
+
+    def _find_arduino(self):
+        """
+        This method will search all potential serial ports for an Arduino
+        containing a sketch that has a matching arduino_instance_id as
+        specified in the input parameters of this class.
+
+        This is used explicitly with the Telemetrix4Arduino sketch.
+        """
+
+        # a list of serial ports to be checked
+        serial_ports = []
+
+        print('Opening all potential serial ports...')
+        the_ports_list = list_ports.comports()
+        for port in the_ports_list:
+            if port.pid is None:
+                continue
+            try:
+                self.serial_port = serial.Serial(port.device, 115200,
+                                                 timeout=1, writeTimeout=0)
+            except SerialException:
+                continue
+            # create a list of serial ports that we opened
+            serial_ports.append(self.serial_port)
+
+            # display to the user
+            print('\t' + port.device)
+
+            # clear out any possible data in the input buffer
+        # wait for arduino to reset
+        print(
+            f'\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '
+            'reset...')
+        # temporary for testing
+        time.sleep(self.arduino_wait)
+        self._run_threads()
+
+        for serial_port in serial_ports:
+            self.serial_port = serial_port
+
+            self._get_arduino_id()
+            if self.reported_arduino_id != self.arduino_instance_id:
+                continue
+            else:
+                print('Valid Arduino ID Found.')
+                self.serial_port.reset_input_buffer()
+                self.serial_port.reset_output_buffer()
+                return
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')
+
+    def _manual_open(self):
+        """
+        Com port was specified by the user - try to open up that port
+
+        """
+        # if port is not found, a serial exception will be thrown
+        try:
+            print(f'Opening {self.com_port}...')
+            self.serial_port = serial.Serial(self.com_port, 115200,
+                                             timeout=1, writeTimeout=0)
+
+            print(
+                f'\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '
+                'reset...')
+            self._run_threads()
+            time.sleep(self.arduino_wait)
+
+            self._get_arduino_id()
+
+            if self.reported_arduino_id != self.arduino_instance_id:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')
+            print('Valid Arduino ID Found.')
+            # get arduino firmware version and print it
+            print('\nRetrieving Telemetrix4Arduino firmware ID...')
+            self._get_firmware_version()
+
+            if not self.firmware_version:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Telemetrix4Arduino Sketch Firmware Version Not Found')
+
+            else:
+                print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'
+                      f'{self.firmware_version[1]}')
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('User Hit Control-C')
+
+    def analog_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (maximum 16 bits)
+
+        """
+        value_msb = value >> 8
+        value_lsb = value & 0xff
+        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+        self._send_command(command)
+
+    def digital_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (1 or 0)
+
+        """
+
+        command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+        self._send_command(command)
+
+    def disable_all_reporting(self):
+        """
+        Disable reporting for all digital and analog input pins
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DISABLE_ALL, 0]
+        self._send_command(command)
+
+    def disable_analog_reporting(self, pin):
+        """
+        Disables analog reporting for a single analog pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+        self._send_command(command)
+
+    def disable_digital_reporting(self, pin):
+        """
+        Disables digital reporting for a single digital input.
+
+        :param pin: Pin number.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+        self._send_command(command)
+
+    def enable_analog_reporting(self, pin):
+        """
+        Enables analog reporting for the specified pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+        self._send_command(command)
+
+    def enable_digital_reporting(self, pin):
+        """
+        Enable reporting on the specified digital pin.
+
+        :param pin: Pin number.
+        """
+
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+        self._send_command(command)
+
+    def _get_arduino_id(self):
+        """
+        Retrieve arduino-telemetrix arduino id
+
+        """
+        command = [PrivateConstants.ARE_U_THERE]
+        self._send_command(command)
+        # provide time for the reply
+        time.sleep(.5)
+
+    def _get_firmware_version(self):
+        """
+        This method retrieves the
+        arduino-telemetrix firmware version
+
+        """
+        command = [PrivateConstants.GET_FIRMWARE_VERSION]
+        self._send_command(command)
+        # provide time for the reply
+        time.sleep(.5)
+
+    def i2c_read(self, address, register, number_of_bytes,
+                 callback=None, i2c_port=0,
+                 write_register=True):
+        """
+        Read the specified number of bytes from the
+        specified register for the i2c device.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                       selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report
+                         i2c data as a result of read command
+
+       :param i2c_port: 0 = default, 1 = secondary
+
+       :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+
+        self._i2c_read_request(address, register, number_of_bytes,
+                               callback=callback, i2c_port=i2c_port,
+                               write_register=write_register)
+
+    def i2c_read_restart_transmission(self, address, register,
+                                      number_of_bytes,
+                                      callback=None, i2c_port=0,
+                                      write_register=True):
+        """
+        Read the specified number of bytes from the specified
+        register for the i2c device. This restarts the transmission
+        after the read. It is required for some i2c devices such as the MMA8452Q
+        accelerometer.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                                    selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c
+                         data as a result of read command
+
+       :param i2c_port: 0 = default 1 = secondary
+
+       :param write_register: If True, the register is written before read
+                              Else, the write is suppressed
+
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+
+        self._i2c_read_request(address, register, number_of_bytes,
+                               stop_transmission=False,
+                               callback=callback, i2c_port=i2c_port,
+                               write_register=write_register)
+
+    def _i2c_read_request(self, address, register, number_of_bytes,
+                          stop_transmission=True, callback=None, i2c_port=0,
+                          write_register=True):
+        """
+        This method requests the read of an i2c device. Results are retrieved
+        via callback.
+
+        :param address: i2c device address
+
+        :param register: register number (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes expected to be returned
+
+        :param stop_transmission: stop transmission after read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command.
+
+       :param write_register: If True, the register is written before read
+                              Else, the write is suppressed
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')
+
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('I2C Read: A callback function must be specified.')
+
+        if not i2c_port:
+            self.i2c_callback = callback
+        else:
+            self.i2c_callback2 = callback
+
+        if not register:
+            register = 0
+
+        if write_register:
+            write_register = 1
+        else:
+            write_register = 0
+
+        # message contains:
+        # 1. address
+        # 2. register
+        # 3. number of bytes
+        # 4. restart_transmission - True or False
+        # 5. i2c port
+        # 6. suppress write flag
+
+        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,
+                   stop_transmission, i2c_port, write_register]
+        self._send_command(command)
+
+    def i2c_write(self, address, args, i2c_port=0):
+        """
+        Write data to an i2c device.
+
+        :param address: i2c device address
+
+        :param i2c_port: 0= port 1, 1 = port 2
+
+        :param args: A variable number of bytes to be sent to the device
+                     passed in as a list
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+        for item in args:
+            command.append(item)
+
+        self._send_command(command)
+
+    def loop_back(self, start_character, callback=None):
+        """
+        This is a debugging method to send a character to the
+        Arduino device, and have the device loop it back.
+
+        :param start_character: The character to loop back. It should be
+                                an integer.
+
+        :param callback: Looped back character will appear in the callback method
+
+        """
+        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+        self.loop_back_callback = callback
+        self._send_command(command)
+
+    def set_analog_scan_interval(self, interval):
+        """
+        Set the analog scanning interval.
+
+        :param interval: value of 0 - 255 - milliseconds
+        """
+
+        if 0 <= interval <= 255:
+            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Analog interval must be between 0 and 255')
+
+    def set_pin_mode_analog_output(self, pin_number):
+        """
+        Set a pin as a pwm (analog output) pin.
+
+        :param pin_number:arduino pin number
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+    def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+        """
+        Set a pin as an analog input.
+
+        :param pin_number: arduino pin number
+
+        :param differential: difference in previous to current value before
+                             report will be generated
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for analog input pins = 3
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,
+                           callback)
+
+    def set_pin_mode_digital_input(self, pin_number, callback=None):
+        """
+        Set a pin as a digital input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)
+
+    def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):
+        """
+        Set a pin as a digital input with pullup enabled.
+
+        :param pin_number: arduino pin number
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                           callback=callback)
+
+    def set_pin_mode_digital_output(self, pin_number):
+        """
+        Set a pin as a digital output pin.
+
+        :param pin_number: arduino pin number
+        """
+
+        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+    def set_pin_mode_i2c(self, i2c_port=0):
+        """
+        Establish the standard Arduino i2c pins for i2c utilization.
+
+        :param i2c_port: 0 = i2c1, 1 = i2c2
+
+        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+               2. Callbacks are set within the individual i2c read methods of this
+              API.
+
+              See i2c_read, or i2c_read_restart_transmission.
+
+        """
+        # test for i2c port 2
+        if i2c_port:
+            # if not previously activated set it to activated
+            # and the send a begin message for this port
+            if not self.i2c_2_active:
+                self.i2c_2_active = True
+            else:
+                return
+        # port 1
+        else:
+            if not self.i2c_1_active:
+                self.i2c_1_active = True
+            else:
+                return
+
+        command = [PrivateConstants.I2C_BEGIN, i2c_port]
+        self._send_command(command)
+
+    def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+        """
+
+        :param pin: connection pin
+
+        :param callback: callback function
+
+        :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+        Temperature,
+        Time]
+
+        DHT_REPORT_TYPE = 12
+        """
+        if self.reported_features & PrivateConstants.DHT_FEATURE:
+            if not callback:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+            if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+                self.dht_callbacks[pin] = callback
+                self.dht_count += 1
+
+                if dht_type != 22 and dht_type != 11:
+                    dht_type = 22
+
+                command = [PrivateConstants.DHT_NEW, pin, dht_type]
+                self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+    # noinspection PyRedundantParentheses
+    def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+        """
+
+        Attach a pin to a servo motor
+
+        :param pin_number: pin
+
+        :param min_pulse: minimum pulse width
+
+        :param max_pulse: maximum pulse width
+
+        """
+        if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+            minv = (min_pulse).to_bytes(2, byteorder="big")
+            maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+            command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                       minv[0], minv[1], maxv[0], maxv[1]]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+    def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                           callback=None):
+        """
+
+        :param trigger_pin:
+
+        :param echo_pin:
+
+        :param callback: callback
+
+        callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+
+        """
+        if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+                self.sonar_callbacks[trigger_pin] = callback
+                self.sonar_count += 1
+
+                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+                self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+    def set_pin_mode_spi(self, chip_select_list=None):
+        """
+        Specify the list of chip select pins.
+
+        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+        Chip Select is any digital output capable pin.
+
+        :param chip_select_list: this is a list of pins to be used for chip select.
+                           The pins will be configured as output, and set to high
+                           ready to be used for chip select.
+                           NOTE: You must specify the chips select pins here!
+
+
+        command message: [command, [cs pins...]]
+        """
+
+        if self.reported_features & PrivateConstants.SPI_FEATURE:
+            if type(chip_select_list) != list:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('chip_select_list must be in the form of a list')
+            if not chip_select_list:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('Chip select pins were not specified')
+
+            self.spi_enabled = True
+
+            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+            for pin in chip_select_list:
+                command.append(pin)
+                self.cs_pins_enabled.append(pin)
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+    # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,
+    #                          pin4=5, enable=True):
+    #     """
+    #     Stepper motor support is implemented as a proxy for the
+    #     the AccelStepper library for the Arduino.
+    #
+    #     This feature is compatible with the TB6600 Motor Driver
+    #
+    #     Note: It may not work for other driver types!
+    #
+    #     https://github.com/waspinator/AccelStepper
+    #
+    #     Instantiate a stepper motor.
+    #
+    #     Initialize the interface and pins for a stepper motor.
+    #
+    #     :param interface: Motor Interface Type:
+    #
+    #             1 = Stepper Driver, 2 driver pins required
+    #
+    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required
+    #
+    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins
+    #                 required
+    #
+    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required
+    #
+    #     :param pin1: Arduino digital pin number for motor pin 1
+    #
+    #     :param pin2: Arduino digital pin number for motor pin 2
+    #
+    #     :param pin3: Arduino digital pin number for motor pin 3
+    #
+    #     :param pin4: Arduino digital pin number for motor pin 4
+    #
+    #     :param enable: If this is true, the output pins at construction time.
+    #
+    #     :return: Motor Reference number
+    #     """
+    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:
+    #
+    #         if self.number_of_steppers == self.max_number_of_steppers:
+    #             if self.shutdown_on_exception:
+    #                 self.shutdown()
+    #             raise RuntimeError('Maximum number of steppers has already been assigned')
+    #
+    #         if interface not in self.valid_stepper_interfaces:
+    #             if self.shutdown_on_exception:
+    #                 self.shutdown()
+    #             raise RuntimeError('Invalid stepper interface')
+    #
+    #         self.number_of_steppers += 1
+    #
+    #         motor_id = self.next_stepper_assigned
+    #         self.next_stepper_assigned += 1
+    #         self.stepper_info_list[motor_id]['instance'] = True
+    #
+    #         # build message and send message to server
+    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,
+    #                    pin2, pin3, pin4, enable]
+    #         self._send_command(command)
+    #
+    #         # return motor id
+    #         return motor_id
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')
+
+    def servo_write(self, pin_number, angle):
+        """
+
+        Set a servo attached to a pin to a given angle.
+
+        :param pin_number: pin
+
+        :param angle: angle (0-180)
+
+        """
+        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+        self._send_command(command)
+
+    def servo_detach(self, pin_number):
+        """
+        Detach a servo for reuse
+
+        :param pin_number: attached pin
+
+        """
+        command = [PrivateConstants.SERVO_DETACH, pin_number]
+        self._send_command(command)
+
+    # def stepper_move_to(self, motor_id, position):
+    #     """
+    #     Set an absolution target position. If position is positive, the movement is
+    #     clockwise, else it is counter-clockwise.
+    #
+    #     The run() function (below) will try to move the motor (at most one step per call)
+    #     from the current position to the target position set by the most
+    #     recent call to this function. Caution: moveTo() also recalculates the
+    #     speed for the next step.
+    #     If you are trying to use constant speed movements, you should call setSpeed()
+    #     after calling moveTo().
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param position: target position. Maximum value is 32 bits.
+    #     """
+    #     if position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(position)
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     self._send_command(command)
+    #
+    # def stepper_move(self, motor_id, relative_position):
+    #     """
+    #     Set the target position relative to the current position.
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param relative_position: The desired position relative to the current
+    #                               position. Negative is anticlockwise from
+    #                               the current position. Maximum value is 32 bits.
+    #     """
+    #     if relative_position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #
+    #     relative_position = abs(relative_position)
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_move: Invalid motor_id.')
+    #
+    #     position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     self._send_command(command)
+    #
+    # def stepper_run(self, motor_id, completion_callback=None):
+    #     """
+    #     This method steps the selected motor based on the current speed.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run: A motion complete callback must be '
+    #                            'specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_run_speed(self, motor_id):
+    #     """
+    #     This method steps the selected motor based at a constant speed as set by the most
+    #     recent call to stepper_set_max_speed(). The motor will run continuously.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_max_speed(self, motor_id, max_speed):
+    #     """
+    #     Sets the maximum permitted speed. The stepper_run() function will accelerate
+    #     up to the speed set by this function.
+    #
+    #     Caution: the maximum speed achievable depends on your processor and clock speed.
+    #     The default maxSpeed is 1 step per second.
+    #
+    #      Caution: Speeds that exceed the maximum speed supported by the processor may
+    #               result in non-linear accelerations and decelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param max_speed: 1 - 1000
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')
+    #
+    #     if not 1 < max_speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')
+    #
+    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed
+    #     max_speed_msb = (max_speed & 0xff00) >> 8
+    #     max_speed_lsb = max_speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,
+    #                max_speed_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_get_max_speed(self, motor_id):
+    #     """
+    #     Returns the maximum speed configured for this stepper
+    #     that was previously set by stepper_set_max_speed()
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :return: The currently configured maximum speed.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['max_speed']
+    #
+    # def stepper_set_acceleration(self, motor_id, acceleration):
+    #     """
+    #     Sets the acceleration/deceleration rate.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param acceleration: The desired acceleration in steps per second
+    #                          per second. Must be > 0.0. This is an
+    #                          expensive call since it requires a square
+    #                          root to be calculated on the server.
+    #                          Dont call more often than needed.
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')
+    #
+    #     if not 1 < acceleration <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration
+    #
+    #     max_accel_msb = acceleration >> 8
+    #     max_accel_lsb = acceleration & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,
+    #                max_accel_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_set_speed(self, motor_id, speed):
+    #     """
+    #     Sets the desired constant speed for use with stepper_run_speed().
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param speed: 0 - 1000 The desired constant speed in steps per
+    #                   second. Positive is clockwise. Speeds of more than 1000 steps per
+    #                   second are unreliable. Speed accuracy depends on the Arduino
+    #                   crystal. Jitter depends on how frequently you call the
+    #                   stepper_run_speed() method.
+    #                   The speed will be limited by the current value of
+    #                   stepper_set_max_speed().
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')
+    #
+    #     if not 0 < speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['speed'] = speed
+    #
+    #     speed_msb = speed >> 8
+    #     speed_lsb = speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_get_speed(self, motor_id):
+    #     """
+    #     Returns the  most recently set speed.
+    #     that was previously set by stepper_set_speed();
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['speed']
+    #
+    # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):
+    #     """
+    #     Request the distance from the current position to the target position
+    #     from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param distance_to_go_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]
+    #
+    #     A positive distance is clockwise from the current position.
+    #
+    #     """
+    #     if not distance_to_go_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')
+    #     self.stepper_info_list[motor_id][
+    #         'distance_to_go_callback'] = distance_to_go_callback
+    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_get_target_position(self, motor_id, target_callback):
+    #     """
+    #     Request the most recently set target position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param target_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #
+    #     """
+    #     if not target_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_target_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id][
+    #         'target_position_callback'] = target_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_get_current_position(self, motor_id, current_position_callback):
+    #     """
+    #     Request the current motor position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param current_position_callback: required callback function to receive report
+    #
+    #     :return: The current motor position returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #     """
+    #     if not current_position_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_current_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_current_position(self, motor_id, position):
+    #     """
+    #     Resets the current position of the motor, so that wherever the motor
+    #     happens to be right now is considered to be the new 0 position. Useful
+    #     for setting a zero position on a stepper after an initial hardware
+    #     positioning move.
+    #
+    #     Has the side effect of setting the current motor speed to 0.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     :param position: Position in steps. This is a 32 bit value
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')
+    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     self._send_command(command)
+    #
+    # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):
+    #     """
+    #     Runs the motor at the currently selected speed until the target position is
+    #     reached.
+    #
+    #     Does not implement accelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '
+    #                            'callback must be '
+    #                            'specified.')
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_stop(self, motor_id):
+    #     """
+    #     Sets a new target position that causes the stepper
+    #     to stop as quickly as possible, using the current speed and
+    #     acceleration parameters.
+    #
+    #     :param motor_id:  0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_stop: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_STOP, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_disable_outputs(self, motor_id):
+    #     """
+    #     Disable motor pin outputs by setting them all LOW.
+    #
+    #     Depending on the design of your electronics this may turn off
+    #     the power to the motor coils, saving power.
+    #
+    #     This is useful to support Arduino low power modes: disable the outputs
+    #     during sleep and then re-enable with enableOutputs() before stepping
+    #     again.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and clears
+    #     the pin to disabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_enable_outputs(self, motor_id):
+    #     """
+    #     Enable motor pin outputs by setting the motor pins to OUTPUT
+    #     mode.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and sets
+    #     the pin to enabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_min_pulse_width(self, motor_id, minimum_width):
+    #     """
+    #     Sets the minimum pulse width allowed by the stepper driver.
+    #
+    #     The minimum practical pulse width is approximately 20 microseconds.
+    #
+    #     Times less than 20 microseconds will usually result in 20 microseconds or so.
+    #
+    #     :param motor_id: 0 -3
+    #
+    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')
+    #
+    #     if not 0 < minimum_width <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '
+    #                            '0-0xffff.')
+    #
+    #     width_msb = minimum_width >> 8
+    #     width_lsb = minimum_width & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,
+    #                width_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_set_enable_pin(self, motor_id, pin=0xff):
+    #     """
+    #     Sets the enable pin number for stepper drivers.
+    #     0xFF indicates unused (default).
+    #
+    #     Otherwise, if a pin is set, the pin will be turned on when
+    #     enableOutputs() is called and switched off when disableOutputs()
+    #     is called.
+    #
+    #     :param motor_id: 0 - 4
+    #     :param pin: 0-0xff
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')
+    #
+    #     if not 0 < pin <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '
+    #                            '0-0xff.')
+    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,
+    #                                 enable=False):
+    #     """
+    #     Sets the inversion for stepper driver pins.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param direction: True=inverted or False
+    #
+    #     :param step: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,
+    #                step, enable]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,
+    #                                 pin3_invert=False, pin4_invert=False, enable=False):
+    #     """
+    #     Sets the inversion for 2, 3 and 4 wire stepper pins
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param pin1_invert: True=inverted or False
+    #
+    #     :param pin2_invert: True=inverted or False
+    #
+    #     :param pin3_invert: True=inverted or False
+    #
+    #     :param pin4_invert: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,
+    #                pin2_invert, pin3_invert, pin4_invert, enable]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_is_running(self, motor_id, callback):
+    #     """
+    #     Checks to see if the motor is currently running to a target.
+    #
+    #     Callback return True if the speed is not zero or not at the target position.
+    #
+    #     :param motor_id: 0-4
+    #
+    #     :param callback: required callback function to receive report
+    #
+    #     :return: The current running state returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]
+    #     """
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_is_running: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback
+    #
+    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]
+    #     self._send_command(command)
+
+    def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):
+        """
+        A private method to set the various pin modes.
+
+        :param pin_number: arduino pin number
+
+        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP
+                         For SERVO use: set_pin_mode_servo
+                         For DHT   use: set_pin_mode_dht
+
+        :param differential: for analog inputs - threshold
+                             value to be achieved for report to
+                             be generated
+
+        :param callback: A reference to a call back function to be
+                         called when pin data value changes
+
+        """
+        if callback:
+            if pin_state == PrivateConstants.AT_INPUT:
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_ANALOG:
+                self.analog_callbacks[pin_number] = callback
+            else:
+                print('{} {}'.format('set_pin_mode: callback ignored for '
+                                     'pin state:', pin_state))
+
+        if pin_state == PrivateConstants.AT_INPUT:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_INPUT, 1]
+
+        elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_INPUT_PULLUP, 1]
+
+        elif pin_state == PrivateConstants.AT_OUTPUT:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_OUTPUT]
+
+        elif pin_state == PrivateConstants.AT_ANALOG:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_ANALOG,
+                       differential >> 8, differential & 0xff, 1]
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Unknown pin state')
+
+        if command:
+            self._send_command(command)
+
+    def shutdown(self):
+        """
+        This method attempts an orderly shutdown
+        If any exceptions are thrown, they are ignored.
+        """
+        self.shutdown_flag = True
+
+        self._stop_threads()
+
+        try:
+            command = [PrivateConstants.STOP_ALL_REPORTS]
+            self._send_command(command)
+            time.sleep(.5)
+
+            if self.hard_reset_on_shutdown:
+                self.r4_hard_reset()
+            else:
+                try:
+                    self.serial_port.reset_input_buffer()
+                    self.serial_port.reset_output_buffer()
+
+                    self.serial_port.close()
+
+                except (RuntimeError, SerialException, OSError):
+                    # ignore error on shutdown
+                    pass
+        except Exception:
+            # raise RuntimeError('Shutdown failed - could not send stop streaming
+            # message')
+            pass
+
+    def sonar_disable(self):
+        """
+        Disable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_DISABLE]
+        self._send_command(command)
+
+    def sonar_enable(self):
+        """
+        Enable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_ENABLE]
+        self._send_command(command)
+
+    def spi_cs_control(self, chip_select_pin, select):
+        """
+        Control an SPI chip select line
+        :param chip_select_pin: pin connected to CS
+
+        :param select: 0=select, 1=deselect
+        """
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+        if chip_select_pin not in self.cs_pins_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+        self._send_command(command)
+
+    def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,
+                          call_back=None):
+        """
+        Read the specified number of bytes from the specified SPI port and
+        call the callback function with the reported data.
+
+        :param chip_select: chip select pin
+
+        :param register_selection: Register to be selected for read.
+
+        :param number_of_bytes_to_read: Number of bytes to read
+
+        :param call_back: Required callback function to report spi data as a
+                   result of read command
+
+
+        callback returns a data list:
+        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+        data bytes, time-stamp]
+
+        SPI_READ_REPORT = 13
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+        if not call_back:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+        self.spi_callback = call_back
+
+        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+                   number_of_bytes_to_read,
+                   register_selection]
+
+        self._send_command(command)
+
+    def spi_set_format(self, clock_divisor, bit_order, data_mode):
+        """
+        Configure how the SPI serializes and de-serializes data on the wire.
+
+        See Arduino SPI reference materials for details.
+
+        :param clock_divisor: 1 - 255
+
+        :param bit_order:
+
+                            LSBFIRST = 0
+
+                            MSBFIRST = 1 (default)
+
+        :param data_mode:
+
+                            SPI_MODE0 = 0x00 (default)
+
+                            SPI_MODE1  = 1
+
+                            SPI_MODE2 = 2
+
+                            SPI_MODE3 = 3
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+        if not 0 < clock_divisor <= 255:
+            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+        if bit_order not in [0, 1]:
+            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+        if data_mode not in [0, 1, 2, 3]:
+            raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+                   data_mode]
+        self._send_command(command)
+
+    def spi_write_blocking(self, chip_select, bytes_to_write):
+        """
+        Write a list of bytes to the SPI device.
+
+        :param chip_select: chip select pin
+
+        :param bytes_to_write: A list of bytes to write. This must
+                                be in the form of a list.
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+        if type(bytes_to_write) is not list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+        for data in bytes_to_write:
+            command.append(data)
+
+        self._send_command(command)
+
+    # def set_pin_mode_one_wire(self, pin):
+    #     """
+    #     Initialize the one wire serial bus.
+    #
+    #     :param pin: Data pin connected to the OneWire device
+    #     """
+    #     if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:
+    #         self.onewire_enabled = True
+    #         command = [PrivateConstants.ONE_WIRE_INIT, pin]
+    #         self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'The OneWire feature is disabled in the server.')
+    #
+    # def onewire_reset(self, callback=None):
+    #     """
+    #     Reset the onewire device
+    #
+    #     :param callback: required  function to report reset result
+    #
+    #     callback returns a list:
+    #     [ReportType = 14, Report Subtype = 25, reset result byte,
+    #                     timestamp]
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_reset: A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_RESET]
+    #     self._send_command(command)
+    #
+    # def onewire_select(self, device_address):
+    #     """
+    #     Select a device based on its address
+    #     :param device_address: A bytearray of 8 bytes
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')
+    #
+    #     if type(device_address) is not list:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #
+    #     if len(device_address) != 8:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #     command = [PrivateConstants.ONE_WIRE_SELECT]
+    #     for data in device_address:
+    #         command.append(data)
+    #     self._send_command(command)
+    #
+    # def onewire_skip(self):
+    #     """
+    #     Skip the device selection. This only works if you have a
+    #     single device, but you can avoid searching and use this to
+    #     immediately access your device.
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SKIP]
+    #     self._send_command(command)
+    #
+    # def onewire_write(self, data, power=0):
+    #     """
+    #     Write a byte to the onewire device. If 'power' is one
+    #     then the wire is held high at the end for
+    #     parasitically powered devices. You
+    #     are responsible for eventually de-powering it by calling
+    #     another read or write.
+    #
+    #     :param data: byte to write.
+    #     :param power: power control (see above)
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')
+    #     if 0 < data < 255:
+    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]
+    #         self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_write: Data must be no larger than 255')
+    #
+    # def onewire_read(self, callback=None):
+    #     """
+    #     Read a byte from the onewire device
+    #     :param callback: required  function to report onewire data as a
+    #                result of read command
+    #
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_READ]
+    #     self._send_command(command)
+    #
+    # def onewire_reset_search(self):
+    #     """
+    #     Begin a new search. The next use of search will begin at the first device
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '
+    #                            f'enabled.')
+    #     else:
+    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]
+    #         self._send_command(command)
+    #
+    # def onewire_search(self, callback=None):
+    #     """
+    #     Search for the next device. The device address will returned in the callback.
+    #     If a device is found, the 8 byte address is contained in the callback.
+    #     If no more devices are found, the address returned contains all elements set
+    #     to 0xff.
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SEARCH]
+    #     self._send_command(command)
+    #
+    # def onewire_crc8(self, address_list, callback=None):
+    #     """
+    #     Compute a CRC check on an array of data.
+    #     :param address_list:
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_crc8 A Callback must be specified')
+    #
+    #     if type(address_list) is not list:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_crc8: address list must be a list.')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     address_length = len(address_list)
+    #
+    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]
+    #
+    #     for data in address_list:
+    #         command.append(data)
+    #
+    #     self._send_command(command)
+
+    def r4_hard_reset(self):
+        """
+        Place the r4 into hard reset
+        """
+        command = [PrivateConstants.RESET, 1]
+        self._send_command(command)
+        time.sleep(.5)
+        command = [PrivateConstants.BOARD_HARD_RESET, 1]
+        self._send_command(command)
+    '''
+    report message handlers
+    '''
+
+    def _analog_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for analog messages.
+
+        :param data: message data
+
+        """
+        pin = data[0]
+        value = (data[1] << 8) + data[2]
+        # set the current value in the pin structure
+        time_stamp = time.time()
+        # self.digital_pins[pin].event_time = time_stamp
+        if self.analog_callbacks[pin]:
+            message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]
+            try:
+                self.analog_callbacks[pin](message)
+            except KeyError:
+                pass
+
+    def _dht_report(self, data):
+        """
+        This is the dht report handler method.
+
+        :param data:            data[0] = report error return
+                                    No Errors = 0
+
+                                    Checksum Error = 1
+
+                                    Timeout Error = 2
+
+                                    Invalid Value = 999
+
+                                data[1] = pin number
+
+                                data[2] = dht type 11 or 22
+
+                                data[3] = humidity positivity flag
+
+                                data[4] = temperature positivity value
+
+                                data[5] = humidity integer
+
+                                data[6] = humidity fractional value
+
+                                data[7] = temperature integer
+
+                                data[8] = temperature fractional value
+
+
+        """
+        if data[0]:  # DHT_ERROR
+            # error report
+            # data[0] = report sub type, data[1] = pin, data[2] = error message
+            if self.dht_callbacks[data[1]]:
+                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time
+                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                           time.time()]
+                try:
+                    self.dht_callbacks[data[1]](message)
+                except KeyError:
+                    pass
+        else:
+            # got valid data DHT_DATA
+            f_humidity = float(data[5] + data[6] / 100)
+            if data[3]:
+                f_humidity *= -1.0
+            f_temperature = float(data[7] + data[8] / 100)
+            if data[4]:
+                f_temperature *= -1.0
+            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                       f_humidity, f_temperature, time.time()]
+
+            try:
+                self.dht_callbacks[data[1]](message)
+            except KeyError:
+                pass
+
+    def _digital_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for Digital Messages.
+
+        :param data: digital message
+
+        """
+        pin = data[0]
+        value = data[1]
+
+        time_stamp = time.time()
+        if self.digital_callbacks[pin]:
+            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]
+            self.digital_callbacks[pin](message)
+
+    def _firmware_message(self, data):
+        """
+        Telemetrix4Arduino firmware version message
+
+        :param data: data[0] = major number, data[1] = minor number.
+
+                               data[2] = patch number
+        """
+
+        self.firmware_version = [data[0], data[1], data[2]]
+
+    def _i2c_read_report(self, data):
+        """
+        Execute callback for i2c reads.
+
+        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]
+        """
+
+        # we receive [# data bytes, address, register, data bytes]
+        # number of bytes of data returned
+
+        # data[0] = number of bytes
+        # data[1] = i2c_port
+        # data[2] = number of bytes returned
+        # data[3] = address
+        # data[4] = register
+        # data[5] ... all the data bytes
+
+        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]
+        cb_list.append(time.time())
+
+        if cb_list[1]:
+            self.i2c_callback2(cb_list)
+        else:
+            self.i2c_callback(cb_list)
+
+    def _i2c_too_few(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    def _i2c_too_many(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    def _i_am_here(self, data):
+        """
+        Reply to are_u_there message
+        :param data: arduino id
+        """
+        self.reported_arduino_id = data[0]
+
+    def _spi_report(self, report):
+
+        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]
+
+        cb_list.append(time.time())
+
+        self.spi_callback(cb_list)
+
+    def _onewire_report(self, report):
+        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]
+        cb_list.append(time.time())
+        self.onewire_callback(cb_list)
+
+    def _report_debug_data(self, data):
+        """
+        Print debug data sent from Arduino
+        :param data: data[0] is a byte followed by 2
+                     bytes that comprise an integer
+        :return:
+        """
+        value = (data[1] << 8) + data[2]
+        print(f'DEBUG ID: {data[0]} Value: {value}')
+
+    def _report_loop_data(self, data):
+        """
+        Print data that was looped back
+        :param data: byte of loop back data
+        :return:
+        """
+        if self.loop_back_callback:
+            self.loop_back_callback(data)
+
+    def _send_command(self, command):
+        """
+        This is a private utility method.
+
+
+        :param command:  command data in the form of a list
+
+        """
+        # the length of the list is added at the head
+        command.insert(0, len(command))
+        send_message = bytes(command)
+
+        if self.serial_port:
+            try:
+                self.serial_port.write(send_message)
+            except SerialException:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('write fail in _send_command')
+        else:
+            raise RuntimeError('No serial port set.')
+
+    def _servo_unavailable(self, report):
+        """
+        Message if no servos are available for use.
+        :param report: pin number
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')
+
+    def _sonar_distance_report(self, report):
+        """
+
+        :param report: data[0] = trigger pin, data[1] and data[2] = distance
+
+        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+        """
+
+        # get callback from pin number
+        cb = self.sonar_callbacks[report[0]]
+
+        # build report data
+        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],
+                   ((report[1] << 8) + report[2]), time.time()]
+
+        cb(cb_list)
+
+    def _stepper_distance_to_go_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper distance to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,
+    #                              data[3] = steps bytes 2, data[4] = steps LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id
+    #                              steps, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     steps = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+
+    def _stepper_target_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper target position to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = target position MSB,
+    #                    data[2] = target position byte MSB+1
+    #                    data[3] = target position byte MSB+2
+    #                    data[4] = target position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id
+    #                              target_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['target_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     target = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     target_position = int.from_bytes(target, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+
+    def _stepper_current_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper current position.
+    #
+    #     :param report: data[0] = motor_id, data[1] = current position MSB,
+    #                    data[2] = current position byte MSB+1
+    #                    data[3] = current position byte MSB+2
+    #                    data[4] = current position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id
+    #                              current_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['current_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     position = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     current_position = int.from_bytes(position, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+
+    def _stepper_is_running_report(self, report):
+        return  # for now
+    #     """
+    #     Report if the motor is currently running
+    #
+    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.
+    #
+    #     callback report format: [18, motor_id,
+    #                              running_state, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['is_running_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]
+    #
+    #     cb(cb_list)
+    #
+
+    def _stepper_run_complete_report(self, report):
+        return  # for now
+    #     """
+    #     The motor completed it motion
+    #
+    #     :param report: data[0] = motor_id
+    #
+    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,
+    #                              time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],
+    #                time.time()]
+    #
+    #     cb(cb_list)
+
+    def _features_report(self, report):
+        self.reported_features = report[0]
+
+    def _run_threads(self):
+        self.run_event.set()
+
+    def _is_running(self):
+        return self.run_event.is_set()
+
+    def _stop_threads(self):
+        self.run_event.clear()
+
+    def _reporter(self):
+        """
+        This is the reporter thread. It continuously pulls data from
+        the deque. When a full message is detected, that message is
+        processed.
+        """
+        self.run_event.wait()
+
+        while self._is_running() and not self.shutdown_flag:
+            if len(self.the_deque):
+                # response_data will be populated with the received data for the report
+                response_data = []
+                packet_length = self.the_deque.popleft()
+                if packet_length:
+                    # get all the data for the report and place it into response_data
+                    for i in range(packet_length):
+                        while not len(self.the_deque):
+                            time.sleep(self.sleep_tune)
+                        data = self.the_deque.popleft()
+                        response_data.append(data)
+
+                    # print(f'response_data {response_data}')
+
+                    # get the report type and look up its dispatch method
+                    # here we pop the report type off of response_data
+                    report_type = response_data.pop(0)
+                    # print(f' reported type {report_type}')
+
+                    # retrieve the report handler from the dispatch table
+                    dispatch_entry = self.report_dispatch.get(report_type)
+
+                    # if there is additional data for the report,
+                    # it will be contained in response_data
+                    # noinspection PyArgumentList
+                    dispatch_entry(response_data)
+                    continue
+                else:
+                    if self.shutdown_on_exception:
+                        self.shutdown()
+                    raise RuntimeError(
+                        'A report with a packet length of zero was received.')
+            else:
+                time.sleep(self.sleep_tune)
+
+    def _serial_receiver(self):
+        """
+        Thread to continuously check for incoming data.
+        When a byte comes in, place it onto the deque.
+        """
+        self.run_event.wait()
+
+        # Don't start this thread if using a tcp/ip transport
+
+        while self._is_running() and not self.shutdown_flag:
+            # we can get an OSError: [Errno9] Bad file descriptor when shutting down
+            # just ignore it
+            try:
+                if self.serial_port.inWaiting():
+                    c = self.serial_port.read()
+                    self.the_deque.append(ord(c))
+                    # print(ord(c))
+                else:
+                    time.sleep(self.sleep_tune)
+                    # continue
+            except OSError:
+                pass
+
+
+ + + +
+ + + + + + + + + + +
+ + + +

+__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True) + +

+ + +
+ +

:param com_port: e.g. COM3 or /dev/ttyACM0. + Only use if you wish to bypass auto com port + detection.

+

:param arduino_instance_id: Match with the value installed on the + arduino-telemetrix sketch.

+

:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.

+

:param sleep_tune: A tuning parameter (typically not changed by user)

+

:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception

+

:param hard_reset_on_shutdown: reset the board on shutdown

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
def __init__(self, com_port=None, arduino_instance_id=1,
+             arduino_wait=1, sleep_tune=0.000001,
+             shutdown_on_exception=True, hard_reset_on_shutdown=True):
+
+    """
+
+    :param com_port: e.g. COM3 or /dev/ttyACM0.
+                     Only use if you wish to bypass auto com port
+                     detection.
+
+    :param arduino_instance_id: Match with the value installed on the
+                                arduino-telemetrix sketch.
+
+    :param arduino_wait: Amount of time to wait for an Arduino to
+                         fully reset itself.
+
+    :param sleep_tune: A tuning parameter (typically not changed by user)
+
+    :param shutdown_on_exception: call shutdown before raising
+                                  a RunTimeError exception, or
+                                  receiving a KeyboardInterrupt exception
+
+    :param hard_reset_on_shutdown: reset the board on shutdown
+
+    """
+
+    # initialize threading parent
+    threading.Thread.__init__(self)
+
+    # create the threads and set them as daemons so
+    # that they stop when the program is closed
+
+    # create a thread to interpret received serial data
+    self.the_reporter_thread = threading.Thread(target=self._reporter)
+    self.the_reporter_thread.daemon = True
+
+    self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)
+
+    self.the_data_receive_thread.daemon = True
+
+    # flag to allow the reporter and receive threads to run.
+    self.run_event = threading.Event()
+
+    # check to make sure that Python interpreter is version 3.7 or greater
+    python_version = sys.version_info
+    if python_version[0] >= 3:
+        if python_version[1] >= 7:
+            pass
+        else:
+            raise RuntimeError("ERROR: Python 3.7 or greater is "
+                               "required for use of this program.")
+
+    # save input parameters as instance variables
+    self.com_port = com_port
+    self.arduino_instance_id = arduino_instance_id
+    self.arduino_wait = arduino_wait
+    self.sleep_tune = sleep_tune
+    self.shutdown_on_exception = shutdown_on_exception
+    self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+    # create a deque to receive and process data from the arduino
+    self.the_deque = deque()
+
+    # The report_dispatch dictionary is used to process
+    # incoming report messages by looking up the report message
+    # and executing its associated processing method.
+
+    self.report_dispatch = {}
+
+    # To add a command to the command dispatch table, append here.
+    self.report_dispatch.update(
+        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+    self.report_dispatch.update(
+        {PrivateConstants.ANALOG_REPORT: self._analog_message})
+    self.report_dispatch.update(
+        {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})
+    self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})
+    self.report_dispatch.update(
+        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+    self.report_dispatch.update(
+        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+    self.report_dispatch.update(
+        {PrivateConstants.SPI_REPORT: self._spi_report})
+    self.report_dispatch.update(
+        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_CURRENT_POSITION:
+             self._stepper_current_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUNNING_REPORT:
+             self._stepper_is_running_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+             self._stepper_run_complete_report})
+
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.FEATURES:
+             self._features_report})
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    self.cs_pins_enabled = []
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    self.dht_count = 0
+
+    # serial port in use
+    self.serial_port = None
+
+    # flag to indicate we are in shutdown mode
+    self.shutdown_flag = False
+
+    # debug loopback callback method
+    self.loop_back_callback = None
+
+    # flag to indicate the start of a new report
+    # self.new_report_start = True
+
+    # firmware version to be stored here
+    self.firmware_version = []
+
+    # reported arduino instance id
+    self.reported_arduino_id = []
+
+    # reported features
+    self.reported_features = 0
+
+    # flag to indicate if i2c was previously enabled
+    self.i2c_enabled = False
+
+    # flag to indicate if spi is initialized
+    self.spi_enabled = False
+
+    # flag to indicate if onewire is initialized
+    self.onewire_enabled = False
+
+    # # stepper motor variables
+    #
+    # # updated when a new motor is added
+    # self.next_stepper_assigned = 0
+    #
+    # # valid list of stepper motor interface types
+    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+    #
+    # # maximum number of steppers supported
+    # self.max_number_of_steppers = 4
+    #
+    # # number of steppers created - not to exceed the maximum
+    # self.number_of_steppers = 0
+    #
+    # # dictionary to hold stepper motor information
+    # self.stepper_info = {'instance': False, 'is_running': None,
+    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+    #                      'distance_to_go_callback': None,
+    #                      'target_position_callback': None,
+    #                      'current_position_callback': None,
+    #                      'is_running_callback': None,
+    #                      'motion_complete_callback': None,
+    #                      'acceleration_callback': None}
+    #
+    # # build a list of stepper motor info items
+    # self.stepper_info_list = []
+    # # a list of dictionaries to hold stepper information
+    # for motor in range(self.max_number_of_steppers):
+    #     self.stepper_info_list.append(self.stepper_info)
+
+    self.the_reporter_thread.start()
+    self.the_data_receive_thread.start()
+
+    print(f"telemetrix_uno_r4_minima:  Version"
+          f" {PrivateConstants.TELEMETRIX_VERSION}\n\n"
+          f"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\n")
+
+    # using the serial link
+    if not self.com_port:
+        # user did not specify a com_port
+        try:
+            self._find_arduino()
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                self.shutdown()
+    else:
+        # com_port specified - set com_port and baud rate
+        try:
+            self._manual_open()
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                self.shutdown()
+
+    if self.serial_port:
+        print(
+            f"Arduino compatible device found and connected to {self.serial_port.port}")
+
+        self.serial_port.reset_input_buffer()
+        self.serial_port.reset_output_buffer()
+
+    # no com_port found - raise a runtime exception
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('No Arduino Found or User Aborted Program')
+
+    # allow the threads to run
+    self._run_threads()
+    print(f'Reset Complete')
+
+    # get telemetrix firmware version and print it
+    print('\nRetrieving Telemetrix4UnoR4Minima firmware ID...')
+    self._get_firmware_version()
+    if not self.firmware_version:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'Telemetrix4UnoR4Minima firmware version')
+
+    else:
+
+        print(f'Telemetrix4UnoR4Minima firmware version: {self.firmware_version[0]}.'
+              f'{self.firmware_version[1]}.{self.firmware_version[2]}')
+    command = [PrivateConstants.ENABLE_ALL_REPORTS]
+    self._send_command(command)
+
+    # get the features list
+    command = [PrivateConstants.GET_FEATURES]
+    self._send_command(command)
+    time.sleep(.2)
+
+    # Have the server reset its data structures
+    command = [PrivateConstants.RESET]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+analog_write(pin, value) + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (maximum 16 bits)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
def analog_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (maximum 16 bits)
+
+    """
+    value_msb = value >> 8
+    value_lsb = value & 0xff
+    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+digital_write(pin, value) + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (1 or 0)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
def digital_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (1 or 0)
+
+    """
+
+    command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_all_reporting() + +

+ + +
+ +

Disable reporting for all digital and analog input pins

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
439
+440
+441
+442
+443
+444
+445
def disable_all_reporting(self):
+    """
+    Disable reporting for all digital and analog input pins
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DISABLE_ALL, 0]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_analog_reporting(pin) + +

+ + +
+ +

Disables analog reporting for a single analog pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
447
+448
+449
+450
+451
+452
+453
+454
+455
+456
def disable_analog_reporting(self, pin):
+    """
+    Disables analog reporting for a single analog pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_digital_reporting(pin) + +

+ + +
+ +

Disables digital reporting for a single digital input.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
458
+459
+460
+461
+462
+463
+464
+465
+466
+467
def disable_digital_reporting(self, pin):
+    """
+    Disables digital reporting for a single digital input.
+
+    :param pin: Pin number.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_analog_reporting(pin) + +

+ + +
+ +

Enables analog reporting for the specified pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
def enable_analog_reporting(self, pin):
+    """
+    Enables analog reporting for the specified pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_digital_reporting(pin) + +

+ + +
+ +

Enable reporting on the specified digital pin.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
481
+482
+483
+484
+485
+486
+487
+488
+489
+490
def enable_digital_reporting(self, pin):
+    """
+    Enable reporting on the specified digital pin.
+
+    :param pin: Pin number.
+    """
+
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True) + +

+ + +
+ +

Read the specified number of bytes from the + specified register for the i2c device.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report + i2c data as a result of read command

+

:param i2c_port: 0 = default, 1 = secondary

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
def i2c_read(self, address, register, number_of_bytes,
+             callback=None, i2c_port=0,
+             write_register=True):
+    """
+    Read the specified number of bytes from the
+    specified register for the i2c device.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                   selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report
+                     i2c data as a result of read command
+
+   :param i2c_port: 0 = default, 1 = secondary
+
+   :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+
+    self._i2c_read_request(address, register, number_of_bytes,
+                           callback=callback, i2c_port=i2c_port,
+                           write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True) + +

+ + +
+ +

Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c + data as a result of read command

+

:param i2c_port: 0 = default 1 = secondary

+

:param write_register: If True, the register is written before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
def i2c_read_restart_transmission(self, address, register,
+                                  number_of_bytes,
+                                  callback=None, i2c_port=0,
+                                  write_register=True):
+    """
+    Read the specified number of bytes from the specified
+    register for the i2c device. This restarts the transmission
+    after the read. It is required for some i2c devices such as the MMA8452Q
+    accelerometer.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                                selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c
+                     data as a result of read command
+
+   :param i2c_port: 0 = default 1 = secondary
+
+   :param write_register: If True, the register is written before read
+                          Else, the write is suppressed
+
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+
+    self._i2c_read_request(address, register, number_of_bytes,
+                           stop_transmission=False,
+                           callback=callback, i2c_port=i2c_port,
+                           write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_write(address, args, i2c_port=0) + +

+ + +
+ +

Write data to an i2c device.

+

:param address: i2c device address

+

:param i2c_port: 0= port 1, 1 = port 2

+

:param args: A variable number of bytes to be sent to the device + passed in as a list

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
655
+656
+657
+658
+659
+660
+661
+662
+663
+664
+665
+666
+667
+668
+669
+670
+671
+672
+673
+674
+675
+676
+677
+678
+679
+680
+681
+682
+683
+684
+685
+686
def i2c_write(self, address, args, i2c_port=0):
+    """
+    Write data to an i2c device.
+
+    :param address: i2c device address
+
+    :param i2c_port: 0= port 1, 1 = port 2
+
+    :param args: A variable number of bytes to be sent to the device
+                 passed in as a list
+
+    """
+    if not i2c_port:
+        if not self.i2c_1_active:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+    if i2c_port:
+        if not self.i2c_2_active:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+    for item in args:
+        command.append(item)
+
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+loop_back(start_character, callback=None) + +

+ + +
+ +

This is a debugging method to send a character to the +Arduino device, and have the device loop it back.

+

:param start_character: The character to loop back. It should be + an integer.

+

:param callback: Looped back character will appear in the callback method

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
688
+689
+690
+691
+692
+693
+694
+695
+696
+697
+698
+699
+700
+701
def loop_back(self, start_character, callback=None):
+    """
+    This is a debugging method to send a character to the
+    Arduino device, and have the device loop it back.
+
+    :param start_character: The character to loop back. It should be
+                            an integer.
+
+    :param callback: Looped back character will appear in the callback method
+
+    """
+    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+    self.loop_back_callback = callback
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+r4_hard_reset() + +

+ + +
+ +

Place the r4 into hard reset

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
def r4_hard_reset(self):
+    """
+    Place the r4 into hard reset
+    """
+    command = [PrivateConstants.RESET, 1]
+    self._send_command(command)
+    time.sleep(.5)
+    command = [PrivateConstants.BOARD_HARD_RESET, 1]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_detach(pin_number) + +

+ + +
+ +

Detach a servo for reuse

+

:param pin_number: attached pin

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
def servo_detach(self, pin_number):
+    """
+    Detach a servo for reuse
+
+    :param pin_number: attached pin
+
+    """
+    command = [PrivateConstants.SERVO_DETACH, pin_number]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_write(pin_number, angle) + +

+ + +
+ +

Set a servo attached to a pin to a given angle.

+

:param pin_number: pin

+

:param angle: angle (0-180)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
def servo_write(self, pin_number, angle):
+    """
+
+    Set a servo attached to a pin to a given angle.
+
+    :param pin_number: pin
+
+    :param angle: angle (0-180)
+
+    """
+    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_analog_scan_interval(interval) + +

+ + +
+ +

Set the analog scanning interval.

+

:param interval: value of 0 - 255 - milliseconds

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+713
+714
+715
+716
def set_analog_scan_interval(self, interval):
+    """
+    Set the analog scanning interval.
+
+    :param interval: value of 0 - 255 - milliseconds
+    """
+
+    if 0 <= interval <= 255:
+        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('Analog interval must be between 0 and 255')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_input(pin_number, differential=0, callback=None) + +

+ + +
+ +

Set a pin as an analog input.

+

:param pin_number: arduino pin number

+

:param differential: difference in previous to current value before + report will be generated

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for analog input pins = 3

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
727
+728
+729
+730
+731
+732
+733
+734
+735
+736
+737
+738
+739
+740
+741
+742
+743
+744
+745
+746
+747
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+    """
+    Set a pin as an analog input.
+
+    :param pin_number: arduino pin number
+
+    :param differential: difference in previous to current value before
+                         report will be generated
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for analog input pins = 3
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,
+                       callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_output(pin_number) + +

+ + +
+ +

Set a pin as a pwm (analog output) pin.

+

:param pin_number:arduino pin number

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
718
+719
+720
+721
+722
+723
+724
+725
def set_pin_mode_analog_output(self, pin_number):
+    """
+    Set a pin as a pwm (analog output) pin.
+
+    :param pin_number:arduino pin number
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_dht(pin, callback=None, dht_type=22) + +

+ + +
+ +

:param pin: connection pin

+

:param callback: callback function

+

:param dht_type: either 22 for DHT22 or 11 for DHT11

+

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

+

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]

+

DHT_REPORT_TYPE = 12

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
825
+826
+827
+828
+829
+830
+831
+832
+833
+834
+835
+836
+837
+838
+839
+840
+841
+842
+843
+844
+845
+846
+847
+848
+849
+850
+851
+852
+853
+854
+855
+856
+857
+858
+859
+860
+861
+862
+863
+864
+865
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+    """
+
+    :param pin: connection pin
+
+    :param callback: callback function
+
+    :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+    Temperature,
+    Time]
+
+    DHT_REPORT_TYPE = 12
+    """
+    if self.reported_features & PrivateConstants.DHT_FEATURE:
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+        if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+            self.dht_callbacks[pin] = callback
+            self.dht_count += 1
+
+            if dht_type != 22 and dht_type != 11:
+                dht_type = 22
+
+            command = [PrivateConstants.DHT_NEW, pin, dht_type]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input(pin_number, callback=None) + +

+ + +
+ +

Set a pin as a digital input.

+

:param pin_number: arduino pin number

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
749
+750
+751
+752
+753
+754
+755
+756
+757
+758
+759
+760
+761
+762
+763
+764
+765
def set_pin_mode_digital_input(self, pin_number, callback=None):
+    """
+    Set a pin as a digital input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input_pullup(pin_number, callback=None) + +

+ + +
+ +

Set a pin as a digital input with pullup enabled.

+

:param pin_number: arduino pin number

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
767
+768
+769
+770
+771
+772
+773
+774
+775
+776
+777
+778
+779
+780
+781
+782
+783
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):
+    """
+    Set a pin as a digital input with pullup enabled.
+
+    :param pin_number: arduino pin number
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                       callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_output(pin_number) + +

+ + +
+ +

Set a pin as a digital output pin.

+

:param pin_number: arduino pin number

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
785
+786
+787
+788
+789
+790
+791
+792
def set_pin_mode_digital_output(self, pin_number):
+    """
+    Set a pin as a digital output pin.
+
+    :param pin_number: arduino pin number
+    """
+
+    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_i2c(i2c_port=0) + +

+ + +
+ +

Establish the standard Arduino i2c pins for i2c utilization.

+

:param i2c_port: 0 = i2c1, 1 = i2c2

+ +
+
    +
  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  2. +
+
    +
  1. Callbacks are set within the individual i2c read methods of this
  2. +
+
  API.
+
+  See i2c_read, or i2c_read_restart_transmission.
+
+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
794
+795
+796
+797
+798
+799
+800
+801
+802
+803
+804
+805
+806
+807
+808
+809
+810
+811
+812
+813
+814
+815
+816
+817
+818
+819
+820
+821
+822
+823
def set_pin_mode_i2c(self, i2c_port=0):
+    """
+    Establish the standard Arduino i2c pins for i2c utilization.
+
+    :param i2c_port: 0 = i2c1, 1 = i2c2
+
+    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+           2. Callbacks are set within the individual i2c read methods of this
+          API.
+
+          See i2c_read, or i2c_read_restart_transmission.
+
+    """
+    # test for i2c port 2
+    if i2c_port:
+        # if not previously activated set it to activated
+        # and the send a begin message for this port
+        if not self.i2c_2_active:
+            self.i2c_2_active = True
+        else:
+            return
+    # port 1
+    else:
+        if not self.i2c_1_active:
+            self.i2c_1_active = True
+        else:
+            return
+
+    command = [PrivateConstants.I2C_BEGIN, i2c_port]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) + +

+ + +
+ +

Attach a pin to a servo motor

+

:param pin_number: pin

+

:param min_pulse: minimum pulse width

+

:param max_pulse: maximum pulse width

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
868
+869
+870
+871
+872
+873
+874
+875
+876
+877
+878
+879
+880
+881
+882
+883
+884
+885
+886
+887
+888
+889
+890
+891
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+    """
+
+    Attach a pin to a servo motor
+
+    :param pin_number: pin
+
+    :param min_pulse: minimum pulse width
+
+    :param max_pulse: maximum pulse width
+
+    """
+    if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+        minv = (min_pulse).to_bytes(2, byteorder="big")
+        maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+        command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                   minv[0], minv[1], maxv[0], maxv[1]]
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_sonar(trigger_pin, echo_pin, callback=None) + +

+ + +
+ +

:param trigger_pin:

+

:param echo_pin:

+

:param callback: callback

+

callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
893
+894
+895
+896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                       callback=None):
+    """
+
+    :param trigger_pin:
+
+    :param echo_pin:
+
+    :param callback: callback
+
+    callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+
+    """
+    if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+            self.sonar_callbacks[trigger_pin] = callback
+            self.sonar_count += 1
+
+            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_spi(chip_select_list=None) + +

+ + +
+ +

Specify the list of chip select pins.

+

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

+

Chip Select is any digital output capable pin.

+

:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!

+

command message: [command, [cs pins...]]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960
+961
+962
+963
+964
+965
+966
+967
def set_pin_mode_spi(self, chip_select_list=None):
+    """
+    Specify the list of chip select pins.
+
+    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+    Chip Select is any digital output capable pin.
+
+    :param chip_select_list: this is a list of pins to be used for chip select.
+                       The pins will be configured as output, and set to high
+                       ready to be used for chip select.
+                       NOTE: You must specify the chips select pins here!
+
+
+    command message: [command, [cs pins...]]
+    """
+
+    if self.reported_features & PrivateConstants.SPI_FEATURE:
+        if type(chip_select_list) != list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('chip_select_list must be in the form of a list')
+        if not chip_select_list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Chip select pins were not specified')
+
+        self.spi_enabled = True
+
+        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+        for pin in chip_select_list:
+            command.append(pin)
+            self.cs_pins_enabled.append(pin)
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+shutdown() + +

+ + +
+ +

This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
def shutdown(self):
+    """
+    This method attempts an orderly shutdown
+    If any exceptions are thrown, they are ignored.
+    """
+    self.shutdown_flag = True
+
+    self._stop_threads()
+
+    try:
+        command = [PrivateConstants.STOP_ALL_REPORTS]
+        self._send_command(command)
+        time.sleep(.5)
+
+        if self.hard_reset_on_shutdown:
+            self.r4_hard_reset()
+        else:
+            try:
+                self.serial_port.reset_input_buffer()
+                self.serial_port.reset_output_buffer()
+
+                self.serial_port.close()
+
+            except (RuntimeError, SerialException, OSError):
+                # ignore error on shutdown
+                pass
+    except Exception:
+        # raise RuntimeError('Shutdown failed - could not send stop streaming
+        # message')
+        pass
+
+
+
+ +
+ + +
+ + + +

+sonar_disable() + +

+ + +
+ +

Disable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1743
+1744
+1745
+1746
+1747
+1748
def sonar_disable(self):
+    """
+    Disable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_DISABLE]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+sonar_enable() + +

+ + +
+ +

Enable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1750
+1751
+1752
+1753
+1754
+1755
def sonar_enable(self):
+    """
+    Enable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_ENABLE]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_cs_control(chip_select_pin, select) + +

+ + +
+ +

Control an SPI chip select line +:param chip_select_pin: pin connected to CS

+

:param select: 0=select, 1=deselect

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
def spi_cs_control(self, chip_select_pin, select):
+    """
+    Control an SPI chip select line
+    :param chip_select_pin: pin connected to CS
+
+    :param select: 0=select, 1=deselect
+    """
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+    if chip_select_pin not in self.cs_pins_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) + +

+ + +
+ +

Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.

+

:param chip_select: chip select pin

+

:param register_selection: Register to be selected for read.

+

:param number_of_bytes_to_read: Number of bytes to read

+

:param call_back: Required callback function to report spi data as a + result of read command

+

callback returns a data list: +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, +data bytes, time-stamp]

+

SPI_READ_REPORT = 13

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,
+                      call_back=None):
+    """
+    Read the specified number of bytes from the specified SPI port and
+    call the callback function with the reported data.
+
+    :param chip_select: chip select pin
+
+    :param register_selection: Register to be selected for read.
+
+    :param number_of_bytes_to_read: Number of bytes to read
+
+    :param call_back: Required callback function to report spi data as a
+               result of read command
+
+
+    callback returns a data list:
+    [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+    data bytes, time-stamp]
+
+    SPI_READ_REPORT = 13
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+    if not call_back:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+    self.spi_callback = call_back
+
+    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+               number_of_bytes_to_read,
+               register_selection]
+
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_set_format(clock_divisor, bit_order, data_mode) + +

+ + +
+ +

Configure how the SPI serializes and de-serializes data on the wire.

+

See Arduino SPI reference materials for details.

+

:param clock_divisor: 1 - 255

+

:param bit_order:

+
                LSBFIRST = 0
+
+                MSBFIRST = 1 (default)
+
+

:param data_mode:

+
                SPI_MODE0 = 0x00 (default)
+
+                SPI_MODE1  = 1
+
+                SPI_MODE2 = 2
+
+                SPI_MODE3 = 3
+
+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
def spi_set_format(self, clock_divisor, bit_order, data_mode):
+    """
+    Configure how the SPI serializes and de-serializes data on the wire.
+
+    See Arduino SPI reference materials for details.
+
+    :param clock_divisor: 1 - 255
+
+    :param bit_order:
+
+                        LSBFIRST = 0
+
+                        MSBFIRST = 1 (default)
+
+    :param data_mode:
+
+                        SPI_MODE0 = 0x00 (default)
+
+                        SPI_MODE1  = 1
+
+                        SPI_MODE2 = 2
+
+                        SPI_MODE3 = 3
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+    if not 0 < clock_divisor <= 255:
+        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+    if bit_order not in [0, 1]:
+        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+    if data_mode not in [0, 1, 2, 3]:
+        raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+               data_mode]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_write_blocking(chip_select, bytes_to_write) + +

+ + +
+ +

Write a list of bytes to the SPI device.

+

:param chip_select: chip select pin

+

:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima/telemetrix_uno_r4_minima.py +
1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
def spi_write_blocking(self, chip_select, bytes_to_write):
+    """
+    Write a list of bytes to the SPI device.
+
+    :param chip_select: chip select pin
+
+    :param bytes_to_write: A list of bytes to write. This must
+                            be in the form of a list.
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+    if type(bytes_to_write) is not list:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+    for data in bytes_to_write:
+        command.append(data)
+
+    self._send_command(command)
+
+
+
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/telemetrix_minima_reference_aio/index.html b/telemetrix_minima_reference_aio/index.html new file mode 100644 index 0000000..de80a7d --- /dev/null +++ b/telemetrix_minima_reference_aio/index.html @@ -0,0 +1,9605 @@ + + + + + + + + + + + + + + + + + + + + + + telemetrix_uno_r4_minima_aio - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +

telemetrix_uno_r4_minima_aio

+ +
+ + + +
+ +

Copyright (c) 2023 Alan Yorinks All rights reserved.

+

This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.

+

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

+ + + +
+ + + + + + + + +
+ + + +

+ TelemetrixUnoR4MinimaAio + + +

+ + +
+ + +

This class exposes and implements the TelemetrixAIO API. +It includes the public API methods as well as +a set of private methods. This is an asyncio API.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
  33
+  34
+  35
+  36
+  37
+  38
+  39
+  40
+  41
+  42
+  43
+  44
+  45
+  46
+  47
+  48
+  49
+  50
+  51
+  52
+  53
+  54
+  55
+  56
+  57
+  58
+  59
+  60
+  61
+  62
+  63
+  64
+  65
+  66
+  67
+  68
+  69
+  70
+  71
+  72
+  73
+  74
+  75
+  76
+  77
+  78
+  79
+  80
+  81
+  82
+  83
+  84
+  85
+  86
+  87
+  88
+  89
+  90
+  91
+  92
+  93
+  94
+  95
+  96
+  97
+  98
+  99
+ 100
+ 101
+ 102
+ 103
+ 104
+ 105
+ 106
+ 107
+ 108
+ 109
+ 110
+ 111
+ 112
+ 113
+ 114
+ 115
+ 116
+ 117
+ 118
+ 119
+ 120
+ 121
+ 122
+ 123
+ 124
+ 125
+ 126
+ 127
+ 128
+ 129
+ 130
+ 131
+ 132
+ 133
+ 134
+ 135
+ 136
+ 137
+ 138
+ 139
+ 140
+ 141
+ 142
+ 143
+ 144
+ 145
+ 146
+ 147
+ 148
+ 149
+ 150
+ 151
+ 152
+ 153
+ 154
+ 155
+ 156
+ 157
+ 158
+ 159
+ 160
+ 161
+ 162
+ 163
+ 164
+ 165
+ 166
+ 167
+ 168
+ 169
+ 170
+ 171
+ 172
+ 173
+ 174
+ 175
+ 176
+ 177
+ 178
+ 179
+ 180
+ 181
+ 182
+ 183
+ 184
+ 185
+ 186
+ 187
+ 188
+ 189
+ 190
+ 191
+ 192
+ 193
+ 194
+ 195
+ 196
+ 197
+ 198
+ 199
+ 200
+ 201
+ 202
+ 203
+ 204
+ 205
+ 206
+ 207
+ 208
+ 209
+ 210
+ 211
+ 212
+ 213
+ 214
+ 215
+ 216
+ 217
+ 218
+ 219
+ 220
+ 221
+ 222
+ 223
+ 224
+ 225
+ 226
+ 227
+ 228
+ 229
+ 230
+ 231
+ 232
+ 233
+ 234
+ 235
+ 236
+ 237
+ 238
+ 239
+ 240
+ 241
+ 242
+ 243
+ 244
+ 245
+ 246
+ 247
+ 248
+ 249
+ 250
+ 251
+ 252
+ 253
+ 254
+ 255
+ 256
+ 257
+ 258
+ 259
+ 260
+ 261
+ 262
+ 263
+ 264
+ 265
+ 266
+ 267
+ 268
+ 269
+ 270
+ 271
+ 272
+ 273
+ 274
+ 275
+ 276
+ 277
+ 278
+ 279
+ 280
+ 281
+ 282
+ 283
+ 284
+ 285
+ 286
+ 287
+ 288
+ 289
+ 290
+ 291
+ 292
+ 293
+ 294
+ 295
+ 296
+ 297
+ 298
+ 299
+ 300
+ 301
+ 302
+ 303
+ 304
+ 305
+ 306
+ 307
+ 308
+ 309
+ 310
+ 311
+ 312
+ 313
+ 314
+ 315
+ 316
+ 317
+ 318
+ 319
+ 320
+ 321
+ 322
+ 323
+ 324
+ 325
+ 326
+ 327
+ 328
+ 329
+ 330
+ 331
+ 332
+ 333
+ 334
+ 335
+ 336
+ 337
+ 338
+ 339
+ 340
+ 341
+ 342
+ 343
+ 344
+ 345
+ 346
+ 347
+ 348
+ 349
+ 350
+ 351
+ 352
+ 353
+ 354
+ 355
+ 356
+ 357
+ 358
+ 359
+ 360
+ 361
+ 362
+ 363
+ 364
+ 365
+ 366
+ 367
+ 368
+ 369
+ 370
+ 371
+ 372
+ 373
+ 374
+ 375
+ 376
+ 377
+ 378
+ 379
+ 380
+ 381
+ 382
+ 383
+ 384
+ 385
+ 386
+ 387
+ 388
+ 389
+ 390
+ 391
+ 392
+ 393
+ 394
+ 395
+ 396
+ 397
+ 398
+ 399
+ 400
+ 401
+ 402
+ 403
+ 404
+ 405
+ 406
+ 407
+ 408
+ 409
+ 410
+ 411
+ 412
+ 413
+ 414
+ 415
+ 416
+ 417
+ 418
+ 419
+ 420
+ 421
+ 422
+ 423
+ 424
+ 425
+ 426
+ 427
+ 428
+ 429
+ 430
+ 431
+ 432
+ 433
+ 434
+ 435
+ 436
+ 437
+ 438
+ 439
+ 440
+ 441
+ 442
+ 443
+ 444
+ 445
+ 446
+ 447
+ 448
+ 449
+ 450
+ 451
+ 452
+ 453
+ 454
+ 455
+ 456
+ 457
+ 458
+ 459
+ 460
+ 461
+ 462
+ 463
+ 464
+ 465
+ 466
+ 467
+ 468
+ 469
+ 470
+ 471
+ 472
+ 473
+ 474
+ 475
+ 476
+ 477
+ 478
+ 479
+ 480
+ 481
+ 482
+ 483
+ 484
+ 485
+ 486
+ 487
+ 488
+ 489
+ 490
+ 491
+ 492
+ 493
+ 494
+ 495
+ 496
+ 497
+ 498
+ 499
+ 500
+ 501
+ 502
+ 503
+ 504
+ 505
+ 506
+ 507
+ 508
+ 509
+ 510
+ 511
+ 512
+ 513
+ 514
+ 515
+ 516
+ 517
+ 518
+ 519
+ 520
+ 521
+ 522
+ 523
+ 524
+ 525
+ 526
+ 527
+ 528
+ 529
+ 530
+ 531
+ 532
+ 533
+ 534
+ 535
+ 536
+ 537
+ 538
+ 539
+ 540
+ 541
+ 542
+ 543
+ 544
+ 545
+ 546
+ 547
+ 548
+ 549
+ 550
+ 551
+ 552
+ 553
+ 554
+ 555
+ 556
+ 557
+ 558
+ 559
+ 560
+ 561
+ 562
+ 563
+ 564
+ 565
+ 566
+ 567
+ 568
+ 569
+ 570
+ 571
+ 572
+ 573
+ 574
+ 575
+ 576
+ 577
+ 578
+ 579
+ 580
+ 581
+ 582
+ 583
+ 584
+ 585
+ 586
+ 587
+ 588
+ 589
+ 590
+ 591
+ 592
+ 593
+ 594
+ 595
+ 596
+ 597
+ 598
+ 599
+ 600
+ 601
+ 602
+ 603
+ 604
+ 605
+ 606
+ 607
+ 608
+ 609
+ 610
+ 611
+ 612
+ 613
+ 614
+ 615
+ 616
+ 617
+ 618
+ 619
+ 620
+ 621
+ 622
+ 623
+ 624
+ 625
+ 626
+ 627
+ 628
+ 629
+ 630
+ 631
+ 632
+ 633
+ 634
+ 635
+ 636
+ 637
+ 638
+ 639
+ 640
+ 641
+ 642
+ 643
+ 644
+ 645
+ 646
+ 647
+ 648
+ 649
+ 650
+ 651
+ 652
+ 653
+ 654
+ 655
+ 656
+ 657
+ 658
+ 659
+ 660
+ 661
+ 662
+ 663
+ 664
+ 665
+ 666
+ 667
+ 668
+ 669
+ 670
+ 671
+ 672
+ 673
+ 674
+ 675
+ 676
+ 677
+ 678
+ 679
+ 680
+ 681
+ 682
+ 683
+ 684
+ 685
+ 686
+ 687
+ 688
+ 689
+ 690
+ 691
+ 692
+ 693
+ 694
+ 695
+ 696
+ 697
+ 698
+ 699
+ 700
+ 701
+ 702
+ 703
+ 704
+ 705
+ 706
+ 707
+ 708
+ 709
+ 710
+ 711
+ 712
+ 713
+ 714
+ 715
+ 716
+ 717
+ 718
+ 719
+ 720
+ 721
+ 722
+ 723
+ 724
+ 725
+ 726
+ 727
+ 728
+ 729
+ 730
+ 731
+ 732
+ 733
+ 734
+ 735
+ 736
+ 737
+ 738
+ 739
+ 740
+ 741
+ 742
+ 743
+ 744
+ 745
+ 746
+ 747
+ 748
+ 749
+ 750
+ 751
+ 752
+ 753
+ 754
+ 755
+ 756
+ 757
+ 758
+ 759
+ 760
+ 761
+ 762
+ 763
+ 764
+ 765
+ 766
+ 767
+ 768
+ 769
+ 770
+ 771
+ 772
+ 773
+ 774
+ 775
+ 776
+ 777
+ 778
+ 779
+ 780
+ 781
+ 782
+ 783
+ 784
+ 785
+ 786
+ 787
+ 788
+ 789
+ 790
+ 791
+ 792
+ 793
+ 794
+ 795
+ 796
+ 797
+ 798
+ 799
+ 800
+ 801
+ 802
+ 803
+ 804
+ 805
+ 806
+ 807
+ 808
+ 809
+ 810
+ 811
+ 812
+ 813
+ 814
+ 815
+ 816
+ 817
+ 818
+ 819
+ 820
+ 821
+ 822
+ 823
+ 824
+ 825
+ 826
+ 827
+ 828
+ 829
+ 830
+ 831
+ 832
+ 833
+ 834
+ 835
+ 836
+ 837
+ 838
+ 839
+ 840
+ 841
+ 842
+ 843
+ 844
+ 845
+ 846
+ 847
+ 848
+ 849
+ 850
+ 851
+ 852
+ 853
+ 854
+ 855
+ 856
+ 857
+ 858
+ 859
+ 860
+ 861
+ 862
+ 863
+ 864
+ 865
+ 866
+ 867
+ 868
+ 869
+ 870
+ 871
+ 872
+ 873
+ 874
+ 875
+ 876
+ 877
+ 878
+ 879
+ 880
+ 881
+ 882
+ 883
+ 884
+ 885
+ 886
+ 887
+ 888
+ 889
+ 890
+ 891
+ 892
+ 893
+ 894
+ 895
+ 896
+ 897
+ 898
+ 899
+ 900
+ 901
+ 902
+ 903
+ 904
+ 905
+ 906
+ 907
+ 908
+ 909
+ 910
+ 911
+ 912
+ 913
+ 914
+ 915
+ 916
+ 917
+ 918
+ 919
+ 920
+ 921
+ 922
+ 923
+ 924
+ 925
+ 926
+ 927
+ 928
+ 929
+ 930
+ 931
+ 932
+ 933
+ 934
+ 935
+ 936
+ 937
+ 938
+ 939
+ 940
+ 941
+ 942
+ 943
+ 944
+ 945
+ 946
+ 947
+ 948
+ 949
+ 950
+ 951
+ 952
+ 953
+ 954
+ 955
+ 956
+ 957
+ 958
+ 959
+ 960
+ 961
+ 962
+ 963
+ 964
+ 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031
+1032
+1033
+1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
+1193
+1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
+1221
+1222
+1223
+1224
+1225
+1226
+1227
+1228
+1229
+1230
+1231
+1232
+1233
+1234
+1235
+1236
+1237
+1238
+1239
+1240
+1241
+1242
+1243
+1244
+1245
+1246
+1247
+1248
+1249
+1250
+1251
+1252
+1253
+1254
+1255
+1256
+1257
+1258
+1259
+1260
+1261
+1262
+1263
+1264
+1265
+1266
+1267
+1268
+1269
+1270
+1271
+1272
+1273
+1274
+1275
+1276
+1277
+1278
+1279
+1280
+1281
+1282
+1283
+1284
+1285
+1286
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1294
+1295
+1296
+1297
+1298
+1299
+1300
+1301
+1302
+1303
+1304
+1305
+1306
+1307
+1308
+1309
+1310
+1311
+1312
+1313
+1314
+1315
+1316
+1317
+1318
+1319
+1320
+1321
+1322
+1323
+1324
+1325
+1326
+1327
+1328
+1329
+1330
+1331
+1332
+1333
+1334
+1335
+1336
+1337
+1338
+1339
+1340
+1341
+1342
+1343
+1344
+1345
+1346
+1347
+1348
+1349
+1350
+1351
+1352
+1353
+1354
+1355
+1356
+1357
+1358
+1359
+1360
+1361
+1362
+1363
+1364
+1365
+1366
+1367
+1368
+1369
+1370
+1371
+1372
+1373
+1374
+1375
+1376
+1377
+1378
+1379
+1380
+1381
+1382
+1383
+1384
+1385
+1386
+1387
+1388
+1389
+1390
+1391
+1392
+1393
+1394
+1395
+1396
+1397
+1398
+1399
+1400
+1401
+1402
+1403
+1404
+1405
+1406
+1407
+1408
+1409
+1410
+1411
+1412
+1413
+1414
+1415
+1416
+1417
+1418
+1419
+1420
+1421
+1422
+1423
+1424
+1425
+1426
+1427
+1428
+1429
+1430
+1431
+1432
+1433
+1434
+1435
+1436
+1437
+1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
+1450
+1451
+1452
+1453
+1454
+1455
+1456
+1457
+1458
+1459
+1460
+1461
+1462
+1463
+1464
+1465
+1466
+1467
+1468
+1469
+1470
+1471
+1472
+1473
+1474
+1475
+1476
+1477
+1478
+1479
+1480
+1481
+1482
+1483
+1484
+1485
+1486
+1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
+1499
+1500
+1501
+1502
+1503
+1504
+1505
+1506
+1507
+1508
+1509
+1510
+1511
+1512
+1513
+1514
+1515
+1516
+1517
+1518
+1519
+1520
+1521
+1522
+1523
+1524
+1525
+1526
+1527
+1528
+1529
+1530
+1531
+1532
+1533
+1534
+1535
+1536
+1537
+1538
+1539
+1540
+1541
+1542
+1543
+1544
+1545
+1546
+1547
+1548
+1549
+1550
+1551
+1552
+1553
+1554
+1555
+1556
+1557
+1558
+1559
+1560
+1561
+1562
+1563
+1564
+1565
+1566
+1567
+1568
+1569
+1570
+1571
+1572
+1573
+1574
+1575
+1576
+1577
+1578
+1579
+1580
+1581
+1582
+1583
+1584
+1585
+1586
+1587
+1588
+1589
+1590
+1591
+1592
+1593
+1594
+1595
+1596
+1597
+1598
+1599
+1600
+1601
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
+1614
+1615
+1616
+1617
+1618
+1619
+1620
+1621
+1622
+1623
+1624
+1625
+1626
+1627
+1628
+1629
+1630
+1631
+1632
+1633
+1634
+1635
+1636
+1637
+1638
+1639
+1640
+1641
+1642
+1643
+1644
+1645
+1646
+1647
+1648
+1649
+1650
+1651
+1652
+1653
+1654
+1655
+1656
+1657
+1658
+1659
+1660
+1661
+1662
+1663
+1664
+1665
+1666
+1667
+1668
+1669
+1670
+1671
+1672
+1673
+1674
+1675
+1676
+1677
+1678
+1679
+1680
+1681
+1682
+1683
+1684
+1685
+1686
+1687
+1688
+1689
+1690
+1691
+1692
+1693
+1694
+1695
+1696
+1697
+1698
+1699
+1700
+1701
+1702
+1703
+1704
+1705
+1706
+1707
+1708
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
+1742
+1743
+1744
+1745
+1746
+1747
+1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
+1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
+1930
+1931
+1932
+1933
+1934
+1935
+1936
+1937
+1938
+1939
+1940
+1941
+1942
+1943
+1944
+1945
+1946
+1947
+1948
+1949
+1950
+1951
+1952
+1953
+1954
+1955
+1956
+1957
+1958
+1959
+1960
+1961
+1962
+1963
+1964
+1965
+1966
+1967
+1968
+1969
+1970
+1971
+1972
+1973
+1974
+1975
+1976
+1977
+1978
+1979
+1980
+1981
+1982
+1983
+1984
+1985
+1986
+1987
+1988
+1989
+1990
+1991
+1992
+1993
+1994
+1995
+1996
+1997
+1998
+1999
+2000
+2001
+2002
+2003
+2004
+2005
+2006
+2007
+2008
+2009
+2010
+2011
+2012
+2013
+2014
+2015
+2016
+2017
+2018
+2019
+2020
+2021
+2022
+2023
+2024
+2025
+2026
+2027
+2028
+2029
+2030
+2031
+2032
+2033
+2034
+2035
+2036
+2037
+2038
+2039
+2040
+2041
+2042
+2043
+2044
+2045
+2046
+2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
+2070
+2071
+2072
+2073
+2074
+2075
+2076
+2077
+2078
+2079
+2080
+2081
+2082
+2083
+2084
+2085
+2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
+2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
+2131
+2132
+2133
+2134
+2135
+2136
+2137
+2138
+2139
+2140
+2141
+2142
+2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
+2153
+2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
+2177
+2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
+2188
+2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
+2206
+2207
+2208
+2209
+2210
+2211
+2212
+2213
+2214
+2215
+2216
+2217
+2218
+2219
+2220
+2221
+2222
+2223
+2224
+2225
+2226
+2227
+2228
+2229
+2230
+2231
+2232
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
+2244
+2245
+2246
+2247
+2248
+2249
+2250
+2251
+2252
+2253
+2254
+2255
+2256
+2257
+2258
+2259
+2260
+2261
+2262
+2263
+2264
+2265
+2266
+2267
+2268
+2269
+2270
+2271
+2272
+2273
+2274
+2275
+2276
+2277
+2278
+2279
+2280
+2281
+2282
+2283
+2284
+2285
+2286
+2287
+2288
+2289
+2290
+2291
+2292
+2293
+2294
+2295
+2296
+2297
+2298
+2299
+2300
+2301
+2302
+2303
+2304
+2305
+2306
+2307
+2308
+2309
+2310
+2311
+2312
+2313
+2314
+2315
+2316
+2317
+2318
+2319
+2320
+2321
+2322
+2323
+2324
+2325
+2326
+2327
+2328
+2329
+2330
+2331
+2332
+2333
+2334
+2335
+2336
+2337
+2338
+2339
+2340
+2341
+2342
+2343
+2344
+2345
+2346
+2347
+2348
+2349
+2350
+2351
+2352
+2353
+2354
+2355
+2356
+2357
+2358
+2359
+2360
+2361
+2362
+2363
+2364
+2365
+2366
+2367
+2368
+2369
+2370
+2371
+2372
+2373
+2374
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+2396
+2397
+2398
+2399
+2400
+2401
+2402
+2403
+2404
+2405
+2406
+2407
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+2417
+2418
+2419
+2420
+2421
+2422
+2423
+2424
+2425
+2426
+2427
+2428
+2429
+2430
+2431
+2432
+2433
+2434
+2435
+2436
+2437
+2438
+2439
+2440
+2441
+2442
+2443
+2444
+2445
+2446
+2447
+2448
+2449
+2450
+2451
+2452
+2453
+2454
+2455
+2456
+2457
+2458
+2459
+2460
+2461
+2462
+2463
+2464
+2465
+2466
+2467
+2468
+2469
+2470
+2471
+2472
+2473
+2474
+2475
+2476
+2477
+2478
+2479
+2480
+2481
+2482
+2483
+2484
+2485
+2486
+2487
+2488
+2489
+2490
+2491
+2492
+2493
+2494
+2495
+2496
+2497
+2498
+2499
+2500
class TelemetrixUnoR4MinimaAio:
+    """
+    This class exposes and implements the TelemetrixAIO API.
+    It includes the public API methods as well as
+    a set of private methods. This is an asyncio API.
+
+    """
+
+    # noinspection PyPep8,PyPep8
+    def __init__(self, com_port=None,
+                 arduino_instance_id=1, arduino_wait=1,
+                 sleep_tune=0.0001, autostart=True,
+                 loop=None, shutdown_on_exception=True,
+                 close_loop_on_shutdown=True, hard_reset_on_shutdown=True):
+
+        """
+        If you have a single Arduino connected to your computer,
+        then you may accept all the default values.
+
+        Otherwise, specify a unique arduino_instance id for each board in use.
+
+        :param com_port: e.g. COM3 or /dev/ttyACM0.
+
+        :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+
+        :param arduino_wait: Amount of time to wait for an Arduino to
+                             fully reset itself.
+
+        :param sleep_tune: A tuning parameter (typically not changed by user)
+
+        :param autostart: If you wish to call the start method within
+                          your application, then set this to False.
+
+        :param loop: optional user provided event loop
+
+        :param shutdown_on_exception: call shutdown before raising
+                                      a RunTimeError exception, or
+                                      receiving a KeyboardInterrupt exception
+
+        :param close_loop_on_shutdown: stop and close the event loop loop
+                                       when a shutdown is called or a serial
+                                       error occurs
+
+       :param hard_reset_on_shutdown: reset the board on shutdown
+
+        """
+        # check to make sure that Python interpreter is version 3.8.3 or greater
+        python_version = sys.version_info
+        if python_version[0] >= 3:
+            if python_version[1] >= 8:
+                if python_version[2] >= 3:
+                    pass
+            else:
+                raise RuntimeError("ERROR: Python 3.7 or greater is "
+                                   "required for use of this program.")
+
+        # save input parameters
+        self.com_port = com_port
+        self.arduino_instance_id = arduino_instance_id
+        self.arduino_wait = arduino_wait
+        self.sleep_tune = sleep_tune
+        self.autostart = autostart
+        self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+        # set the event loop
+        if loop is None:
+            self.loop = asyncio.get_event_loop()
+        else:
+            self.loop = loop
+
+        self.shutdown_on_exception = shutdown_on_exception
+        self.close_loop_on_shutdown = close_loop_on_shutdown
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        # debug loopback callback method
+        self.loop_back_callback = None
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        self.dht_count = 0
+
+        # serial port in use
+        self.serial_port = None
+
+        # generic asyncio task holder
+        self.the_task = None
+
+        # flag to indicate we are in shutdown mode
+        self.shutdown_flag = False
+
+        self.report_dispatch = {}
+
+        # reported features
+        self.reported_features = 0
+
+        # To add a command to the command dispatch table, append here.
+        self.report_dispatch.update(
+            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+        self.report_dispatch.update(
+            {PrivateConstants.ANALOG_REPORT: self._analog_message})
+        self.report_dispatch.update(
+            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+        self.report_dispatch.update(
+            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+        self.report_dispatch.update(
+            {PrivateConstants.SPI_REPORT: self._spi_report})
+        self.report_dispatch.update(
+            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_CURRENT_POSITION:
+                 self._stepper_current_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUNNING_REPORT:
+                 self._stepper_is_running_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+                 self._stepper_run_complete_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.FEATURES:
+                 self._features_report})
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        self.cs_pins_enabled = []
+
+        # flag to indicate if spi is initialized
+        self.spi_enabled = False
+
+        # flag to indicate if onewire is initialized
+        self.onewire_enabled = False
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        # # stepper motor variables
+        #
+        # # updated when a new motor is added
+        # self.next_stepper_assigned = 0
+        #
+        # # valid list of stepper motor interface types
+        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+        #
+        # # maximum number of steppers supported
+        # self.max_number_of_steppers = 4
+        #
+        # # number of steppers created - not to exceed the maximum
+        # self.number_of_steppers = 0
+        #
+        # # dictionary to hold stepper motor information
+        # self.stepper_info = {'instance': False, 'is_running': None,
+        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+        #                      'distance_to_go_callback': None,
+        #                      'target_position_callback': None,
+        #                      'current_position_callback': None,
+        #                      'is_running_callback': None,
+        #                      'motion_complete_callback': None,
+        #                      'acceleration_callback': None}
+        #
+        # # build a list of stepper motor info items
+        # self.stepper_info_list = []
+        # # a list of dictionaries to hold stepper information
+        # for motor in range(self.max_number_of_steppers):
+        #     self.stepper_info_list.append(self.stepper_info)
+
+        print(f'telemetrix_uno_r4_minima_aio Version:'
+              f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')
+        print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\n')
+
+        if autostart:
+            self.loop.run_until_complete(self.start_aio())
+
+    async def start_aio(self):
+        """
+        This method may be called directly, if the autostart
+        parameter in __init__ is set to false.
+
+        This method instantiates the serial interface and then performs auto pin
+        discovery if using a serial interface, or creates and connects to
+        a TCP/IP enabled device running StandardFirmataWiFi.
+
+        Use this method if you wish to start TelemetrixAIO manually from
+        an asyncio function.
+         """
+
+        if not self.com_port:
+            # user did not specify a com_port
+            try:
+                await self._find_arduino()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+        else:
+            # com_port specified - set com_port and baud rate
+            try:
+                await self._manual_open()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+
+        if self.com_port:
+            print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')
+
+            # no com_port found - raise a runtime exception
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('No Arduino Found or User Aborted Program')
+
+        # get arduino firmware version and print it
+        firmware_version = await self._get_firmware_version()
+        if not firmware_version:
+            print('*** Firmware Version retrieval timed out. ***')
+            print('\nDo you have Arduino connectivity and do you have the ')
+            print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')
+            print('to the correct serial port.\n')
+            print('To see a list of serial ports, type: '
+                  '"list_serial_ports" in your console.')
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError
+        else:
+
+            print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'
+                  f'{firmware_version[3]}.{firmware_version[4]}')
+            # start the command dispatcher loop
+            command = [PrivateConstants.ENABLE_ALL_REPORTS]
+            await self._send_command(command)
+            if not self.loop:
+                self.loop = asyncio.get_event_loop()
+            self.the_task = self.loop.create_task(self._arduino_report_dispatcher())
+
+            # get the features list
+            command = [PrivateConstants.GET_FEATURES]
+            await self._send_command(command)
+            await asyncio.sleep(.5)
+
+            # Have the server reset its data structures
+            command = [PrivateConstants.RESET]
+            await self._send_command(command)
+
+    async def get_event_loop(self):
+        """
+        Return the currently active asyncio event loop
+
+        :return: Active event loop
+
+        """
+        return self.loop
+
+    async def _find_arduino(self):
+        """
+        This method will search all potential serial ports for an Arduino
+        containing a sketch that has a matching arduino_instance_id as
+        specified in the input parameters of this class.
+
+        This is used explicitly with the FirmataExpress sketch.
+        """
+
+        # a list of serial ports to be checked
+        serial_ports = []
+
+        print('Opening all potential serial ports...')
+        the_ports_list = list_ports.comports()
+        for port in the_ports_list:
+            if port.pid is None:
+                continue
+            print('\nChecking {}'.format(port.device))
+            try:
+                self.serial_port = TelemetrixAioSerial(port.device, 115200,
+                                                       telemetrix_aio_instance=self,
+                                                       close_loop_on_error=self.close_loop_on_shutdown)
+            except SerialException:
+                continue
+            # create a list of serial ports that we opened
+            serial_ports.append(self.serial_port)
+
+            # display to the user
+            print('\t' + port.device)
+
+            # clear out any possible data in the input buffer
+            await self.serial_port.reset_input_buffer()
+
+        # wait for arduino to reset
+        print('\nWaiting {} seconds(arduino_wait) for Arduino devices to '
+              'reset...'.format(self.arduino_wait))
+        await asyncio.sleep(self.arduino_wait)
+
+        print('\nSearching for an Arduino configured with an arduino_instance = ',
+              self.arduino_instance_id)
+
+        for serial_port in serial_ports:
+            self.serial_port = serial_port
+
+            command = [PrivateConstants.ARE_U_THERE]
+            await self._send_command(command)
+            # provide time for the reply
+            await asyncio.sleep(.1)
+
+            i_am_here = await self.serial_port.read(3)
+
+            if not i_am_here:
+                continue
+
+            # got an I am here message - is it the correct ID?
+            if i_am_here[2] == self.arduino_instance_id:
+                self.com_port = serial_port.com_port
+                return
+
+    async def _manual_open(self):
+        """
+        Com port was specified by the user - try to open up that port
+
+        """
+        # if port is not found, a serial exception will be thrown
+        print('Opening {} ...'.format(self.com_port))
+        self.serial_port = TelemetrixAioSerial(self.com_port, 115200,
+                                               telemetrix_aio_instance=self,
+                                               close_loop_on_error=self.close_loop_on_shutdown)
+
+        print('Waiting {} seconds for the Arduino To Reset.'
+              .format(self.arduino_wait))
+        await asyncio.sleep(self.arduino_wait)
+        command = [PrivateConstants.ARE_U_THERE]
+        await self._send_command(command)
+        # provide time for the reply
+        await asyncio.sleep(.1)
+
+        print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')
+        i_am_here = await self.serial_port.read(3)
+
+        if not i_am_here:
+            print(f'ERROR: correct arduino_instance_id not found')
+
+        print('Correct arduino_instance_id found')
+
+    async def _get_firmware_version(self):
+        """
+        This method retrieves the Arduino4Telemetrix firmware version
+
+        :returns: Firmata firmware version
+        """
+        command = [PrivateConstants.GET_FIRMWARE_VERSION]
+        await self._send_command(command)
+        # provide time for the reply
+        await asyncio.sleep(.1)
+        firmware_version = await self.serial_port.read(5)
+
+        return firmware_version
+
+    async def analog_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (maximum 16 bits)
+
+        """
+        value_msb = value >> 8
+        value_lsb = value & 0xff
+        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+        await self._send_command(command)
+
+    async def digital_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (1 or 0)
+
+        """
+        command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+        await self._send_command(command)
+
+    async def i2c_read(self, address, register, number_of_bytes,
+                       callback, i2c_port=0,
+                       write_register=True):
+        """
+        Read the specified number of bytes from the specified register for
+        the i2c device.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command
+
+        :param i2c_port: select the default port (0) or secondary port (1)
+
+        :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('i2c_read: A Callback must be specified')
+
+        await self._i2c_read_request(address, register, number_of_bytes,
+                                     callback=callback, i2c_port=i2c_port,
+                                     write_register=write_register)
+
+    async def i2c_read_restart_transmission(self, address, register,
+                                            number_of_bytes,
+                                            callback, i2c_port=0,
+                                            write_register=True):
+        """
+        Read the specified number of bytes from the specified register for
+        the i2c device. This restarts the transmission after the read. It is
+        required for some i2c devices such as the MMA8452Q accelerometer.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                                    selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command
+
+        :param i2c_port: select the default port (0) or secondary port (1)
+
+        :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'i2c_read_restart_transmission: A Callback must be specified')
+
+        await self._i2c_read_request(address, register, number_of_bytes,
+                                     stop_transmission=False,
+                                     callback=callback, i2c_port=i2c_port,
+                                     write_register=write_register)
+
+    async def _i2c_read_request(self, address, register, number_of_bytes,
+                                stop_transmission=True, callback=None,
+                                i2c_port=0, write_register=True):
+        """
+        This method requests the read of an i2c device. Results are retrieved
+        via callback.
+
+        :param address: i2c device address
+
+        :param register: register number (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes expected to be returned
+
+        :param stop_transmission: stop transmission after read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command.
+
+       :param i2c_port: select the default port (0) or secondary port (1)
+
+       :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('I2C Read: A callback function must be specified.')
+
+        if not i2c_port:
+            self.i2c_callback = callback
+        else:
+            self.i2c_callback2 = callback
+
+        if not register:
+            register = 0
+
+        if write_register:
+            write_register = 1
+        else:
+            write_register = 0
+
+        # message contains:
+        # 1. address
+        # 2. register
+        # 3. number of bytes
+        # 4. restart_transmission - True or False
+        # 5. i2c port
+        # 6. suppress write flag
+
+        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,
+                   stop_transmission, i2c_port, write_register]
+        await self._send_command(command)
+
+    async def i2c_write(self, address, args, i2c_port=0):
+        """
+        Write data to an i2c device.
+
+        :param address: i2c device address
+
+        :param i2c_port: 0= port 1, 1 = port 2
+
+        :param args: A variable number of bytes to be sent to the device
+                     passed in as a list
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+        for item in args:
+            command.append(item)
+
+        await self._send_command(command)
+
+    async def loop_back(self, start_character, callback):
+        """
+        This is a debugging method to send a character to the
+        Arduino device, and have the device loop it back.
+
+        :param start_character: The character to loop back. It should be
+                                an integer.
+
+        :param callback: Looped back character will appear in the callback method
+
+        """
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('loop_back: A callback function must be specified.')
+        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+        self.loop_back_callback = callback
+        await self._send_command(command)
+
+    async def set_analog_scan_interval(self, interval):
+        """
+        Set the analog scanning interval.
+
+        :param interval: value of 0 - 255 - milliseconds
+        """
+
+        if 0 <= interval <= 255:
+            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('Analog interval must be between 0 and 255')
+
+    async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+        """
+        Set a pin as an analog input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        :param differential: difference in previous to current value before
+                             report will be generated
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for analog input pins = 3
+
+        """
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'set_pin_mode_analog_input: A callback function must be specified.')
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,
+                                 differential, callback=callback)
+
+    async def set_pin_mode_analog_output(self, pin_number):
+        """
+
+        Set a pin as a pwm (analog output) pin.
+
+        :param pin_number:arduino pin number
+
+        """
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                                 callback=None)
+
+    async def set_pin_mode_digital_input(self, pin_number, callback):
+        """
+        Set a pin as a digital input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,
+                                 callback=callback)
+
+    async def set_pin_mode_digital_input_pullup(self, pin_number, callback):
+        """
+        Set a pin as a digital input with pullup enabled.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'set_pin_mode_digital_input_pullup: A callback function must be specified.')
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                                 differential=0, callback=callback)
+
+    async def set_pin_mode_digital_output(self, pin_number):
+        """
+        Set a pin as a digital output pin.
+
+        :param pin_number: arduino pin number
+        """
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                                 callback=None)
+
+    # noinspection PyIncorrectDocstring
+    async def set_pin_mode_i2c(self, i2c_port=0):
+        """
+        Establish the standard Arduino i2c pins for i2c utilization.
+
+        :param i2c_port: 0 = i2c1, 1 = i2c2
+
+        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+               2. Callbacks are set within the individual i2c read methods of this
+              API.
+
+              See i2c_read, or i2c_read_restart_transmission.
+
+        """
+        # test for i2c port 2
+        if i2c_port:
+            # if not previously activated set it to activated
+            # and the send a begin message for this port
+            if not self.i2c_2_active:
+                self.i2c_2_active = True
+            else:
+                return
+        # port 1
+        else:
+            if not self.i2c_1_active:
+                self.i2c_1_active = True
+            else:
+                return
+
+        command = [PrivateConstants.I2C_BEGIN, i2c_port]
+        await self._send_command(command)
+
+    async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+        """
+
+        :param pin: connection pin
+
+        :param callback: callback function
+
+        :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+        Temperature,
+        Time]
+
+        """
+        if self.reported_features & PrivateConstants.DHT_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+            if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+                self.dht_callbacks[pin] = callback
+                self.dht_count += 1
+
+                if dht_type != 22 and dht_type != 11:
+                    dht_type = 22
+
+                command = [PrivateConstants.DHT_NEW, pin, dht_type]
+                await self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+    async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+        """
+
+        Attach a pin to a servo motor
+
+        :param pin_number: pin
+
+        :param min_pulse: minimum pulse width
+
+        :param max_pulse: maximum pulse width
+
+        """
+        if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+            minv = (min_pulse).to_bytes(2, byteorder="big")
+            maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+            command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                       minv[0], minv[1], maxv[0], maxv[1]]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+    async def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                                 callback):
+        """
+
+        :param trigger_pin:
+
+        :param echo_pin:
+
+        :param callback:  callback
+
+        """
+        if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+                self.sonar_callbacks[trigger_pin] = callback
+                self.sonar_count += 1
+
+                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+                await self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+    async def set_pin_mode_spi(self, chip_select_list=None):
+        """
+        Specify the list of chip select pins.
+
+        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+        Chip Select is any digital output capable pin.
+
+        :param chip_select_list: this is a list of pins to be used for chip select.
+                           The pins will be configured as output, and set to high
+                           ready to be used for chip select.
+                           NOTE: You must specify the chips select pins here!
+
+
+        command message: [command, number of cs pins, [cs pins...]]
+        """
+        if self.reported_features & PrivateConstants.SPI_FEATURE:
+
+            if type(chip_select_list) != list:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('chip_select_list must be in the form of a list')
+            if not chip_select_list:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('Chip select pins were not specified')
+
+            self.spi_enabled = True
+
+            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+            for pin in chip_select_list:
+                command.append(pin)
+                self.cs_pins_enabled.append(pin)
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+    # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,
+    #                          pin4=5, enable=True):
+    #     """
+    #     Stepper motor support is implemented as a proxy for the
+    #     the AccelStepper library for the Arduino.
+    #
+    #     This feature is compatible with the TB6600 Motor Driver
+    #
+    #     Note: It may not work for other driver types!
+    #
+    #     https://github.com/waspinator/AccelStepper
+    #
+    #     Instantiate a stepper motor.
+    #
+    #     Initialize the interface and pins for a stepper motor.
+    #
+    #     :param interface: Motor Interface Type:
+    #
+    #             1 = Stepper Driver, 2 driver pins required
+    #
+    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required
+    #
+    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins
+    #                 required
+    #
+    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required
+    #
+    #     :param pin1: Arduino digital pin number for motor pin 1
+    #
+    #     :param pin2: Arduino digital pin number for motor pin 2
+    #
+    #     :param pin3: Arduino digital pin number for motor pin 3
+    #
+    #     :param pin4: Arduino digital pin number for motor pin 4
+    #
+    #     :param enable: If this is true, the output pins at construction time.
+    #
+    #     :return: Motor Reference number
+    #     """
+    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:
+    #
+    #         if self.number_of_steppers == self.max_number_of_steppers:
+    #             if self.shutdown_on_exception:
+    #                 await self.shutdown()
+    #             raise RuntimeError('Maximum number of steppers has already been assigned')
+    #
+    #         if interface not in self.valid_stepper_interfaces:
+    #             if self.shutdown_on_exception:
+    #                 await self.shutdown()
+    #             raise RuntimeError('Invalid stepper interface')
+    #
+    #         self.number_of_steppers += 1
+    #
+    #         motor_id = self.next_stepper_assigned
+    #         self.next_stepper_assigned += 1
+    #         self.stepper_info_list[motor_id]['instance'] = True
+    #
+    #         # build message and send message to server
+    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,
+    #                    pin2, pin3, pin4, enable]
+    #         await self._send_command(command)
+    #
+    #         # return motor id
+    #         return motor_id
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')
+
+    async def sonar_disable(self):
+        """
+        Disable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_DISABLE]
+        await self._send_command(command)
+
+    async def sonar_enable(self):
+        """
+        Enable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_ENABLE]
+        await self._send_command(command)
+
+    async def spi_cs_control(self, chip_select_pin, select):
+        """
+        Control an SPI chip select line
+        :param chip_select_pin: pin connected to CS
+
+        :param select: 0=select, 1=deselect
+        """
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+        if chip_select_pin not in self.cs_pins_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+        await self._send_command(command)
+
+    async def spi_read_blocking(self, chip_select, register_selection,
+                                number_of_bytes_to_read,
+                          call_back=None):
+        """
+        Read the specified number of bytes from the specified SPI port and
+        call the callback function with the reported data.
+
+        :param chip_select: chip select pin
+
+        :param register_selection: Register to be selected for read.
+
+        :param number_of_bytes_to_read: Number of bytes to read
+
+        :param call_back: Required callback function to report spi data as a
+                   result of read command
+
+
+        callback returns a data list:
+            [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+             data bytes, time-stamp]
+        SPI_READ_REPORT = 13
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+        if not call_back:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+        self.spi_callback = call_back
+
+        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+                   number_of_bytes_to_read,
+                   register_selection]
+
+        await self._send_command(command)
+
+    async def spi_set_format(self, clock_divisor, bit_order, data_mode):
+        """
+        Configure how the SPI serializes and de-serializes data on the wire.
+
+        See Arduino SPI reference materials for details.
+
+        :param clock_divisor: 1 - 255
+
+        :param bit_order:
+
+                            LSBFIRST = 0
+
+                            MSBFIRST = 1 (default)
+
+        :param data_mode:
+
+                            SPI_MODE0 = 0x00 (default)
+
+                            SPI_MODE1  = 1
+
+                            SPI_MODE2 = 2
+
+                            SPI_MODE3 = 3
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+        if not 0 < clock_divisor <= 255:
+            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+        if bit_order not in [0, 1]:
+            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+        if data_mode not in [0, 1, 2, 3]:
+            raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+                   data_mode]
+        await self._send_command(command)
+
+    async def spi_write_blocking(self, chip_select, bytes_to_write):
+        """
+        Write a list of bytes to the SPI device.
+
+        :param chip_select: chip select pin
+
+        :param bytes_to_write: A list of bytes to write. This must
+                                be in the form of a list.
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+        if type(bytes_to_write) is not list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+        for data in bytes_to_write:
+            command.append(data)
+
+        await self._send_command(command)
+
+    # async def set_pin_mode_one_wire(self, pin):
+    #     """
+    #     Initialize the one wire serial bus.
+    #
+    #     :param pin: Data pin connected to the OneWire device
+    #     """
+    #     self.onewire_enabled = True
+    #     command = [PrivateConstants.ONE_WIRE_INIT, pin]
+    #     await self._send_command(command)
+    #
+    # async def onewire_reset(self, callback=None):
+    #     """
+    #     Reset the onewire device
+    #
+    #     :param callback: required  function to report reset result
+    #
+    #     callback returns a list:
+    #     [ReportType = 14, Report Subtype = 25, reset result byte,
+    #                     timestamp]
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_reset: A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_RESET]
+    #     await self._send_command(command)
+    #
+    # async def onewire_select(self, device_address):
+    #     """
+    #     Select a device based on its address
+    #     :param device_address: A bytearray of 8 bytes
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')
+    #
+    #     if type(device_address) is not list:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #
+    #     if len(device_address) != 8:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #     command = [PrivateConstants.ONE_WIRE_SELECT]
+    #     for data in device_address:
+    #         command.append(data)
+    #     await self._send_command(command)
+    #
+    # async def onewire_skip(self):
+    #     """
+    #     Skip the device selection. This only works if you have a
+    #     single device, but you can avoid searching and use this to
+    #     immediately access your device.
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SKIP]
+    #     await self._send_command(command)
+    #
+    # async def onewire_write(self, data, power=0):
+    #     """
+    #     Write a byte to the onewire device. If 'power' is one
+    #     then the wire is held high at the end for
+    #     parasitically powered devices. You
+    #     are responsible for eventually de-powering it by calling
+    #     another read or write.
+    #
+    #     :param data: byte to write.
+    #     :param power: power control (see above)
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')
+    #     if 0 < data < 255:
+    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]
+    #         await self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_write: Data must be no larger than 255')
+    #
+    # async def onewire_read(self, callback=None):
+    #     """
+    #     Read a byte from the onewire device
+    #     :param callback: required  function to report onewire data as a
+    #                result of read command
+    #
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_READ]
+    #     await self._send_command(command)
+    #
+    # async def onewire_reset_search(self):
+    #     """
+    #     Begin a new search. The next use of search will begin at the first device
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '
+    #                            f'enabled.')
+    #     else:
+    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]
+    #         await self._send_command(command)
+    #
+    # async def onewire_search(self, callback=None):
+    #     """
+    #     Search for the next device. The device address will returned in the callback.
+    #     If a device is found, the 8 byte address is contained in the callback.
+    #     If no more devices are found, the address returned contains all elements set
+    #     to 0xff.
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SEARCH]
+    #     await self._send_command(command)
+    #
+    # async def onewire_crc8(self, address_list, callback=None):
+    #     """
+    #     Compute a CRC check on an array of data.
+    #     :param address_list:
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_crc8 A Callback must be specified')
+    #
+    #     if type(address_list) is not list:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_crc8: address list must be a list.')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     address_length = len(address_list)
+    #
+    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]
+    #
+    #     for data in address_list:
+    #         command.append(data)
+    #
+    #     await self._send_command(command)
+
+    async def _set_pin_mode(self, pin_number, pin_state, differential, callback):
+        """
+        A private method to set the various pin modes.
+
+        :param pin_number: arduino pin number
+
+        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use
+                          servo_config()
+                          For DHT   use: set_pin_mode_dht
+
+        :param differential: for analog inputs - threshold
+                             value to be achieved for report to
+                             be generated
+
+        :param callback: A reference to an async call back function to be
+                         called when pin data value changes
+
+        """
+        if not callback and pin_state != PrivateConstants.AT_OUTPUT:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('_set_pin_mode: A Callback must be specified')
+        else:
+            if pin_state == PrivateConstants.AT_INPUT:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_INPUT, 1]
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_INPUT_PULLUP, 1]
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_ANALOG:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_ANALOG,
+                           differential >> 8, differential & 0xff, 1]
+                self.analog_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_OUTPUT:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_OUTPUT, 1]
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('Unknown pin state')
+
+        if command:
+            await self._send_command(command)
+
+        await asyncio.sleep(.05)
+
+    async def servo_detach(self, pin_number):
+        """
+        Detach a servo for reuse
+        :param pin_number: attached pin
+        """
+        command = [PrivateConstants.SERVO_DETACH, pin_number]
+        await self._send_command(command)
+
+    async def servo_write(self, pin_number, angle):
+        """
+
+        Set a servo attached to a pin to a given angle.
+
+        :param pin_number: pin
+
+        :param angle: angle (0-180)
+
+        """
+        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+        await self._send_command(command)
+
+    # async def stepper_move_to(self, motor_id, position):
+    #     """
+    #     Set an absolution target position. If position is positive, the movement is
+    #     clockwise, else it is counter-clockwise.
+    #
+    #     The run() function (below) will try to move the motor (at most one step per call)
+    #     from the current position to the target position set by the most
+    #     recent call to this function. Caution: moveTo() also recalculates the
+    #     speed for the next step.
+    #     If you are trying to use constant speed movements, you should call setSpeed()
+    #     after calling moveTo().
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param position: target position. Maximum value is 32 bits.
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')
+    #
+    #     if position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(position)
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_move(self, motor_id, relative_position):
+    #     """
+    #     Set the target position relative to the current position.
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param relative_position: The desired position relative to the current
+    #                               position. Negative is anticlockwise from
+    #                               the current position. Maximum value is 32 bits.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_move: Invalid motor_id.')
+    #
+    #     if relative_position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(relative_position)
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     await self._send_command(command)
+    #
+    # async def stepper_run(self, motor_id, completion_callback=None):
+    #     """
+    #     This method steps the selected motor based on the current speed.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run: A motion complete callback must be '
+    #                            'specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_run_speed(self, motor_id):
+    #     """
+    #     This method steps the selected motor based at a constant speed as set by the most
+    #     recent call to stepper_set_max_speed(). The motor will run continuously.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_max_speed(self, motor_id, max_speed):
+    #     """
+    #     Sets the maximum permitted speed. The stepper_run() function will accelerate
+    #     up to the speed set by this function.
+    #
+    #     Caution: the maximum speed achievable depends on your processor and clock speed.
+    #     The default maxSpeed is 1 step per second.
+    #
+    #      Caution: Speeds that exceed the maximum speed supported by the processor may
+    #               result in non-linear accelerations and decelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param max_speed: 1 - 1000
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')
+    #
+    #     if not 1 < max_speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')
+    #
+    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed
+    #     max_speed_msb = (max_speed & 0xff00) >> 8
+    #     max_speed_lsb = max_speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,
+    #                max_speed_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_max_speed(self, motor_id):
+    #     """
+    #     Returns the maximum speed configured for this stepper
+    #     that was previously set by stepper_set_max_speed()
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :return: The currently configured maximum speed.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['max_speed']
+    #
+    # async def stepper_set_acceleration(self, motor_id, acceleration):
+    #     """
+    #     Sets the acceleration/deceleration rate.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param acceleration: The desired acceleration in steps per second
+    #                          per second. Must be > 0.0. This is an
+    #                          expensive call since it requires a square
+    #                          root to be calculated on the server.
+    #                          Dont call more often than needed.
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')
+    #
+    #     if not 1 < acceleration <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration
+    #
+    #     max_accel_msb = acceleration >> 8
+    #     max_accel_lsb = acceleration & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,
+    #                max_accel_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_speed(self, motor_id, speed):
+    #     """
+    #     Sets the desired constant speed for use with stepper_run_speed().
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param speed: 0 - 1000 The desired constant speed in steps per
+    #                   second. Positive is clockwise. Speeds of more than 1000 steps per
+    #                   second are unreliable. Speed accuracy depends on the Arduino
+    #                   crystal. Jitter depends on how frequently you call the
+    #                   stepper_run_speed() method.
+    #                   The speed will be limited by the current value of
+    #                   stepper_set_max_speed().
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')
+    #
+    #     if not 0 < speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['speed'] = speed
+    #
+    #     speed_msb = speed >> 8
+    #     speed_lsb = speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_speed(self, motor_id):
+    #     """
+    #     Returns the  most recently set speed.
+    #     that was previously set by stepper_set_speed();
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['speed']
+    #
+    # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):
+    #     """
+    #     Request the distance from the current position to the target position
+    #     from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param distance_to_go_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]
+    #
+    #     A positive distance is clockwise from the current position.
+    #
+    #     """
+    #     if not distance_to_go_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')
+    #     self.stepper_info_list[motor_id][
+    #         'distance_to_go_callback'] = distance_to_go_callback
+    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_target_position(self, motor_id, target_callback):
+    #     """
+    #     Request the most recently set target position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param target_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #
+    #     """
+    #     if not target_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_target_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id][
+    #         'target_position_callback'] = target_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_current_position(self, motor_id, current_position_callback):
+    #     """
+    #     Request the current motor position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param current_position_callback: required callback function to receive report
+    #
+    #     :return: The current motor position returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #     """
+    #     if not current_position_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_current_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_current_position(self, motor_id, position):
+    #     """
+    #     Resets the current position of the motor, so that wherever the motor
+    #     happens to be right now is considered to be the new 0 position. Useful
+    #     for setting a zero position on a stepper after an initial hardware
+    #     positioning move.
+    #
+    #     Has the side effect of setting the current motor speed to 0.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     :param position: Position in steps. This is a 32 bit value
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')
+    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     await self._send_command(command)
+    #
+    # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):
+    #     """
+    #     Runs the motor at the currently selected speed until the target position is
+    #     reached.
+    #
+    #     Does not implement accelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '
+    #                            'callback must be '
+    #                            'specified.')
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_stop(self, motor_id):
+    #     """
+    #     Sets a new target position that causes the stepper
+    #     to stop as quickly as possible, using the current speed and
+    #     acceleration parameters.
+    #
+    #     :param motor_id:  0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_stop: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_STOP, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_disable_outputs(self, motor_id):
+    #     """
+    #     Disable motor pin outputs by setting them all LOW.
+    #
+    #     Depending on the design of your electronics this may turn off
+    #     the power to the motor coils, saving power.
+    #
+    #     This is useful to support Arduino low power modes: disable the outputs
+    #     during sleep and then re-enable with enableOutputs() before stepping
+    #     again.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and clears
+    #     the pin to disabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_enable_outputs(self, motor_id):
+    #     """
+    #     Enable motor pin outputs by setting the motor pins to OUTPUT
+    #     mode.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and sets
+    #     the pin to enabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):
+    #     """
+    #     Sets the minimum pulse width allowed by the stepper driver.
+    #
+    #     The minimum practical pulse width is approximately 20 microseconds.
+    #
+    #     Times less than 20 microseconds will usually result in 20 microseconds or so.
+    #
+    #     :param motor_id: 0 -3
+    #
+    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')
+    #
+    #     if not 0 < minimum_width <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '
+    #                            '0-0xffff.')
+    #
+    #     width_msb = minimum_width >> 8
+    #     width_lsb = minimum_width & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,
+    #                width_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_enable_pin(self, motor_id, pin=0xff):
+    #     """
+    #     Sets the enable pin number for stepper drivers.
+    #     0xFF indicates unused (default).
+    #
+    #     Otherwise, if a pin is set, the pin will be turned on when
+    #     enableOutputs() is called and switched off when disableOutputs()
+    #     is called.
+    #
+    #     :param motor_id: 0 - 4
+    #     :param pin: 0-0xff
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')
+    #
+    #     if not 0 < pin <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '
+    #                            '0-0xff.')
+    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,
+    #                                 enable=False):
+    #     """
+    #     Sets the inversion for stepper driver pins.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param direction: True=inverted or False
+    #
+    #     :param step: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,
+    #                step, enable]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,
+    #                                   pin2_invert=False,
+    #                                 pin3_invert=False, pin4_invert=False, enable=False):
+    #     """
+    #     Sets the inversion for 2, 3 and 4 wire stepper pins
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param pin1_invert: True=inverted or False
+    #
+    #     :param pin2_invert: True=inverted or False
+    #
+    #     :param pin3_invert: True=inverted or False
+    #
+    #     :param pin4_invert: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,
+    #                pin2_invert, pin3_invert, pin4_invert, enable]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_is_running(self, motor_id, callback):
+    #     """
+    #     Checks to see if the motor is currently running to a target.
+    #
+    #     Callback return True if the speed is not zero or not at the target position.
+    #
+    #     :param motor_id: 0-4
+    #
+    #     :param callback: required callback function to receive report
+    #
+    #     :return: The current running state returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]
+    #     """
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_is_running: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback
+    #
+    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]
+    #     await self._send_command(command)
+
+    async def shutdown(self):
+        """
+        This method attempts an orderly shutdown
+        If any exceptions are thrown, they are ignored.
+
+        """
+        self.shutdown_flag = True
+
+        if self.hard_reset_on_shutdown:
+            await self.r4_hard_reset()
+        # stop all reporting - both analog and digital
+        else:
+            try:
+                command = [PrivateConstants.STOP_ALL_REPORTS]
+                await self._send_command(command)
+
+                await asyncio.sleep(.5)
+                await self.serial_port.reset_input_buffer()
+                await self.serial_port.close()
+                if self.close_loop_on_shutdown:
+                    self.loop.stop()
+            except (RuntimeError, SerialException):
+                pass
+
+    async def r4_hard_reset(self):
+        """
+        Place the r4 into hard reset
+        """
+        command = [PrivateConstants.BOARD_HARD_RESET, 1]
+        await self._send_command(command)
+
+    async def disable_all_reporting(self):
+        """
+        Disable reporting for all digital and analog input pins
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DISABLE_ALL, 0]
+        await self._send_command(command)
+
+    async def disable_analog_reporting(self, pin):
+        """
+        Disables analog reporting for a single analog pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+        await self._send_command(command)
+
+    async def disable_digital_reporting(self, pin):
+        """
+        Disables digital reporting for a single digital pin
+
+
+        :param pin: pin number
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+        await self._send_command(command)
+
+    async def enable_analog_reporting(self, pin):
+        """
+        Enables analog reporting for the specified pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+        await self._send_command(command)
+
+    async def enable_digital_reporting(self, pin):
+        """
+        Enable reporting on the specified digital pin.
+
+        :param pin: Pin number.
+        """
+
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+        await self._send_command(command)
+
+    async def _arduino_report_dispatcher(self):
+        """
+        This is a private method.
+        It continually accepts and interprets data coming from Telemetrix4Arduino,and then
+        dispatches the correct handler to process the data.
+
+        It first receives the length of the packet, and then reads in the rest of the
+        packet. A packet consists of a length, report identifier and then the report data.
+        Using the report identifier, the report handler is fetched from report_dispatch.
+
+        :returns: This method never returns
+        """
+
+        while True:
+            if self.shutdown_flag:
+                break
+            try:
+                packet_length = await self.serial_port.read()
+            except TypeError:
+                continue
+
+            # get the rest of the packet
+            packet = await self.serial_port.read(packet_length)
+
+            report = packet[0]
+            # print(report)
+            # handle all other messages by looking them up in the
+            # command dictionary
+
+            await self.report_dispatch[report](packet[1:])
+            await asyncio.sleep(self.sleep_tune)
+
+    '''
+    Report message handlers
+    '''
+
+    async def _report_loop_data(self, data):
+        """
+        Print data that was looped back
+
+        :param data: byte of loop back data
+        """
+        if self.loop_back_callback:
+            await self.loop_back_callback(data)
+
+    async def _spi_report(self, report):
+
+        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]
+
+        cb_list.append(time.time())
+
+        await self.spi_callback(cb_list)
+
+    async def _onewire_report(self, report):
+        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]
+        cb_list.append(time.time())
+        await self.onewire_callback(cb_list)
+
+    async def _report_debug_data(self, data):
+        """
+        Print debug data sent from Arduino
+
+        :param data: data[0] is a byte followed by 2
+                     bytes that comprise an integer
+        """
+        value = (data[1] << 8) + data[2]
+        print(f'DEBUG ID: {data[0]} Value: {value}')
+
+    async def _analog_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for analog messages.
+
+        :param data: message data
+
+        """
+        pin = data[0]
+        value = (data[1] << 8) + data[2]
+
+        time_stamp = time.time()
+
+        # append pin number, pin value, and pin type to return value and return as a list
+        message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]
+
+        await self.analog_callbacks[pin](message)
+
+    async def _dht_report(self, data):
+        """
+        This is a private message handler for dht reports
+
+        :param data:            data[0] = report error return
+                                    No Errors = 0
+
+                                    Checksum Error = 1
+
+                                    Timeout Error = 2
+
+                                    Invalid Value = 999
+
+                                data[1] = pin number
+
+                                data[2] = dht type 11 or 22
+
+                                data[3] = humidity positivity flag
+
+                                data[4] = temperature positivity value
+
+                                data[5] = humidity integer
+
+                                data[6] = humidity fractional value
+
+                                data[7] = temperature integer
+
+                                data[8] = temperature fractional value
+        """
+        if data[0]:  # DHT_ERROR
+            # error report
+            # data[0] = report sub type, data[1] = pin, data[2] = error message
+            if self.dht_callbacks[data[1]]:
+                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time
+                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                           time.time()]
+                await self.dht_callbacks[data[1]](message)
+        else:
+            # got valid data DHT_DATA
+            f_humidity = float(data[5] + data[6] / 100)
+            if data[3]:
+                f_humidity *= -1.0
+            f_temperature = float(data[7] + data[8] / 100)
+            if data[4]:
+                f_temperature *= -1.0
+            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                       f_humidity, f_temperature, time.time()]
+
+            await self.dht_callbacks[data[1]](message)
+
+    async def _digital_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for Digital Messages.
+
+        :param data: digital message
+
+        """
+        pin = data[0]
+        value = data[1]
+
+        time_stamp = time.time()
+        if self.digital_callbacks[pin]:
+            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]
+            await self.digital_callbacks[pin](message)
+
+    async def _servo_unavailable(self, report):
+        """
+        Message if no servos are available for use.
+
+        :param report: pin number
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')
+
+    async def _i2c_read_report(self, data):
+        """
+        Execute callback for i2c reads.
+
+        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]
+        """
+
+        # we receive [# data bytes, address, register, data bytes]
+        # number of bytes of data returned
+
+        # data[0] = number of bytes
+        # data[1] = i2c_port
+        # data[2] = number of bytes returned
+        # data[3] = address
+        # data[4] = register
+        # data[5] ... all the data bytes
+
+        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]
+        cb_list.append(time.time())
+
+        if cb_list[1]:
+            await self.i2c_callback2(cb_list)
+        else:
+            await self.i2c_callback(cb_list)
+
+    async def _i2c_too_few(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    async def _i2c_too_many(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    async def _sonar_distance_report(self, report):
+        """
+
+        :param report: data[0] = trigger pin, data[1] and data[2] = distance
+
+        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+        """
+
+        # get callback from pin number
+        cb = self.sonar_callbacks[report[0]]
+
+        # build report data
+        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],
+                   ((report[1] << 8) + report[2]), time.time()]
+
+        await cb(cb_list)
+
+    async def _stepper_distance_to_go_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper distance to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,
+    #                              data[3] = steps bytes 2, data[4] = steps LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id
+    #                              steps, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     steps = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+
+    async def _stepper_target_position_report(self, report):
+        return  # for now
+
+    #     """
+    #     Report stepper target position to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = target position MSB,
+    #                    data[2] = target position byte MSB+1
+    #                    data[3] = target position byte MSB+2
+    #                    data[4] = target position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id
+    #                              target_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['target_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     target = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     target_position = int.from_bytes(target, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+    async def _stepper_current_position_report(self, report):
+        return  # for now
+
+    #     """
+    #     Report stepper current position.
+    #
+    #     :param report: data[0] = motor_id, data[1] = current position MSB,
+    #                    data[2] = current position byte MSB+1
+    #                    data[3] = current position byte MSB+2
+    #                    data[4] = current position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id
+    #                              current_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['current_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     position = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     current_position = int.from_bytes(position, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+    async def _stepper_is_running_report(self, report):
+        return  # for now
+
+    #     """
+    #     Report if the motor is currently running
+    #
+    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.
+    #
+    #     callback report format: [18, motor_id,
+    #                              running_state, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['is_running_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]
+    #
+    #     await cb(cb_list)
+    #
+    async def _stepper_run_complete_report(self, report):
+        return  # for now
+
+    #     """
+    #     The motor completed it motion
+    #
+    #     :param report: data[0] = motor_id
+    #
+    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,
+    #                              time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+
+    async def _features_report(self, report):
+        self.reported_features = report[0]
+
+    async def _send_command(self, command):
+        """
+        This is a private utility method.
+
+
+        :param command:  command data in the form of a list
+
+        :returns: number of bytes sent
+        """
+        # the length of the list is added at the head
+        command.insert(0, len(command))
+        # print(command)
+        send_message = bytes(command)
+
+        await self.serial_port.write(send_message)
+
+
+ + + +
+ + + + + + + + + + +
+ + + +

+__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True) + +

+ + +
+ +

If you have a single Arduino connected to your computer, + then you may accept all the default values.

+

Otherwise, specify a unique arduino_instance id for each board in use.

+

:param com_port: e.g. COM3 or /dev/ttyACM0.

+

:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch

+

:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.

+

:param sleep_tune: A tuning parameter (typically not changed by user)

+

:param autostart: If you wish to call the start method within + your application, then set this to False.

+

:param loop: optional user provided event loop

+

:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception

+

:param close_loop_on_shutdown: stop and close the event loop loop + when a shutdown is called or a serial + error occurs

+

:param hard_reset_on_shutdown: reset the board on shutdown

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
def __init__(self, com_port=None,
+             arduino_instance_id=1, arduino_wait=1,
+             sleep_tune=0.0001, autostart=True,
+             loop=None, shutdown_on_exception=True,
+             close_loop_on_shutdown=True, hard_reset_on_shutdown=True):
+
+    """
+    If you have a single Arduino connected to your computer,
+    then you may accept all the default values.
+
+    Otherwise, specify a unique arduino_instance id for each board in use.
+
+    :param com_port: e.g. COM3 or /dev/ttyACM0.
+
+    :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+
+    :param arduino_wait: Amount of time to wait for an Arduino to
+                         fully reset itself.
+
+    :param sleep_tune: A tuning parameter (typically not changed by user)
+
+    :param autostart: If you wish to call the start method within
+                      your application, then set this to False.
+
+    :param loop: optional user provided event loop
+
+    :param shutdown_on_exception: call shutdown before raising
+                                  a RunTimeError exception, or
+                                  receiving a KeyboardInterrupt exception
+
+    :param close_loop_on_shutdown: stop and close the event loop loop
+                                   when a shutdown is called or a serial
+                                   error occurs
+
+   :param hard_reset_on_shutdown: reset the board on shutdown
+
+    """
+    # check to make sure that Python interpreter is version 3.8.3 or greater
+    python_version = sys.version_info
+    if python_version[0] >= 3:
+        if python_version[1] >= 8:
+            if python_version[2] >= 3:
+                pass
+        else:
+            raise RuntimeError("ERROR: Python 3.7 or greater is "
+                               "required for use of this program.")
+
+    # save input parameters
+    self.com_port = com_port
+    self.arduino_instance_id = arduino_instance_id
+    self.arduino_wait = arduino_wait
+    self.sleep_tune = sleep_tune
+    self.autostart = autostart
+    self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+    # set the event loop
+    if loop is None:
+        self.loop = asyncio.get_event_loop()
+    else:
+        self.loop = loop
+
+    self.shutdown_on_exception = shutdown_on_exception
+    self.close_loop_on_shutdown = close_loop_on_shutdown
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    # debug loopback callback method
+    self.loop_back_callback = None
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    self.dht_count = 0
+
+    # serial port in use
+    self.serial_port = None
+
+    # generic asyncio task holder
+    self.the_task = None
+
+    # flag to indicate we are in shutdown mode
+    self.shutdown_flag = False
+
+    self.report_dispatch = {}
+
+    # reported features
+    self.reported_features = 0
+
+    # To add a command to the command dispatch table, append here.
+    self.report_dispatch.update(
+        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+    self.report_dispatch.update(
+        {PrivateConstants.ANALOG_REPORT: self._analog_message})
+    self.report_dispatch.update(
+        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+    self.report_dispatch.update(
+        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+    self.report_dispatch.update(
+        {PrivateConstants.SPI_REPORT: self._spi_report})
+    self.report_dispatch.update(
+        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_CURRENT_POSITION:
+             self._stepper_current_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUNNING_REPORT:
+             self._stepper_is_running_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+             self._stepper_run_complete_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.FEATURES:
+             self._features_report})
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    self.cs_pins_enabled = []
+
+    # flag to indicate if spi is initialized
+    self.spi_enabled = False
+
+    # flag to indicate if onewire is initialized
+    self.onewire_enabled = False
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    # # stepper motor variables
+    #
+    # # updated when a new motor is added
+    # self.next_stepper_assigned = 0
+    #
+    # # valid list of stepper motor interface types
+    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+    #
+    # # maximum number of steppers supported
+    # self.max_number_of_steppers = 4
+    #
+    # # number of steppers created - not to exceed the maximum
+    # self.number_of_steppers = 0
+    #
+    # # dictionary to hold stepper motor information
+    # self.stepper_info = {'instance': False, 'is_running': None,
+    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+    #                      'distance_to_go_callback': None,
+    #                      'target_position_callback': None,
+    #                      'current_position_callback': None,
+    #                      'is_running_callback': None,
+    #                      'motion_complete_callback': None,
+    #                      'acceleration_callback': None}
+    #
+    # # build a list of stepper motor info items
+    # self.stepper_info_list = []
+    # # a list of dictionaries to hold stepper information
+    # for motor in range(self.max_number_of_steppers):
+    #     self.stepper_info_list.append(self.stepper_info)
+
+    print(f'telemetrix_uno_r4_minima_aio Version:'
+          f' {PrivateConstants.TELEMETRIX_AIO_VERSION}')
+    print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\n')
+
+    if autostart:
+        self.loop.run_until_complete(self.start_aio())
+
+
+
+ +
+ + +
+ + + +

+analog_write(pin, value) + + + async + + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (maximum 16 bits)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
async def analog_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (maximum 16 bits)
+
+    """
+    value_msb = value >> 8
+    value_lsb = value & 0xff
+    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+digital_write(pin, value) + + + async + + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (1 or 0)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
async def digital_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (1 or 0)
+
+    """
+    command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_all_reporting() + + + async + + +

+ + +
+ +

Disable reporting for all digital and analog input pins

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2078
+2079
+2080
+2081
+2082
+2083
+2084
async def disable_all_reporting(self):
+    """
+    Disable reporting for all digital and analog input pins
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DISABLE_ALL, 0]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_analog_reporting(pin) + + + async + + +

+ + +
+ +

Disables analog reporting for a single analog pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
async def disable_analog_reporting(self, pin):
+    """
+    Disables analog reporting for a single analog pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_digital_reporting(pin) + + + async + + +

+ + +
+ +

Disables digital reporting for a single digital pin

+

:param pin: pin number

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
async def disable_digital_reporting(self, pin):
+    """
+    Disables digital reporting for a single digital pin
+
+
+    :param pin: pin number
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_analog_reporting(pin) + + + async + + +

+ + +
+ +

Enables analog reporting for the specified pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
async def enable_analog_reporting(self, pin):
+    """
+    Enables analog reporting for the specified pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_digital_reporting(pin) + + + async + + +

+ + +
+ +

Enable reporting on the specified digital pin.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
async def enable_digital_reporting(self, pin):
+    """
+    Enable reporting on the specified digital pin.
+
+    :param pin: Pin number.
+    """
+
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+get_event_loop() + + + async + + +

+ + +
+ +

Return the currently active asyncio event loop

+

:return: Active event loop

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
334
+335
+336
+337
+338
+339
+340
+341
async def get_event_loop(self):
+    """
+    Return the currently active asyncio event loop
+
+    :return: Active event loop
+
+    """
+    return self.loop
+
+
+
+ +
+ + +
+ + + +

+i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified register for +the i2c device.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c data as a + result of read command

+

:param i2c_port: select the default port (0) or secondary port (1)

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
async def i2c_read(self, address, register, number_of_bytes,
+                   callback, i2c_port=0,
+                   write_register=True):
+    """
+    Read the specified number of bytes from the specified register for
+    the i2c device.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c data as a
+               result of read command
+
+    :param i2c_port: select the default port (0) or secondary port (1)
+
+    :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('i2c_read: A Callback must be specified')
+
+    await self._i2c_read_request(address, register, number_of_bytes,
+                                 callback=callback, i2c_port=i2c_port,
+                                 write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified register for +the i2c device. This restarts the transmission after the read. It is +required for some i2c devices such as the MMA8452Q accelerometer.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c data as a + result of read command

+

:param i2c_port: select the default port (0) or secondary port (1)

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
async def i2c_read_restart_transmission(self, address, register,
+                                        number_of_bytes,
+                                        callback, i2c_port=0,
+                                        write_register=True):
+    """
+    Read the specified number of bytes from the specified register for
+    the i2c device. This restarts the transmission after the read. It is
+    required for some i2c devices such as the MMA8452Q accelerometer.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                                selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c data as a
+               result of read command
+
+    :param i2c_port: select the default port (0) or secondary port (1)
+
+    :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'i2c_read_restart_transmission: A Callback must be specified')
+
+    await self._i2c_read_request(address, register, number_of_bytes,
+                                 stop_transmission=False,
+                                 callback=callback, i2c_port=i2c_port,
+                                 write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_write(address, args, i2c_port=0) + + + async + + +

+ + +
+ +

Write data to an i2c device.

+

:param address: i2c device address

+

:param i2c_port: 0= port 1, 1 = port 2

+

:param args: A variable number of bytes to be sent to the device + passed in as a list

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
async def i2c_write(self, address, args, i2c_port=0):
+    """
+    Write data to an i2c device.
+
+    :param address: i2c device address
+
+    :param i2c_port: 0= port 1, 1 = port 2
+
+    :param args: A variable number of bytes to be sent to the device
+                 passed in as a list
+
+    """
+    if not i2c_port:
+        if not self.i2c_1_active:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+    if i2c_port:
+        if not self.i2c_2_active:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+    for item in args:
+        command.append(item)
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+loop_back(start_character, callback) + + + async + + +

+ + +
+ +

This is a debugging method to send a character to the +Arduino device, and have the device loop it back.

+

:param start_character: The character to loop back. It should be + an integer.

+

:param callback: Looped back character will appear in the callback method

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
653
+654
+655
+656
+657
+658
+659
+660
+661
+662
+663
+664
+665
+666
+667
+668
+669
+670
+671
async def loop_back(self, start_character, callback):
+    """
+    This is a debugging method to send a character to the
+    Arduino device, and have the device loop it back.
+
+    :param start_character: The character to loop back. It should be
+                            an integer.
+
+    :param callback: Looped back character will appear in the callback method
+
+    """
+
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('loop_back: A callback function must be specified.')
+    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+    self.loop_back_callback = callback
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+r4_hard_reset() + + + async + + +

+ + +
+ +

Place the r4 into hard reset

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2071
+2072
+2073
+2074
+2075
+2076
async def r4_hard_reset(self):
+    """
+    Place the r4 into hard reset
+    """
+    command = [PrivateConstants.BOARD_HARD_RESET, 1]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_detach(pin_number) + + + async + + +

+ + +
+ +

Detach a servo for reuse +:param pin_number: attached pin

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1430
+1431
+1432
+1433
+1434
+1435
+1436
async def servo_detach(self, pin_number):
+    """
+    Detach a servo for reuse
+    :param pin_number: attached pin
+    """
+    command = [PrivateConstants.SERVO_DETACH, pin_number]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_write(pin_number, angle) + + + async + + +

+ + +
+ +

Set a servo attached to a pin to a given angle.

+

:param pin_number: pin

+

:param angle: angle (0-180)

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
async def servo_write(self, pin_number, angle):
+    """
+
+    Set a servo attached to a pin to a given angle.
+
+    :param pin_number: pin
+
+    :param angle: angle (0-180)
+
+    """
+    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_analog_scan_interval(interval) + + + async + + +

+ + +
+ +

Set the analog scanning interval.

+

:param interval: value of 0 - 255 - milliseconds

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
673
+674
+675
+676
+677
+678
+679
+680
+681
+682
+683
+684
+685
+686
async def set_analog_scan_interval(self, interval):
+    """
+    Set the analog scanning interval.
+
+    :param interval: value of 0 - 255 - milliseconds
+    """
+
+    if 0 <= interval <= 255:
+        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('Analog interval must be between 0 and 255')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_input(pin_number, differential=0, callback=None) + + + async + + +

+ + +
+ +

Set a pin as an analog input.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

:param differential: difference in previous to current value before + report will be generated

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for analog input pins = 3

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
688
+689
+690
+691
+692
+693
+694
+695
+696
+697
+698
+699
+700
+701
+702
+703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+713
+714
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+    """
+    Set a pin as an analog input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    :param differential: difference in previous to current value before
+                         report will be generated
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for analog input pins = 3
+
+    """
+
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'set_pin_mode_analog_input: A callback function must be specified.')
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,
+                             differential, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_output(pin_number) + + + async + + +

+ + +
+ +

Set a pin as a pwm (analog output) pin.

+

:param pin_number:arduino pin number

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
716
+717
+718
+719
+720
+721
+722
+723
+724
+725
+726
async def set_pin_mode_analog_output(self, pin_number):
+    """
+
+    Set a pin as a pwm (analog output) pin.
+
+    :param pin_number:arduino pin number
+
+    """
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                             callback=None)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_dht(pin, callback=None, dht_type=22) + + + async + + +

+ + +
+ +

:param pin: connection pin

+

:param callback: callback function

+

:param dht_type: either 22 for DHT22 or 11 for DHT11

+

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

+

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
812
+813
+814
+815
+816
+817
+818
+819
+820
+821
+822
+823
+824
+825
+826
+827
+828
+829
+830
+831
+832
+833
+834
+835
+836
+837
+838
+839
+840
+841
+842
+843
+844
+845
+846
+847
+848
+849
+850
+851
+852
+853
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+    """
+
+    :param pin: connection pin
+
+    :param callback: callback function
+
+    :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+    Temperature,
+    Time]
+
+    """
+    if self.reported_features & PrivateConstants.DHT_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+        if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+            self.dht_callbacks[pin] = callback
+            self.dht_count += 1
+
+            if dht_type != 22 and dht_type != 11:
+                dht_type = 22
+
+            command = [PrivateConstants.DHT_NEW, pin, dht_type]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input(pin_number, callback) + + + async + + +

+ + +
+ +

Set a pin as a digital input.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
728
+729
+730
+731
+732
+733
+734
+735
+736
+737
+738
+739
+740
+741
+742
+743
+744
async def set_pin_mode_digital_input(self, pin_number, callback):
+    """
+    Set a pin as a digital input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,
+                             callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input_pullup(pin_number, callback) + + + async + + +

+ + +
+ +

Set a pin as a digital input with pullup enabled.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
746
+747
+748
+749
+750
+751
+752
+753
+754
+755
+756
+757
+758
+759
+760
+761
+762
+763
+764
+765
+766
+767
+768
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):
+    """
+    Set a pin as a digital input with pullup enabled.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'set_pin_mode_digital_input_pullup: A callback function must be specified.')
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                             differential=0, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_output(pin_number) + + + async + + +

+ + +
+ +

Set a pin as a digital output pin.

+

:param pin_number: arduino pin number

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
770
+771
+772
+773
+774
+775
+776
+777
+778
async def set_pin_mode_digital_output(self, pin_number):
+    """
+    Set a pin as a digital output pin.
+
+    :param pin_number: arduino pin number
+    """
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                             callback=None)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_i2c(i2c_port=0) + + + async + + +

+ + +
+ +

Establish the standard Arduino i2c pins for i2c utilization.

+

:param i2c_port: 0 = i2c1, 1 = i2c2

+ +
+
    +
  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  2. +
+
    +
  1. Callbacks are set within the individual i2c read methods of this
  2. +
+
  API.
+
+  See i2c_read, or i2c_read_restart_transmission.
+
+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
781
+782
+783
+784
+785
+786
+787
+788
+789
+790
+791
+792
+793
+794
+795
+796
+797
+798
+799
+800
+801
+802
+803
+804
+805
+806
+807
+808
+809
+810
async def set_pin_mode_i2c(self, i2c_port=0):
+    """
+    Establish the standard Arduino i2c pins for i2c utilization.
+
+    :param i2c_port: 0 = i2c1, 1 = i2c2
+
+    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+           2. Callbacks are set within the individual i2c read methods of this
+          API.
+
+          See i2c_read, or i2c_read_restart_transmission.
+
+    """
+    # test for i2c port 2
+    if i2c_port:
+        # if not previously activated set it to activated
+        # and the send a begin message for this port
+        if not self.i2c_2_active:
+            self.i2c_2_active = True
+        else:
+            return
+    # port 1
+    else:
+        if not self.i2c_1_active:
+            self.i2c_1_active = True
+        else:
+            return
+
+    command = [PrivateConstants.I2C_BEGIN, i2c_port]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) + + + async + + +

+ + +
+ +

Attach a pin to a servo motor

+

:param pin_number: pin

+

:param min_pulse: minimum pulse width

+

:param max_pulse: maximum pulse width

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
855
+856
+857
+858
+859
+860
+861
+862
+863
+864
+865
+866
+867
+868
+869
+870
+871
+872
+873
+874
+875
+876
+877
+878
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+    """
+
+    Attach a pin to a servo motor
+
+    :param pin_number: pin
+
+    :param min_pulse: minimum pulse width
+
+    :param max_pulse: maximum pulse width
+
+    """
+    if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+        minv = (min_pulse).to_bytes(2, byteorder="big")
+        maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+        command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                   minv[0], minv[1], maxv[0], maxv[1]]
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_sonar(trigger_pin, echo_pin, callback) + + + async + + +

+ + +
+ +

:param trigger_pin:

+

:param echo_pin:

+

:param callback: callback

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
880
+881
+882
+883
+884
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
+902
+903
+904
+905
+906
+907
+908
+909
+910
+911
+912
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                             callback):
+    """
+
+    :param trigger_pin:
+
+    :param echo_pin:
+
+    :param callback:  callback
+
+    """
+    if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+            self.sonar_callbacks[trigger_pin] = callback
+            self.sonar_count += 1
+
+            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_spi(chip_select_list=None) + + + async + + +

+ + +
+ +

Specify the list of chip select pins.

+

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

+

Chip Select is any digital output capable pin.

+

:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!

+

command message: [command, number of cs pins, [cs pins...]]

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
+928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
async def set_pin_mode_spi(self, chip_select_list=None):
+    """
+    Specify the list of chip select pins.
+
+    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+    Chip Select is any digital output capable pin.
+
+    :param chip_select_list: this is a list of pins to be used for chip select.
+                       The pins will be configured as output, and set to high
+                       ready to be used for chip select.
+                       NOTE: You must specify the chips select pins here!
+
+
+    command message: [command, number of cs pins, [cs pins...]]
+    """
+    if self.reported_features & PrivateConstants.SPI_FEATURE:
+
+        if type(chip_select_list) != list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('chip_select_list must be in the form of a list')
+        if not chip_select_list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('Chip select pins were not specified')
+
+        self.spi_enabled = True
+
+        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+        for pin in chip_select_list:
+            command.append(pin)
+            self.cs_pins_enabled.append(pin)
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+shutdown() + + + async + + +

+ + +
+ +

This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
async def shutdown(self):
+    """
+    This method attempts an orderly shutdown
+    If any exceptions are thrown, they are ignored.
+
+    """
+    self.shutdown_flag = True
+
+    if self.hard_reset_on_shutdown:
+        await self.r4_hard_reset()
+    # stop all reporting - both analog and digital
+    else:
+        try:
+            command = [PrivateConstants.STOP_ALL_REPORTS]
+            await self._send_command(command)
+
+            await asyncio.sleep(.5)
+            await self.serial_port.reset_input_buffer()
+            await self.serial_port.close()
+            if self.close_loop_on_shutdown:
+                self.loop.stop()
+        except (RuntimeError, SerialException):
+            pass
+
+
+
+ +
+ + +
+ + + +

+sonar_disable() + + + async + + +

+ + +
+ +

Disable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1029
+1030
+1031
+1032
+1033
+1034
async def sonar_disable(self):
+    """
+    Disable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_DISABLE]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+sonar_enable() + + + async + + +

+ + +
+ +

Enable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1036
+1037
+1038
+1039
+1040
+1041
async def sonar_enable(self):
+    """
+    Enable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_ENABLE]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_cs_control(chip_select_pin, select) + + + async + + +

+ + +
+ +

Control an SPI chip select line +:param chip_select_pin: pin connected to CS

+

:param select: 0=select, 1=deselect

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
async def spi_cs_control(self, chip_select_pin, select):
+    """
+    Control an SPI chip select line
+    :param chip_select_pin: pin connected to CS
+
+    :param select: 0=select, 1=deselect
+    """
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+    if chip_select_pin not in self.cs_pins_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.

+

:param chip_select: chip select pin

+

:param register_selection: Register to be selected for read.

+

:param number_of_bytes_to_read: Number of bytes to read

+

:param call_back: Required callback function to report spi data as a + result of read command

+ +
+ callback returns a data list +

[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, + data bytes, time-stamp]

+

SPI_READ_REPORT = 13

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
async def spi_read_blocking(self, chip_select, register_selection,
+                            number_of_bytes_to_read,
+                      call_back=None):
+    """
+    Read the specified number of bytes from the specified SPI port and
+    call the callback function with the reported data.
+
+    :param chip_select: chip select pin
+
+    :param register_selection: Register to be selected for read.
+
+    :param number_of_bytes_to_read: Number of bytes to read
+
+    :param call_back: Required callback function to report spi data as a
+               result of read command
+
+
+    callback returns a data list:
+        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+         data bytes, time-stamp]
+    SPI_READ_REPORT = 13
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+    if not call_back:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+    self.spi_callback = call_back
+
+    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+               number_of_bytes_to_read,
+               register_selection]
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_set_format(clock_divisor, bit_order, data_mode) + + + async + + +

+ + +
+ +

Configure how the SPI serializes and de-serializes data on the wire.

+

See Arduino SPI reference materials for details.

+

:param clock_divisor: 1 - 255

+

:param bit_order:

+
                LSBFIRST = 0
+
+                MSBFIRST = 1 (default)
+
+

:param data_mode:

+
                SPI_MODE0 = 0x00 (default)
+
+                SPI_MODE1  = 1
+
+                SPI_MODE2 = 2
+
+                SPI_MODE3 = 3
+
+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
async def spi_set_format(self, clock_divisor, bit_order, data_mode):
+    """
+    Configure how the SPI serializes and de-serializes data on the wire.
+
+    See Arduino SPI reference materials for details.
+
+    :param clock_divisor: 1 - 255
+
+    :param bit_order:
+
+                        LSBFIRST = 0
+
+                        MSBFIRST = 1 (default)
+
+    :param data_mode:
+
+                        SPI_MODE0 = 0x00 (default)
+
+                        SPI_MODE1  = 1
+
+                        SPI_MODE2 = 2
+
+                        SPI_MODE3 = 3
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+    if not 0 < clock_divisor <= 255:
+        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+    if bit_order not in [0, 1]:
+        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+    if data_mode not in [0, 1, 2, 3]:
+        raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+               data_mode]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_write_blocking(chip_select, bytes_to_write) + + + async + + +

+ + +
+ +

Write a list of bytes to the SPI device.

+

:param chip_select: chip select pin

+

:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
async def spi_write_blocking(self, chip_select, bytes_to_write):
+    """
+    Write a list of bytes to the SPI device.
+
+    :param chip_select: chip select pin
+
+    :param bytes_to_write: A list of bytes to write. This must
+                            be in the form of a list.
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+    if type(bytes_to_write) is not list:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+    for data in bytes_to_write:
+        command.append(data)
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+start_aio() + + + async + + +

+ + +
+ +

This method may be called directly, if the autostart +parameter in init is set to false.

+

This method instantiates the serial interface and then performs auto pin +discovery if using a serial interface, or creates and connects to +a TCP/IP enabled device running StandardFirmataWiFi.

+

Use this method if you wish to start TelemetrixAIO manually from +an asyncio function.

+ +
+ Source code in telemetrix_uno_r4/minima/telemetrix_uno_r4_minima_aio/telemetrix_uno_r4_minima_aio.py +
265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
async def start_aio(self):
+    """
+    This method may be called directly, if the autostart
+    parameter in __init__ is set to false.
+
+    This method instantiates the serial interface and then performs auto pin
+    discovery if using a serial interface, or creates and connects to
+    a TCP/IP enabled device running StandardFirmataWiFi.
+
+    Use this method if you wish to start TelemetrixAIO manually from
+    an asyncio function.
+     """
+
+    if not self.com_port:
+        # user did not specify a com_port
+        try:
+            await self._find_arduino()
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+    else:
+        # com_port specified - set com_port and baud rate
+        try:
+            await self._manual_open()
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+
+    if self.com_port:
+        print(f'Telemetrix4UnoR4 found and connected to {self.com_port}')
+
+        # no com_port found - raise a runtime exception
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('No Arduino Found or User Aborted Program')
+
+    # get arduino firmware version and print it
+    firmware_version = await self._get_firmware_version()
+    if not firmware_version:
+        print('*** Firmware Version retrieval timed out. ***')
+        print('\nDo you have Arduino connectivity and do you have the ')
+        print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')
+        print('to the correct serial port.\n')
+        print('To see a list of serial ports, type: '
+              '"list_serial_ports" in your console.')
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError
+    else:
+
+        print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'
+              f'{firmware_version[3]}.{firmware_version[4]}')
+        # start the command dispatcher loop
+        command = [PrivateConstants.ENABLE_ALL_REPORTS]
+        await self._send_command(command)
+        if not self.loop:
+            self.loop = asyncio.get_event_loop()
+        self.the_task = self.loop.create_task(self._arduino_report_dispatcher())
+
+        # get the features list
+        command = [PrivateConstants.GET_FEATURES]
+        await self._send_command(command)
+        await asyncio.sleep(.5)
+
+        # Have the server reset its data structures
+        command = [PrivateConstants.RESET]
+        await self._send_command(command)
+
+
+
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/telemetrix_wifi_reference/index.html b/telemetrix_wifi_reference/index.html new file mode 100644 index 0000000..e283420 --- /dev/null +++ b/telemetrix_wifi_reference/index.html @@ -0,0 +1,9806 @@ + + + + + + + + + + + + + + + + + + + + + + telemetrix_uno_r4_wifi - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +

telemetrix_uno_r4_wifi

+ +
+ + + +
+ +

Copyright (c) 2023 Alan Yorinks All rights reserved.

+

This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.

+

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

+ + + +
+ + + + + + + + +
+ + + +

+ TelemetrixUnoR4WiFi + + +

+ + +
+

+ Bases: threading.Thread

+ + +

This class exposes and implements the telemetrix API. +It uses threading to accommodate concurrency. +It includes the public API methods as well as +a set of private methods.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
  35
+  36
+  37
+  38
+  39
+  40
+  41
+  42
+  43
+  44
+  45
+  46
+  47
+  48
+  49
+  50
+  51
+  52
+  53
+  54
+  55
+  56
+  57
+  58
+  59
+  60
+  61
+  62
+  63
+  64
+  65
+  66
+  67
+  68
+  69
+  70
+  71
+  72
+  73
+  74
+  75
+  76
+  77
+  78
+  79
+  80
+  81
+  82
+  83
+  84
+  85
+  86
+  87
+  88
+  89
+  90
+  91
+  92
+  93
+  94
+  95
+  96
+  97
+  98
+  99
+ 100
+ 101
+ 102
+ 103
+ 104
+ 105
+ 106
+ 107
+ 108
+ 109
+ 110
+ 111
+ 112
+ 113
+ 114
+ 115
+ 116
+ 117
+ 118
+ 119
+ 120
+ 121
+ 122
+ 123
+ 124
+ 125
+ 126
+ 127
+ 128
+ 129
+ 130
+ 131
+ 132
+ 133
+ 134
+ 135
+ 136
+ 137
+ 138
+ 139
+ 140
+ 141
+ 142
+ 143
+ 144
+ 145
+ 146
+ 147
+ 148
+ 149
+ 150
+ 151
+ 152
+ 153
+ 154
+ 155
+ 156
+ 157
+ 158
+ 159
+ 160
+ 161
+ 162
+ 163
+ 164
+ 165
+ 166
+ 167
+ 168
+ 169
+ 170
+ 171
+ 172
+ 173
+ 174
+ 175
+ 176
+ 177
+ 178
+ 179
+ 180
+ 181
+ 182
+ 183
+ 184
+ 185
+ 186
+ 187
+ 188
+ 189
+ 190
+ 191
+ 192
+ 193
+ 194
+ 195
+ 196
+ 197
+ 198
+ 199
+ 200
+ 201
+ 202
+ 203
+ 204
+ 205
+ 206
+ 207
+ 208
+ 209
+ 210
+ 211
+ 212
+ 213
+ 214
+ 215
+ 216
+ 217
+ 218
+ 219
+ 220
+ 221
+ 222
+ 223
+ 224
+ 225
+ 226
+ 227
+ 228
+ 229
+ 230
+ 231
+ 232
+ 233
+ 234
+ 235
+ 236
+ 237
+ 238
+ 239
+ 240
+ 241
+ 242
+ 243
+ 244
+ 245
+ 246
+ 247
+ 248
+ 249
+ 250
+ 251
+ 252
+ 253
+ 254
+ 255
+ 256
+ 257
+ 258
+ 259
+ 260
+ 261
+ 262
+ 263
+ 264
+ 265
+ 266
+ 267
+ 268
+ 269
+ 270
+ 271
+ 272
+ 273
+ 274
+ 275
+ 276
+ 277
+ 278
+ 279
+ 280
+ 281
+ 282
+ 283
+ 284
+ 285
+ 286
+ 287
+ 288
+ 289
+ 290
+ 291
+ 292
+ 293
+ 294
+ 295
+ 296
+ 297
+ 298
+ 299
+ 300
+ 301
+ 302
+ 303
+ 304
+ 305
+ 306
+ 307
+ 308
+ 309
+ 310
+ 311
+ 312
+ 313
+ 314
+ 315
+ 316
+ 317
+ 318
+ 319
+ 320
+ 321
+ 322
+ 323
+ 324
+ 325
+ 326
+ 327
+ 328
+ 329
+ 330
+ 331
+ 332
+ 333
+ 334
+ 335
+ 336
+ 337
+ 338
+ 339
+ 340
+ 341
+ 342
+ 343
+ 344
+ 345
+ 346
+ 347
+ 348
+ 349
+ 350
+ 351
+ 352
+ 353
+ 354
+ 355
+ 356
+ 357
+ 358
+ 359
+ 360
+ 361
+ 362
+ 363
+ 364
+ 365
+ 366
+ 367
+ 368
+ 369
+ 370
+ 371
+ 372
+ 373
+ 374
+ 375
+ 376
+ 377
+ 378
+ 379
+ 380
+ 381
+ 382
+ 383
+ 384
+ 385
+ 386
+ 387
+ 388
+ 389
+ 390
+ 391
+ 392
+ 393
+ 394
+ 395
+ 396
+ 397
+ 398
+ 399
+ 400
+ 401
+ 402
+ 403
+ 404
+ 405
+ 406
+ 407
+ 408
+ 409
+ 410
+ 411
+ 412
+ 413
+ 414
+ 415
+ 416
+ 417
+ 418
+ 419
+ 420
+ 421
+ 422
+ 423
+ 424
+ 425
+ 426
+ 427
+ 428
+ 429
+ 430
+ 431
+ 432
+ 433
+ 434
+ 435
+ 436
+ 437
+ 438
+ 439
+ 440
+ 441
+ 442
+ 443
+ 444
+ 445
+ 446
+ 447
+ 448
+ 449
+ 450
+ 451
+ 452
+ 453
+ 454
+ 455
+ 456
+ 457
+ 458
+ 459
+ 460
+ 461
+ 462
+ 463
+ 464
+ 465
+ 466
+ 467
+ 468
+ 469
+ 470
+ 471
+ 472
+ 473
+ 474
+ 475
+ 476
+ 477
+ 478
+ 479
+ 480
+ 481
+ 482
+ 483
+ 484
+ 485
+ 486
+ 487
+ 488
+ 489
+ 490
+ 491
+ 492
+ 493
+ 494
+ 495
+ 496
+ 497
+ 498
+ 499
+ 500
+ 501
+ 502
+ 503
+ 504
+ 505
+ 506
+ 507
+ 508
+ 509
+ 510
+ 511
+ 512
+ 513
+ 514
+ 515
+ 516
+ 517
+ 518
+ 519
+ 520
+ 521
+ 522
+ 523
+ 524
+ 525
+ 526
+ 527
+ 528
+ 529
+ 530
+ 531
+ 532
+ 533
+ 534
+ 535
+ 536
+ 537
+ 538
+ 539
+ 540
+ 541
+ 542
+ 543
+ 544
+ 545
+ 546
+ 547
+ 548
+ 549
+ 550
+ 551
+ 552
+ 553
+ 554
+ 555
+ 556
+ 557
+ 558
+ 559
+ 560
+ 561
+ 562
+ 563
+ 564
+ 565
+ 566
+ 567
+ 568
+ 569
+ 570
+ 571
+ 572
+ 573
+ 574
+ 575
+ 576
+ 577
+ 578
+ 579
+ 580
+ 581
+ 582
+ 583
+ 584
+ 585
+ 586
+ 587
+ 588
+ 589
+ 590
+ 591
+ 592
+ 593
+ 594
+ 595
+ 596
+ 597
+ 598
+ 599
+ 600
+ 601
+ 602
+ 603
+ 604
+ 605
+ 606
+ 607
+ 608
+ 609
+ 610
+ 611
+ 612
+ 613
+ 614
+ 615
+ 616
+ 617
+ 618
+ 619
+ 620
+ 621
+ 622
+ 623
+ 624
+ 625
+ 626
+ 627
+ 628
+ 629
+ 630
+ 631
+ 632
+ 633
+ 634
+ 635
+ 636
+ 637
+ 638
+ 639
+ 640
+ 641
+ 642
+ 643
+ 644
+ 645
+ 646
+ 647
+ 648
+ 649
+ 650
+ 651
+ 652
+ 653
+ 654
+ 655
+ 656
+ 657
+ 658
+ 659
+ 660
+ 661
+ 662
+ 663
+ 664
+ 665
+ 666
+ 667
+ 668
+ 669
+ 670
+ 671
+ 672
+ 673
+ 674
+ 675
+ 676
+ 677
+ 678
+ 679
+ 680
+ 681
+ 682
+ 683
+ 684
+ 685
+ 686
+ 687
+ 688
+ 689
+ 690
+ 691
+ 692
+ 693
+ 694
+ 695
+ 696
+ 697
+ 698
+ 699
+ 700
+ 701
+ 702
+ 703
+ 704
+ 705
+ 706
+ 707
+ 708
+ 709
+ 710
+ 711
+ 712
+ 713
+ 714
+ 715
+ 716
+ 717
+ 718
+ 719
+ 720
+ 721
+ 722
+ 723
+ 724
+ 725
+ 726
+ 727
+ 728
+ 729
+ 730
+ 731
+ 732
+ 733
+ 734
+ 735
+ 736
+ 737
+ 738
+ 739
+ 740
+ 741
+ 742
+ 743
+ 744
+ 745
+ 746
+ 747
+ 748
+ 749
+ 750
+ 751
+ 752
+ 753
+ 754
+ 755
+ 756
+ 757
+ 758
+ 759
+ 760
+ 761
+ 762
+ 763
+ 764
+ 765
+ 766
+ 767
+ 768
+ 769
+ 770
+ 771
+ 772
+ 773
+ 774
+ 775
+ 776
+ 777
+ 778
+ 779
+ 780
+ 781
+ 782
+ 783
+ 784
+ 785
+ 786
+ 787
+ 788
+ 789
+ 790
+ 791
+ 792
+ 793
+ 794
+ 795
+ 796
+ 797
+ 798
+ 799
+ 800
+ 801
+ 802
+ 803
+ 804
+ 805
+ 806
+ 807
+ 808
+ 809
+ 810
+ 811
+ 812
+ 813
+ 814
+ 815
+ 816
+ 817
+ 818
+ 819
+ 820
+ 821
+ 822
+ 823
+ 824
+ 825
+ 826
+ 827
+ 828
+ 829
+ 830
+ 831
+ 832
+ 833
+ 834
+ 835
+ 836
+ 837
+ 838
+ 839
+ 840
+ 841
+ 842
+ 843
+ 844
+ 845
+ 846
+ 847
+ 848
+ 849
+ 850
+ 851
+ 852
+ 853
+ 854
+ 855
+ 856
+ 857
+ 858
+ 859
+ 860
+ 861
+ 862
+ 863
+ 864
+ 865
+ 866
+ 867
+ 868
+ 869
+ 870
+ 871
+ 872
+ 873
+ 874
+ 875
+ 876
+ 877
+ 878
+ 879
+ 880
+ 881
+ 882
+ 883
+ 884
+ 885
+ 886
+ 887
+ 888
+ 889
+ 890
+ 891
+ 892
+ 893
+ 894
+ 895
+ 896
+ 897
+ 898
+ 899
+ 900
+ 901
+ 902
+ 903
+ 904
+ 905
+ 906
+ 907
+ 908
+ 909
+ 910
+ 911
+ 912
+ 913
+ 914
+ 915
+ 916
+ 917
+ 918
+ 919
+ 920
+ 921
+ 922
+ 923
+ 924
+ 925
+ 926
+ 927
+ 928
+ 929
+ 930
+ 931
+ 932
+ 933
+ 934
+ 935
+ 936
+ 937
+ 938
+ 939
+ 940
+ 941
+ 942
+ 943
+ 944
+ 945
+ 946
+ 947
+ 948
+ 949
+ 950
+ 951
+ 952
+ 953
+ 954
+ 955
+ 956
+ 957
+ 958
+ 959
+ 960
+ 961
+ 962
+ 963
+ 964
+ 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031
+1032
+1033
+1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
+1193
+1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
+1221
+1222
+1223
+1224
+1225
+1226
+1227
+1228
+1229
+1230
+1231
+1232
+1233
+1234
+1235
+1236
+1237
+1238
+1239
+1240
+1241
+1242
+1243
+1244
+1245
+1246
+1247
+1248
+1249
+1250
+1251
+1252
+1253
+1254
+1255
+1256
+1257
+1258
+1259
+1260
+1261
+1262
+1263
+1264
+1265
+1266
+1267
+1268
+1269
+1270
+1271
+1272
+1273
+1274
+1275
+1276
+1277
+1278
+1279
+1280
+1281
+1282
+1283
+1284
+1285
+1286
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1294
+1295
+1296
+1297
+1298
+1299
+1300
+1301
+1302
+1303
+1304
+1305
+1306
+1307
+1308
+1309
+1310
+1311
+1312
+1313
+1314
+1315
+1316
+1317
+1318
+1319
+1320
+1321
+1322
+1323
+1324
+1325
+1326
+1327
+1328
+1329
+1330
+1331
+1332
+1333
+1334
+1335
+1336
+1337
+1338
+1339
+1340
+1341
+1342
+1343
+1344
+1345
+1346
+1347
+1348
+1349
+1350
+1351
+1352
+1353
+1354
+1355
+1356
+1357
+1358
+1359
+1360
+1361
+1362
+1363
+1364
+1365
+1366
+1367
+1368
+1369
+1370
+1371
+1372
+1373
+1374
+1375
+1376
+1377
+1378
+1379
+1380
+1381
+1382
+1383
+1384
+1385
+1386
+1387
+1388
+1389
+1390
+1391
+1392
+1393
+1394
+1395
+1396
+1397
+1398
+1399
+1400
+1401
+1402
+1403
+1404
+1405
+1406
+1407
+1408
+1409
+1410
+1411
+1412
+1413
+1414
+1415
+1416
+1417
+1418
+1419
+1420
+1421
+1422
+1423
+1424
+1425
+1426
+1427
+1428
+1429
+1430
+1431
+1432
+1433
+1434
+1435
+1436
+1437
+1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
+1450
+1451
+1452
+1453
+1454
+1455
+1456
+1457
+1458
+1459
+1460
+1461
+1462
+1463
+1464
+1465
+1466
+1467
+1468
+1469
+1470
+1471
+1472
+1473
+1474
+1475
+1476
+1477
+1478
+1479
+1480
+1481
+1482
+1483
+1484
+1485
+1486
+1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
+1499
+1500
+1501
+1502
+1503
+1504
+1505
+1506
+1507
+1508
+1509
+1510
+1511
+1512
+1513
+1514
+1515
+1516
+1517
+1518
+1519
+1520
+1521
+1522
+1523
+1524
+1525
+1526
+1527
+1528
+1529
+1530
+1531
+1532
+1533
+1534
+1535
+1536
+1537
+1538
+1539
+1540
+1541
+1542
+1543
+1544
+1545
+1546
+1547
+1548
+1549
+1550
+1551
+1552
+1553
+1554
+1555
+1556
+1557
+1558
+1559
+1560
+1561
+1562
+1563
+1564
+1565
+1566
+1567
+1568
+1569
+1570
+1571
+1572
+1573
+1574
+1575
+1576
+1577
+1578
+1579
+1580
+1581
+1582
+1583
+1584
+1585
+1586
+1587
+1588
+1589
+1590
+1591
+1592
+1593
+1594
+1595
+1596
+1597
+1598
+1599
+1600
+1601
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
+1614
+1615
+1616
+1617
+1618
+1619
+1620
+1621
+1622
+1623
+1624
+1625
+1626
+1627
+1628
+1629
+1630
+1631
+1632
+1633
+1634
+1635
+1636
+1637
+1638
+1639
+1640
+1641
+1642
+1643
+1644
+1645
+1646
+1647
+1648
+1649
+1650
+1651
+1652
+1653
+1654
+1655
+1656
+1657
+1658
+1659
+1660
+1661
+1662
+1663
+1664
+1665
+1666
+1667
+1668
+1669
+1670
+1671
+1672
+1673
+1674
+1675
+1676
+1677
+1678
+1679
+1680
+1681
+1682
+1683
+1684
+1685
+1686
+1687
+1688
+1689
+1690
+1691
+1692
+1693
+1694
+1695
+1696
+1697
+1698
+1699
+1700
+1701
+1702
+1703
+1704
+1705
+1706
+1707
+1708
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
+1742
+1743
+1744
+1745
+1746
+1747
+1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
+1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
+1930
+1931
+1932
+1933
+1934
+1935
+1936
+1937
+1938
+1939
+1940
+1941
+1942
+1943
+1944
+1945
+1946
+1947
+1948
+1949
+1950
+1951
+1952
+1953
+1954
+1955
+1956
+1957
+1958
+1959
+1960
+1961
+1962
+1963
+1964
+1965
+1966
+1967
+1968
+1969
+1970
+1971
+1972
+1973
+1974
+1975
+1976
+1977
+1978
+1979
+1980
+1981
+1982
+1983
+1984
+1985
+1986
+1987
+1988
+1989
+1990
+1991
+1992
+1993
+1994
+1995
+1996
+1997
+1998
+1999
+2000
+2001
+2002
+2003
+2004
+2005
+2006
+2007
+2008
+2009
+2010
+2011
+2012
+2013
+2014
+2015
+2016
+2017
+2018
+2019
+2020
+2021
+2022
+2023
+2024
+2025
+2026
+2027
+2028
+2029
+2030
+2031
+2032
+2033
+2034
+2035
+2036
+2037
+2038
+2039
+2040
+2041
+2042
+2043
+2044
+2045
+2046
+2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
+2070
+2071
+2072
+2073
+2074
+2075
+2076
+2077
+2078
+2079
+2080
+2081
+2082
+2083
+2084
+2085
+2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
+2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
+2131
+2132
+2133
+2134
+2135
+2136
+2137
+2138
+2139
+2140
+2141
+2142
+2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
+2153
+2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
+2177
+2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
+2188
+2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
+2206
+2207
+2208
+2209
+2210
+2211
+2212
+2213
+2214
+2215
+2216
+2217
+2218
+2219
+2220
+2221
+2222
+2223
+2224
+2225
+2226
+2227
+2228
+2229
+2230
+2231
+2232
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
+2244
+2245
+2246
+2247
+2248
+2249
+2250
+2251
+2252
+2253
+2254
+2255
+2256
+2257
+2258
+2259
+2260
+2261
+2262
+2263
+2264
+2265
+2266
+2267
+2268
+2269
+2270
+2271
+2272
+2273
+2274
+2275
+2276
+2277
+2278
+2279
+2280
+2281
+2282
+2283
+2284
+2285
+2286
+2287
+2288
+2289
+2290
+2291
+2292
+2293
+2294
+2295
+2296
+2297
+2298
+2299
+2300
+2301
+2302
+2303
+2304
+2305
+2306
+2307
+2308
+2309
+2310
+2311
+2312
+2313
+2314
+2315
+2316
+2317
+2318
+2319
+2320
+2321
+2322
+2323
+2324
+2325
+2326
+2327
+2328
+2329
+2330
+2331
+2332
+2333
+2334
+2335
+2336
+2337
+2338
+2339
+2340
+2341
+2342
+2343
+2344
+2345
+2346
+2347
+2348
+2349
+2350
+2351
+2352
+2353
+2354
+2355
+2356
+2357
+2358
+2359
+2360
+2361
+2362
+2363
+2364
+2365
+2366
+2367
+2368
+2369
+2370
+2371
+2372
+2373
+2374
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+2396
+2397
+2398
+2399
+2400
+2401
+2402
+2403
+2404
+2405
+2406
+2407
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+2417
+2418
+2419
+2420
+2421
+2422
+2423
+2424
+2425
+2426
+2427
+2428
+2429
+2430
+2431
+2432
+2433
+2434
+2435
+2436
+2437
+2438
+2439
+2440
+2441
+2442
+2443
+2444
+2445
+2446
+2447
+2448
+2449
+2450
+2451
+2452
+2453
+2454
+2455
+2456
+2457
+2458
+2459
+2460
+2461
+2462
+2463
+2464
+2465
+2466
+2467
+2468
+2469
+2470
+2471
+2472
+2473
+2474
+2475
+2476
+2477
+2478
+2479
+2480
+2481
+2482
+2483
+2484
+2485
+2486
+2487
+2488
+2489
+2490
+2491
+2492
+2493
+2494
+2495
+2496
+2497
+2498
+2499
+2500
+2501
+2502
+2503
+2504
+2505
+2506
+2507
+2508
+2509
+2510
+2511
+2512
+2513
+2514
+2515
+2516
+2517
+2518
+2519
+2520
+2521
+2522
+2523
+2524
+2525
+2526
+2527
+2528
+2529
+2530
+2531
+2532
+2533
+2534
+2535
+2536
+2537
+2538
+2539
+2540
+2541
+2542
+2543
+2544
+2545
+2546
+2547
+2548
+2549
+2550
+2551
+2552
+2553
+2554
+2555
+2556
+2557
+2558
+2559
+2560
+2561
+2562
+2563
+2564
+2565
+2566
+2567
+2568
+2569
+2570
+2571
+2572
+2573
+2574
+2575
+2576
+2577
+2578
+2579
+2580
+2581
+2582
+2583
+2584
+2585
+2586
+2587
+2588
+2589
+2590
+2591
+2592
+2593
+2594
+2595
+2596
+2597
+2598
+2599
+2600
+2601
+2602
+2603
+2604
+2605
+2606
+2607
+2608
+2609
+2610
+2611
+2612
+2613
+2614
+2615
+2616
+2617
+2618
+2619
+2620
+2621
+2622
+2623
+2624
+2625
+2626
+2627
+2628
+2629
+2630
+2631
+2632
+2633
+2634
+2635
+2636
+2637
+2638
+2639
+2640
+2641
+2642
+2643
+2644
+2645
class TelemetrixUnoR4WiFi(threading.Thread):
+    """
+    This class exposes and implements the telemetrix API.
+    It uses threading to accommodate concurrency.
+    It includes the public API methods as well as
+    a set of private methods.
+
+    """
+
+    # noinspection PyPep8,PyPep8,PyPep8
+    def __init__(self, com_port=None, arduino_instance_id=1,
+                 arduino_wait=1, sleep_tune=0.000001,
+                 shutdown_on_exception=True, hard_reset_on_shutdown=True,
+                 transport_address=None, ip_port=31336, transport_type=0):
+
+        """
+
+        :param com_port: e.g. COM3 or /dev/ttyACM0.
+                         Only use if you wish to bypass auto com port
+                         detection.
+
+        :param arduino_instance_id: Match with the value installed on the
+                                    arduino-telemetrix sketch.
+
+        :param arduino_wait: Amount of time to wait for an Arduino to
+                             fully reset itself.
+
+        :param sleep_tune: A tuning parameter (typically not changed by user)
+
+        :param shutdown_on_exception: call shutdown before raising
+                                      a RunTimeError exception, or
+                                      receiving a KeyboardInterrupt exception
+
+        :param hard_reset_on_shutdown: reset the board on shutdown
+
+        :param transport_address: ip address of tcp/ip connected device.
+
+        :param ip_port: ip port of tcp/ip connected device
+
+        :param transport_type: 0 = WiFI
+                               1 = USBSerial
+                               2 = BLE
+
+
+        """
+
+        # initialize threading parent
+        threading.Thread.__init__(self)
+
+        # create the threads and set them as daemons so
+        # that they stop when the program is closed
+
+        # create a thread to interpret received serial data
+        self.the_reporter_thread = threading.Thread(target=self._reporter)
+        self.the_reporter_thread.daemon = True
+
+        self.transport_address = transport_address
+        self.ip_port = ip_port
+
+        if transport_type not in [0, 1, 2]:
+            raise RuntimeError("Valid transport_type value is 0, 1, or 2")
+
+        self.transport_type = transport_type
+
+        if transport_type == 0:
+            if not transport_address:
+                raise RuntimeError("An IP address must be specified.")
+
+        if not self.transport_address:
+            self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)
+        else:
+            self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)
+
+        self.the_data_receive_thread.daemon = True
+
+        # flag to allow the reporter and receive threads to run.
+        self.run_event = threading.Event()
+
+        # check to make sure that Python interpreter is version 3.7 or greater
+        python_version = sys.version_info
+        if python_version[0] >= 3:
+            if python_version[1] >= 7:
+                pass
+            else:
+                raise RuntimeError("ERROR: Python 3.7 or greater is "
+                                   "required for use of this program.")
+
+        # save input parameters as instance variables
+        self.com_port = com_port
+        self.arduino_instance_id = arduino_instance_id
+        self.arduino_wait = arduino_wait
+        self.sleep_tune = sleep_tune
+        self.shutdown_on_exception = shutdown_on_exception
+        self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+        # create a deque to receive and process data from the arduino
+        self.the_deque = deque()
+
+        # The report_dispatch dictionary is used to process
+        # incoming report messages by looking up the report message
+        # and executing its associated processing method.
+
+        self.report_dispatch = {}
+
+        # To add a command to the command dispatch table, append here.
+        self.report_dispatch.update(
+            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+        self.report_dispatch.update(
+            {PrivateConstants.ANALOG_REPORT: self._analog_message})
+        self.report_dispatch.update(
+            {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})
+        self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})
+        self.report_dispatch.update(
+            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+        self.report_dispatch.update(
+            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+        self.report_dispatch.update(
+            {PrivateConstants.SPI_REPORT: self._spi_report})
+        self.report_dispatch.update(
+            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_CURRENT_POSITION:
+                 self._stepper_current_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUNNING_REPORT:
+                 self._stepper_is_running_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+                 self._stepper_run_complete_report})
+
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.FEATURES:
+                 self._features_report})
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        self.cs_pins_enabled = []
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        self.dht_count = 0
+
+        # serial port in use
+        self.serial_port = None
+
+        # socket for tcp/ip communications
+        self.sock = None
+
+        # flag to indicate we are in shutdown mode
+        self.shutdown_flag = False
+
+        # debug loopback callback method
+        self.loop_back_callback = None
+
+        # flag to indicate the start of a new report
+        # self.new_report_start = True
+
+        # firmware version to be stored here
+        self.firmware_version = []
+
+        # reported arduino instance id
+        self.reported_arduino_id = []
+
+        # reported features
+        self.reported_features = 0
+
+        # flag to indicate if i2c was previously enabled
+        self.i2c_enabled = False
+
+        # flag to indicate if spi is initialized
+        self.spi_enabled = False
+
+        # flag to indicate if onewire is initialized
+        self.onewire_enabled = False
+
+        # stepper motor variables
+
+        # updated when a new motor is added
+        # self.next_stepper_assigned = 0
+        #
+        # # valid list of stepper motor interface types
+        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+        #
+        # # maximum number of steppers supported
+        # self.max_number_of_steppers = 4
+        #
+        # # number of steppers created - not to exceed the maximum
+        # self.number_of_steppers = 0
+        #
+        # # dictionary to hold stepper motor information
+        # self.stepper_info = {'instance': False, 'is_running': None,
+        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+        #                      'distance_to_go_callback': None,
+        #                      'target_position_callback': None,
+        #                      'current_position_callback': None,
+        #                      'is_running_callback': None,
+        #                      'motion_complete_callback': None,
+        #                      'acceleration_callback': None}
+        #
+        # # build a list of stepper motor info items
+        # self.stepper_info_list = []
+        # # a list of dictionaries to hold stepper information
+        # for motor in range(self.max_number_of_steppers):
+        #     self.stepper_info_list.append(self.stepper_info)
+
+        self.the_reporter_thread.start()
+        self.the_data_receive_thread.start()
+
+        print(f"telemetrix_uno_r4_wifi:  Version"
+              f" {PrivateConstants.TELEMETRIX_VERSION}\n\n"
+              f"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\n")
+
+        # using the serial link
+        if not self.transport_address:
+            if not self.com_port:
+                # user did not specify a com_port
+                try:
+                    self._find_arduino()
+                except KeyboardInterrupt:
+                    if self.shutdown_on_exception:
+                        self.shutdown()
+            else:
+                # com_port specified - set com_port and baud rate
+                try:
+                    self._manual_open()
+                except KeyboardInterrupt:
+                    if self.shutdown_on_exception:
+                        self.shutdown()
+
+            if self.serial_port:
+                print(
+                    f"Arduino compatible device found and connected to {self.serial_port.port}")
+
+                self.serial_port.reset_input_buffer()
+                self.serial_port.reset_output_buffer()
+                self.disable_scroll_message()
+
+            # no com_port found - raise a runtime exception
+            else:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('No Arduino Found or User Aborted Program')
+        else:
+            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.sock.connect((self.transport_address, self.ip_port))
+            print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')
+
+        # allow the threads to run
+        self._run_threads()
+        print(f'Waiting for Arduino to reset')
+        print(f'Reset Complete')
+
+        # get telemetrix firmware version and print it
+        print('\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')
+        self._get_firmware_version()
+        if not self.firmware_version:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')
+
+        else:
+
+            print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'
+                  f'{self.firmware_version[1]}.{self.firmware_version[2]}')
+        command = [PrivateConstants.ENABLE_ALL_REPORTS]
+        self._send_command(command)
+
+        # get the features list
+        command = [PrivateConstants.GET_FEATURES]
+        self._send_command(command)
+        time.sleep(.2)
+
+        # Have the server reset its data structures
+        command = [PrivateConstants.RESET]
+        self._send_command(command)
+        time.sleep(.2)
+
+    def _find_arduino(self):
+        """
+        This method will search all potential serial ports for an Arduino
+        containing a sketch that has a matching arduino_instance_id as
+        specified in the input parameters of this class.
+
+        This is used explicitly with the Telemetrix4Arduino sketch.
+        """
+
+        # a list of serial ports to be checked
+        serial_ports = []
+
+        print('Opening all potential serial ports...')
+        the_ports_list = list_ports.comports()
+        for port in the_ports_list:
+            if port.pid is None:
+                continue
+            try:
+                self.serial_port = serial.Serial(port.device, 115200,
+                                                 timeout=1, writeTimeout=0)
+            except SerialException:
+                continue
+            # create a list of serial ports that we opened
+            serial_ports.append(self.serial_port)
+
+            # display to the user
+            print('\t' + port.device)
+
+            # clear out any possible data in the input buffer
+        # wait for arduino to reset
+        print(
+            f'\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '
+            'reset...')
+        # temporary for testing
+        time.sleep(self.arduino_wait)
+        self._run_threads()
+
+        for serial_port in serial_ports:
+            self.serial_port = serial_port
+
+            self._get_arduino_id()
+            if self.reported_arduino_id != self.arduino_instance_id:
+                continue
+            else:
+                print('Valid Arduino ID Found.')
+                self.serial_port.reset_input_buffer()
+                self.serial_port.reset_output_buffer()
+                return
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')
+
+    def _manual_open(self):
+        """
+        Com port was specified by the user - try to open up that port
+
+        """
+        # if port is not found, a serial exception will be thrown
+        try:
+            print(f'Opening {self.com_port}...')
+            self.serial_port = serial.Serial(self.com_port, 115200,
+                                             timeout=1, writeTimeout=0)
+
+            print(
+                f'\nWaiting {self.arduino_wait} seconds(arduino_wait) for Arduino devices to '
+                'reset...')
+            self._run_threads()
+            time.sleep(self.arduino_wait)
+
+            self._get_arduino_id()
+
+            if self.reported_arduino_id != self.arduino_instance_id:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}')
+            print('Valid Arduino ID Found.')
+            # get arduino firmware version and print it
+            print('\nRetrieving Telemetrix4Arduino firmware ID...')
+            self._get_firmware_version()
+
+            if not self.firmware_version:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Telemetrix4Arduino Sketch Firmware Version Not Found')
+
+            else:
+                print(f'Telemetrix4UnoR4 firmware version: {self.firmware_version[0]}.'
+                      f'{self.firmware_version[1]}')
+        except KeyboardInterrupt:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('User Hit Control-C')
+
+    def analog_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (maximum 16 bits)
+
+        """
+        value_msb = value >> 8
+        value_lsb = value & 0xff
+        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+        self._send_command(command)
+
+    def digital_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (1 or 0)
+
+        """
+
+        command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+        self._send_command(command)
+
+    def disable_all_reporting(self):
+        """
+        Disable reporting for all digital and analog input pins
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DISABLE_ALL, 0]
+        self._send_command(command)
+
+    def disable_analog_reporting(self, pin):
+        """
+        Disables analog reporting for a single analog pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+        self._send_command(command)
+
+    def disable_digital_reporting(self, pin):
+        """
+        Disables digital reporting for a single digital input.
+
+        :param pin: Pin number.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+        self._send_command(command)
+
+    def enable_analog_reporting(self, pin):
+        """
+        Enables analog reporting for the specified pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+        self._send_command(command)
+
+    def enable_digital_reporting(self, pin):
+        """
+        Enable reporting on the specified digital pin.
+
+        :param pin: Pin number.
+        """
+
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+        self._send_command(command)
+
+    def _get_arduino_id(self):
+        """
+        Retrieve arduino-telemetrix arduino id
+
+        """
+        command = [PrivateConstants.ARE_U_THERE]
+        self._send_command(command)
+        # provide time for the reply
+        time.sleep(.5)
+
+    def _get_firmware_version(self):
+        """
+        This method retrieves the
+        arduino-telemetrix firmware version
+
+        """
+        command = [PrivateConstants.GET_FIRMWARE_VERSION]
+        self._send_command(command)
+        # provide time for the reply
+        time.sleep(.5)
+
+    def i2c_read(self, address, register, number_of_bytes,
+                 callback=None, i2c_port=0,
+                 write_register=True):
+        """
+        Read the specified number of bytes from the
+        specified register for the i2c device.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                       selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report
+                         i2c data as a result of read command
+
+       :param i2c_port: 0 = default, 1 = secondary
+
+       :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+
+        self._i2c_read_request(address, register, number_of_bytes,
+                               callback=callback, i2c_port=i2c_port,
+                               write_register=write_register)
+
+    def i2c_read_restart_transmission(self, address, register,
+                                      number_of_bytes,
+                                      callback=None, i2c_port=0,
+                                      write_register=True):
+        """
+        Read the specified number of bytes from the specified
+        register for the i2c device. This restarts the transmission
+        after the read. It is required for some i2c devices such as the MMA8452Q
+        accelerometer.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                                    selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c
+                         data as a result of read command
+
+       :param i2c_port: 0 = default 1 = secondary
+
+       :param write_register: If True, the register is written before read
+                              Else, the write is suppressed
+
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+
+        self._i2c_read_request(address, register, number_of_bytes,
+                               stop_transmission=False,
+                               callback=callback, i2c_port=i2c_port,
+                               write_register=write_register)
+
+    def _i2c_read_request(self, address, register, number_of_bytes,
+                          stop_transmission=True, callback=None, i2c_port=0,
+                          write_register=True):
+        """
+        This method requests the read of an i2c device. Results are retrieved
+        via callback.
+
+        :param address: i2c device address
+
+        :param register: register number (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes expected to be returned
+
+        :param stop_transmission: stop transmission after read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command.
+
+       :param write_register: If True, the register is written before read
+                              Else, the write is suppressed
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')
+
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('I2C Read: A callback function must be specified.')
+
+        if not i2c_port:
+            self.i2c_callback = callback
+        else:
+            self.i2c_callback2 = callback
+
+        if not register:
+            register = 0
+
+        if write_register:
+            write_register = 1
+        else:
+            write_register = 0
+
+        # message contains:
+        # 1. address
+        # 2. register
+        # 3. number of bytes
+        # 4. restart_transmission - True or False
+        # 5. i2c port
+        # 6. suppress write flag
+
+        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,
+                   stop_transmission, i2c_port, write_register]
+        self._send_command(command)
+
+    def i2c_write(self, address, args, i2c_port=0):
+        """
+        Write data to an i2c device.
+
+        :param address: i2c device address
+
+        :param i2c_port: 0= port 1, 1 = port 2
+
+        :param args: A variable number of bytes to be sent to the device
+                     passed in as a list
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+        for item in args:
+            command.append(item)
+
+        self._send_command(command)
+
+    def loop_back(self, start_character, callback=None):
+        """
+        This is a debugging method to send a character to the
+        Arduino device, and have the device loop it back.
+
+        :param start_character: The character to loop back. It should be
+                                an integer.
+
+        :param callback: Looped back character will appear in the callback method
+
+        """
+        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+        self.loop_back_callback = callback
+        self._send_command(command)
+
+    def set_analog_scan_interval(self, interval):
+        """
+        Set the analog scanning interval.
+
+        :param interval: value of 0 - 255 - milliseconds
+        """
+
+        if 0 <= interval <= 255:
+            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Analog interval must be between 0 and 255')
+
+    def set_pin_mode_analog_output(self, pin_number):
+        """
+        Set a pin as a pwm (analog output) pin.
+
+        :param pin_number:arduino pin number
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+    def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+        """
+        Set a pin as an analog input.
+
+        :param pin_number: arduino pin number
+
+        :param differential: difference in previous to current value before
+                             report will be generated
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for analog input pins = 3
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,
+                           callback)
+
+    def set_pin_mode_digital_input(self, pin_number, callback=None):
+        """
+        Set a pin as a digital input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)
+
+    def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):
+        """
+        Set a pin as a digital input with pullup enabled.
+
+        :param pin_number: arduino pin number
+
+        :param callback: callback function
+
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+        """
+        self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                           callback=callback)
+
+    def set_pin_mode_digital_output(self, pin_number):
+        """
+        Set a pin as a digital output pin.
+
+        :param pin_number: arduino pin number
+        """
+
+        self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+    def set_pin_mode_i2c(self, i2c_port=0):
+        """
+        Establish the standard Arduino i2c pins for i2c utilization.
+
+        :param i2c_port: 0 = i2c1, 1 = i2c2
+
+        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+               2. Callbacks are set within the individual i2c read methods of this
+              API.
+
+              See i2c_read, or i2c_read_restart_transmission.
+
+        """
+        # test for i2c port 2
+        if i2c_port:
+            # if not previously activated set it to activated
+            # and the send a begin message for this port
+            if not self.i2c_2_active:
+                self.i2c_2_active = True
+            else:
+                return
+        # port 1
+        else:
+            if not self.i2c_1_active:
+                self.i2c_1_active = True
+            else:
+                return
+
+        command = [PrivateConstants.I2C_BEGIN, i2c_port]
+        self._send_command(command)
+
+    def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+        """
+
+        :param pin: connection pin
+
+        :param callback: callback function
+
+        :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+        Temperature,
+        Time]
+
+        DHT_REPORT_TYPE = 12
+        """
+        if self.reported_features & PrivateConstants.DHT_FEATURE:
+            if not callback:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+            if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+                self.dht_callbacks[pin] = callback
+                self.dht_count += 1
+
+                if dht_type != 22 and dht_type != 11:
+                    dht_type = 22
+
+                command = [PrivateConstants.DHT_NEW, pin, dht_type]
+                self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+    # noinspection PyRedundantParentheses
+    def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+        """
+
+        Attach a pin to a servo motor
+
+        :param pin_number: pin
+
+        :param min_pulse: minimum pulse width
+
+        :param max_pulse: maximum pulse width
+
+        """
+        if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+            minv = (min_pulse).to_bytes(2, byteorder="big")
+            maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+            command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                       minv[0], minv[1], maxv[0], maxv[1]]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+    def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                           callback=None):
+        """
+
+        :param trigger_pin:
+
+        :param echo_pin:
+
+        :param callback: callback
+
+        callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+
+        """
+        if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+                self.sonar_callbacks[trigger_pin] = callback
+                self.sonar_count += 1
+
+                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+                self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+    def set_pin_mode_spi(self, chip_select_list=None):
+        """
+        Specify the list of chip select pins.
+
+        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+        Chip Select is any digital output capable pin.
+
+        :param chip_select_list: this is a list of pins to be used for chip select.
+                           The pins will be configured as output, and set to high
+                           ready to be used for chip select.
+                           NOTE: You must specify the chips select pins here!
+
+
+        command message: [command, [cs pins...]]
+        """
+
+        if self.reported_features & PrivateConstants.SPI_FEATURE:
+            if type(chip_select_list) != list:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('chip_select_list must be in the form of a list')
+            if not chip_select_list:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('Chip select pins were not specified')
+
+            self.spi_enabled = True
+
+            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+            for pin in chip_select_list:
+                command.append(pin)
+                self.cs_pins_enabled.append(pin)
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+    # def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,
+    #                          pin4=5, enable=True):
+    #     """
+    #     Stepper motor support is implemented as a proxy for the
+    #     the AccelStepper library for the Arduino.
+    #
+    #     This feature is compatible with the TB6600 Motor Driver
+    #
+    #     Note: It may not work for other driver types!
+    #
+    #     https://github.com/waspinator/AccelStepper
+    #
+    #     Instantiate a stepper motor.
+    #
+    #     Initialize the interface and pins for a stepper motor.
+    #
+    #     :param interface: Motor Interface Type:
+    #
+    #             1 = Stepper Driver, 2 driver pins required
+    #
+    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required
+    #
+    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins
+    #                 required
+    #
+    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required
+    #
+    #     :param pin1: Arduino digital pin number for motor pin 1
+    #
+    #     :param pin2: Arduino digital pin number for motor pin 2
+    #
+    #     :param pin3: Arduino digital pin number for motor pin 3
+    #
+    #     :param pin4: Arduino digital pin number for motor pin 4
+    #
+    #     :param enable: If this is true, the output pins at construction time.
+    #
+    #     :return: Motor Reference number
+    #     """
+    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:
+    #
+    #         if self.number_of_steppers == self.max_number_of_steppers:
+    #             if self.shutdown_on_exception:
+    #                 self.shutdown()
+    #             raise RuntimeError('Maximum number of steppers has already been assigned')
+    #
+    #         if interface not in self.valid_stepper_interfaces:
+    #             if self.shutdown_on_exception:
+    #                 self.shutdown()
+    #             raise RuntimeError('Invalid stepper interface')
+    #
+    #         self.number_of_steppers += 1
+    #
+    #         motor_id = self.next_stepper_assigned
+    #         self.next_stepper_assigned += 1
+    #         self.stepper_info_list[motor_id]['instance'] = True
+    #
+    #         # build message and send message to server
+    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,
+    #                    pin2, pin3, pin4, enable]
+    #         self._send_command(command)
+    #
+    #         # return motor id
+    #         return motor_id
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')
+
+    def servo_write(self, pin_number, angle):
+        """
+
+        Set a servo attached to a pin to a given angle.
+
+        :param pin_number: pin
+
+        :param angle: angle (0-180)
+
+        """
+        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+        self._send_command(command)
+
+    def servo_detach(self, pin_number):
+        """
+        Detach a servo for reuse
+
+        :param pin_number: attached pin
+
+        """
+        command = [PrivateConstants.SERVO_DETACH, pin_number]
+        self._send_command(command)
+
+    # def stepper_move_to(self, motor_id, position):
+    #     """
+    #     Set an absolution target position. If position is positive, the movement is
+    #     clockwise, else it is counter-clockwise.
+    #
+    #     The run() function (below) will try to move the motor (at most one step per call)
+    #     from the current position to the target position set by the most
+    #     recent call to this function. Caution: moveTo() also recalculates the
+    #     speed for the next step.
+    #     If you are trying to use constant speed movements, you should call setSpeed()
+    #     after calling moveTo().
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param position: target position. Maximum value is 32 bits.
+    #     """
+    #     if position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(position)
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     self._send_command(command)
+    #
+    # def stepper_move(self, motor_id, relative_position):
+    #     """
+    #     Set the target position relative to the current position.
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param relative_position: The desired position relative to the current
+    #                               position. Negative is anticlockwise from
+    #                               the current position. Maximum value is 32 bits.
+    #     """
+    #     if relative_position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #
+    #     relative_position = abs(relative_position)
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_move: Invalid motor_id.')
+    #
+    #     position_bytes = list(relative_position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     self._send_command(command)
+    #
+    # def stepper_run(self, motor_id, completion_callback=None):
+    #     """
+    #     This method steps the selected motor based on the current speed.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run: A motion complete callback must be '
+    #                            'specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_run_speed(self, motor_id):
+    #     """
+    #     This method steps the selected motor based at a constant speed as set by the most
+    #     recent call to stepper_set_max_speed(). The motor will run continuously.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_max_speed(self, motor_id, max_speed):
+    #     """
+    #     Sets the maximum permitted speed. The stepper_run() function will accelerate
+    #     up to the speed set by this function.
+    #
+    #     Caution: the maximum speed achievable depends on your processor and clock speed.
+    #     The default maxSpeed is 1 step per second.
+    #
+    #      Caution: Speeds that exceed the maximum speed supported by the processor may
+    #               result in non-linear accelerations and decelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param max_speed: 1 - 1000
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')
+    #
+    #     if not 1 < max_speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')
+    #
+    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed
+    #     max_speed_msb = (max_speed & 0xff00) >> 8
+    #     max_speed_lsb = max_speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,
+    #                max_speed_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_get_max_speed(self, motor_id):
+    #     """
+    #     Returns the maximum speed configured for this stepper
+    #     that was previously set by stepper_set_max_speed()
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :return: The currently configured maximum speed.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['max_speed']
+    #
+    # def stepper_set_acceleration(self, motor_id, acceleration):
+    #     """
+    #     Sets the acceleration/deceleration rate.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param acceleration: The desired acceleration in steps per second
+    #                          per second. Must be > 0.0. This is an
+    #                          expensive call since it requires a square
+    #                          root to be calculated on the server.
+    #                          Dont call more often than needed.
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')
+    #
+    #     if not 1 < acceleration <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration
+    #
+    #     max_accel_msb = acceleration >> 8
+    #     max_accel_lsb = acceleration & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,
+    #                max_accel_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_set_speed(self, motor_id, speed):
+    #     """
+    #     Sets the desired constant speed for use with stepper_run_speed().
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param speed: 0 - 1000 The desired constant speed in steps per
+    #                   second. Positive is clockwise. Speeds of more than 1000 steps per
+    #                   second are unreliable. Speed accuracy depends on the Arduino
+    #                   crystal. Jitter depends on how frequently you call the
+    #                   stepper_run_speed() method.
+    #                   The speed will be limited by the current value of
+    #                   stepper_set_max_speed().
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')
+    #
+    #     if not 0 < speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['speed'] = speed
+    #
+    #     speed_msb = speed >> 8
+    #     speed_lsb = speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_get_speed(self, motor_id):
+    #     """
+    #     Returns the  most recently set speed.
+    #     that was previously set by stepper_set_speed();
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['speed']
+    #
+    # def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):
+    #     """
+    #     Request the distance from the current position to the target position
+    #     from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param distance_to_go_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]
+    #
+    #     A positive distance is clockwise from the current position.
+    #
+    #     """
+    #     if not distance_to_go_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')
+    #     self.stepper_info_list[motor_id][
+    #         'distance_to_go_callback'] = distance_to_go_callback
+    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_get_target_position(self, motor_id, target_callback):
+    #     """
+    #     Request the most recently set target position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param target_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #
+    #     """
+    #     if not target_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_target_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id][
+    #         'target_position_callback'] = target_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_get_current_position(self, motor_id, current_position_callback):
+    #     """
+    #     Request the current motor position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param current_position_callback: required callback function to receive report
+    #
+    #     :return: The current motor position returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #     """
+    #     if not current_position_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_current_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_current_position(self, motor_id, position):
+    #     """
+    #     Resets the current position of the motor, so that wherever the motor
+    #     happens to be right now is considered to be the new 0 position. Useful
+    #     for setting a zero position on a stepper after an initial hardware
+    #     positioning move.
+    #
+    #     Has the side effect of setting the current motor speed to 0.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     :param position: Position in steps. This is a 32 bit value
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')
+    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     self._send_command(command)
+    #
+    # def stepper_run_speed_to_position(self, motor_id, completion_callback=None):
+    #     """
+    #     Runs the motor at the currently selected speed until the target position is
+    #     reached.
+    #
+    #     Does not implement accelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '
+    #                            'callback must be '
+    #                            'specified.')
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_stop(self, motor_id):
+    #     """
+    #     Sets a new target position that causes the stepper
+    #     to stop as quickly as possible, using the current speed and
+    #     acceleration parameters.
+    #
+    #     :param motor_id:  0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_stop: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_STOP, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_disable_outputs(self, motor_id):
+    #     """
+    #     Disable motor pin outputs by setting them all LOW.
+    #
+    #     Depending on the design of your electronics this may turn off
+    #     the power to the motor coils, saving power.
+    #
+    #     This is useful to support Arduino low power modes: disable the outputs
+    #     during sleep and then re-enable with enableOutputs() before stepping
+    #     again.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and clears
+    #     the pin to disabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_enable_outputs(self, motor_id):
+    #     """
+    #     Enable motor pin outputs by setting the motor pins to OUTPUT
+    #     mode.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and sets
+    #     the pin to enabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]
+    #     self._send_command(command)
+    #
+    # def stepper_set_min_pulse_width(self, motor_id, minimum_width):
+    #     """
+    #     Sets the minimum pulse width allowed by the stepper driver.
+    #
+    #     The minimum practical pulse width is approximately 20 microseconds.
+    #
+    #     Times less than 20 microseconds will usually result in 20 microseconds or so.
+    #
+    #     :param motor_id: 0 -3
+    #
+    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')
+    #
+    #     if not 0 < minimum_width <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '
+    #                            '0-0xffff.')
+    #
+    #     width_msb = minimum_width >> 8
+    #     width_lsb = minimum_width & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,
+    #                width_lsb]
+    #     self._send_command(command)
+    #
+    # def stepper_set_enable_pin(self, motor_id, pin=0xff):
+    #     """
+    #     Sets the enable pin number for stepper drivers.
+    #     0xFF indicates unused (default).
+    #
+    #     Otherwise, if a pin is set, the pin will be turned on when
+    #     enableOutputs() is called and switched off when disableOutputs()
+    #     is called.
+    #
+    #     :param motor_id: 0 - 4
+    #     :param pin: 0-0xff
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')
+    #
+    #     if not 0 < pin <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '
+    #                            '0-0xff.')
+    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,
+    #                                 enable=False):
+    #     """
+    #     Sets the inversion for stepper driver pins.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param direction: True=inverted or False
+    #
+    #     :param step: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,
+    #                step, enable]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False, pin2_invert=False,
+    #                                 pin3_invert=False, pin4_invert=False, enable=False):
+    #     """
+    #     Sets the inversion for 2, 3 and 4 wire stepper pins
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param pin1_invert: True=inverted or False
+    #
+    #     :param pin2_invert: True=inverted or False
+    #
+    #     :param pin3_invert: True=inverted or False
+    #
+    #     :param pin4_invert: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,
+    #                pin2_invert, pin3_invert, pin4_invert, enable]
+    #
+    #     self._send_command(command)
+    #
+    # def stepper_is_running(self, motor_id, callback):
+    #     """
+    #     Checks to see if the motor is currently running to a target.
+    #
+    #     Callback return True if the speed is not zero or not at the target position.
+    #
+    #     :param motor_id: 0-4
+    #
+    #     :param callback: required callback function to receive report
+    #
+    #     :return: The current running state returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]
+    #     """
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_is_running: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback
+    #
+    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]
+    #     self._send_command(command)
+
+    def _set_pin_mode(self, pin_number, pin_state, differential=0, callback=None):
+        """
+        A private method to set the various pin modes.
+
+        :param pin_number: arduino pin number
+
+        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP
+                         For SERVO use: set_pin_mode_servo
+                         For DHT   use: set_pin_mode_dht
+
+        :param differential: for analog inputs - threshold
+                             value to be achieved for report to
+                             be generated
+
+        :param callback: A reference to a call back function to be
+                         called when pin data value changes
+
+        """
+        if callback:
+            if pin_state == PrivateConstants.AT_INPUT:
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_ANALOG:
+                self.analog_callbacks[pin_number] = callback
+            else:
+                print('{} {}'.format('set_pin_mode: callback ignored for '
+                                     'pin state:', pin_state))
+
+        if pin_state == PrivateConstants.AT_INPUT:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_INPUT, 1]
+
+        elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_INPUT_PULLUP, 1]
+
+        elif pin_state == PrivateConstants.AT_OUTPUT:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_OUTPUT]
+
+        elif pin_state == PrivateConstants.AT_ANALOG:
+            command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                       PrivateConstants.AT_ANALOG,
+                       differential >> 8, differential & 0xff, 1]
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Unknown pin state')
+
+        if command:
+            self._send_command(command)
+
+    def shutdown(self):
+        """
+        This method attempts an orderly shutdown
+        If any exceptions are thrown, they are ignored.
+        """
+        self.shutdown_flag = True
+
+        self._stop_threads()
+
+        try:
+            command = [PrivateConstants.STOP_ALL_REPORTS]
+            self._send_command(command)
+            time.sleep(.5)
+
+            if self.hard_reset_on_shutdown:
+                self.r4_hard_reset()
+
+            if self.transport_address:
+                try:
+                    self.sock.shutdown(socket.SHUT_RDWR)
+                    self.sock.close()
+                except Exception:
+                    pass
+            else:
+                try:
+                    self.serial_port.reset_input_buffer()
+                    self.serial_port.reset_output_buffer()
+
+                    self.serial_port.close()
+
+                except (RuntimeError, SerialException, OSError):
+                    # ignore error on shutdown
+                    pass
+        except Exception:
+            # raise RuntimeError('Shutdown failed - could not send stop streaming
+            # message')
+            pass
+
+    def sonar_disable(self):
+        """
+        Disable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_DISABLE]
+        self._send_command(command)
+
+    def sonar_enable(self):
+        """
+        Enable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_ENABLE]
+        self._send_command(command)
+
+    def spi_cs_control(self, chip_select_pin, select):
+        """
+        Control an SPI chip select line
+        :param chip_select_pin: pin connected to CS
+
+        :param select: 0=select, 1=deselect
+        """
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+        if chip_select_pin not in self.cs_pins_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+        self._send_command(command)
+
+    def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,
+                          call_back=None):
+        """
+        Read the specified number of bytes from the specified SPI port and
+        call the callback function with the reported data.
+
+        :param chip_select: chip select pin
+
+        :param register_selection: Register to be selected for read.
+
+        :param number_of_bytes_to_read: Number of bytes to read
+
+        :param call_back: Required callback function to report spi data as a
+                   result of read command
+
+
+        callback returns a data list:
+        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+        data bytes, time-stamp]
+
+        SPI_READ_REPORT = 13
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+        if not call_back:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+        self.spi_callback = call_back
+
+        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+                   number_of_bytes_to_read,
+                   register_selection]
+
+        self._send_command(command)
+
+    def spi_set_format(self, clock_divisor, bit_order, data_mode):
+        """
+        Configure how the SPI serializes and de-serializes data on the wire.
+
+        See Arduino SPI reference materials for details.
+
+        :param clock_divisor: 1 - 255
+
+        :param bit_order:
+
+                            LSBFIRST = 0
+
+                            MSBFIRST = 1 (default)
+
+        :param data_mode:
+
+                            SPI_MODE0 = 0x00 (default)
+
+                            SPI_MODE1  = 1
+
+                            SPI_MODE2 = 2
+
+                            SPI_MODE3 = 3
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+        if not 0 < clock_divisor <= 255:
+            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+        if bit_order not in [0, 1]:
+            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+        if data_mode not in [0, 1, 2, 3]:
+            raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+                   data_mode]
+        self._send_command(command)
+
+    def spi_write_blocking(self, chip_select, bytes_to_write):
+        """
+        Write a list of bytes to the SPI device.
+
+        :param chip_select: chip select pin
+
+        :param bytes_to_write: A list of bytes to write. This must
+                                be in the form of a list.
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+        if type(bytes_to_write) is not list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+        for data in bytes_to_write:
+            command.append(data)
+
+        self._send_command(command)
+
+    # def set_pin_mode_one_wire(self, pin):
+    #     """
+    #     Initialize the one wire serial bus.
+    #
+    #     :param pin: Data pin connected to the OneWire device
+    #     """
+    #     if self.reported_features & PrivateConstants.ONEWIRE_FEATURE:
+    #         self.onewire_enabled = True
+    #         command = [PrivateConstants.ONE_WIRE_INIT, pin]
+    #         self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'The OneWire feature is disabled in the server.')
+    #
+    # def onewire_reset(self, callback=None):
+    #     """
+    #     Reset the onewire device
+    #
+    #     :param callback: required  function to report reset result
+    #
+    #     callback returns a list:
+    #     [ReportType = 14, Report Subtype = 25, reset result byte,
+    #                     timestamp]
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_reset: A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_RESET]
+    #     self._send_command(command)
+    #
+    # def onewire_select(self, device_address):
+    #     """
+    #     Select a device based on its address
+    #     :param device_address: A bytearray of 8 bytes
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')
+    #
+    #     if type(device_address) is not list:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #
+    #     if len(device_address) != 8:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #     command = [PrivateConstants.ONE_WIRE_SELECT]
+    #     for data in device_address:
+    #         command.append(data)
+    #     self._send_command(command)
+    #
+    # def onewire_skip(self):
+    #     """
+    #     Skip the device selection. This only works if you have a
+    #     single device, but you can avoid searching and use this to
+    #     immediately access your device.
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SKIP]
+    #     self._send_command(command)
+    #
+    # def onewire_write(self, data, power=0):
+    #     """
+    #     Write a byte to the onewire device. If 'power' is one
+    #     then the wire is held high at the end for
+    #     parasitically powered devices. You
+    #     are responsible for eventually de-powering it by calling
+    #     another read or write.
+    #
+    #     :param data: byte to write.
+    #     :param power: power control (see above)
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')
+    #     if 0 < data < 255:
+    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]
+    #         self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_write: Data must be no larger than 255')
+    #
+    # def onewire_read(self, callback=None):
+    #     """
+    #     Read a byte from the onewire device
+    #     :param callback: required  function to report onewire data as a
+    #                result of read command
+    #
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_READ]
+    #     self._send_command(command)
+    #     time.sleep(.2)
+    #
+    # def onewire_reset_search(self):
+    #     """
+    #     Begin a new search. The next use of search will begin at the first device
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '
+    #                            f'enabled.')
+    #     else:
+    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]
+    #         self._send_command(command)
+    #
+    # def onewire_search(self, callback=None):
+    #     """
+    #     Search for the next device. The device address will returned in the callback.
+    #     If a device is found, the 8 byte address is contained in the callback.
+    #     If no more devices are found, the address returned contains all elements set
+    #     to 0xff.
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SEARCH]
+    #     self._send_command(command)
+    #
+    # def onewire_crc8(self, address_list, callback=None):
+    #     """
+    #     Compute a CRC check on an array of data.
+    #     :param address_list:
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_crc8 A Callback must be specified')
+    #
+    #     if type(address_list) is not list:
+    #         if self.shutdown_on_exception:
+    #             self.shutdown()
+    #         raise RuntimeError('onewire_crc8: address list must be a list.')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     address_length = len(address_list)
+    #
+    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]
+    #
+    #     for data in address_list:
+    #         command.append(data)
+    #
+    #     self._send_command(command)
+
+    def r4_hard_reset(self):
+        """
+        Place the r4 into hard reset
+        """
+        command = [PrivateConstants.RESET, 1]
+        self._send_command(command)
+        time.sleep(.5)
+        command = [PrivateConstants.BOARD_HARD_RESET, 1]
+        self._send_command(command)
+
+    def enable_scroll_message(self, message, scroll_speed=50):
+        """
+
+        :param message: Message with maximum length of 25
+        :param scroll_speed: in milliseconds (maximum of 255)
+        """
+        if len(message) > 25:
+            raise RuntimeError("Scroll message size is maximum of 25 characters.")
+
+        if scroll_speed > 255:
+            raise RuntimeError("Scroll speed maximum of 255 milliseconds.")
+
+        message = message.encode()
+        command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]
+        for x in message:
+            command.append(x)
+        self._send_command(command)
+
+    def disable_scroll_message(self):
+        """
+        Turn off a scrolling message
+        """
+
+        command = [PrivateConstants.SCROLL_MESSAGE_OFF]
+        self._send_command(command)
+
+    '''
+    report message handlers
+    '''
+
+    def _analog_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for analog messages.
+
+        :param data: message data
+
+        """
+        pin = data[0]
+        value = (data[1] << 8) + data[2]
+        # set the current value in the pin structure
+        time_stamp = time.time()
+        # self.digital_pins[pin].event_time = time_stamp
+        if self.analog_callbacks[pin]:
+            message = [PrivateConstants.ANALOG_REPORT, pin, value, time_stamp]
+            try:
+                self.analog_callbacks[pin](message)
+            except KeyError:
+                pass
+
+    def _dht_report(self, data):
+        """
+        This is the dht report handler method.
+
+        :param data:            data[0] = report error return
+                                    No Errors = 0
+
+                                    Checksum Error = 1
+
+                                    Timeout Error = 2
+
+                                    Invalid Value = 999
+
+                                data[1] = pin number
+
+                                data[2] = dht type 11 or 22
+
+                                data[3] = humidity positivity flag
+
+                                data[4] = temperature positivity value
+
+                                data[5] = humidity integer
+
+                                data[6] = humidity fractional value
+
+                                data[7] = temperature integer
+
+                                data[8] = temperature fractional value
+
+
+        """
+        if data[0]:  # DHT_ERROR
+            # error report
+            # data[0] = report sub type, data[1] = pin, data[2] = error message
+            if self.dht_callbacks[data[1]]:
+                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time
+                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                           time.time()]
+                try:
+                    self.dht_callbacks[data[1]](message)
+                except KeyError:
+                    pass
+        else:
+            # got valid data DHT_DATA
+            f_humidity = float(data[5] + data[6] / 100)
+            if data[3]:
+                f_humidity *= -1.0
+            f_temperature = float(data[7] + data[8] / 100)
+            if data[4]:
+                f_temperature *= -1.0
+            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                       f_humidity, f_temperature, time.time()]
+
+            try:
+                self.dht_callbacks[data[1]](message)
+            except KeyError:
+                pass
+
+    def _digital_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for Digital Messages.
+
+        :param data: digital message
+
+        """
+        pin = data[0]
+        value = data[1]
+
+        time_stamp = time.time()
+        if self.digital_callbacks[pin]:
+            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]
+            self.digital_callbacks[pin](message)
+
+    def _firmware_message(self, data):
+        """
+        Telemetrix4Arduino firmware version message
+
+        :param data: data[0] = major number, data[1] = minor number.
+
+                               data[2] = patch number
+        """
+
+        self.firmware_version = [data[0], data[1], data[2]]
+
+    def _i2c_read_report(self, data):
+        """
+        Execute callback for i2c reads.
+
+        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]
+        """
+
+        # we receive [# data bytes, address, register, data bytes]
+        # number of bytes of data returned
+
+        # data[0] = number of bytes
+        # data[1] = i2c_port
+        # data[2] = number of bytes returned
+        # data[3] = address
+        # data[4] = register
+        # data[5] ... all the data bytes
+
+        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]
+        cb_list.append(time.time())
+
+        if cb_list[1]:
+            self.i2c_callback2(cb_list)
+        else:
+            self.i2c_callback(cb_list)
+
+    def _i2c_too_few(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    def _i2c_too_many(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    def _i_am_here(self, data):
+        """
+        Reply to are_u_there message
+        :param data: arduino id
+        """
+        self.reported_arduino_id = data[0]
+
+    def _spi_report(self, report):
+
+        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]
+
+        cb_list.append(time.time())
+
+        self.spi_callback(cb_list)
+
+    def _onewire_report(self, report):
+        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]
+        cb_list.append(time.time())
+        self.onewire_callback(cb_list)
+
+    def _report_debug_data(self, data):
+        """
+        Print debug data sent from Arduino
+        :param data: data[0] is a byte followed by 2
+                     bytes that comprise an integer
+        :return:
+        """
+        value = (data[1] << 8) + data[2]
+        print(f'DEBUG ID: {data[0]} Value: {value}')
+
+    def _report_loop_data(self, data):
+        """
+        Print data that was looped back
+        :param data: byte of loop back data
+        :return:
+        """
+        if self.loop_back_callback:
+            self.loop_back_callback(data)
+
+    def _send_command(self, command):
+        """
+        This is a private utility method.
+
+
+        :param command:  command data in the form of a list
+
+        """
+        # the length of the list is added at the head
+        command.insert(0, len(command))
+        send_message = bytes(command)
+
+        if self.serial_port:
+            try:
+                self.serial_port.write(send_message)
+            except SerialException:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+                raise RuntimeError('write fail in _send_command')
+        elif self.transport_address:
+            self.sock.sendall(send_message)
+        else:
+            raise RuntimeError('No serial port or ip address set.')
+
+    def _servo_unavailable(self, report):
+        """
+        Message if no servos are available for use.
+        :param report: pin number
+        """
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(
+            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')
+
+    def _sonar_distance_report(self, report):
+        """
+
+        :param report: data[0] = trigger pin, data[1] and data[2] = distance
+
+        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+        """
+
+        # get callback from pin number
+        cb = self.sonar_callbacks[report[0]]
+
+        # build report data
+        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],
+                   ((report[1] << 8) + report[2]), time.time()]
+
+        cb(cb_list)
+
+    def _stepper_distance_to_go_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper distance to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,
+    #                              data[3] = steps bytes 2, data[4] = steps LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id
+    #                              steps, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     steps = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+    def _stepper_target_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper target position to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = target position MSB,
+    #                    data[2] = target position byte MSB+1
+    #                    data[3] = target position byte MSB+2
+    #                    data[4] = target position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id
+    #                              target_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['target_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     target = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     target_position = int.from_bytes(target, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+    def _stepper_current_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper current position.
+    #
+    #     :param report: data[0] = motor_id, data[1] = current position MSB,
+    #                    data[2] = current position byte MSB+1
+    #                    data[3] = current position byte MSB+2
+    #                    data[4] = current position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id
+    #                              current_position, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['current_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     position = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     current_position = int.from_bytes(position, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,
+    #                time.time()]
+    #
+    #     cb(cb_list)
+    #
+    def _stepper_is_running_report(self, report):
+        return  # for now
+    #     """
+    #     Report if the motor is currently running
+    #
+    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.
+    #
+    #     callback report format: [18, motor_id,
+    #                              running_state, time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['is_running_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]
+    #
+    #     cb(cb_list)
+    #
+    def _stepper_run_complete_report(self, report):
+        return  # for now
+    #     """
+    #     The motor completed it motion
+    #
+    #     :param report: data[0] = motor_id
+    #
+    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,
+    #                              time_stamp]
+    #     """
+    #
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],
+    #                time.time()]
+    #
+    #     cb(cb_list)
+
+    def _features_report(self, report):
+        self.reported_features = report[0]
+
+    def _run_threads(self):
+        self.run_event.set()
+
+    def _is_running(self):
+        return self.run_event.is_set()
+
+    def _stop_threads(self):
+        self.run_event.clear()
+
+    def _reporter(self):
+        """
+        This is the reporter thread. It continuously pulls data from
+        the deque. When a full message is detected, that message is
+        processed.
+        """
+        self.run_event.wait()
+
+        while self._is_running() and not self.shutdown_flag:
+            if len(self.the_deque):
+                # response_data will be populated with the received data for the report
+                response_data = []
+                packet_length = self.the_deque.popleft()
+                # print(f'packet_length {packet_length}')
+                if packet_length:
+                    # get all the data for the report and place it into response_data
+                    for i in range(packet_length):
+                        while not len(self.the_deque):
+                            time.sleep(self.sleep_tune)
+                        data = self.the_deque.popleft()
+                        response_data.append(data)
+
+                    # print(f'response_data {response_data}')
+
+                    # get the report type and look up its dispatch method
+                    # here we pop the report type off of response_data
+                    report_type = response_data.pop(0)
+                    # print(f' reported type {report_type}')
+
+                    # retrieve the report handler from the dispatch table
+                    dispatch_entry = self.report_dispatch.get(report_type)
+
+                    # if there is additional data for the report,
+                    # it will be contained in response_data
+                    # noinspection PyArgumentList
+                    dispatch_entry(response_data)
+                    continue
+                else:
+                    if self.shutdown_on_exception:
+                        self.shutdown()
+                    raise RuntimeError(
+                        'A report with a packet length of zero was received.')
+            else:
+                time.sleep(self.sleep_tune)
+
+    def _serial_receiver(self):
+        """
+        Thread to continuously check for incoming data.
+        When a byte comes in, place it onto the deque.
+        """
+        self.run_event.wait()
+
+        # Don't start this thread if using a tcp/ip transport
+        if self.transport_address:
+            return
+
+        while self._is_running() and not self.shutdown_flag:
+            # we can get an OSError: [Errno9] Bad file descriptor when shutting down
+            # just ignore it
+            try:
+                if self.serial_port.inWaiting():
+                    c = self.serial_port.read()
+                    self.the_deque.append(ord(c))
+                    # print(ord(c))
+                else:
+                    time.sleep(self.sleep_tune)
+                    # continue
+            except OSError:
+                pass
+
+    def _tcp_receiver(self):
+        """
+        Thread to continuously check for incoming data.
+        When a byte comes in, place it onto the deque.
+        """
+        self.run_event.wait()
+
+        # Start this thread only if transport_address is set
+
+        if self.transport_address:
+
+            while self._is_running() and not self.shutdown_flag:
+                try:
+                    payload = self.sock.recv(1)
+                    self.the_deque.append(ord(payload))
+                except Exception:
+                    pass
+        else:
+            return
+
+
+ + + +
+ + + + + + + + + + +
+ + + +

+__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=1e-06, shutdown_on_exception=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0) + +

+ + +
+ +

:param com_port: e.g. COM3 or /dev/ttyACM0. + Only use if you wish to bypass auto com port + detection.

+

:param arduino_instance_id: Match with the value installed on the + arduino-telemetrix sketch.

+

:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.

+

:param sleep_tune: A tuning parameter (typically not changed by user)

+

:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception

+

:param hard_reset_on_shutdown: reset the board on shutdown

+

:param transport_address: ip address of tcp/ip connected device.

+

:param ip_port: ip port of tcp/ip connected device

+

:param transport_type: 0 = WiFI + 1 = USBSerial + 2 = BLE

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
def __init__(self, com_port=None, arduino_instance_id=1,
+             arduino_wait=1, sleep_tune=0.000001,
+             shutdown_on_exception=True, hard_reset_on_shutdown=True,
+             transport_address=None, ip_port=31336, transport_type=0):
+
+    """
+
+    :param com_port: e.g. COM3 or /dev/ttyACM0.
+                     Only use if you wish to bypass auto com port
+                     detection.
+
+    :param arduino_instance_id: Match with the value installed on the
+                                arduino-telemetrix sketch.
+
+    :param arduino_wait: Amount of time to wait for an Arduino to
+                         fully reset itself.
+
+    :param sleep_tune: A tuning parameter (typically not changed by user)
+
+    :param shutdown_on_exception: call shutdown before raising
+                                  a RunTimeError exception, or
+                                  receiving a KeyboardInterrupt exception
+
+    :param hard_reset_on_shutdown: reset the board on shutdown
+
+    :param transport_address: ip address of tcp/ip connected device.
+
+    :param ip_port: ip port of tcp/ip connected device
+
+    :param transport_type: 0 = WiFI
+                           1 = USBSerial
+                           2 = BLE
+
+
+    """
+
+    # initialize threading parent
+    threading.Thread.__init__(self)
+
+    # create the threads and set them as daemons so
+    # that they stop when the program is closed
+
+    # create a thread to interpret received serial data
+    self.the_reporter_thread = threading.Thread(target=self._reporter)
+    self.the_reporter_thread.daemon = True
+
+    self.transport_address = transport_address
+    self.ip_port = ip_port
+
+    if transport_type not in [0, 1, 2]:
+        raise RuntimeError("Valid transport_type value is 0, 1, or 2")
+
+    self.transport_type = transport_type
+
+    if transport_type == 0:
+        if not transport_address:
+            raise RuntimeError("An IP address must be specified.")
+
+    if not self.transport_address:
+        self.the_data_receive_thread = threading.Thread(target=self._serial_receiver)
+    else:
+        self.the_data_receive_thread = threading.Thread(target=self._tcp_receiver)
+
+    self.the_data_receive_thread.daemon = True
+
+    # flag to allow the reporter and receive threads to run.
+    self.run_event = threading.Event()
+
+    # check to make sure that Python interpreter is version 3.7 or greater
+    python_version = sys.version_info
+    if python_version[0] >= 3:
+        if python_version[1] >= 7:
+            pass
+        else:
+            raise RuntimeError("ERROR: Python 3.7 or greater is "
+                               "required for use of this program.")
+
+    # save input parameters as instance variables
+    self.com_port = com_port
+    self.arduino_instance_id = arduino_instance_id
+    self.arduino_wait = arduino_wait
+    self.sleep_tune = sleep_tune
+    self.shutdown_on_exception = shutdown_on_exception
+    self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+    # create a deque to receive and process data from the arduino
+    self.the_deque = deque()
+
+    # The report_dispatch dictionary is used to process
+    # incoming report messages by looking up the report message
+    # and executing its associated processing method.
+
+    self.report_dispatch = {}
+
+    # To add a command to the command dispatch table, append here.
+    self.report_dispatch.update(
+        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+    self.report_dispatch.update(
+        {PrivateConstants.ANALOG_REPORT: self._analog_message})
+    self.report_dispatch.update(
+        {PrivateConstants.FIRMWARE_REPORT: self._firmware_message})
+    self.report_dispatch.update({PrivateConstants.I_AM_HERE_REPORT: self._i_am_here})
+    self.report_dispatch.update(
+        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+    self.report_dispatch.update(
+        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+    self.report_dispatch.update(
+        {PrivateConstants.SPI_REPORT: self._spi_report})
+    self.report_dispatch.update(
+        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_CURRENT_POSITION:
+             self._stepper_current_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUNNING_REPORT:
+             self._stepper_is_running_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+             self._stepper_run_complete_report})
+
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.FEATURES:
+             self._features_report})
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    self.cs_pins_enabled = []
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    self.dht_count = 0
+
+    # serial port in use
+    self.serial_port = None
+
+    # socket for tcp/ip communications
+    self.sock = None
+
+    # flag to indicate we are in shutdown mode
+    self.shutdown_flag = False
+
+    # debug loopback callback method
+    self.loop_back_callback = None
+
+    # flag to indicate the start of a new report
+    # self.new_report_start = True
+
+    # firmware version to be stored here
+    self.firmware_version = []
+
+    # reported arduino instance id
+    self.reported_arduino_id = []
+
+    # reported features
+    self.reported_features = 0
+
+    # flag to indicate if i2c was previously enabled
+    self.i2c_enabled = False
+
+    # flag to indicate if spi is initialized
+    self.spi_enabled = False
+
+    # flag to indicate if onewire is initialized
+    self.onewire_enabled = False
+
+    # stepper motor variables
+
+    # updated when a new motor is added
+    # self.next_stepper_assigned = 0
+    #
+    # # valid list of stepper motor interface types
+    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+    #
+    # # maximum number of steppers supported
+    # self.max_number_of_steppers = 4
+    #
+    # # number of steppers created - not to exceed the maximum
+    # self.number_of_steppers = 0
+    #
+    # # dictionary to hold stepper motor information
+    # self.stepper_info = {'instance': False, 'is_running': None,
+    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+    #                      'distance_to_go_callback': None,
+    #                      'target_position_callback': None,
+    #                      'current_position_callback': None,
+    #                      'is_running_callback': None,
+    #                      'motion_complete_callback': None,
+    #                      'acceleration_callback': None}
+    #
+    # # build a list of stepper motor info items
+    # self.stepper_info_list = []
+    # # a list of dictionaries to hold stepper information
+    # for motor in range(self.max_number_of_steppers):
+    #     self.stepper_info_list.append(self.stepper_info)
+
+    self.the_reporter_thread.start()
+    self.the_data_receive_thread.start()
+
+    print(f"telemetrix_uno_r4_wifi:  Version"
+          f" {PrivateConstants.TELEMETRIX_VERSION}\n\n"
+          f"Copyright (c) 2023 Alan Yorinks All Rights Reserved.\n")
+
+    # using the serial link
+    if not self.transport_address:
+        if not self.com_port:
+            # user did not specify a com_port
+            try:
+                self._find_arduino()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+        else:
+            # com_port specified - set com_port and baud rate
+            try:
+                self._manual_open()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    self.shutdown()
+
+        if self.serial_port:
+            print(
+                f"Arduino compatible device found and connected to {self.serial_port.port}")
+
+            self.serial_port.reset_input_buffer()
+            self.serial_port.reset_output_buffer()
+            self.disable_scroll_message()
+
+        # no com_port found - raise a runtime exception
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('No Arduino Found or User Aborted Program')
+    else:
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.sock.connect((self.transport_address, self.ip_port))
+        print(f'Successfully connected to: {self.transport_address}:{self.ip_port}')
+
+    # allow the threads to run
+    self._run_threads()
+    print(f'Waiting for Arduino to reset')
+    print(f'Reset Complete')
+
+    # get telemetrix firmware version and print it
+    print('\nRetrieving Telemetrix4UnoR4WiFi firmware ID...')
+    self._get_firmware_version()
+    if not self.firmware_version:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'Telemetrix4UnoR4WiFi firmware version')
+
+    else:
+
+        print(f'Telemetrix4UnoR4WiFi firmware version: {self.firmware_version[0]}.'
+              f'{self.firmware_version[1]}.{self.firmware_version[2]}')
+    command = [PrivateConstants.ENABLE_ALL_REPORTS]
+    self._send_command(command)
+
+    # get the features list
+    command = [PrivateConstants.GET_FEATURES]
+    self._send_command(command)
+    time.sleep(.2)
+
+    # Have the server reset its data structures
+    command = [PrivateConstants.RESET]
+    self._send_command(command)
+    time.sleep(.2)
+
+
+
+ +
+ + +
+ + + +

+analog_write(pin, value) + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (maximum 16 bits)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
def analog_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (maximum 16 bits)
+
+    """
+    value_msb = value >> 8
+    value_lsb = value & 0xff
+    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+digital_write(pin, value) + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (1 or 0)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
def digital_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (1 or 0)
+
+    """
+
+    command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_all_reporting() + +

+ + +
+ +

Disable reporting for all digital and analog input pins

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
475
+476
+477
+478
+479
+480
+481
def disable_all_reporting(self):
+    """
+    Disable reporting for all digital and analog input pins
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DISABLE_ALL, 0]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_analog_reporting(pin) + +

+ + +
+ +

Disables analog reporting for a single analog pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
483
+484
+485
+486
+487
+488
+489
+490
+491
+492
def disable_analog_reporting(self, pin):
+    """
+    Disables analog reporting for a single analog pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_digital_reporting(pin) + +

+ + +
+ +

Disables digital reporting for a single digital input.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
494
+495
+496
+497
+498
+499
+500
+501
+502
+503
def disable_digital_reporting(self, pin):
+    """
+    Disables digital reporting for a single digital input.
+
+    :param pin: Pin number.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_scroll_message() + +

+ + +
+ +

Turn off a scrolling message

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
2172
+2173
+2174
+2175
+2176
+2177
+2178
def disable_scroll_message(self):
+    """
+    Turn off a scrolling message
+    """
+
+    command = [PrivateConstants.SCROLL_MESSAGE_OFF]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_analog_reporting(pin) + +

+ + +
+ +

Enables analog reporting for the specified pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
def enable_analog_reporting(self, pin):
+    """
+    Enables analog reporting for the specified pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_digital_reporting(pin) + +

+ + +
+ +

Enable reporting on the specified digital pin.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
517
+518
+519
+520
+521
+522
+523
+524
+525
+526
def enable_digital_reporting(self, pin):
+    """
+    Enable reporting on the specified digital pin.
+
+    :param pin: Pin number.
+    """
+
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_scroll_message(message, scroll_speed=50) + +

+ + +
+ +

:param message: Message with maximum length of 25 +:param scroll_speed: in milliseconds (maximum of 255)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
def enable_scroll_message(self, message, scroll_speed=50):
+    """
+
+    :param message: Message with maximum length of 25
+    :param scroll_speed: in milliseconds (maximum of 255)
+    """
+    if len(message) > 25:
+        raise RuntimeError("Scroll message size is maximum of 25 characters.")
+
+    if scroll_speed > 255:
+        raise RuntimeError("Scroll speed maximum of 255 milliseconds.")
+
+    message = message.encode()
+    command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]
+    for x in message:
+        command.append(x)
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+i2c_read(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True) + +

+ + +
+ +

Read the specified number of bytes from the + specified register for the i2c device.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report + i2c data as a result of read command

+

:param i2c_port: 0 = default, 1 = secondary

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
def i2c_read(self, address, register, number_of_bytes,
+             callback=None, i2c_port=0,
+             write_register=True):
+    """
+    Read the specified number of bytes from the
+    specified register for the i2c device.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                   selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report
+                     i2c data as a result of read command
+
+   :param i2c_port: 0 = default, 1 = secondary
+
+   :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+
+    self._i2c_read_request(address, register, number_of_bytes,
+                           callback=callback, i2c_port=i2c_port,
+                           write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_read_restart_transmission(address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True) + +

+ + +
+ +

Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c + data as a result of read command

+

:param i2c_port: 0 = default 1 = secondary

+

:param write_register: If True, the register is written before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
def i2c_read_restart_transmission(self, address, register,
+                                  number_of_bytes,
+                                  callback=None, i2c_port=0,
+                                  write_register=True):
+    """
+    Read the specified number of bytes from the specified
+    register for the i2c device. This restarts the transmission
+    after the read. It is required for some i2c devices such as the MMA8452Q
+    accelerometer.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                                selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c
+                     data as a result of read command
+
+   :param i2c_port: 0 = default 1 = secondary
+
+   :param write_register: If True, the register is written before read
+                          Else, the write is suppressed
+
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+
+    self._i2c_read_request(address, register, number_of_bytes,
+                           stop_transmission=False,
+                           callback=callback, i2c_port=i2c_port,
+                           write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_write(address, args, i2c_port=0) + +

+ + +
+ +

Write data to an i2c device.

+

:param address: i2c device address

+

:param i2c_port: 0= port 1, 1 = port 2

+

:param args: A variable number of bytes to be sent to the device + passed in as a list

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
691
+692
+693
+694
+695
+696
+697
+698
+699
+700
+701
+702
+703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+713
+714
+715
+716
+717
+718
+719
+720
+721
+722
def i2c_write(self, address, args, i2c_port=0):
+    """
+    Write data to an i2c device.
+
+    :param address: i2c device address
+
+    :param i2c_port: 0= port 1, 1 = port 2
+
+    :param args: A variable number of bytes to be sent to the device
+                 passed in as a list
+
+    """
+    if not i2c_port:
+        if not self.i2c_1_active:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+    if i2c_port:
+        if not self.i2c_2_active:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+    for item in args:
+        command.append(item)
+
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+loop_back(start_character, callback=None) + +

+ + +
+ +

This is a debugging method to send a character to the +Arduino device, and have the device loop it back.

+

:param start_character: The character to loop back. It should be + an integer.

+

:param callback: Looped back character will appear in the callback method

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
724
+725
+726
+727
+728
+729
+730
+731
+732
+733
+734
+735
+736
+737
def loop_back(self, start_character, callback=None):
+    """
+    This is a debugging method to send a character to the
+    Arduino device, and have the device loop it back.
+
+    :param start_character: The character to loop back. It should be
+                            an integer.
+
+    :param callback: Looped back character will appear in the callback method
+
+    """
+    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+    self.loop_back_callback = callback
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+r4_hard_reset() + +

+ + +
+ +

Place the r4 into hard reset

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
def r4_hard_reset(self):
+    """
+    Place the r4 into hard reset
+    """
+    command = [PrivateConstants.RESET, 1]
+    self._send_command(command)
+    time.sleep(.5)
+    command = [PrivateConstants.BOARD_HARD_RESET, 1]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_detach(pin_number) + +

+ + +
+ +

Detach a servo for reuse

+

:param pin_number: attached pin

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
def servo_detach(self, pin_number):
+    """
+    Detach a servo for reuse
+
+    :param pin_number: attached pin
+
+    """
+    command = [PrivateConstants.SERVO_DETACH, pin_number]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_write(pin_number, angle) + +

+ + +
+ +

Set a servo attached to a pin to a given angle.

+

:param pin_number: pin

+

:param angle: angle (0-180)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
def servo_write(self, pin_number, angle):
+    """
+
+    Set a servo attached to a pin to a given angle.
+
+    :param pin_number: pin
+
+    :param angle: angle (0-180)
+
+    """
+    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_analog_scan_interval(interval) + +

+ + +
+ +

Set the analog scanning interval.

+

:param interval: value of 0 - 255 - milliseconds

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
739
+740
+741
+742
+743
+744
+745
+746
+747
+748
+749
+750
+751
+752
def set_analog_scan_interval(self, interval):
+    """
+    Set the analog scanning interval.
+
+    :param interval: value of 0 - 255 - milliseconds
+    """
+
+    if 0 <= interval <= 255:
+        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('Analog interval must be between 0 and 255')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_input(pin_number, differential=0, callback=None) + +

+ + +
+ +

Set a pin as an analog input.

+

:param pin_number: arduino pin number

+

:param differential: difference in previous to current value before + report will be generated

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for analog input pins = 3

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
763
+764
+765
+766
+767
+768
+769
+770
+771
+772
+773
+774
+775
+776
+777
+778
+779
+780
+781
+782
+783
def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+    """
+    Set a pin as an analog input.
+
+    :param pin_number: arduino pin number
+
+    :param differential: difference in previous to current value before
+                         report will be generated
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for analog input pins = 3
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG, differential,
+                       callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_output(pin_number) + +

+ + +
+ +

Set a pin as a pwm (analog output) pin.

+

:param pin_number:arduino pin number

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
754
+755
+756
+757
+758
+759
+760
+761
def set_pin_mode_analog_output(self, pin_number):
+    """
+    Set a pin as a pwm (analog output) pin.
+
+    :param pin_number:arduino pin number
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_dht(pin, callback=None, dht_type=22) + +

+ + +
+ +

:param pin: connection pin

+

:param callback: callback function

+

:param dht_type: either 22 for DHT22 or 11 for DHT11

+

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

+

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]

+

DHT_REPORT_TYPE = 12

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
861
+862
+863
+864
+865
+866
+867
+868
+869
+870
+871
+872
+873
+874
+875
+876
+877
+878
+879
+880
+881
+882
+883
+884
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+    """
+
+    :param pin: connection pin
+
+    :param callback: callback function
+
+    :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+    Temperature,
+    Time]
+
+    DHT_REPORT_TYPE = 12
+    """
+    if self.reported_features & PrivateConstants.DHT_FEATURE:
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+        if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+            self.dht_callbacks[pin] = callback
+            self.dht_count += 1
+
+            if dht_type != 22 and dht_type != 11:
+                dht_type = 22
+
+            command = [PrivateConstants.DHT_NEW, pin, dht_type]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input(pin_number, callback=None) + +

+ + +
+ +

Set a pin as a digital input.

+

:param pin_number: arduino pin number

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
785
+786
+787
+788
+789
+790
+791
+792
+793
+794
+795
+796
+797
+798
+799
+800
+801
def set_pin_mode_digital_input(self, pin_number, callback=None):
+    """
+    Set a pin as a digital input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input_pullup(pin_number, callback=None) + +

+ + +
+ +

Set a pin as a digital input with pullup enabled.

+

:param pin_number: arduino pin number

+

:param callback: callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
803
+804
+805
+806
+807
+808
+809
+810
+811
+812
+813
+814
+815
+816
+817
+818
+819
def set_pin_mode_digital_input_pullup(self, pin_number, callback=None):
+    """
+    Set a pin as a digital input with pullup enabled.
+
+    :param pin_number: arduino pin number
+
+    :param callback: callback function
+
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+    """
+    self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                       callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_output(pin_number) + +

+ + +
+ +

Set a pin as a digital output pin.

+

:param pin_number: arduino pin number

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
821
+822
+823
+824
+825
+826
+827
+828
def set_pin_mode_digital_output(self, pin_number):
+    """
+    Set a pin as a digital output pin.
+
+    :param pin_number: arduino pin number
+    """
+
+    self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_i2c(i2c_port=0) + +

+ + +
+ +

Establish the standard Arduino i2c pins for i2c utilization.

+

:param i2c_port: 0 = i2c1, 1 = i2c2

+ +
+
    +
  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  2. +
+
    +
  1. Callbacks are set within the individual i2c read methods of this
  2. +
+
  API.
+
+  See i2c_read, or i2c_read_restart_transmission.
+
+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
830
+831
+832
+833
+834
+835
+836
+837
+838
+839
+840
+841
+842
+843
+844
+845
+846
+847
+848
+849
+850
+851
+852
+853
+854
+855
+856
+857
+858
+859
def set_pin_mode_i2c(self, i2c_port=0):
+    """
+    Establish the standard Arduino i2c pins for i2c utilization.
+
+    :param i2c_port: 0 = i2c1, 1 = i2c2
+
+    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+           2. Callbacks are set within the individual i2c read methods of this
+          API.
+
+          See i2c_read, or i2c_read_restart_transmission.
+
+    """
+    # test for i2c port 2
+    if i2c_port:
+        # if not previously activated set it to activated
+        # and the send a begin message for this port
+        if not self.i2c_2_active:
+            self.i2c_2_active = True
+        else:
+            return
+    # port 1
+    else:
+        if not self.i2c_1_active:
+            self.i2c_1_active = True
+        else:
+            return
+
+    command = [PrivateConstants.I2C_BEGIN, i2c_port]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) + +

+ + +
+ +

Attach a pin to a servo motor

+

:param pin_number: pin

+

:param min_pulse: minimum pulse width

+

:param max_pulse: maximum pulse width

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+    """
+
+    Attach a pin to a servo motor
+
+    :param pin_number: pin
+
+    :param min_pulse: minimum pulse width
+
+    :param max_pulse: maximum pulse width
+
+    """
+    if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+        minv = (min_pulse).to_bytes(2, byteorder="big")
+        maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+        command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                   minv[0], minv[1], maxv[0], maxv[1]]
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_sonar(trigger_pin, echo_pin, callback=None) + +

+ + +
+ +

:param trigger_pin:

+

:param echo_pin:

+

:param callback: callback

+

callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960
+961
+962
+963
def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                       callback=None):
+    """
+
+    :param trigger_pin:
+
+    :param echo_pin:
+
+    :param callback: callback
+
+    callback data: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+
+    """
+    if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+            self.sonar_callbacks[trigger_pin] = callback
+            self.sonar_count += 1
+
+            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+            self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_spi(chip_select_list=None) + +

+ + +
+ +

Specify the list of chip select pins.

+

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

+

Chip Select is any digital output capable pin.

+

:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!

+

command message: [command, [cs pins...]]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
+1001
+1002
+1003
def set_pin_mode_spi(self, chip_select_list=None):
+    """
+    Specify the list of chip select pins.
+
+    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+    Chip Select is any digital output capable pin.
+
+    :param chip_select_list: this is a list of pins to be used for chip select.
+                       The pins will be configured as output, and set to high
+                       ready to be used for chip select.
+                       NOTE: You must specify the chips select pins here!
+
+
+    command message: [command, [cs pins...]]
+    """
+
+    if self.reported_features & PrivateConstants.SPI_FEATURE:
+        if type(chip_select_list) != list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('chip_select_list must be in the form of a list')
+        if not chip_select_list:
+            if self.shutdown_on_exception:
+                self.shutdown()
+            raise RuntimeError('Chip select pins were not specified')
+
+        self.spi_enabled = True
+
+        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+        for pin in chip_select_list:
+            command.append(pin)
+            self.cs_pins_enabled.append(pin)
+        self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+shutdown() + +

+ + +
+ +

This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
def shutdown(self):
+    """
+    This method attempts an orderly shutdown
+    If any exceptions are thrown, they are ignored.
+    """
+    self.shutdown_flag = True
+
+    self._stop_threads()
+
+    try:
+        command = [PrivateConstants.STOP_ALL_REPORTS]
+        self._send_command(command)
+        time.sleep(.5)
+
+        if self.hard_reset_on_shutdown:
+            self.r4_hard_reset()
+
+        if self.transport_address:
+            try:
+                self.sock.shutdown(socket.SHUT_RDWR)
+                self.sock.close()
+            except Exception:
+                pass
+        else:
+            try:
+                self.serial_port.reset_input_buffer()
+                self.serial_port.reset_output_buffer()
+
+                self.serial_port.close()
+
+            except (RuntimeError, SerialException, OSError):
+                # ignore error on shutdown
+                pass
+    except Exception:
+        # raise RuntimeError('Shutdown failed - could not send stop streaming
+        # message')
+        pass
+
+
+
+ +
+ + +
+ + + +

+sonar_disable() + +

+ + +
+ +

Disable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1786
+1787
+1788
+1789
+1790
+1791
def sonar_disable(self):
+    """
+    Disable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_DISABLE]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+sonar_enable() + +

+ + +
+ +

Enable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1793
+1794
+1795
+1796
+1797
+1798
def sonar_enable(self):
+    """
+    Enable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_ENABLE]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_cs_control(chip_select_pin, select) + +

+ + +
+ +

Control an SPI chip select line +:param chip_select_pin: pin connected to CS

+

:param select: 0=select, 1=deselect

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
def spi_cs_control(self, chip_select_pin, select):
+    """
+    Control an SPI chip select line
+    :param chip_select_pin: pin connected to CS
+
+    :param select: 0=select, 1=deselect
+    """
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+    if chip_select_pin not in self.cs_pins_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) + +

+ + +
+ +

Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.

+

:param chip_select: chip select pin

+

:param register_selection: Register to be selected for read.

+

:param number_of_bytes_to_read: Number of bytes to read

+

:param call_back: Required callback function to report spi data as a + result of read command

+

callback returns a data list: +[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, +data bytes, time-stamp]

+

SPI_READ_REPORT = 13

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
def spi_read_blocking(self, chip_select, register_selection, number_of_bytes_to_read,
+                      call_back=None):
+    """
+    Read the specified number of bytes from the specified SPI port and
+    call the callback function with the reported data.
+
+    :param chip_select: chip select pin
+
+    :param register_selection: Register to be selected for read.
+
+    :param number_of_bytes_to_read: Number of bytes to read
+
+    :param call_back: Required callback function to report spi data as a
+               result of read command
+
+
+    callback returns a data list:
+    [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+    data bytes, time-stamp]
+
+    SPI_READ_REPORT = 13
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+    if not call_back:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+    self.spi_callback = call_back
+
+    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+               number_of_bytes_to_read,
+               register_selection]
+
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_set_format(clock_divisor, bit_order, data_mode) + +

+ + +
+ +

Configure how the SPI serializes and de-serializes data on the wire.

+

See Arduino SPI reference materials for details.

+

:param clock_divisor: 1 - 255

+

:param bit_order:

+
                LSBFIRST = 0
+
+                MSBFIRST = 1 (default)
+
+

:param data_mode:

+
                SPI_MODE0 = 0x00 (default)
+
+                SPI_MODE1  = 1
+
+                SPI_MODE2 = 2
+
+                SPI_MODE3 = 3
+
+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
def spi_set_format(self, clock_divisor, bit_order, data_mode):
+    """
+    Configure how the SPI serializes and de-serializes data on the wire.
+
+    See Arduino SPI reference materials for details.
+
+    :param clock_divisor: 1 - 255
+
+    :param bit_order:
+
+                        LSBFIRST = 0
+
+                        MSBFIRST = 1 (default)
+
+    :param data_mode:
+
+                        SPI_MODE0 = 0x00 (default)
+
+                        SPI_MODE1  = 1
+
+                        SPI_MODE2 = 2
+
+                        SPI_MODE3 = 3
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+    if not 0 < clock_divisor <= 255:
+        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+    if bit_order not in [0, 1]:
+        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+    if data_mode not in [0, 1, 2, 3]:
+        raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+               data_mode]
+    self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_write_blocking(chip_select, bytes_to_write) + +

+ + +
+ +

Write a list of bytes to the SPI device.

+

:param chip_select: chip select pin

+

:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi/telemetrix_uno_r4_wifi.py +
1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
def spi_write_blocking(self, chip_select, bytes_to_write):
+    """
+    Write a list of bytes to the SPI device.
+
+    :param chip_select: chip select pin
+
+    :param bytes_to_write: A list of bytes to write. This must
+                            be in the form of a list.
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+    if type(bytes_to_write) is not list:
+        if self.shutdown_on_exception:
+            self.shutdown()
+        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+    for data in bytes_to_write:
+        command.append(data)
+
+    self._send_command(command)
+
+
+
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/telemetrix_wifi_reference_aio/index.html b/telemetrix_wifi_reference_aio/index.html new file mode 100644 index 0000000..7e67245 --- /dev/null +++ b/telemetrix_wifi_reference_aio/index.html @@ -0,0 +1,10077 @@ + + + + + + + + + + + + + + + + + + + + + + telemetrix_uno_r4_wifi_aio - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + + + + + +
+
+ + + + +

telemetrix_uno_r4_wifi_aio

+ +
+ + + +
+ +

Copyright (c) 2023 Alan Yorinks All rights reserved.

+

This program is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +Version 3 as published by the Free Software Foundation; either +or (at your option) any later version. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details.

+

You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

+ + + +
+ + + + + + + + +
+ + + +

+ TelemetrixUnoR4WiFiAio + + +

+ + +
+ + +

This class exposes and implements the TelemetrixUnoR4WifiAio API. +It includes the public API methods as well as +a set of private methods. This is an asyncio API.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
  39
+  40
+  41
+  42
+  43
+  44
+  45
+  46
+  47
+  48
+  49
+  50
+  51
+  52
+  53
+  54
+  55
+  56
+  57
+  58
+  59
+  60
+  61
+  62
+  63
+  64
+  65
+  66
+  67
+  68
+  69
+  70
+  71
+  72
+  73
+  74
+  75
+  76
+  77
+  78
+  79
+  80
+  81
+  82
+  83
+  84
+  85
+  86
+  87
+  88
+  89
+  90
+  91
+  92
+  93
+  94
+  95
+  96
+  97
+  98
+  99
+ 100
+ 101
+ 102
+ 103
+ 104
+ 105
+ 106
+ 107
+ 108
+ 109
+ 110
+ 111
+ 112
+ 113
+ 114
+ 115
+ 116
+ 117
+ 118
+ 119
+ 120
+ 121
+ 122
+ 123
+ 124
+ 125
+ 126
+ 127
+ 128
+ 129
+ 130
+ 131
+ 132
+ 133
+ 134
+ 135
+ 136
+ 137
+ 138
+ 139
+ 140
+ 141
+ 142
+ 143
+ 144
+ 145
+ 146
+ 147
+ 148
+ 149
+ 150
+ 151
+ 152
+ 153
+ 154
+ 155
+ 156
+ 157
+ 158
+ 159
+ 160
+ 161
+ 162
+ 163
+ 164
+ 165
+ 166
+ 167
+ 168
+ 169
+ 170
+ 171
+ 172
+ 173
+ 174
+ 175
+ 176
+ 177
+ 178
+ 179
+ 180
+ 181
+ 182
+ 183
+ 184
+ 185
+ 186
+ 187
+ 188
+ 189
+ 190
+ 191
+ 192
+ 193
+ 194
+ 195
+ 196
+ 197
+ 198
+ 199
+ 200
+ 201
+ 202
+ 203
+ 204
+ 205
+ 206
+ 207
+ 208
+ 209
+ 210
+ 211
+ 212
+ 213
+ 214
+ 215
+ 216
+ 217
+ 218
+ 219
+ 220
+ 221
+ 222
+ 223
+ 224
+ 225
+ 226
+ 227
+ 228
+ 229
+ 230
+ 231
+ 232
+ 233
+ 234
+ 235
+ 236
+ 237
+ 238
+ 239
+ 240
+ 241
+ 242
+ 243
+ 244
+ 245
+ 246
+ 247
+ 248
+ 249
+ 250
+ 251
+ 252
+ 253
+ 254
+ 255
+ 256
+ 257
+ 258
+ 259
+ 260
+ 261
+ 262
+ 263
+ 264
+ 265
+ 266
+ 267
+ 268
+ 269
+ 270
+ 271
+ 272
+ 273
+ 274
+ 275
+ 276
+ 277
+ 278
+ 279
+ 280
+ 281
+ 282
+ 283
+ 284
+ 285
+ 286
+ 287
+ 288
+ 289
+ 290
+ 291
+ 292
+ 293
+ 294
+ 295
+ 296
+ 297
+ 298
+ 299
+ 300
+ 301
+ 302
+ 303
+ 304
+ 305
+ 306
+ 307
+ 308
+ 309
+ 310
+ 311
+ 312
+ 313
+ 314
+ 315
+ 316
+ 317
+ 318
+ 319
+ 320
+ 321
+ 322
+ 323
+ 324
+ 325
+ 326
+ 327
+ 328
+ 329
+ 330
+ 331
+ 332
+ 333
+ 334
+ 335
+ 336
+ 337
+ 338
+ 339
+ 340
+ 341
+ 342
+ 343
+ 344
+ 345
+ 346
+ 347
+ 348
+ 349
+ 350
+ 351
+ 352
+ 353
+ 354
+ 355
+ 356
+ 357
+ 358
+ 359
+ 360
+ 361
+ 362
+ 363
+ 364
+ 365
+ 366
+ 367
+ 368
+ 369
+ 370
+ 371
+ 372
+ 373
+ 374
+ 375
+ 376
+ 377
+ 378
+ 379
+ 380
+ 381
+ 382
+ 383
+ 384
+ 385
+ 386
+ 387
+ 388
+ 389
+ 390
+ 391
+ 392
+ 393
+ 394
+ 395
+ 396
+ 397
+ 398
+ 399
+ 400
+ 401
+ 402
+ 403
+ 404
+ 405
+ 406
+ 407
+ 408
+ 409
+ 410
+ 411
+ 412
+ 413
+ 414
+ 415
+ 416
+ 417
+ 418
+ 419
+ 420
+ 421
+ 422
+ 423
+ 424
+ 425
+ 426
+ 427
+ 428
+ 429
+ 430
+ 431
+ 432
+ 433
+ 434
+ 435
+ 436
+ 437
+ 438
+ 439
+ 440
+ 441
+ 442
+ 443
+ 444
+ 445
+ 446
+ 447
+ 448
+ 449
+ 450
+ 451
+ 452
+ 453
+ 454
+ 455
+ 456
+ 457
+ 458
+ 459
+ 460
+ 461
+ 462
+ 463
+ 464
+ 465
+ 466
+ 467
+ 468
+ 469
+ 470
+ 471
+ 472
+ 473
+ 474
+ 475
+ 476
+ 477
+ 478
+ 479
+ 480
+ 481
+ 482
+ 483
+ 484
+ 485
+ 486
+ 487
+ 488
+ 489
+ 490
+ 491
+ 492
+ 493
+ 494
+ 495
+ 496
+ 497
+ 498
+ 499
+ 500
+ 501
+ 502
+ 503
+ 504
+ 505
+ 506
+ 507
+ 508
+ 509
+ 510
+ 511
+ 512
+ 513
+ 514
+ 515
+ 516
+ 517
+ 518
+ 519
+ 520
+ 521
+ 522
+ 523
+ 524
+ 525
+ 526
+ 527
+ 528
+ 529
+ 530
+ 531
+ 532
+ 533
+ 534
+ 535
+ 536
+ 537
+ 538
+ 539
+ 540
+ 541
+ 542
+ 543
+ 544
+ 545
+ 546
+ 547
+ 548
+ 549
+ 550
+ 551
+ 552
+ 553
+ 554
+ 555
+ 556
+ 557
+ 558
+ 559
+ 560
+ 561
+ 562
+ 563
+ 564
+ 565
+ 566
+ 567
+ 568
+ 569
+ 570
+ 571
+ 572
+ 573
+ 574
+ 575
+ 576
+ 577
+ 578
+ 579
+ 580
+ 581
+ 582
+ 583
+ 584
+ 585
+ 586
+ 587
+ 588
+ 589
+ 590
+ 591
+ 592
+ 593
+ 594
+ 595
+ 596
+ 597
+ 598
+ 599
+ 600
+ 601
+ 602
+ 603
+ 604
+ 605
+ 606
+ 607
+ 608
+ 609
+ 610
+ 611
+ 612
+ 613
+ 614
+ 615
+ 616
+ 617
+ 618
+ 619
+ 620
+ 621
+ 622
+ 623
+ 624
+ 625
+ 626
+ 627
+ 628
+ 629
+ 630
+ 631
+ 632
+ 633
+ 634
+ 635
+ 636
+ 637
+ 638
+ 639
+ 640
+ 641
+ 642
+ 643
+ 644
+ 645
+ 646
+ 647
+ 648
+ 649
+ 650
+ 651
+ 652
+ 653
+ 654
+ 655
+ 656
+ 657
+ 658
+ 659
+ 660
+ 661
+ 662
+ 663
+ 664
+ 665
+ 666
+ 667
+ 668
+ 669
+ 670
+ 671
+ 672
+ 673
+ 674
+ 675
+ 676
+ 677
+ 678
+ 679
+ 680
+ 681
+ 682
+ 683
+ 684
+ 685
+ 686
+ 687
+ 688
+ 689
+ 690
+ 691
+ 692
+ 693
+ 694
+ 695
+ 696
+ 697
+ 698
+ 699
+ 700
+ 701
+ 702
+ 703
+ 704
+ 705
+ 706
+ 707
+ 708
+ 709
+ 710
+ 711
+ 712
+ 713
+ 714
+ 715
+ 716
+ 717
+ 718
+ 719
+ 720
+ 721
+ 722
+ 723
+ 724
+ 725
+ 726
+ 727
+ 728
+ 729
+ 730
+ 731
+ 732
+ 733
+ 734
+ 735
+ 736
+ 737
+ 738
+ 739
+ 740
+ 741
+ 742
+ 743
+ 744
+ 745
+ 746
+ 747
+ 748
+ 749
+ 750
+ 751
+ 752
+ 753
+ 754
+ 755
+ 756
+ 757
+ 758
+ 759
+ 760
+ 761
+ 762
+ 763
+ 764
+ 765
+ 766
+ 767
+ 768
+ 769
+ 770
+ 771
+ 772
+ 773
+ 774
+ 775
+ 776
+ 777
+ 778
+ 779
+ 780
+ 781
+ 782
+ 783
+ 784
+ 785
+ 786
+ 787
+ 788
+ 789
+ 790
+ 791
+ 792
+ 793
+ 794
+ 795
+ 796
+ 797
+ 798
+ 799
+ 800
+ 801
+ 802
+ 803
+ 804
+ 805
+ 806
+ 807
+ 808
+ 809
+ 810
+ 811
+ 812
+ 813
+ 814
+ 815
+ 816
+ 817
+ 818
+ 819
+ 820
+ 821
+ 822
+ 823
+ 824
+ 825
+ 826
+ 827
+ 828
+ 829
+ 830
+ 831
+ 832
+ 833
+ 834
+ 835
+ 836
+ 837
+ 838
+ 839
+ 840
+ 841
+ 842
+ 843
+ 844
+ 845
+ 846
+ 847
+ 848
+ 849
+ 850
+ 851
+ 852
+ 853
+ 854
+ 855
+ 856
+ 857
+ 858
+ 859
+ 860
+ 861
+ 862
+ 863
+ 864
+ 865
+ 866
+ 867
+ 868
+ 869
+ 870
+ 871
+ 872
+ 873
+ 874
+ 875
+ 876
+ 877
+ 878
+ 879
+ 880
+ 881
+ 882
+ 883
+ 884
+ 885
+ 886
+ 887
+ 888
+ 889
+ 890
+ 891
+ 892
+ 893
+ 894
+ 895
+ 896
+ 897
+ 898
+ 899
+ 900
+ 901
+ 902
+ 903
+ 904
+ 905
+ 906
+ 907
+ 908
+ 909
+ 910
+ 911
+ 912
+ 913
+ 914
+ 915
+ 916
+ 917
+ 918
+ 919
+ 920
+ 921
+ 922
+ 923
+ 924
+ 925
+ 926
+ 927
+ 928
+ 929
+ 930
+ 931
+ 932
+ 933
+ 934
+ 935
+ 936
+ 937
+ 938
+ 939
+ 940
+ 941
+ 942
+ 943
+ 944
+ 945
+ 946
+ 947
+ 948
+ 949
+ 950
+ 951
+ 952
+ 953
+ 954
+ 955
+ 956
+ 957
+ 958
+ 959
+ 960
+ 961
+ 962
+ 963
+ 964
+ 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
+1001
+1002
+1003
+1004
+1005
+1006
+1007
+1008
+1009
+1010
+1011
+1012
+1013
+1014
+1015
+1016
+1017
+1018
+1019
+1020
+1021
+1022
+1023
+1024
+1025
+1026
+1027
+1028
+1029
+1030
+1031
+1032
+1033
+1034
+1035
+1036
+1037
+1038
+1039
+1040
+1041
+1042
+1043
+1044
+1045
+1046
+1047
+1048
+1049
+1050
+1051
+1052
+1053
+1054
+1055
+1056
+1057
+1058
+1059
+1060
+1061
+1062
+1063
+1064
+1065
+1066
+1067
+1068
+1069
+1070
+1071
+1072
+1073
+1074
+1075
+1076
+1077
+1078
+1079
+1080
+1081
+1082
+1083
+1084
+1085
+1086
+1087
+1088
+1089
+1090
+1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
+1109
+1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
+1151
+1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
+1193
+1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
+1221
+1222
+1223
+1224
+1225
+1226
+1227
+1228
+1229
+1230
+1231
+1232
+1233
+1234
+1235
+1236
+1237
+1238
+1239
+1240
+1241
+1242
+1243
+1244
+1245
+1246
+1247
+1248
+1249
+1250
+1251
+1252
+1253
+1254
+1255
+1256
+1257
+1258
+1259
+1260
+1261
+1262
+1263
+1264
+1265
+1266
+1267
+1268
+1269
+1270
+1271
+1272
+1273
+1274
+1275
+1276
+1277
+1278
+1279
+1280
+1281
+1282
+1283
+1284
+1285
+1286
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1294
+1295
+1296
+1297
+1298
+1299
+1300
+1301
+1302
+1303
+1304
+1305
+1306
+1307
+1308
+1309
+1310
+1311
+1312
+1313
+1314
+1315
+1316
+1317
+1318
+1319
+1320
+1321
+1322
+1323
+1324
+1325
+1326
+1327
+1328
+1329
+1330
+1331
+1332
+1333
+1334
+1335
+1336
+1337
+1338
+1339
+1340
+1341
+1342
+1343
+1344
+1345
+1346
+1347
+1348
+1349
+1350
+1351
+1352
+1353
+1354
+1355
+1356
+1357
+1358
+1359
+1360
+1361
+1362
+1363
+1364
+1365
+1366
+1367
+1368
+1369
+1370
+1371
+1372
+1373
+1374
+1375
+1376
+1377
+1378
+1379
+1380
+1381
+1382
+1383
+1384
+1385
+1386
+1387
+1388
+1389
+1390
+1391
+1392
+1393
+1394
+1395
+1396
+1397
+1398
+1399
+1400
+1401
+1402
+1403
+1404
+1405
+1406
+1407
+1408
+1409
+1410
+1411
+1412
+1413
+1414
+1415
+1416
+1417
+1418
+1419
+1420
+1421
+1422
+1423
+1424
+1425
+1426
+1427
+1428
+1429
+1430
+1431
+1432
+1433
+1434
+1435
+1436
+1437
+1438
+1439
+1440
+1441
+1442
+1443
+1444
+1445
+1446
+1447
+1448
+1449
+1450
+1451
+1452
+1453
+1454
+1455
+1456
+1457
+1458
+1459
+1460
+1461
+1462
+1463
+1464
+1465
+1466
+1467
+1468
+1469
+1470
+1471
+1472
+1473
+1474
+1475
+1476
+1477
+1478
+1479
+1480
+1481
+1482
+1483
+1484
+1485
+1486
+1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
+1499
+1500
+1501
+1502
+1503
+1504
+1505
+1506
+1507
+1508
+1509
+1510
+1511
+1512
+1513
+1514
+1515
+1516
+1517
+1518
+1519
+1520
+1521
+1522
+1523
+1524
+1525
+1526
+1527
+1528
+1529
+1530
+1531
+1532
+1533
+1534
+1535
+1536
+1537
+1538
+1539
+1540
+1541
+1542
+1543
+1544
+1545
+1546
+1547
+1548
+1549
+1550
+1551
+1552
+1553
+1554
+1555
+1556
+1557
+1558
+1559
+1560
+1561
+1562
+1563
+1564
+1565
+1566
+1567
+1568
+1569
+1570
+1571
+1572
+1573
+1574
+1575
+1576
+1577
+1578
+1579
+1580
+1581
+1582
+1583
+1584
+1585
+1586
+1587
+1588
+1589
+1590
+1591
+1592
+1593
+1594
+1595
+1596
+1597
+1598
+1599
+1600
+1601
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
+1610
+1611
+1612
+1613
+1614
+1615
+1616
+1617
+1618
+1619
+1620
+1621
+1622
+1623
+1624
+1625
+1626
+1627
+1628
+1629
+1630
+1631
+1632
+1633
+1634
+1635
+1636
+1637
+1638
+1639
+1640
+1641
+1642
+1643
+1644
+1645
+1646
+1647
+1648
+1649
+1650
+1651
+1652
+1653
+1654
+1655
+1656
+1657
+1658
+1659
+1660
+1661
+1662
+1663
+1664
+1665
+1666
+1667
+1668
+1669
+1670
+1671
+1672
+1673
+1674
+1675
+1676
+1677
+1678
+1679
+1680
+1681
+1682
+1683
+1684
+1685
+1686
+1687
+1688
+1689
+1690
+1691
+1692
+1693
+1694
+1695
+1696
+1697
+1698
+1699
+1700
+1701
+1702
+1703
+1704
+1705
+1706
+1707
+1708
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
+1733
+1734
+1735
+1736
+1737
+1738
+1739
+1740
+1741
+1742
+1743
+1744
+1745
+1746
+1747
+1748
+1749
+1750
+1751
+1752
+1753
+1754
+1755
+1756
+1757
+1758
+1759
+1760
+1761
+1762
+1763
+1764
+1765
+1766
+1767
+1768
+1769
+1770
+1771
+1772
+1773
+1774
+1775
+1776
+1777
+1778
+1779
+1780
+1781
+1782
+1783
+1784
+1785
+1786
+1787
+1788
+1789
+1790
+1791
+1792
+1793
+1794
+1795
+1796
+1797
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
+1822
+1823
+1824
+1825
+1826
+1827
+1828
+1829
+1830
+1831
+1832
+1833
+1834
+1835
+1836
+1837
+1838
+1839
+1840
+1841
+1842
+1843
+1844
+1845
+1846
+1847
+1848
+1849
+1850
+1851
+1852
+1853
+1854
+1855
+1856
+1857
+1858
+1859
+1860
+1861
+1862
+1863
+1864
+1865
+1866
+1867
+1868
+1869
+1870
+1871
+1872
+1873
+1874
+1875
+1876
+1877
+1878
+1879
+1880
+1881
+1882
+1883
+1884
+1885
+1886
+1887
+1888
+1889
+1890
+1891
+1892
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
+1917
+1918
+1919
+1920
+1921
+1922
+1923
+1924
+1925
+1926
+1927
+1928
+1929
+1930
+1931
+1932
+1933
+1934
+1935
+1936
+1937
+1938
+1939
+1940
+1941
+1942
+1943
+1944
+1945
+1946
+1947
+1948
+1949
+1950
+1951
+1952
+1953
+1954
+1955
+1956
+1957
+1958
+1959
+1960
+1961
+1962
+1963
+1964
+1965
+1966
+1967
+1968
+1969
+1970
+1971
+1972
+1973
+1974
+1975
+1976
+1977
+1978
+1979
+1980
+1981
+1982
+1983
+1984
+1985
+1986
+1987
+1988
+1989
+1990
+1991
+1992
+1993
+1994
+1995
+1996
+1997
+1998
+1999
+2000
+2001
+2002
+2003
+2004
+2005
+2006
+2007
+2008
+2009
+2010
+2011
+2012
+2013
+2014
+2015
+2016
+2017
+2018
+2019
+2020
+2021
+2022
+2023
+2024
+2025
+2026
+2027
+2028
+2029
+2030
+2031
+2032
+2033
+2034
+2035
+2036
+2037
+2038
+2039
+2040
+2041
+2042
+2043
+2044
+2045
+2046
+2047
+2048
+2049
+2050
+2051
+2052
+2053
+2054
+2055
+2056
+2057
+2058
+2059
+2060
+2061
+2062
+2063
+2064
+2065
+2066
+2067
+2068
+2069
+2070
+2071
+2072
+2073
+2074
+2075
+2076
+2077
+2078
+2079
+2080
+2081
+2082
+2083
+2084
+2085
+2086
+2087
+2088
+2089
+2090
+2091
+2092
+2093
+2094
+2095
+2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
+2127
+2128
+2129
+2130
+2131
+2132
+2133
+2134
+2135
+2136
+2137
+2138
+2139
+2140
+2141
+2142
+2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
+2153
+2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
+2165
+2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
+2177
+2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
+2188
+2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
+2206
+2207
+2208
+2209
+2210
+2211
+2212
+2213
+2214
+2215
+2216
+2217
+2218
+2219
+2220
+2221
+2222
+2223
+2224
+2225
+2226
+2227
+2228
+2229
+2230
+2231
+2232
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
+2244
+2245
+2246
+2247
+2248
+2249
+2250
+2251
+2252
+2253
+2254
+2255
+2256
+2257
+2258
+2259
+2260
+2261
+2262
+2263
+2264
+2265
+2266
+2267
+2268
+2269
+2270
+2271
+2272
+2273
+2274
+2275
+2276
+2277
+2278
+2279
+2280
+2281
+2282
+2283
+2284
+2285
+2286
+2287
+2288
+2289
+2290
+2291
+2292
+2293
+2294
+2295
+2296
+2297
+2298
+2299
+2300
+2301
+2302
+2303
+2304
+2305
+2306
+2307
+2308
+2309
+2310
+2311
+2312
+2313
+2314
+2315
+2316
+2317
+2318
+2319
+2320
+2321
+2322
+2323
+2324
+2325
+2326
+2327
+2328
+2329
+2330
+2331
+2332
+2333
+2334
+2335
+2336
+2337
+2338
+2339
+2340
+2341
+2342
+2343
+2344
+2345
+2346
+2347
+2348
+2349
+2350
+2351
+2352
+2353
+2354
+2355
+2356
+2357
+2358
+2359
+2360
+2361
+2362
+2363
+2364
+2365
+2366
+2367
+2368
+2369
+2370
+2371
+2372
+2373
+2374
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+2396
+2397
+2398
+2399
+2400
+2401
+2402
+2403
+2404
+2405
+2406
+2407
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+2417
+2418
+2419
+2420
+2421
+2422
+2423
+2424
+2425
+2426
+2427
+2428
+2429
+2430
+2431
+2432
+2433
+2434
+2435
+2436
+2437
+2438
+2439
+2440
+2441
+2442
+2443
+2444
+2445
+2446
+2447
+2448
+2449
+2450
+2451
+2452
+2453
+2454
+2455
+2456
+2457
+2458
+2459
+2460
+2461
+2462
+2463
+2464
+2465
+2466
+2467
+2468
+2469
+2470
+2471
+2472
+2473
+2474
+2475
+2476
+2477
+2478
+2479
+2480
+2481
+2482
+2483
+2484
+2485
+2486
+2487
+2488
+2489
+2490
+2491
+2492
+2493
+2494
+2495
+2496
+2497
+2498
+2499
+2500
+2501
+2502
+2503
+2504
+2505
+2506
+2507
+2508
+2509
+2510
+2511
+2512
+2513
+2514
+2515
+2516
+2517
+2518
+2519
+2520
+2521
+2522
+2523
+2524
+2525
+2526
+2527
+2528
+2529
+2530
+2531
+2532
+2533
+2534
+2535
+2536
+2537
+2538
+2539
+2540
+2541
+2542
+2543
+2544
+2545
+2546
+2547
+2548
+2549
+2550
+2551
+2552
+2553
+2554
+2555
+2556
+2557
+2558
+2559
+2560
+2561
+2562
+2563
+2564
+2565
+2566
+2567
+2568
+2569
+2570
+2571
+2572
+2573
+2574
+2575
+2576
+2577
+2578
+2579
+2580
+2581
+2582
+2583
+2584
+2585
+2586
+2587
+2588
+2589
+2590
+2591
+2592
+2593
+2594
+2595
+2596
+2597
+2598
+2599
+2600
+2601
+2602
+2603
+2604
+2605
+2606
+2607
+2608
+2609
+2610
+2611
+2612
+2613
+2614
+2615
+2616
+2617
+2618
+2619
+2620
+2621
+2622
+2623
+2624
+2625
+2626
+2627
+2628
+2629
class TelemetrixUnoR4WiFiAio:
+    """
+    This class exposes and implements the TelemetrixUnoR4WifiAio API.
+    It includes the public API methods as well as
+    a set of private methods. This is an asyncio API.
+
+    """
+
+    # noinspection PyPep8,PyPep8
+    def __init__(self, com_port=None,
+                 arduino_instance_id=1, arduino_wait=1,
+                 sleep_tune=0.0001, autostart=True,
+                 loop=None, shutdown_on_exception=True,
+                 close_loop_on_shutdown=True, hard_reset_on_shutdown=True,
+                 transport_address=None, ip_port=31336, transport_type=0,
+                 ble_device_name='Telemetrix4UnoR4 BLE'):
+
+        """
+        If you have a single Arduino connected to your computer,
+        then you may accept all the default values.
+
+        Otherwise, specify a unique arduino_instance id for each board in use.
+
+        :param com_port: e.g. COM3 or /dev/ttyACM0.
+
+        :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+
+        :param arduino_wait: Amount of time to wait for an Arduino to
+                             fully reset itself.
+
+        :param sleep_tune: A tuning parameter (typically not changed by user)
+
+        :param autostart: If you wish to call the start method within
+                          your application, then set this to False.
+
+        :param loop: optional user provided event loop
+
+        :param shutdown_on_exception: call shutdown before raising
+                                      a RunTimeError exception, or
+                                      receiving a KeyboardInterrupt exception
+
+        :param close_loop_on_shutdown: stop and close the event loop loop
+                                       when a shutdown is called or a serial
+                                       error occurs
+
+       :param hard_reset_on_shutdown: reset the board on shutdown
+
+       :param transport_address: ip address of tcp/ip connected device.
+
+        :param ip_port: ip port of tcp/ip connected device
+
+        :param transport_type: 0 = WiFi
+                               1 = SerialUSB
+                               2 = BLE
+
+       :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.
+                               It must match that of Telemetrix4UnoR4BLE.ino
+
+        """
+        # check to make sure that Python interpreter is version 3.8.3 or greater
+        python_version = sys.version_info
+        if python_version[0] >= 3:
+            if python_version[1] >= 8:
+                if python_version[2] >= 3:
+                    pass
+            else:
+                raise RuntimeError("ERROR: Python 3.7 or greater is "
+                                   "required for use of this program.")
+
+        # save input parameters
+        self.com_port = com_port
+        self.arduino_instance_id = arduino_instance_id
+        self.arduino_wait = arduino_wait
+        self.sleep_tune = sleep_tune
+        self.autostart = autostart
+        self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+        self.transport_address = transport_address
+        self.ip_port = ip_port
+        if transport_type not in [0, 1, 2]:
+            raise RuntimeError('Invalid transport type')
+        self.transport_type = transport_type
+        self.firmware_version = None
+        # if tcp, this variable is set to the connected socket
+        self.sock = None
+
+        self.ble_device_name = ble_device_name
+
+        # instance of telemetrix_aio_ble
+        self.ble_instance = None
+
+        # set the event loop
+        if loop is None:
+            self.loop = asyncio.get_event_loop()
+        else:
+            self.loop = loop
+
+        self.shutdown_on_exception = shutdown_on_exception
+        self.close_loop_on_shutdown = close_loop_on_shutdown
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        # debug loopback callback method
+        self.loop_back_callback = None
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        self.dht_count = 0
+
+        # serial port in use
+        self.serial_port = None
+
+        # generic asyncio task holder
+        self.the_task = None
+
+        # flag to indicate we are in shutdown mode
+        self.shutdown_flag = False
+
+        self.report_dispatch = {}
+
+        # reported features
+        self.reported_features = 0
+
+        # To add a command to the command dispatch table, append here.
+        self.report_dispatch.update(
+            {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+        self.report_dispatch.update(
+            {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+        self.report_dispatch.update(
+            {PrivateConstants.ANALOG_REPORT: self._analog_message})
+        self.report_dispatch.update(
+            {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+        self.report_dispatch.update(
+            {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+        self.report_dispatch.update(
+            {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+        self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+        self.report_dispatch.update(
+            {PrivateConstants.SPI_REPORT: self._spi_report})
+        self.report_dispatch.update(
+            {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_CURRENT_POSITION:
+                 self._stepper_current_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUNNING_REPORT:
+                 self._stepper_is_running_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+                 self._stepper_run_complete_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+                 self._stepper_distance_to_go_report})
+        self.report_dispatch.update(
+            {PrivateConstants.STEPPER_TARGET_POSITION:
+                 self._stepper_target_position_report})
+        self.report_dispatch.update(
+            {PrivateConstants.FEATURES:
+                 self._features_report})
+
+        # dictionaries to store the callbacks for each pin
+        self.analog_callbacks = {}
+
+        self.digital_callbacks = {}
+
+        self.i2c_callback = None
+        self.i2c_callback2 = None
+
+        self.i2c_1_active = False
+        self.i2c_2_active = False
+
+        self.spi_callback = None
+
+        self.onewire_callback = None
+
+        self.cs_pins_enabled = []
+
+        # flag to indicate if spi is initialized
+        self.spi_enabled = False
+
+        # flag to indicate if onewire is initialized
+        self.onewire_enabled = False
+
+        # the trigger pin will be the key to retrieve
+        # the callback for a specific HC-SR04
+        self.sonar_callbacks = {}
+
+        self.sonar_count = 0
+
+        self.dht_callbacks = {}
+
+        # # stepper motor variables
+        #
+        # # updated when a new motor is added
+        # self.next_stepper_assigned = 0
+        #
+        # # valid list of stepper motor interface types
+        # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+        #
+        # # maximum number of steppers supported
+        # self.max_number_of_steppers = 4
+        #
+        # # number of steppers created - not to exceed the maximum
+        # self.number_of_steppers = 0
+        #
+        # # dictionary to hold stepper motor information
+        # self.stepper_info = {'instance': False, 'is_running': None,
+        #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+        #                      'distance_to_go_callback': None,
+        #                      'target_position_callback': None,
+        #                      'current_position_callback': None,
+        #                      'is_running_callback': None,
+        #                      'motion_complete_callback': None,
+        #                      'acceleration_callback': None}
+        #
+        # # build a list of stepper motor info items
+        # self.stepper_info_list = []
+        # # a list of dictionaries to hold stepper information
+        # for motor in range(self.max_number_of_steppers):
+        #     self.stepper_info_list.append(self.stepper_info)
+
+        print(f'telemetrix_uno_r4_wifi_aio Version:'
+              f' {PrivateConstants.TELEMETRIX_VERSION}')
+        print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\n')
+
+        if autostart:
+            self.loop.run_until_complete(self.start_aio())
+
+    async def start_aio(self):
+        """
+        This method may be called directly, if the autostart
+        parameter in __init__ is set to false.
+
+        This method instantiates the serial interface and then performs auto pin
+        discovery if using a serial interface, or creates and connects to
+        a TCP/IP enabled device running StandardFirmataWiFi.
+
+        Use this method if you wish to start TelemetrixAIO manually from
+        an asyncio function.
+         """
+
+        if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:
+            if not self.com_port:
+                # user did not specify a com_port
+                try:
+                    await self._find_arduino()
+                except KeyboardInterrupt:
+                    if self.shutdown_on_exception:
+                        await self.shutdown()
+            else:
+                # com_port specified - set com_port and baud rate
+                try:
+                    await self._manual_open()
+                except KeyboardInterrupt:
+                    if self.shutdown_on_exception:
+                        await self.shutdown()
+
+            if self.com_port:
+                print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')
+
+                # no com_port found - raise a runtime exception
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('No Arduino Found or User Aborted Program')
+            await self.disable_scroll_message()
+            # using tcp/ip
+        elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:
+            self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)
+            await self.sock.start()
+        else:  # ble
+            self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)
+            await self.ble_instance.connect()
+
+        # get arduino firmware version and print it
+        firmware_version = await self._get_firmware_version()
+        if not firmware_version:
+            print('*** Firmware Version retrieval timed out. ***')
+            print('\nDo you have Arduino connectivity and do you have the ')
+            print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')
+            print('to the correct serial port.\n')
+            print('To see a list of serial ports, type: '
+                  '"list_serial_ports" in your console.')
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError
+        else:
+
+            print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'
+                  f'{firmware_version[3]}.{firmware_version[4]}')
+            # start the command dispatcher loop
+            command = [PrivateConstants.ENABLE_ALL_REPORTS]
+            await self._send_command(command)
+            if not self.loop:
+                self.loop = asyncio.get_event_loop()
+            self.the_task = self.loop.create_task(self._arduino_report_dispatcher())
+
+            # get the features list
+            command = [PrivateConstants.GET_FEATURES]
+            await self._send_command(command)
+            await asyncio.sleep(.5)
+
+            # Have the server reset its data structures
+            command = [PrivateConstants.RESET]
+            await self._send_command(command)
+            await asyncio.sleep(.1)
+
+    async def get_event_loop(self):
+        """
+        Return the currently active asyncio event loop
+
+        :return: Active event loop
+
+        """
+        return self.loop
+
+    async def _find_arduino(self):
+        """
+        This method will search all potential serial ports for an Arduino
+        containing a sketch that has a matching arduino_instance_id as
+        specified in the input parameters of this class.
+
+        This is used explicitly with the FirmataExpress sketch.
+        """
+
+        # a list of serial ports to be checked
+        serial_ports = []
+
+        print('Opening all potential serial ports...')
+        the_ports_list = list_ports.comports()
+        for port in the_ports_list:
+            if port.pid is None:
+                continue
+            print('\nChecking {}'.format(port.device))
+            try:
+                self.serial_port = TelemetrixAioSerial(port.device, 115200,
+                                                       telemetrix_aio_instance=self,
+                                                       close_loop_on_error=self.close_loop_on_shutdown)
+            except SerialException:
+                continue
+            # create a list of serial ports that we opened
+            serial_ports.append(self.serial_port)
+
+            # display to the user
+            print('\t' + port.device)
+
+            # clear out any possible data in the input buffer
+            await self.serial_port.reset_input_buffer()
+
+        # wait for arduino to reset
+        print('\nWaiting {} seconds(arduino_wait) for Arduino devices to '
+              'reset...'.format(self.arduino_wait))
+        await asyncio.sleep(self.arduino_wait)
+
+        print('\nSearching for an Arduino configured with an arduino_instance = ',
+              self.arduino_instance_id)
+
+        for serial_port in serial_ports:
+            self.serial_port = serial_port
+
+            command = [PrivateConstants.ARE_U_THERE]
+            await self._send_command(command)
+            # provide time for the reply
+            await asyncio.sleep(.1)
+
+            i_am_here = await self.serial_port.read(3)
+
+            if not i_am_here:
+                continue
+
+            # got an I am here message - is it the correct ID?
+            if i_am_here[2] == self.arduino_instance_id:
+                self.com_port = serial_port.com_port
+                return
+
+    async def _manual_open(self):
+        """
+        Com port was specified by the user - try to open up that port
+
+        """
+        # if port is not found, a serial exception will be thrown
+        print('Opening {} ...'.format(self.com_port))
+        self.serial_port = TelemetrixAioSerial(self.com_port, 115200,
+                                               telemetrix_aio_instance=self,
+                                               close_loop_on_error=self.close_loop_on_shutdown)
+
+        print('Waiting {} seconds for the Arduino To Reset.'
+              .format(self.arduino_wait))
+        await asyncio.sleep(self.arduino_wait)
+        command = [PrivateConstants.ARE_U_THERE]
+        await self._send_command(command)
+        # provide time for the reply
+        await asyncio.sleep(.1)
+
+        print(f'Searching for correct arduino_instance_id: {self.arduino_instance_id}')
+        i_am_here = await self.serial_port.read(3)
+
+        if not i_am_here:
+            print(f'ERROR: correct arduino_instance_id not found')
+
+        print('Correct arduino_instance_id found')
+
+    async def _get_firmware_version(self):
+        """
+        This method retrieves the Arduino4Telemetrix firmware version
+
+        :returns: Firmata firmware version
+        """
+        self.firmware_version = None
+        command = [PrivateConstants.GET_FIRMWARE_VERSION]
+        await self._send_command(command)
+        # provide time for the reply
+        await asyncio.sleep(.3)
+        if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:
+            self.firmware_version = await self.serial_port.read(5)
+        elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:
+            self.firmware_version = list(await self.sock.read(5))
+        else:
+            pass
+        return self.firmware_version
+
+    async def analog_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (maximum 16 bits)
+
+        """
+        value_msb = value >> 8
+        value_lsb = value & 0xff
+        command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+        await self._send_command(command)
+
+    async def digital_write(self, pin, value):
+        """
+        Set the specified pin to the specified value.
+
+        :param pin: arduino pin number
+
+        :param value: pin value (1 or 0)
+
+        """
+        command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+        await self._send_command(command)
+
+    async def i2c_read(self, address, register, number_of_bytes,
+                       callback, i2c_port=0,
+                       write_register=True):
+        """
+        Read the specified number of bytes from the specified register for
+        the i2c device.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command
+
+        :param i2c_port: select the default port (0) or secondary port (1)
+
+        :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('i2c_read: A Callback must be specified')
+
+        await self._i2c_read_request(address, register, number_of_bytes,
+                                     callback=callback, i2c_port=i2c_port,
+                                     write_register=write_register)
+
+    async def i2c_read_restart_transmission(self, address, register,
+                                            number_of_bytes,
+                                            callback, i2c_port=0,
+                                            write_register=True):
+        """
+        Read the specified number of bytes from the specified register for
+        the i2c device. This restarts the transmission after the read. It is
+        required for some i2c devices such as the MMA8452Q accelerometer.
+
+
+        :param address: i2c device address
+
+        :param register: i2c register (or None if no register
+                                                    selection is needed)
+
+        :param number_of_bytes: number of bytes to be read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command
+
+        :param i2c_port: select the default port (0) or secondary port (1)
+
+        :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+        callback returns a data list:
+
+        [I2C_READ_REPORT, address, register, count of data bytes,
+         data bytes, time-stamp]
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'i2c_read_restart_transmission: A Callback must be specified')
+
+        await self._i2c_read_request(address, register, number_of_bytes,
+                                     stop_transmission=False,
+                                     callback=callback, i2c_port=i2c_port,
+                                     write_register=write_register)
+
+    async def _i2c_read_request(self, address, register, number_of_bytes,
+                                stop_transmission=True, callback=None,
+                                i2c_port=0, write_register=True):
+        """
+        This method requests the read of an i2c device. Results are retrieved
+        via callback.
+
+        :param address: i2c device address
+
+        :param register: register number (or None if no register selection is needed)
+
+        :param number_of_bytes: number of bytes expected to be returned
+
+        :param stop_transmission: stop transmission after read
+
+        :param callback: Required callback function to report i2c data as a
+                   result of read command.
+
+       :param i2c_port: select the default port (0) or secondary port (1)
+
+       :param write_register: If True, the register is written
+                                       before read
+                              Else, the write is suppressed
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Read: set_pin_mode i2c never called for i2c port 2.')
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('I2C Read: A callback function must be specified.')
+
+        if not i2c_port:
+            self.i2c_callback = callback
+        else:
+            self.i2c_callback2 = callback
+
+        if not register:
+            register = 0
+
+        if write_register:
+            write_register = 1
+        else:
+            write_register = 0
+
+        # message contains:
+        # 1. address
+        # 2. register
+        # 3. number of bytes
+        # 4. restart_transmission - True or False
+        # 5. i2c port
+        # 6. suppress write flag
+
+        command = [PrivateConstants.I2C_READ, address, register, number_of_bytes,
+                   stop_transmission, i2c_port, write_register]
+        await self._send_command(command)
+
+    async def i2c_write(self, address, args, i2c_port=0):
+        """
+        Write data to an i2c device.
+
+        :param address: i2c device address
+
+        :param i2c_port: 0= port 1, 1 = port 2
+
+        :param args: A variable number of bytes to be sent to the device
+                     passed in as a list
+
+        """
+        if not i2c_port:
+            if not self.i2c_1_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+        if i2c_port:
+            if not self.i2c_2_active:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+        command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+        for item in args:
+            command.append(item)
+
+        await self._send_command(command)
+
+    async def loop_back(self, start_character, callback):
+        """
+        This is a debugging method to send a character to the
+        Arduino device, and have the device loop it back.
+
+        :param start_character: The character to loop back. It should be
+                                an integer.
+
+        :param callback: Looped back character will appear in the callback method
+
+        """
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('loop_back: A callback function must be specified.')
+        command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+        self.loop_back_callback = callback
+        await self._send_command(command)
+
+    async def set_analog_scan_interval(self, interval):
+        """
+        Set the analog scanning interval.
+
+        :param interval: value of 0 - 255 - milliseconds
+        """
+
+        if 0 <= interval <= 255:
+            command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('Analog interval must be between 0 and 255')
+
+    async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+        """
+        Set a pin as an analog input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        :param differential: difference in previous to current value before
+                             report will be generated
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for analog input pins = 3
+
+        """
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'set_pin_mode_analog_input: A callback function must be specified.')
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,
+                                 differential, callback=callback)
+
+    async def set_pin_mode_analog_output(self, pin_number):
+        """
+
+        Set a pin as a pwm (analog output) pin.
+
+        :param pin_number:arduino pin number
+
+        """
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                                 callback=None)
+
+    async def set_pin_mode_digital_input(self, pin_number, callback):
+        """
+        Set a pin as a digital input.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,
+                                 callback=callback)
+
+    async def set_pin_mode_digital_input_pullup(self, pin_number, callback):
+        """
+        Set a pin as a digital input with pullup enabled.
+
+        :param pin_number: arduino pin number
+
+        :param callback: async callback function
+
+        callback returns a data list:
+
+        [pin_type, pin_number, pin_value, raw_time_stamp]
+
+        The pin_type for all digital input pins = 2
+
+        """
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'set_pin_mode_digital_input_pullup: A callback function must be specified.')
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                                 differential=0, callback=callback)
+
+    async def set_pin_mode_digital_output(self, pin_number):
+        """
+        Set a pin as a digital output pin.
+
+        :param pin_number: arduino pin number
+        """
+
+        await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                                 callback=None)
+
+    # noinspection PyIncorrectDocstring
+    async def set_pin_mode_i2c(self, i2c_port=0):
+        """
+        Establish the standard Arduino i2c pins for i2c utilization.
+
+        :param i2c_port: 0 = i2c1, 1 = i2c2
+
+        NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+               2. Callbacks are set within the individual i2c read methods of this
+              API.
+
+              See i2c_read, or i2c_read_restart_transmission.
+
+        """
+        # test for i2c port 2
+        if i2c_port:
+            # if not previously activated set it to activated
+            # and the send a begin message for this port
+            if not self.i2c_2_active:
+                self.i2c_2_active = True
+            else:
+                return
+        # port 1
+        else:
+            if not self.i2c_1_active:
+                self.i2c_1_active = True
+            else:
+                return
+
+        command = [PrivateConstants.I2C_BEGIN, i2c_port]
+        await self._send_command(command)
+
+    async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+        """
+
+        :param pin: connection pin
+
+        :param callback: callback function
+
+        :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+        Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+        Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+        Temperature,
+        Time]
+
+        """
+        if self.reported_features & PrivateConstants.DHT_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+            if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+                self.dht_callbacks[pin] = callback
+                self.dht_count += 1
+
+                if dht_type != 22 and dht_type != 11:
+                    dht_type = 22
+
+                command = [PrivateConstants.DHT_NEW, pin, dht_type]
+                await self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+    async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+        """
+
+        Attach a pin to a servo motor
+
+        :param pin_number: pin
+
+        :param min_pulse: minimum pulse width
+
+        :param max_pulse: maximum pulse width
+
+        """
+        if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+            minv = (min_pulse).to_bytes(2, byteorder="big")
+            maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+            command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                       minv[0], minv[1], maxv[0], maxv[1]]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+    async def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                                 callback):
+        """
+
+        :param trigger_pin:
+
+        :param echo_pin:
+
+        :param callback:  callback
+
+        """
+        if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+            if not callback:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+            if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+                self.sonar_callbacks[trigger_pin] = callback
+                self.sonar_count += 1
+
+                command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+                await self._send_command(command)
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError(
+                    f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+    async def set_pin_mode_spi(self, chip_select_list=None):
+        """
+        Specify the list of chip select pins.
+
+        Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+        Chip Select is any digital output capable pin.
+
+        :param chip_select_list: this is a list of pins to be used for chip select.
+                           The pins will be configured as output, and set to high
+                           ready to be used for chip select.
+                           NOTE: You must specify the chips select pins here!
+
+
+        command message: [command, number of cs pins, [cs pins...]]
+        """
+        if self.reported_features & PrivateConstants.SPI_FEATURE:
+
+            if type(chip_select_list) != list:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('chip_select_list must be in the form of a list')
+            if not chip_select_list:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('Chip select pins were not specified')
+
+            self.spi_enabled = True
+
+            command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+            for pin in chip_select_list:
+                command.append(pin)
+                self.cs_pins_enabled.append(pin)
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+    # async def set_pin_mode_stepper(self, interface=1, pin1=2, pin2=3, pin3=4,
+    #                          pin4=5, enable=True):
+    #     """
+    #     Stepper motor support is implemented as a proxy for the
+    #     the AccelStepper library for the Arduino.
+    #
+    #     This feature is compatible with the TB6600 Motor Driver
+    #
+    #     Note: It may not work for other driver types!
+    #
+    #     https://github.com/waspinator/AccelStepper
+    #
+    #     Instantiate a stepper motor.
+    #
+    #     Initialize the interface and pins for a stepper motor.
+    #
+    #     :param interface: Motor Interface Type:
+    #
+    #             1 = Stepper Driver, 2 driver pins required
+    #
+    #             2 = FULL2WIRE  2 wire stepper, 2 motor pins required
+    #
+    #             3 = FULL3WIRE 3 wire stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             4 = FULL4WIRE, 4 wire full stepper, 4 motor pins
+    #                 required
+    #
+    #             6 = HALF3WIRE, 3 wire half stepper, such as HDD spindle,
+    #                 3 motor pins required
+    #
+    #             8 = HALF4WIRE, 4 wire half stepper, 4 motor pins required
+    #
+    #     :param pin1: Arduino digital pin number for motor pin 1
+    #
+    #     :param pin2: Arduino digital pin number for motor pin 2
+    #
+    #     :param pin3: Arduino digital pin number for motor pin 3
+    #
+    #     :param pin4: Arduino digital pin number for motor pin 4
+    #
+    #     :param enable: If this is true, the output pins at construction time.
+    #
+    #     :return: Motor Reference number
+    #     """
+    #     if self.reported_features & PrivateConstants.STEPPERS_FEATURE:
+    #
+    #         if self.number_of_steppers == self.max_number_of_steppers:
+    #             if self.shutdown_on_exception:
+    #                 await self.shutdown()
+    #             raise RuntimeError('Maximum number of steppers has already been assigned')
+    #
+    #         if interface not in self.valid_stepper_interfaces:
+    #             if self.shutdown_on_exception:
+    #                 await self.shutdown()
+    #             raise RuntimeError('Invalid stepper interface')
+    #
+    #         self.number_of_steppers += 1
+    #
+    #         motor_id = self.next_stepper_assigned
+    #         self.next_stepper_assigned += 1
+    #         self.stepper_info_list[motor_id]['instance'] = True
+    #
+    #         # build message and send message to server
+    #         command = [PrivateConstants.SET_PIN_MODE_STEPPER, motor_id, interface, pin1,
+    #                    pin2, pin3, pin4, enable]
+    #         await self._send_command(command)
+    #
+    #         # return motor id
+    #         return motor_id
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'The Stepper feature is disabled in the server.')
+
+    async def sonar_disable(self):
+        """
+        Disable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_DISABLE]
+        await self._send_command(command)
+
+    async def sonar_enable(self):
+        """
+        Enable sonar scanning for all sonar sensors
+        """
+        command = [PrivateConstants.SONAR_ENABLE]
+        await self._send_command(command)
+
+    async def spi_cs_control(self, chip_select_pin, select):
+        """
+        Control an SPI chip select line
+        :param chip_select_pin: pin connected to CS
+
+        :param select: 0=select, 1=deselect
+        """
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+        if chip_select_pin not in self.cs_pins_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+        command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+        await self._send_command(command)
+
+    async def spi_read_blocking(self, chip_select, register_selection,
+                                number_of_bytes_to_read,
+                          call_back=None):
+        """
+        Read the specified number of bytes from the specified SPI port and
+        call the callback function with the reported data.
+
+        :param chip_select: chip select pin
+
+        :param register_selection: Register to be selected for read.
+
+        :param number_of_bytes_to_read: Number of bytes to read
+
+        :param call_back: Required callback function to report spi data as a
+                   result of read command
+
+
+        callback returns a data list:
+            [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+             data bytes, time-stamp]
+        SPI_READ_REPORT = 13
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+        if not call_back:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+        self.spi_callback = call_back
+
+        command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+                   number_of_bytes_to_read,
+                   register_selection]
+
+        await self._send_command(command)
+
+    async def spi_set_format(self, clock_divisor, bit_order, data_mode):
+        """
+        Configure how the SPI serializes and de-serializes data on the wire.
+
+        See Arduino SPI reference materials for details.
+
+        :param clock_divisor: 1 - 255
+
+        :param bit_order:
+
+                            LSBFIRST = 0
+
+                            MSBFIRST = 1 (default)
+
+        :param data_mode:
+
+                            SPI_MODE0 = 0x00 (default)
+
+                            SPI_MODE1  = 1
+
+                            SPI_MODE2 = 2
+
+                            SPI_MODE3 = 3
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+        if not 0 < clock_divisor <= 255:
+            raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+        if bit_order not in [0, 1]:
+            raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+        if data_mode not in [0, 1, 2, 3]:
+            raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+        command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+                   data_mode]
+        await self._send_command(command)
+
+    async def spi_write_blocking(self, chip_select, bytes_to_write):
+        """
+        Write a list of bytes to the SPI device.
+
+        :param chip_select: chip select pin
+
+        :param bytes_to_write: A list of bytes to write. This must
+                                be in the form of a list.
+
+        """
+
+        if not self.spi_enabled:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+        if type(bytes_to_write) is not list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+        command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+        for data in bytes_to_write:
+            command.append(data)
+
+        await self._send_command(command)
+
+    # async def set_pin_mode_one_wire(self, pin):
+    #     """
+    #     Initialize the one wire serial bus.
+    #
+    #     :param pin: Data pin connected to the OneWire device
+    #     """
+    #     self.onewire_enabled = True
+    #     command = [PrivateConstants.ONE_WIRE_INIT, pin]
+    #     await self._send_command(command)
+    #
+    # async def onewire_reset(self, callback=None):
+    #     """
+    #     Reset the onewire device
+    #
+    #     :param callback: required  function to report reset result
+    #
+    #     callback returns a list:
+    #     [ReportType = 14, Report Subtype = 25, reset result byte,
+    #                     timestamp]
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_reset: OneWire interface is not enabled.')
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_reset: A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_RESET]
+    #     await self._send_command(command)
+    #
+    # async def onewire_select(self, device_address):
+    #     """
+    #     Select a device based on its address
+    #     :param device_address: A bytearray of 8 bytes
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_select: OneWire interface is not enabled.')
+    #
+    #     if type(device_address) is not list:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #
+    #     if len(device_address) != 8:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_select: device address must be an array of 8 '
+    #                            'bytes.')
+    #     command = [PrivateConstants.ONE_WIRE_SELECT]
+    #     for data in device_address:
+    #         command.append(data)
+    #     await self._send_command(command)
+    #
+    # async def onewire_skip(self):
+    #     """
+    #     Skip the device selection. This only works if you have a
+    #     single device, but you can avoid searching and use this to
+    #     immediately access your device.
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_skip: OneWire interface is not enabled.')
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SKIP]
+    #     await self._send_command(command)
+    #
+    # async def onewire_write(self, data, power=0):
+    #     """
+    #     Write a byte to the onewire device. If 'power' is one
+    #     then the wire is held high at the end for
+    #     parasitically powered devices. You
+    #     are responsible for eventually de-powering it by calling
+    #     another read or write.
+    #
+    #     :param data: byte to write.
+    #     :param power: power control (see above)
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_write: OneWire interface is not enabled.')
+    #     if 0 < data < 255:
+    #         command = [PrivateConstants.ONE_WIRE_WRITE, data, power]
+    #         await self._send_command(command)
+    #     else:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_write: Data must be no larger than 255')
+    #
+    # async def onewire_read(self, callback=None):
+    #     """
+    #     Read a byte from the onewire device
+    #     :param callback: required  function to report onewire data as a
+    #                result of read command
+    #
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_READ=29, data byte, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_read: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_READ]
+    #     await self._send_command(command)
+    #     await asynio.sleep(.2)
+    #
+    # async def onewire_reset_search(self):
+    #     """
+    #     Begin a new search. The next use of search will begin at the first device
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_reset_search: OneWire interface is not '
+    #                            f'enabled.')
+    #     else:
+    #         command = [PrivateConstants.ONE_WIRE_RESET_SEARCH]
+    #         await self._send_command(command)
+    #
+    # async def onewire_search(self, callback=None):
+    #     """
+    #     Search for the next device. The device address will returned in the callback.
+    #     If a device is found, the 8 byte address is contained in the callback.
+    #     If no more devices are found, the address returned contains all elements set
+    #     to 0xff.
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_SEARCH=31, 8 byte address, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #     """
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_search: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_read A Callback must be specified')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     command = [PrivateConstants.ONE_WIRE_SEARCH]
+    #     await self._send_command(command)
+    #
+    # async def onewire_crc8(self, address_list, callback=None):
+    #     """
+    #     Compute a CRC check on an array of data.
+    #     :param address_list:
+    #
+    #     :param callback: required  function to report a onewire device address
+    #
+    #     callback returns a data list:
+    #     [ONEWIRE_REPORT, ONEWIRE_CRC8=32, CRC, time-stamp]
+    #
+    #     ONEWIRE_REPORT = 14
+    #
+    #     """
+    #
+    #     if not self.onewire_enabled:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(f'onewire_crc8: OneWire interface is not enabled.')
+    #
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_crc8 A Callback must be specified')
+    #
+    #     if type(address_list) is not list:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('onewire_crc8: address list must be a list.')
+    #
+    #     self.onewire_callback = callback
+    #
+    #     address_length = len(address_list)
+    #
+    #     command = [PrivateConstants.ONE_WIRE_CRC8, address_length - 1]
+    #
+    #     for data in address_list:
+    #         command.append(data)
+    #
+    #     await self._send_command(command)
+
+    async def _set_pin_mode(self, pin_number, pin_state, differential, callback):
+        """
+        A private method to set the various pin modes.
+
+        :param pin_number: arduino pin number
+
+        :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use
+                          servo_config()
+                          For DHT   use: set_pin_mode_dht
+
+        :param differential: for analog inputs - threshold
+                             value to be achieved for report to
+                             be generated
+
+        :param callback: A reference to an async call back function to be
+                         called when pin data value changes
+
+        """
+        if not callback and pin_state != PrivateConstants.AT_OUTPUT:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('_set_pin_mode: A Callback must be specified')
+        else:
+            if pin_state == PrivateConstants.AT_INPUT:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_INPUT, 1]
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_INPUT_PULLUP:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_INPUT_PULLUP, 1]
+                self.digital_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_ANALOG:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_ANALOG,
+                           differential >> 8, differential & 0xff, 1]
+                self.analog_callbacks[pin_number] = callback
+            elif pin_state == PrivateConstants.AT_OUTPUT:
+                command = [PrivateConstants.SET_PIN_MODE, pin_number,
+                           PrivateConstants.AT_OUTPUT, 1]
+            else:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('Unknown pin state')
+
+        if command:
+            await self._send_command(command)
+
+        await asyncio.sleep(.05)
+
+    async def servo_detach(self, pin_number):
+        """
+        Detach a servo for reuse
+        :param pin_number: attached pin
+        """
+        command = [PrivateConstants.SERVO_DETACH, pin_number]
+        await self._send_command(command)
+
+    async def servo_write(self, pin_number, angle):
+        """
+
+        Set a servo attached to a pin to a given angle.
+
+        :param pin_number: pin
+
+        :param angle: angle (0-180)
+
+        """
+        command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+        await self._send_command(command)
+
+    # async def stepper_move_to(self, motor_id, position):
+    #     """
+    #     Set an absolution target position. If position is positive, the movement is
+    #     clockwise, else it is counter-clockwise.
+    #
+    #     The run() function (below) will try to move the motor (at most one step per call)
+    #     from the current position to the target position set by the most
+    #     recent call to this function. Caution: moveTo() also recalculates the
+    #     speed for the next step.
+    #     If you are trying to use constant speed movements, you should call setSpeed()
+    #     after calling moveTo().
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param position: target position. Maximum value is 32 bits.
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_move_to: Invalid motor_id.')
+    #
+    #     if position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(position)
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE_TO, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_move(self, motor_id, relative_position):
+    #     """
+    #     Set the target position relative to the current position.
+    #
+    #     :param motor_id: motor id: 0 - 3
+    #
+    #     :param relative_position: The desired position relative to the current
+    #                               position. Negative is anticlockwise from
+    #                               the current position. Maximum value is 32 bits.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_move: Invalid motor_id.')
+    #
+    #     if relative_position < 0:
+    #         polarity = 1
+    #     else:
+    #         polarity = 0
+    #     position = abs(relative_position)
+    #
+    #     position_bytes = list(position.to_bytes(4, 'big', signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_MOVE, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     command.append(polarity)
+    #     await self._send_command(command)
+    #
+    # async def stepper_run(self, motor_id, completion_callback=None):
+    #     """
+    #     This method steps the selected motor based on the current speed.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run: A motion complete callback must be '
+    #                            'specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_run_speed(self, motor_id):
+    #     """
+    #     This method steps the selected motor based at a constant speed as set by the most
+    #     recent call to stepper_set_max_speed(). The motor will run continuously.
+    #
+    #     Once called, the server will continuously attempt to step the motor.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_max_speed(self, motor_id, max_speed):
+    #     """
+    #     Sets the maximum permitted speed. The stepper_run() function will accelerate
+    #     up to the speed set by this function.
+    #
+    #     Caution: the maximum speed achievable depends on your processor and clock speed.
+    #     The default maxSpeed is 1 step per second.
+    #
+    #      Caution: Speeds that exceed the maximum speed supported by the processor may
+    #               result in non-linear accelerations and decelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param max_speed: 1 - 1000
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Invalid motor_id.')
+    #
+    #     if not 1 < max_speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_max_speed: Speed range is 1 - 1000.')
+    #
+    #     self.stepper_info_list[motor_id]['max_speed'] = max_speed
+    #     max_speed_msb = (max_speed & 0xff00) >> 8
+    #     max_speed_lsb = max_speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MAX_SPEED, motor_id, max_speed_msb,
+    #                max_speed_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_max_speed(self, motor_id):
+    #     """
+    #     Returns the maximum speed configured for this stepper
+    #     that was previously set by stepper_set_max_speed()
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :return: The currently configured maximum speed.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_max_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['max_speed']
+    #
+    # async def stepper_set_acceleration(self, motor_id, acceleration):
+    #     """
+    #     Sets the acceleration/deceleration rate.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param acceleration: The desired acceleration in steps per second
+    #                          per second. Must be > 0.0. This is an
+    #                          expensive call since it requires a square
+    #                          root to be calculated on the server.
+    #                          Dont call more often than needed.
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Invalid motor_id.')
+    #
+    #     if not 1 < acceleration <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_acceleration: Acceleration range is 1 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['acceleration'] = acceleration
+    #
+    #     max_accel_msb = acceleration >> 8
+    #     max_accel_lsb = acceleration & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_ACCELERATION, motor_id, max_accel_msb,
+    #                max_accel_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_speed(self, motor_id, speed):
+    #     """
+    #     Sets the desired constant speed for use with stepper_run_speed().
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param speed: 0 - 1000 The desired constant speed in steps per
+    #                   second. Positive is clockwise. Speeds of more than 1000 steps per
+    #                   second are unreliable. Speed accuracy depends on the Arduino
+    #                   crystal. Jitter depends on how frequently you call the
+    #                   stepper_run_speed() method.
+    #                   The speed will be limited by the current value of
+    #                   stepper_set_max_speed().
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Invalid motor_id.')
+    #
+    #     if not 0 < speed <= 1000:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_speed: Speed range is 0 - '
+    #                            '1000.')
+    #
+    #     self.stepper_info_list[motor_id]['speed'] = speed
+    #
+    #     speed_msb = speed >> 8
+    #     speed_lsb = speed & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_speed(self, motor_id):
+    #     """
+    #     Returns the  most recently set speed.
+    #     that was previously set by stepper_set_speed();
+    #
+    #     Value is stored in the client, so no callback is required.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_speed: Invalid motor_id.')
+    #
+    #     return self.stepper_info_list[motor_id]['speed']
+    #
+    # async def stepper_get_distance_to_go(self, motor_id, distance_to_go_callback):
+    #     """
+    #     Request the distance from the current position to the target position
+    #     from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param distance_to_go_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=15, motor_id, distance in steps, time_stamp]
+    #
+    #     A positive distance is clockwise from the current position.
+    #
+    #     """
+    #     if not distance_to_go_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_distance_to_go: Invalid motor_id.')
+    #     self.stepper_info_list[motor_id][
+    #         'distance_to_go_callback'] = distance_to_go_callback
+    #     command = [PrivateConstants.STEPPER_GET_DISTANCE_TO_GO, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_target_position(self, motor_id, target_callback):
+    #     """
+    #     Request the most recently set target position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param target_callback: required callback function to receive report
+    #
+    #     :return: The distance to go is returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=16, motor_id, target position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #
+    #     """
+    #     if not target_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_target_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_target_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id][
+    #         'target_position_callback'] = target_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_TARGET_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_get_current_position(self, motor_id, current_position_callback):
+    #     """
+    #     Request the current motor position from the server.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param current_position_callback: required callback function to receive report
+    #
+    #     :return: The current motor position returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=17, motor_id, current position in steps, time_stamp]
+    #
+    #     Positive is clockwise from the 0 position.
+    #     """
+    #     if not current_position_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_get_current_position Read: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_get_current_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['current_position_callback'] = current_position_callback
+    #
+    #     command = [PrivateConstants.STEPPER_GET_CURRENT_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_current_position(self, motor_id, position):
+    #     """
+    #     Resets the current position of the motor, so that wherever the motor
+    #     happens to be right now is considered to be the new 0 position. Useful
+    #     for setting a zero position on a stepper after an initial hardware
+    #     positioning move.
+    #
+    #     Has the side effect of setting the current motor speed to 0.
+    #
+    #     :param motor_id:  0 - 3
+    #
+    #     :param position: Position in steps. This is a 32 bit value
+    #     """
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_current_position: Invalid motor_id.')
+    #     position_bytes = list(position.to_bytes(4, 'big',  signed=True))
+    #
+    #     command = [PrivateConstants.STEPPER_SET_CURRENT_POSITION, motor_id]
+    #     for value in position_bytes:
+    #         command.append(value)
+    #     await self._send_command(command)
+    #
+    # async def stepper_run_speed_to_position(self, motor_id, completion_callback=None):
+    #     """
+    #     Runs the motor at the currently selected speed until the target position is
+    #     reached.
+    #
+    #     Does not implement accelerations.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param completion_callback: call back function to receive motion complete
+    #                                 notification
+    #
+    #     callback returns a data list:
+    #
+    #     [report_type, motor_id, raw_time_stamp]
+    #
+    #     The report_type = 19
+    #     """
+    #     if not completion_callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: A motion complete '
+    #                            'callback must be '
+    #                            'specified.')
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_run_speed_to_position: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['motion_complete_callback'] = completion_callback
+    #     command = [PrivateConstants.STEPPER_RUN_SPEED_TO_POSITION, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_stop(self, motor_id):
+    #     """
+    #     Sets a new target position that causes the stepper
+    #     to stop as quickly as possible, using the current speed and
+    #     acceleration parameters.
+    #
+    #     :param motor_id:  0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_stop: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_STOP, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_disable_outputs(self, motor_id):
+    #     """
+    #     Disable motor pin outputs by setting them all LOW.
+    #
+    #     Depending on the design of your electronics this may turn off
+    #     the power to the motor coils, saving power.
+    #
+    #     This is useful to support Arduino low power modes: disable the outputs
+    #     during sleep and then re-enable with enableOutputs() before stepping
+    #     again.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and clears
+    #     the pin to disabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_disable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_DISABLE_OUTPUTS, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_enable_outputs(self, motor_id):
+    #     """
+    #     Enable motor pin outputs by setting the motor pins to OUTPUT
+    #     mode.
+    #
+    #     If the enable Pin is defined, sets it to OUTPUT mode and sets
+    #     the pin to enabled.
+    #
+    #     :param motor_id: 0 - 3
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_enable_outputs: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_ENABLE_OUTPUTS, motor_id]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_min_pulse_width(self, motor_id, minimum_width):
+    #     """
+    #     Sets the minimum pulse width allowed by the stepper driver.
+    #
+    #     The minimum practical pulse width is approximately 20 microseconds.
+    #
+    #     Times less than 20 microseconds will usually result in 20 microseconds or so.
+    #
+    #     :param motor_id: 0 -3
+    #
+    #     :param minimum_width: A 16 bit unsigned value expressed in microseconds.
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Invalid motor_id.')
+    #
+    #     if not 0 < minimum_width <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_min_pulse_width: Pulse width range = '
+    #                            '0-0xffff.')
+    #
+    #     width_msb = minimum_width >> 8
+    #     width_lsb = minimum_width & 0xff
+    #
+    #     command = [PrivateConstants.STEPPER_SET_MINIMUM_PULSE_WIDTH, motor_id, width_msb,
+    #                width_lsb]
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_enable_pin(self, motor_id, pin=0xff):
+    #     """
+    #     Sets the enable pin number for stepper drivers.
+    #     0xFF indicates unused (default).
+    #
+    #     Otherwise, if a pin is set, the pin will be turned on when
+    #     enableOutputs() is called and switched off when disableOutputs()
+    #     is called.
+    #
+    #     :param motor_id: 0 - 4
+    #     :param pin: 0-0xff
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Invalid motor_id.')
+    #
+    #     if not 0 < pin <= 0xff:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_enable_pin: Pulse width range = '
+    #                            '0-0xff.')
+    #     command = [PrivateConstants.STEPPER_SET_ENABLE_PIN, motor_id, pin]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_3_pins_inverted(self, motor_id, direction=False, step=False,
+    #                                 enable=False):
+    #     """
+    #     Sets the inversion for stepper driver pins.
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param direction: True=inverted or False
+    #
+    #     :param step: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_3_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_3_PINS_INVERTED, motor_id, direction,
+    #                step, enable]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_set_4_pins_inverted(self, motor_id, pin1_invert=False,
+    #                                   pin2_invert=False,
+    #                                 pin3_invert=False, pin4_invert=False, enable=False):
+    #     """
+    #     Sets the inversion for 2, 3 and 4 wire stepper pins
+    #
+    #     :param motor_id: 0 - 3
+    #
+    #     :param pin1_invert: True=inverted or False
+    #
+    #     :param pin2_invert: True=inverted or False
+    #
+    #     :param pin3_invert: True=inverted or False
+    #
+    #     :param pin4_invert: True=inverted or False
+    #
+    #     :param enable: True=inverted or False
+    #     """
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_set_4_pins_inverted: Invalid motor_id.')
+    #
+    #     command = [PrivateConstants.STEPPER_SET_4_PINS_INVERTED, motor_id, pin1_invert,
+    #                pin2_invert, pin3_invert, pin4_invert, enable]
+    #
+    #     await self._send_command(command)
+    #
+    # async def stepper_is_running(self, motor_id, callback):
+    #     """
+    #     Checks to see if the motor is currently running to a target.
+    #
+    #     Callback return True if the speed is not zero or not at the target position.
+    #
+    #     :param motor_id: 0-4
+    #
+    #     :param callback: required callback function to receive report
+    #
+    #     :return: The current running state returned via the callback as a list:
+    #
+    #     [REPORT_TYPE=18, motor_id, True or False for running state, time_stamp]
+    #     """
+    #     if not callback:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError(
+    #             'stepper_is_running: A callback function must be specified.')
+    #
+    #     if not self.stepper_info_list[motor_id]['instance']:
+    #         if self.shutdown_on_exception:
+    #             await self.shutdown()
+    #         raise RuntimeError('stepper_is_running: Invalid motor_id.')
+    #
+    #     self.stepper_info_list[motor_id]['is_running_callback'] = callback
+    #
+    #     command = [PrivateConstants.STEPPER_IS_RUNNING, motor_id]
+    #     await self._send_command(command)
+
+    async def shutdown(self):
+        """
+        This method attempts an orderly shutdown
+        If any exceptions are thrown, they are ignored.
+
+        """
+        self.shutdown_flag = True
+
+        if self.hard_reset_on_shutdown:
+            await self.r4_hard_reset()
+        # stop all reporting - both analog and digital
+        try:
+            if self.serial_port:
+                command = [PrivateConstants.STOP_ALL_REPORTS]
+                await self._send_command(command)
+
+                await asyncio.sleep(.5)
+
+                await self.serial_port.reset_input_buffer()
+                await self.serial_port.close()
+                if self.close_loop_on_shutdown:
+                    self.loop.stop()
+            elif self.sock:
+                command = [PrivateConstants.STOP_ALL_REPORTS]
+                await self._send_command(command)
+                self.the_task.cancel()
+                await asyncio.sleep(.5)
+                if self.close_loop_on_shutdown:
+                    self.loop.stop()
+        except (RuntimeError, SerialException):
+            pass
+
+    async def r4_hard_reset(self):
+        """
+        Place the r4 into hard reset
+        """
+        command = [PrivateConstants.BOARD_HARD_RESET, 1]
+        await self._send_command(command)
+
+    async def disable_all_reporting(self):
+        """
+        Disable reporting for all digital and analog input pins
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DISABLE_ALL, 0]
+        await self._send_command(command)
+
+    async def disable_analog_reporting(self, pin):
+        """
+        Disables analog reporting for a single analog pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+        await self._send_command(command)
+
+    async def disable_digital_reporting(self, pin):
+        """
+        Disables digital reporting for a single digital pin
+
+
+        :param pin: pin number
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+        await self._send_command(command)
+
+    async def enable_analog_reporting(self, pin):
+        """
+        Enables analog reporting for the specified pin.
+
+        :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+        """
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+        await self._send_command(command)
+
+    async def enable_digital_reporting(self, pin):
+        """
+        Enable reporting on the specified digital pin.
+
+        :param pin: Pin number.
+        """
+
+        command = [PrivateConstants.MODIFY_REPORTING,
+                   PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+        await self._send_command(command)
+
+    async def enable_scroll_message(self, message, scroll_speed=50):
+        """
+
+        :param message: Message with maximum length of 25
+        :param scroll_speed: in milliseconds (maximum of 255)
+        """
+        if len(message) > 25:
+            raise RuntimeError("Scroll message size is maximum of 25 characters.")
+
+        if scroll_speed > 255:
+            raise RuntimeError("Scroll speed maximum of 255 milliseconds.")
+
+        message = message.encode()
+        command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]
+        for x in message:
+            command.append(x)
+        await self._send_command(command)
+
+    async def disable_scroll_message(self):
+        """
+        Turn off a scrolling message
+        """
+
+        command = [PrivateConstants.SCROLL_MESSAGE_OFF]
+        await self._send_command(command)
+
+    async def _arduino_report_dispatcher(self):
+        """
+        This is a private method.
+        It continually accepts and interprets data coming from Telemetrix4Arduino,and then
+        dispatches the correct handler to process the data.
+
+        It first receives the length of the packet, and then reads in the rest of the
+        packet. A packet consists of a length, report identifier and then the report data.
+        Using the report identifier, the report handler is fetched from report_dispatch.
+
+        :returns: This method never returns
+        """
+
+        while True:
+            if self.shutdown_flag:
+                break
+            try:
+                if not self.transport_address:
+                    packet_length = await self.serial_port.read()
+                else:
+
+                    packet_length = ord(await self.sock.read())
+            except TypeError:
+                continue
+
+            # get the rest of the packet
+            if not self.transport_address:
+                packet = await self.serial_port.read(packet_length)
+            else:
+                packet = list(await self.sock.read(packet_length))
+                if len(packet) != packet_length:
+                    continue
+                # print(f'packet.len() {}')
+                # await asyncio.sleep(.1)
+
+            report = packet[0]
+            # print(report)
+            # handle all other messages by looking them up in the
+            # command dictionary
+
+            await self.report_dispatch[report](packet[1:])
+            await asyncio.sleep(self.sleep_tune)
+
+    async def _ble_report_dispatcher(self, sender=None, data=None):
+        """
+        This is a private method called by the incoming data notifier
+
+        Using the report identifier, the report handler is fetched from report_dispatch.
+
+        :param sender: BLE sender ID
+        :param data: data received over the ble link
+
+        """
+        self.the_sender = sender
+        data = list(data)
+        report = data[1]
+
+        if report == 5:  # get firmware data reply
+            self.firmware_version = list(data)
+            print()
+        # noinspection PyArgumentList
+        else:
+            await self.report_dispatch[report](data[2:])
+
+    '''
+    Report message handlers
+    '''
+
+    async def _report_loop_data(self, data):
+        """
+        Print data that was looped back
+
+        :param data: byte of loop back data
+        """
+        if self.loop_back_callback:
+            await self.loop_back_callback(data)
+
+    async def _spi_report(self, report):
+        report = list(report)
+        cb_list = [PrivateConstants.SPI_REPORT, report[0]] + report[1:]
+
+        cb_list.append(time.time())
+
+        await self.spi_callback(cb_list)
+
+    async def _onewire_report(self, report):
+        report = list(report)
+
+        cb_list = [PrivateConstants.ONE_WIRE_REPORT, report[0]] + report[1:]
+        cb_list.append(time.time())
+        await self.onewire_callback(cb_list)
+
+    async def _report_debug_data(self, data):
+        """
+        Print debug data sent from Arduino
+
+        :param data: data[0] is a byte followed by 2
+                     bytes that comprise an integer
+        """
+        value = (data[1] << 8) + data[2]
+        print(f'DEBUG ID: {data[0]} Value: {value}')
+
+    async def _analog_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for analog messages.
+
+        :param data: message data
+
+        """
+        pin = data[0]
+        value = (data[1] << 8) + data[2]
+
+        time_stamp = time.time()
+
+        # append pin number, pin value, and pin type to return value and return as a list
+        message = [PrivateConstants.AT_ANALOG, pin, value, time_stamp]
+
+        await self.analog_callbacks[pin](message)
+
+    async def _dht_report(self, data):
+        """
+        This is a private message handler for dht reports
+
+        :param data:            data[0] = report error return
+                                    No Errors = 0
+
+                                    Checksum Error = 1
+
+                                    Timeout Error = 2
+
+                                    Invalid Value = 999
+
+                                data[1] = pin number
+
+                                data[2] = dht type 11 or 22
+
+                                data[3] = humidity positivity flag
+
+                                data[4] = temperature positivity value
+
+                                data[5] = humidity integer
+
+                                data[6] = humidity fractional value
+
+                                data[7] = temperature integer
+
+                                data[8] = temperature fractional value
+        """
+        data = list(data)
+        if data[0]:  # DHT_ERROR
+            # error report
+            # data[0] = report sub type, data[1] = pin, data[2] = error message
+            if self.dht_callbacks[data[1]]:
+                # Callback 0=DHT REPORT, DHT_ERROR, PIN, Time
+                message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                           time.time()]
+                await self.dht_callbacks[data[1]](message)
+        else:
+            # got valid data DHT_DATA
+            f_humidity = float(data[5] + data[6] / 100)
+            if data[3]:
+                f_humidity *= -1.0
+            f_temperature = float(data[7] + data[8] / 100)
+            if data[4]:
+                f_temperature *= -1.0
+            message = [PrivateConstants.DHT_REPORT, data[0], data[1], data[2],
+                       f_humidity, f_temperature, time.time()]
+
+            await self.dht_callbacks[data[1]](message)
+
+    async def _digital_message(self, data):
+        """
+        This is a private message handler method.
+        It is a message handler for Digital Messages.
+
+        :param data: digital message
+
+        """
+        pin = data[0]
+        value = data[1]
+
+        time_stamp = time.time()
+        if self.digital_callbacks[pin]:
+            message = [PrivateConstants.DIGITAL_REPORT, pin, value, time_stamp]
+            await self.digital_callbacks[pin](message)
+
+    async def _servo_unavailable(self, report):
+        """
+        Message if no servos are available for use.
+
+        :param report: pin number
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'Servo Attach For Pin {report[0]} Failed: No Available Servos')
+
+    async def _i2c_read_report(self, data):
+        """
+        Execute callback for i2c reads.
+
+        :param data: [I2C_READ_REPORT, i2c_port, number of bytes read, address, register, bytes read..., time-stamp]
+        """
+
+        # we receive [# data bytes, address, register, data bytes]
+        # number of bytes of data returned
+
+        # data[0] = number of bytes
+        # data[1] = i2c_port
+        # data[2] = number of bytes returned
+        # data[3] = address
+        # data[4] = register
+        # data[5] ... all the data bytes
+        data = list(data)
+        cb_list = [PrivateConstants.I2C_READ_REPORT, data[0], data[1]] + data[2:]
+        cb_list.append(time.time())
+
+        if cb_list[1]:
+            await self.i2c_callback2(cb_list)
+        else:
+            await self.i2c_callback(cb_list)
+
+    async def _i2c_too_few(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'i2c too few bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    async def _i2c_too_many(self, data):
+        """
+        I2c reports too few bytes received
+
+        :param data: data[0] = device address
+        """
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            f'i2c too many bytes received from i2c port {data[0]} i2c address {data[1]}')
+
+    async def _sonar_distance_report(self, report):
+        """
+
+        :param report: data[0] = trigger pin, data[1] and data[2] = distance
+
+        callback report format: [PrivateConstants.SONAR_DISTANCE, trigger_pin, distance_value, time_stamp]
+        """
+        report = list(report)
+        # get callback from pin number
+        cb = self.sonar_callbacks[report[0]]
+
+        # build report data
+        cb_list = [PrivateConstants.SONAR_DISTANCE, report[0],
+                   ((report[1] << 8) + report[2]), time.time()]
+
+        await cb(cb_list)
+
+    async def _stepper_distance_to_go_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper distance to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = steps MSB, data[2] = steps byte 1,
+    #                              data[3] = steps bytes 2, data[4] = steps LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_DISTANCE_TO_GO, motor_id
+    #                              steps, time_stamp]
+    #     """
+    #     report = list(report)
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['distance_to_go_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     steps = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     num_steps = int.from_bytes(steps, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_DISTANCE_TO_GO, report[0], num_steps,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+
+    async def _stepper_target_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper target position to go.
+    #
+    #     :param report: data[0] = motor_id, data[1] = target position MSB,
+    #                    data[2] = target position byte MSB+1
+    #                    data[3] = target position byte MSB+2
+    #                    data[4] = target position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_TARGET_POSITION, motor_id
+    #                              target_position, time_stamp]
+    #     """
+    #     report = list(report)
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['target_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     target = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     target_position = int.from_bytes(target, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_TARGET_POSITION, report[0], target_position,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+
+    async def _stepper_current_position_report(self, report):
+        return  # for now
+    #     """
+    #     Report stepper current position.
+    #
+    #     :param report: data[0] = motor_id, data[1] = current position MSB,
+    #                    data[2] = current position byte MSB+1
+    #                    data[3] = current position byte MSB+2
+    #                    data[4] = current position LSB
+    #
+    #     callback report format: [PrivateConstants.STEPPER_CURRENT_POSITION, motor_id
+    #                              current_position, time_stamp]
+    #     """
+    #     report = list(report)
+
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['current_position_callback']
+    #
+    #     # isolate the steps bytes and covert list to bytes
+    #     position = bytes(report[1:])
+    #
+    #     # get value from steps
+    #     current_position = int.from_bytes(position, byteorder='big', signed=True)
+    #
+    #     cb_list = [PrivateConstants.STEPPER_CURRENT_POSITION, report[0], current_position,
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+    #
+
+    async def _stepper_is_running_report(self, report):
+        return  # for now
+    #     """
+    #     Report if the motor is currently running
+    #
+    #     :param report: data[0] = motor_id, True if motor is running or False if it is not.
+    #
+    #     callback report format: [18, motor_id,
+    #                              running_state, time_stamp]
+    #     """
+    #     report = list(report)
+
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['is_running_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUNNING_REPORT, report[0], time.time()]
+    #
+    #     await cb(cb_list)
+    #
+
+    async def _stepper_run_complete_report(self, report):
+        return  # for now
+    #     """
+    #     The motor completed it motion
+    #
+    #     :param report: data[0] = motor_id
+    #
+    #     callback report format: [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, motor_id,
+    #                              time_stamp]
+    #     """
+    #     report = list(report)
+    #     # get callback
+    #     cb = self.stepper_info_list[report[0]]['motion_complete_callback']
+    #
+    #     cb_list = [PrivateConstants.STEPPER_RUN_COMPLETE_REPORT, report[0],
+    #                time.time()]
+    #
+    #     await cb(cb_list)
+
+    async def _features_report(self, report):
+        self.reported_features = report[0]
+
+    async def _send_command(self, command):
+        """
+        This is a private utility method.
+
+
+        :param command:  command data in the form of a list
+
+        :returns: number of bytes sent
+        """
+        # the length of the list is added at the head
+        # the length of the list is added at the head
+        command.insert(0, len(command))
+        send_message = bytes(command)
+
+        if self.transport_type == 1:
+            try:
+                await self.serial_port.write(send_message)
+            except SerialException:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+                raise RuntimeError('write fail in _send_command')
+        elif self.transport_type == 0:
+            await self.sock.write(send_message)
+        else:
+            await self.ble_instance.write(send_message)
+
+
+ + + +
+ + + + + + + + + + +
+ + + +

+__init__(com_port=None, arduino_instance_id=1, arduino_wait=1, sleep_tune=0.0001, autostart=True, loop=None, shutdown_on_exception=True, close_loop_on_shutdown=True, hard_reset_on_shutdown=True, transport_address=None, ip_port=31336, transport_type=0, ble_device_name='Telemetrix4UnoR4 BLE') + +

+ + +
+ +

If you have a single Arduino connected to your computer, + then you may accept all the default values.

+

Otherwise, specify a unique arduino_instance id for each board in use.

+

:param com_port: e.g. COM3 or /dev/ttyACM0.

+

:param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch

+

:param arduino_wait: Amount of time to wait for an Arduino to + fully reset itself.

+

:param sleep_tune: A tuning parameter (typically not changed by user)

+

:param autostart: If you wish to call the start method within + your application, then set this to False.

+

:param loop: optional user provided event loop

+

:param shutdown_on_exception: call shutdown before raising + a RunTimeError exception, or + receiving a KeyboardInterrupt exception

+

:param close_loop_on_shutdown: stop and close the event loop loop + when a shutdown is called or a serial + error occurs

+

:param hard_reset_on_shutdown: reset the board on shutdown

+

:param transport_address: ip address of tcp/ip connected device.

+

:param ip_port: ip port of tcp/ip connected device

+

:param transport_type: 0 = WiFi + 1 = SerialUSB + 2 = BLE

+

:param ble_device_name: name of Arduino UNO R4 WIFI BLE device. + It must match that of Telemetrix4UnoR4BLE.ino

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
def __init__(self, com_port=None,
+             arduino_instance_id=1, arduino_wait=1,
+             sleep_tune=0.0001, autostart=True,
+             loop=None, shutdown_on_exception=True,
+             close_loop_on_shutdown=True, hard_reset_on_shutdown=True,
+             transport_address=None, ip_port=31336, transport_type=0,
+             ble_device_name='Telemetrix4UnoR4 BLE'):
+
+    """
+    If you have a single Arduino connected to your computer,
+    then you may accept all the default values.
+
+    Otherwise, specify a unique arduino_instance id for each board in use.
+
+    :param com_port: e.g. COM3 or /dev/ttyACM0.
+
+    :param arduino_instance_id: Must match value in the Telemetrix4Arduino sketch
+
+    :param arduino_wait: Amount of time to wait for an Arduino to
+                         fully reset itself.
+
+    :param sleep_tune: A tuning parameter (typically not changed by user)
+
+    :param autostart: If you wish to call the start method within
+                      your application, then set this to False.
+
+    :param loop: optional user provided event loop
+
+    :param shutdown_on_exception: call shutdown before raising
+                                  a RunTimeError exception, or
+                                  receiving a KeyboardInterrupt exception
+
+    :param close_loop_on_shutdown: stop and close the event loop loop
+                                   when a shutdown is called or a serial
+                                   error occurs
+
+   :param hard_reset_on_shutdown: reset the board on shutdown
+
+   :param transport_address: ip address of tcp/ip connected device.
+
+    :param ip_port: ip port of tcp/ip connected device
+
+    :param transport_type: 0 = WiFi
+                           1 = SerialUSB
+                           2 = BLE
+
+   :param ble_device_name: name of Arduino UNO R4 WIFI BLE device.
+                           It must match that of Telemetrix4UnoR4BLE.ino
+
+    """
+    # check to make sure that Python interpreter is version 3.8.3 or greater
+    python_version = sys.version_info
+    if python_version[0] >= 3:
+        if python_version[1] >= 8:
+            if python_version[2] >= 3:
+                pass
+        else:
+            raise RuntimeError("ERROR: Python 3.7 or greater is "
+                               "required for use of this program.")
+
+    # save input parameters
+    self.com_port = com_port
+    self.arduino_instance_id = arduino_instance_id
+    self.arduino_wait = arduino_wait
+    self.sleep_tune = sleep_tune
+    self.autostart = autostart
+    self.hard_reset_on_shutdown = hard_reset_on_shutdown
+
+    self.transport_address = transport_address
+    self.ip_port = ip_port
+    if transport_type not in [0, 1, 2]:
+        raise RuntimeError('Invalid transport type')
+    self.transport_type = transport_type
+    self.firmware_version = None
+    # if tcp, this variable is set to the connected socket
+    self.sock = None
+
+    self.ble_device_name = ble_device_name
+
+    # instance of telemetrix_aio_ble
+    self.ble_instance = None
+
+    # set the event loop
+    if loop is None:
+        self.loop = asyncio.get_event_loop()
+    else:
+        self.loop = loop
+
+    self.shutdown_on_exception = shutdown_on_exception
+    self.close_loop_on_shutdown = close_loop_on_shutdown
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    # debug loopback callback method
+    self.loop_back_callback = None
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    self.dht_count = 0
+
+    # serial port in use
+    self.serial_port = None
+
+    # generic asyncio task holder
+    self.the_task = None
+
+    # flag to indicate we are in shutdown mode
+    self.shutdown_flag = False
+
+    self.report_dispatch = {}
+
+    # reported features
+    self.reported_features = 0
+
+    # To add a command to the command dispatch table, append here.
+    self.report_dispatch.update(
+        {PrivateConstants.LOOP_COMMAND: self._report_loop_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DEBUG_PRINT: self._report_debug_data})
+    self.report_dispatch.update(
+        {PrivateConstants.DIGITAL_REPORT: self._digital_message})
+    self.report_dispatch.update(
+        {PrivateConstants.ANALOG_REPORT: self._analog_message})
+    self.report_dispatch.update(
+        {PrivateConstants.SERVO_UNAVAILABLE: self._servo_unavailable})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_READ_REPORT: self._i2c_read_report})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_FEW_BYTES_RCVD: self._i2c_too_few})
+    self.report_dispatch.update(
+        {PrivateConstants.I2C_TOO_MANY_BYTES_RCVD: self._i2c_too_many})
+    self.report_dispatch.update(
+        {PrivateConstants.SONAR_DISTANCE: self._sonar_distance_report})
+    self.report_dispatch.update({PrivateConstants.DHT_REPORT: self._dht_report})
+    self.report_dispatch.update(
+        {PrivateConstants.SPI_REPORT: self._spi_report})
+    self.report_dispatch.update(
+        {PrivateConstants.ONE_WIRE_REPORT: self._onewire_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_CURRENT_POSITION:
+             self._stepper_current_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUNNING_REPORT:
+             self._stepper_is_running_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_RUN_COMPLETE_REPORT:
+             self._stepper_run_complete_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_DISTANCE_TO_GO:
+             self._stepper_distance_to_go_report})
+    self.report_dispatch.update(
+        {PrivateConstants.STEPPER_TARGET_POSITION:
+             self._stepper_target_position_report})
+    self.report_dispatch.update(
+        {PrivateConstants.FEATURES:
+             self._features_report})
+
+    # dictionaries to store the callbacks for each pin
+    self.analog_callbacks = {}
+
+    self.digital_callbacks = {}
+
+    self.i2c_callback = None
+    self.i2c_callback2 = None
+
+    self.i2c_1_active = False
+    self.i2c_2_active = False
+
+    self.spi_callback = None
+
+    self.onewire_callback = None
+
+    self.cs_pins_enabled = []
+
+    # flag to indicate if spi is initialized
+    self.spi_enabled = False
+
+    # flag to indicate if onewire is initialized
+    self.onewire_enabled = False
+
+    # the trigger pin will be the key to retrieve
+    # the callback for a specific HC-SR04
+    self.sonar_callbacks = {}
+
+    self.sonar_count = 0
+
+    self.dht_callbacks = {}
+
+    # # stepper motor variables
+    #
+    # # updated when a new motor is added
+    # self.next_stepper_assigned = 0
+    #
+    # # valid list of stepper motor interface types
+    # self.valid_stepper_interfaces = [1, 2, 3, 4, 6, 8]
+    #
+    # # maximum number of steppers supported
+    # self.max_number_of_steppers = 4
+    #
+    # # number of steppers created - not to exceed the maximum
+    # self.number_of_steppers = 0
+    #
+    # # dictionary to hold stepper motor information
+    # self.stepper_info = {'instance': False, 'is_running': None,
+    #                      'maximum_speed': 1, 'speed': 0, 'acceleration': 0,
+    #                      'distance_to_go_callback': None,
+    #                      'target_position_callback': None,
+    #                      'current_position_callback': None,
+    #                      'is_running_callback': None,
+    #                      'motion_complete_callback': None,
+    #                      'acceleration_callback': None}
+    #
+    # # build a list of stepper motor info items
+    # self.stepper_info_list = []
+    # # a list of dictionaries to hold stepper information
+    # for motor in range(self.max_number_of_steppers):
+    #     self.stepper_info_list.append(self.stepper_info)
+
+    print(f'telemetrix_uno_r4_wifi_aio Version:'
+          f' {PrivateConstants.TELEMETRIX_VERSION}')
+    print(f'Copyright (c) 2023 Alan Yorinks All rights reserved.\n')
+
+    if autostart:
+        self.loop.run_until_complete(self.start_aio())
+
+
+
+ +
+ + +
+ + + +

+analog_write(pin, value) + + + async + + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (maximum 16 bits)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
async def analog_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (maximum 16 bits)
+
+    """
+    value_msb = value >> 8
+    value_lsb = value & 0xff
+    command = [PrivateConstants.ANALOG_WRITE, pin, value_msb, value_lsb]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+digital_write(pin, value) + + + async + + +

+ + +
+ +

Set the specified pin to the specified value.

+

:param pin: arduino pin number

+

:param value: pin value (1 or 0)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
async def digital_write(self, pin, value):
+    """
+    Set the specified pin to the specified value.
+
+    :param pin: arduino pin number
+
+    :param value: pin value (1 or 0)
+
+    """
+    command = [PrivateConstants.DIGITAL_WRITE, pin, value]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_all_reporting() + + + async + + +

+ + +
+ +

Disable reporting for all digital and analog input pins

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2135
+2136
+2137
+2138
+2139
+2140
+2141
async def disable_all_reporting(self):
+    """
+    Disable reporting for all digital and analog input pins
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DISABLE_ALL, 0]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_analog_reporting(pin) + + + async + + +

+ + +
+ +

Disables analog reporting for a single analog pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2143
+2144
+2145
+2146
+2147
+2148
+2149
+2150
+2151
+2152
async def disable_analog_reporting(self, pin):
+    """
+    Disables analog reporting for a single analog pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_DISABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_digital_reporting(pin) + + + async + + +

+ + +
+ +

Disables digital reporting for a single digital pin

+

:param pin: pin number

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2154
+2155
+2156
+2157
+2158
+2159
+2160
+2161
+2162
+2163
+2164
async def disable_digital_reporting(self, pin):
+    """
+    Disables digital reporting for a single digital pin
+
+
+    :param pin: pin number
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_DISABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+disable_scroll_message() + + + async + + +

+ + +
+ +

Turn off a scrolling message

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2207
+2208
+2209
+2210
+2211
+2212
+2213
async def disable_scroll_message(self):
+    """
+    Turn off a scrolling message
+    """
+
+    command = [PrivateConstants.SCROLL_MESSAGE_OFF]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_analog_reporting(pin) + + + async + + +

+ + +
+ +

Enables analog reporting for the specified pin.

+

:param pin: Analog pin number. For example for A0, the number is 0.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2166
+2167
+2168
+2169
+2170
+2171
+2172
+2173
+2174
+2175
+2176
async def enable_analog_reporting(self, pin):
+    """
+    Enables analog reporting for the specified pin.
+
+    :param pin: Analog pin number. For example for A0, the number is 0.
+
+
+    """
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_ANALOG_ENABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_digital_reporting(pin) + + + async + + +

+ + +
+ +

Enable reporting on the specified digital pin.

+

:param pin: Pin number.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2178
+2179
+2180
+2181
+2182
+2183
+2184
+2185
+2186
+2187
async def enable_digital_reporting(self, pin):
+    """
+    Enable reporting on the specified digital pin.
+
+    :param pin: Pin number.
+    """
+
+    command = [PrivateConstants.MODIFY_REPORTING,
+               PrivateConstants.REPORTING_DIGITAL_ENABLE, pin]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+enable_scroll_message(message, scroll_speed=50) + + + async + + +

+ + +
+ +

:param message: Message with maximum length of 25 +:param scroll_speed: in milliseconds (maximum of 255)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2189
+2190
+2191
+2192
+2193
+2194
+2195
+2196
+2197
+2198
+2199
+2200
+2201
+2202
+2203
+2204
+2205
async def enable_scroll_message(self, message, scroll_speed=50):
+    """
+
+    :param message: Message with maximum length of 25
+    :param scroll_speed: in milliseconds (maximum of 255)
+    """
+    if len(message) > 25:
+        raise RuntimeError("Scroll message size is maximum of 25 characters.")
+
+    if scroll_speed > 255:
+        raise RuntimeError("Scroll speed maximum of 255 milliseconds.")
+
+    message = message.encode()
+    command = [PrivateConstants.SCROLL_MESSAGE_ON, len(message), scroll_speed]
+    for x in message:
+        command.append(x)
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+get_event_loop() + + + async + + +

+ + +
+ +

Return the currently active asyncio event loop

+

:return: Active event loop

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
377
+378
+379
+380
+381
+382
+383
+384
async def get_event_loop(self):
+    """
+    Return the currently active asyncio event loop
+
+    :return: Active event loop
+
+    """
+    return self.loop
+
+
+
+ +
+ + +
+ + + +

+i2c_read(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified register for +the i2c device.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c data as a + result of read command

+

:param i2c_port: select the default port (0) or secondary port (1)

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
async def i2c_read(self, address, register, number_of_bytes,
+                   callback, i2c_port=0,
+                   write_register=True):
+    """
+    Read the specified number of bytes from the specified register for
+    the i2c device.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c data as a
+               result of read command
+
+    :param i2c_port: select the default port (0) or secondary port (1)
+
+    :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('i2c_read: A Callback must be specified')
+
+    await self._i2c_read_request(address, register, number_of_bytes,
+                                 callback=callback, i2c_port=i2c_port,
+                                 write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_read_restart_transmission(address, register, number_of_bytes, callback, i2c_port=0, write_register=True) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified register for +the i2c device. This restarts the transmission after the read. It is +required for some i2c devices such as the MMA8452Q accelerometer.

+

:param address: i2c device address

+

:param register: i2c register (or None if no register + selection is needed)

+

:param number_of_bytes: number of bytes to be read

+

:param callback: Required callback function to report i2c data as a + result of read command

+

:param i2c_port: select the default port (0) or secondary port (1)

+

:param write_register: If True, the register is written + before read + Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
async def i2c_read_restart_transmission(self, address, register,
+                                        number_of_bytes,
+                                        callback, i2c_port=0,
+                                        write_register=True):
+    """
+    Read the specified number of bytes from the specified register for
+    the i2c device. This restarts the transmission after the read. It is
+    required for some i2c devices such as the MMA8452Q accelerometer.
+
+
+    :param address: i2c device address
+
+    :param register: i2c register (or None if no register
+                                                selection is needed)
+
+    :param number_of_bytes: number of bytes to be read
+
+    :param callback: Required callback function to report i2c data as a
+               result of read command
+
+    :param i2c_port: select the default port (0) or secondary port (1)
+
+    :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
+    callback returns a data list:
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'i2c_read_restart_transmission: A Callback must be specified')
+
+    await self._i2c_read_request(address, register, number_of_bytes,
+                                 stop_transmission=False,
+                                 callback=callback, i2c_port=i2c_port,
+                                 write_register=write_register)
+
+
+
+ +
+ + +
+ + + +

+i2c_write(address, args, i2c_port=0) + + + async + + +

+ + +
+ +

Write data to an i2c device.

+

:param address: i2c device address

+

:param i2c_port: 0= port 1, 1 = port 2

+

:param args: A variable number of bytes to be sent to the device + passed in as a list

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
668
+669
+670
+671
+672
+673
+674
+675
+676
+677
+678
+679
+680
+681
+682
+683
+684
+685
+686
+687
+688
+689
+690
+691
+692
+693
+694
+695
+696
+697
+698
+699
async def i2c_write(self, address, args, i2c_port=0):
+    """
+    Write data to an i2c device.
+
+    :param address: i2c device address
+
+    :param i2c_port: 0= port 1, 1 = port 2
+
+    :param args: A variable number of bytes to be sent to the device
+                 passed in as a list
+
+    """
+    if not i2c_port:
+        if not self.i2c_1_active:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 1.')
+
+    if i2c_port:
+        if not self.i2c_2_active:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                'I2C Write: set_pin_mode i2c never called for i2c port 2.')
+
+    command = [PrivateConstants.I2C_WRITE, len(args), address, i2c_port]
+
+    for item in args:
+        command.append(item)
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+loop_back(start_character, callback) + + + async + + +

+ + +
+ +

This is a debugging method to send a character to the +Arduino device, and have the device loop it back.

+

:param start_character: The character to loop back. It should be + an integer.

+

:param callback: Looped back character will appear in the callback method

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
701
+702
+703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+713
+714
+715
+716
+717
+718
+719
async def loop_back(self, start_character, callback):
+    """
+    This is a debugging method to send a character to the
+    Arduino device, and have the device loop it back.
+
+    :param start_character: The character to loop back. It should be
+                            an integer.
+
+    :param callback: Looped back character will appear in the callback method
+
+    """
+
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('loop_back: A callback function must be specified.')
+    command = [PrivateConstants.LOOP_COMMAND, ord(start_character)]
+    self.loop_back_callback = callback
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+r4_hard_reset() + + + async + + +

+ + +
+ +

Place the r4 into hard reset

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2128
+2129
+2130
+2131
+2132
+2133
async def r4_hard_reset(self):
+    """
+    Place the r4 into hard reset
+    """
+    command = [PrivateConstants.BOARD_HARD_RESET, 1]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_detach(pin_number) + + + async + + +

+ + +
+ +

Detach a servo for reuse +:param pin_number: attached pin

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1479
+1480
+1481
+1482
+1483
+1484
+1485
async def servo_detach(self, pin_number):
+    """
+    Detach a servo for reuse
+    :param pin_number: attached pin
+    """
+    command = [PrivateConstants.SERVO_DETACH, pin_number]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+servo_write(pin_number, angle) + + + async + + +

+ + +
+ +

Set a servo attached to a pin to a given angle.

+

:param pin_number: pin

+

:param angle: angle (0-180)

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1487
+1488
+1489
+1490
+1491
+1492
+1493
+1494
+1495
+1496
+1497
+1498
async def servo_write(self, pin_number, angle):
+    """
+
+    Set a servo attached to a pin to a given angle.
+
+    :param pin_number: pin
+
+    :param angle: angle (0-180)
+
+    """
+    command = [PrivateConstants.SERVO_WRITE, pin_number, angle]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_analog_scan_interval(interval) + + + async + + +

+ + +
+ +

Set the analog scanning interval.

+

:param interval: value of 0 - 255 - milliseconds

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
721
+722
+723
+724
+725
+726
+727
+728
+729
+730
+731
+732
+733
+734
async def set_analog_scan_interval(self, interval):
+    """
+    Set the analog scanning interval.
+
+    :param interval: value of 0 - 255 - milliseconds
+    """
+
+    if 0 <= interval <= 255:
+        command = [PrivateConstants.SET_ANALOG_SCANNING_INTERVAL, interval]
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('Analog interval must be between 0 and 255')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_input(pin_number, differential=0, callback=None) + + + async + + +

+ + +
+ +

Set a pin as an analog input.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

:param differential: difference in previous to current value before + report will be generated

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for analog input pins = 3

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
736
+737
+738
+739
+740
+741
+742
+743
+744
+745
+746
+747
+748
+749
+750
+751
+752
+753
+754
+755
+756
+757
+758
+759
+760
+761
+762
async def set_pin_mode_analog_input(self, pin_number, differential=0, callback=None):
+    """
+    Set a pin as an analog input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    :param differential: difference in previous to current value before
+                         report will be generated
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for analog input pins = 3
+
+    """
+
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'set_pin_mode_analog_input: A callback function must be specified.')
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_ANALOG,
+                             differential, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_analog_output(pin_number) + + + async + + +

+ + +
+ +

Set a pin as a pwm (analog output) pin.

+

:param pin_number:arduino pin number

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
764
+765
+766
+767
+768
+769
+770
+771
+772
+773
+774
async def set_pin_mode_analog_output(self, pin_number):
+    """
+
+    Set a pin as a pwm (analog output) pin.
+
+    :param pin_number:arduino pin number
+
+    """
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                             callback=None)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_dht(pin, callback=None, dht_type=22) + + + async + + +

+ + +
+ +

:param pin: connection pin

+

:param callback: callback function

+

:param dht_type: either 22 for DHT22 or 11 for DHT11

+

Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]

+

Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity, +Temperature, +Time]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
860
+861
+862
+863
+864
+865
+866
+867
+868
+869
+870
+871
+872
+873
+874
+875
+876
+877
+878
+879
+880
+881
+882
+883
+884
+885
+886
+887
+888
+889
+890
+891
+892
+893
+894
+895
+896
+897
+898
+899
+900
+901
async def set_pin_mode_dht(self, pin, callback=None, dht_type=22):
+    """
+
+    :param pin: connection pin
+
+    :param callback: callback function
+
+    :param dht_type: either 22 for DHT22 or 11 for DHT11
+
+    Error Callback: [DHT REPORT Type, DHT_ERROR_NUMBER, PIN, DHT_TYPE, Time]
+
+    Valid Data Callback: DHT REPORT Type, DHT_DATA=, PIN, DHT_TYPE, Humidity,
+    Temperature,
+    Time]
+
+    """
+    if self.reported_features & PrivateConstants.DHT_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('set_pin_mode_dht: A Callback must be specified')
+
+        if self.dht_count < PrivateConstants.MAX_DHTS - 1:
+            self.dht_callbacks[pin] = callback
+            self.dht_count += 1
+
+            if dht_type != 22 and dht_type != 11:
+                dht_type = 22
+
+            command = [PrivateConstants.DHT_NEW, pin, dht_type]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of DHTs Exceeded - set_pin_mode_dht fails for pin {pin}')
+
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The DHT feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input(pin_number, callback) + + + async + + +

+ + +
+ +

Set a pin as a digital input.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
776
+777
+778
+779
+780
+781
+782
+783
+784
+785
+786
+787
+788
+789
+790
+791
+792
async def set_pin_mode_digital_input(self, pin_number, callback):
+    """
+    Set a pin as a digital input.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT, differential=0,
+                             callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_input_pullup(pin_number, callback) + + + async + + +

+ + +
+ +

Set a pin as a digital input with pullup enabled.

+

:param pin_number: arduino pin number

+

:param callback: async callback function

+

callback returns a data list:

+

[pin_type, pin_number, pin_value, raw_time_stamp]

+

The pin_type for all digital input pins = 2

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
794
+795
+796
+797
+798
+799
+800
+801
+802
+803
+804
+805
+806
+807
+808
+809
+810
+811
+812
+813
+814
+815
+816
async def set_pin_mode_digital_input_pullup(self, pin_number, callback):
+    """
+    Set a pin as a digital input with pullup enabled.
+
+    :param pin_number: arduino pin number
+
+    :param callback: async callback function
+
+    callback returns a data list:
+
+    [pin_type, pin_number, pin_value, raw_time_stamp]
+
+    The pin_type for all digital input pins = 2
+
+    """
+    if not callback:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(
+            'set_pin_mode_digital_input_pullup: A callback function must be specified.')
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP,
+                             differential=0, callback=callback)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_digital_output(pin_number) + + + async + + +

+ + +
+ +

Set a pin as a digital output pin.

+

:param pin_number: arduino pin number

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
818
+819
+820
+821
+822
+823
+824
+825
+826
async def set_pin_mode_digital_output(self, pin_number):
+    """
+    Set a pin as a digital output pin.
+
+    :param pin_number: arduino pin number
+    """
+
+    await self._set_pin_mode(pin_number, PrivateConstants.AT_OUTPUT, differential=0,
+                             callback=None)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_i2c(i2c_port=0) + + + async + + +

+ + +
+ +

Establish the standard Arduino i2c pins for i2c utilization.

+

:param i2c_port: 0 = i2c1, 1 = i2c2

+ +
+
    +
  1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
  2. +
+
    +
  1. Callbacks are set within the individual i2c read methods of this
  2. +
+
  API.
+
+  See i2c_read, or i2c_read_restart_transmission.
+
+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
829
+830
+831
+832
+833
+834
+835
+836
+837
+838
+839
+840
+841
+842
+843
+844
+845
+846
+847
+848
+849
+850
+851
+852
+853
+854
+855
+856
+857
+858
async def set_pin_mode_i2c(self, i2c_port=0):
+    """
+    Establish the standard Arduino i2c pins for i2c utilization.
+
+    :param i2c_port: 0 = i2c1, 1 = i2c2
+
+    NOTES: 1. THIS METHOD MUST BE CALLED BEFORE ANY I2C REQUEST IS MADE
+           2. Callbacks are set within the individual i2c read methods of this
+          API.
+
+          See i2c_read, or i2c_read_restart_transmission.
+
+    """
+    # test for i2c port 2
+    if i2c_port:
+        # if not previously activated set it to activated
+        # and the send a begin message for this port
+        if not self.i2c_2_active:
+            self.i2c_2_active = True
+        else:
+            return
+    # port 1
+    else:
+        if not self.i2c_1_active:
+            self.i2c_1_active = True
+        else:
+            return
+
+    command = [PrivateConstants.I2C_BEGIN, i2c_port]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_servo(pin_number, min_pulse=544, max_pulse=2400) + + + async + + +

+ + +
+ +

Attach a pin to a servo motor

+

:param pin_number: pin

+

:param min_pulse: minimum pulse width

+

:param max_pulse: maximum pulse width

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
903
+904
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
async def set_pin_mode_servo(self, pin_number, min_pulse=544, max_pulse=2400):
+    """
+
+    Attach a pin to a servo motor
+
+    :param pin_number: pin
+
+    :param min_pulse: minimum pulse width
+
+    :param max_pulse: maximum pulse width
+
+    """
+    if self.reported_features & PrivateConstants.SERVO_FEATURE:
+
+        minv = (min_pulse).to_bytes(2, byteorder="big")
+        maxv = (max_pulse).to_bytes(2, byteorder="big")
+
+        command = [PrivateConstants.SERVO_ATTACH, pin_number,
+                   minv[0], minv[1], maxv[0], maxv[1]]
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SERVO feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_sonar(trigger_pin, echo_pin, callback) + + + async + + +

+ + +
+ +

:param trigger_pin:

+

:param echo_pin:

+

:param callback: callback

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960
async def set_pin_mode_sonar(self, trigger_pin, echo_pin,
+                             callback):
+    """
+
+    :param trigger_pin:
+
+    :param echo_pin:
+
+    :param callback:  callback
+
+    """
+    if self.reported_features & PrivateConstants.SONAR_FEATURE:
+
+        if not callback:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('set_pin_mode_sonar: A Callback must be specified')
+
+        if self.sonar_count < PrivateConstants.MAX_SONARS - 1:
+            self.sonar_callbacks[trigger_pin] = callback
+            self.sonar_count += 1
+
+            command = [PrivateConstants.SONAR_NEW, trigger_pin, echo_pin]
+            await self._send_command(command)
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError(
+                f'Maximum Number Of Sonars Exceeded - set_pin_mode_sonar fails for pin {trigger_pin}')
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SONAR feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+set_pin_mode_spi(chip_select_list=None) + + + async + + +

+ + +
+ +

Specify the list of chip select pins.

+

Standard Arduino MISO, MOSI and CLK pins are used for the board in use.

+

Chip Select is any digital output capable pin.

+

:param chip_select_list: this is a list of pins to be used for chip select. + The pins will be configured as output, and set to high + ready to be used for chip select. + NOTE: You must specify the chips select pins here!

+

command message: [command, number of cs pins, [cs pins...]]

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
 962
+ 963
+ 964
+ 965
+ 966
+ 967
+ 968
+ 969
+ 970
+ 971
+ 972
+ 973
+ 974
+ 975
+ 976
+ 977
+ 978
+ 979
+ 980
+ 981
+ 982
+ 983
+ 984
+ 985
+ 986
+ 987
+ 988
+ 989
+ 990
+ 991
+ 992
+ 993
+ 994
+ 995
+ 996
+ 997
+ 998
+ 999
+1000
async def set_pin_mode_spi(self, chip_select_list=None):
+    """
+    Specify the list of chip select pins.
+
+    Standard Arduino MISO, MOSI and CLK pins are used for the board in use.
+
+    Chip Select is any digital output capable pin.
+
+    :param chip_select_list: this is a list of pins to be used for chip select.
+                       The pins will be configured as output, and set to high
+                       ready to be used for chip select.
+                       NOTE: You must specify the chips select pins here!
+
+
+    command message: [command, number of cs pins, [cs pins...]]
+    """
+    if self.reported_features & PrivateConstants.SPI_FEATURE:
+
+        if type(chip_select_list) != list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('chip_select_list must be in the form of a list')
+        if not chip_select_list:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('Chip select pins were not specified')
+
+        self.spi_enabled = True
+
+        command = [PrivateConstants.SPI_INIT, len(chip_select_list)]
+
+        for pin in chip_select_list:
+            command.append(pin)
+            self.cs_pins_enabled.append(pin)
+        await self._send_command(command)
+    else:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'The SPI feature is disabled in the server.')
+
+
+
+ +
+ + +
+ + + +

+shutdown() + + + async + + +

+ + +
+ +

This method attempts an orderly shutdown +If any exceptions are thrown, they are ignored.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
2096
+2097
+2098
+2099
+2100
+2101
+2102
+2103
+2104
+2105
+2106
+2107
+2108
+2109
+2110
+2111
+2112
+2113
+2114
+2115
+2116
+2117
+2118
+2119
+2120
+2121
+2122
+2123
+2124
+2125
+2126
async def shutdown(self):
+    """
+    This method attempts an orderly shutdown
+    If any exceptions are thrown, they are ignored.
+
+    """
+    self.shutdown_flag = True
+
+    if self.hard_reset_on_shutdown:
+        await self.r4_hard_reset()
+    # stop all reporting - both analog and digital
+    try:
+        if self.serial_port:
+            command = [PrivateConstants.STOP_ALL_REPORTS]
+            await self._send_command(command)
+
+            await asyncio.sleep(.5)
+
+            await self.serial_port.reset_input_buffer()
+            await self.serial_port.close()
+            if self.close_loop_on_shutdown:
+                self.loop.stop()
+        elif self.sock:
+            command = [PrivateConstants.STOP_ALL_REPORTS]
+            await self._send_command(command)
+            self.the_task.cancel()
+            await asyncio.sleep(.5)
+            if self.close_loop_on_shutdown:
+                self.loop.stop()
+    except (RuntimeError, SerialException):
+        pass
+
+
+
+ +
+ + +
+ + + +

+sonar_disable() + + + async + + +

+ + +
+ +

Disable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1077
+1078
+1079
+1080
+1081
+1082
async def sonar_disable(self):
+    """
+    Disable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_DISABLE]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+sonar_enable() + + + async + + +

+ + +
+ +

Enable sonar scanning for all sonar sensors

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1084
+1085
+1086
+1087
+1088
+1089
async def sonar_enable(self):
+    """
+    Enable sonar scanning for all sonar sensors
+    """
+    command = [PrivateConstants.SONAR_ENABLE]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_cs_control(chip_select_pin, select) + + + async + + +

+ + +
+ +

Control an SPI chip select line +:param chip_select_pin: pin connected to CS

+

:param select: 0=select, 1=deselect

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1091
+1092
+1093
+1094
+1095
+1096
+1097
+1098
+1099
+1100
+1101
+1102
+1103
+1104
+1105
+1106
+1107
+1108
async def spi_cs_control(self, chip_select_pin, select):
+    """
+    Control an SPI chip select line
+    :param chip_select_pin: pin connected to CS
+
+    :param select: 0=select, 1=deselect
+    """
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_cs_control: SPI interface is not enabled.')
+
+    if chip_select_pin not in self.cs_pins_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_cs_control: chip select pin never enabled.')
+    command = [PrivateConstants.SPI_CS_CONTROL, chip_select_pin, select]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_read_blocking(chip_select, register_selection, number_of_bytes_to_read, call_back=None) + + + async + + +

+ + +
+ +

Read the specified number of bytes from the specified SPI port and +call the callback function with the reported data.

+

:param chip_select: chip select pin

+

:param register_selection: Register to be selected for read.

+

:param number_of_bytes_to_read: Number of bytes to read

+

:param call_back: Required callback function to report spi data as a + result of read command

+ +
+ callback returns a data list +

[SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read, + data bytes, time-stamp]

+

SPI_READ_REPORT = 13

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1110
+1111
+1112
+1113
+1114
+1115
+1116
+1117
+1118
+1119
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
+1130
+1131
+1132
+1133
+1134
+1135
+1136
+1137
+1138
+1139
+1140
+1141
+1142
+1143
+1144
+1145
+1146
+1147
+1148
+1149
+1150
async def spi_read_blocking(self, chip_select, register_selection,
+                            number_of_bytes_to_read,
+                      call_back=None):
+    """
+    Read the specified number of bytes from the specified SPI port and
+    call the callback function with the reported data.
+
+    :param chip_select: chip select pin
+
+    :param register_selection: Register to be selected for read.
+
+    :param number_of_bytes_to_read: Number of bytes to read
+
+    :param call_back: Required callback function to report spi data as a
+               result of read command
+
+
+    callback returns a data list:
+        [SPI_READ_REPORT, chip select pin, SPI Register, count of data bytes read,
+         data bytes, time-stamp]
+    SPI_READ_REPORT = 13
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_read_blocking: SPI interface is not enabled.')
+
+    if not call_back:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('spi_read_blocking: A Callback must be specified')
+
+    self.spi_callback = call_back
+
+    command = [PrivateConstants.SPI_READ_BLOCKING, chip_select,
+               number_of_bytes_to_read,
+               register_selection]
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_set_format(clock_divisor, bit_order, data_mode) + + + async + + +

+ + +
+ +

Configure how the SPI serializes and de-serializes data on the wire.

+

See Arduino SPI reference materials for details.

+

:param clock_divisor: 1 - 255

+

:param bit_order:

+
                LSBFIRST = 0
+
+                MSBFIRST = 1 (default)
+
+

:param data_mode:

+
                SPI_MODE0 = 0x00 (default)
+
+                SPI_MODE1  = 1
+
+                SPI_MODE2 = 2
+
+                SPI_MODE3 = 3
+
+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1152
+1153
+1154
+1155
+1156
+1157
+1158
+1159
+1160
+1161
+1162
+1163
+1164
+1165
+1166
+1167
+1168
+1169
+1170
+1171
+1172
+1173
+1174
+1175
+1176
+1177
+1178
+1179
+1180
+1181
+1182
+1183
+1184
+1185
+1186
+1187
+1188
+1189
+1190
+1191
+1192
async def spi_set_format(self, clock_divisor, bit_order, data_mode):
+    """
+    Configure how the SPI serializes and de-serializes data on the wire.
+
+    See Arduino SPI reference materials for details.
+
+    :param clock_divisor: 1 - 255
+
+    :param bit_order:
+
+                        LSBFIRST = 0
+
+                        MSBFIRST = 1 (default)
+
+    :param data_mode:
+
+                        SPI_MODE0 = 0x00 (default)
+
+                        SPI_MODE1  = 1
+
+                        SPI_MODE2 = 2
+
+                        SPI_MODE3 = 3
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_set_format: SPI interface is not enabled.')
+
+    if not 0 < clock_divisor <= 255:
+        raise RuntimeError(f'spi_set_format: illegal clock divisor selected.')
+    if bit_order not in [0, 1]:
+        raise RuntimeError(f'spi_set_format: illegal bit_order selected.')
+    if data_mode not in [0, 1, 2, 3]:
+        raise RuntimeError(f'spi_set_format: illegal data_order selected.')
+
+    command = [PrivateConstants.SPI_SET_FORMAT, clock_divisor, bit_order,
+               data_mode]
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+spi_write_blocking(chip_select, bytes_to_write) + + + async + + +

+ + +
+ +

Write a list of bytes to the SPI device.

+

:param chip_select: chip select pin

+

:param bytes_to_write: A list of bytes to write. This must + be in the form of a list.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
1194
+1195
+1196
+1197
+1198
+1199
+1200
+1201
+1202
+1203
+1204
+1205
+1206
+1207
+1208
+1209
+1210
+1211
+1212
+1213
+1214
+1215
+1216
+1217
+1218
+1219
+1220
async def spi_write_blocking(self, chip_select, bytes_to_write):
+    """
+    Write a list of bytes to the SPI device.
+
+    :param chip_select: chip select pin
+
+    :param bytes_to_write: A list of bytes to write. This must
+                            be in the form of a list.
+
+    """
+
+    if not self.spi_enabled:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError(f'spi_write_blocking: SPI interface is not enabled.')
+
+    if type(bytes_to_write) is not list:
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError('spi_write_blocking: bytes_to_write must be a list.')
+
+    command = [PrivateConstants.SPI_WRITE_BLOCKING, chip_select, len(bytes_to_write)]
+
+    for data in bytes_to_write:
+        command.append(data)
+
+    await self._send_command(command)
+
+
+
+ +
+ + +
+ + + +

+start_aio() + + + async + + +

+ + +
+ +

This method may be called directly, if the autostart +parameter in init is set to false.

+

This method instantiates the serial interface and then performs auto pin +discovery if using a serial interface, or creates and connects to +a TCP/IP enabled device running StandardFirmataWiFi.

+

Use this method if you wish to start TelemetrixAIO manually from +an asyncio function.

+ +
+ Source code in telemetrix_uno_r4/wifi/telemetrix_uno_r4_wifi_aio/telemetrix_uno_r4_wifi_aio.py +
298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
async def start_aio(self):
+    """
+    This method may be called directly, if the autostart
+    parameter in __init__ is set to false.
+
+    This method instantiates the serial interface and then performs auto pin
+    discovery if using a serial interface, or creates and connects to
+    a TCP/IP enabled device running StandardFirmataWiFi.
+
+    Use this method if you wish to start TelemetrixAIO manually from
+    an asyncio function.
+     """
+
+    if self.transport_type == PrivateConstants.SERIAL_TRANSPORT:
+        if not self.com_port:
+            # user did not specify a com_port
+            try:
+                await self._find_arduino()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+        else:
+            # com_port specified - set com_port and baud rate
+            try:
+                await self._manual_open()
+            except KeyboardInterrupt:
+                if self.shutdown_on_exception:
+                    await self.shutdown()
+
+        if self.com_port:
+            print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')
+
+            # no com_port found - raise a runtime exception
+        else:
+            if self.shutdown_on_exception:
+                await self.shutdown()
+            raise RuntimeError('No Arduino Found or User Aborted Program')
+        await self.disable_scroll_message()
+        # using tcp/ip
+    elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:
+        self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)
+        await self.sock.start()
+    else:  # ble
+        self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)
+        await self.ble_instance.connect()
+
+    # get arduino firmware version and print it
+    firmware_version = await self._get_firmware_version()
+    if not firmware_version:
+        print('*** Firmware Version retrieval timed out. ***')
+        print('\nDo you have Arduino connectivity and do you have the ')
+        print('Telemetrix4UnoR4 sketch uploaded to the board and are connected')
+        print('to the correct serial port.\n')
+        print('To see a list of serial ports, type: '
+              '"list_serial_ports" in your console.')
+        if self.shutdown_on_exception:
+            await self.shutdown()
+        raise RuntimeError
+    else:
+
+        print(f'Telemetrix4UnoR4 Version Number: {firmware_version[2]}.'
+              f'{firmware_version[3]}.{firmware_version[4]}')
+        # start the command dispatcher loop
+        command = [PrivateConstants.ENABLE_ALL_REPORTS]
+        await self._send_command(command)
+        if not self.loop:
+            self.loop = asyncio.get_event_loop()
+        self.the_task = self.loop.create_task(self._arduino_report_dispatcher())
+
+        # get the features list
+        command = [PrivateConstants.GET_FEATURES]
+        await self._send_command(command)
+        await asyncio.sleep(.5)
+
+        # Have the server reset its data structures
+        command = [PrivateConstants.RESET]
+        await self._send_command(command)
+        await asyncio.sleep(.1)
+
+
+
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_ble/index.html b/template_ble/index.html new file mode 100644 index 0000000..6c710cc --- /dev/null +++ b/template_ble/index.html @@ -0,0 +1,1094 @@ + + + + + + + + + + + + + + + + + + + + + + BLE AIO - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

BLE AIO

+ +

Here, we need to instantiate the class passing in two parameters. +We need to pass in auto_start=False. This is because we are using the Bleak BLE +library, and this allows for a clean shutdown. +We also need to pass in transport_type=2, which enables the BLE transport.

+

Lastly, we need to manually start the asyncio portion of the API by calling +board.start_aio() in our main function.

+

+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(my_board):
+    # THIS NEXT LINE MUST BE ADDED HERE
+    await my_board.start_aio()
+
+    # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(autostart=False,
+                                                          transport_type=2)
+
+try:
+    # start the main function
+    loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+    try:
+        loop.run_until_complete(board.shutdown())
+    except:
+        pass
+    sys.exit(0)
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_minima_aio/index.html b/template_minima_aio/index.html new file mode 100644 index 0000000..bf1d3cd --- /dev/null +++ b/template_minima_aio/index.html @@ -0,0 +1,1080 @@ + + + + + + + + + + + + + + + + + + + + + + Minima AIO - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Minima AIO

+ +

+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima_aio import telemetrix_uno_r4_minima_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+    # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+board = telemetrix_uno_r4_minima_aio.TelemetrixUnoR4MinimaAio()
+
+try:
+    # start the main function
+    loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+    try:
+        loop.run_until_complete(board.shutdown())
+    except:
+        pass
+    sys.exit(0)
+
+
+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_minima_threaded/index.html b/template_minima_threaded/index.html new file mode 100644 index 0000000..736e0d0 --- /dev/null +++ b/template_minima_threaded/index.html @@ -0,0 +1,1072 @@ + + + + + + + + + + + + + + + + + + + + + + Minima Threaded - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Minima Threaded

+ +
import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.minima.telemetrix_uno_r4_minima import telemetrix_uno_r4_minima
+"""
+
+# INSTANTIATE THE API CLASS
+board = telemetrix_uno_r4_minima.TelemetrixUnoR4Minima()
+
+try:
+    # WRITE YOUR APPLICATION HERE
+except:
+    board.shutdown()
+
+
+
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_usb_serial_aio/index.html b/template_usb_serial_aio/index.html new file mode 100644 index 0000000..55f523d --- /dev/null +++ b/template_usb_serial_aio/index.html @@ -0,0 +1,1087 @@ + + + + + + + + + + + + + + + + + + + + + + USBSerial AIO - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

USBSerial AIO

+ +

Here, we need to instantiate the class passing in a transport_type of 1. +This parameter value enables the serial transport.

+

+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+    # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(transport_type=1)
+
+try:
+    # start the main function
+    loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+    try:
+        loop.run_until_complete(board.shutdown())
+    except:
+        pass
+    sys.exit(0)
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_usb_serial_threaded/index.html b/template_usb_serial_threaded/index.html new file mode 100644 index 0000000..9f11fb9 --- /dev/null +++ b/template_usb_serial_threaded/index.html @@ -0,0 +1,1074 @@ + + + + + + + + + + + + + + + + + + + + + + USBSerial Threaded - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

USBSerial Threaded

+ +

Here, we need to instantiate the class passing in a transport_type of 1. This enables +the serial transport.

+
import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi
+
+# INSTANTIATE THE API CLASS
+board = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_type=1)
+try:
+    # WRITE YOUR APPLICATION HERE
+except:
+    board.shutdown()
+
+
+
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_wifi_aio/index.html b/template_wifi_aio/index.html new file mode 100644 index 0000000..4c4283a --- /dev/null +++ b/template_wifi_aio/index.html @@ -0,0 +1,1089 @@ + + + + + + + + + + + + + + + + + + + + + + WIFI AIO - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

WIFI AIO

+ +

Here, we need to instantiate the class passing in the IP address assigned by your +router. This parameter enables the WIFI transport.

+

+import sys
+import asyncio
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi_aio import telemetrix_uno_r4_wifi_aio
+
+# An async method for running your application.
+# We pass in the instance of the API created below .
+async def my_app(the_board):
+    # Your Application code
+
+# get the event loop
+loop = asyncio.new_event_loop()
+asyncio.set_event_loop(loop)
+
+# instantiate telemetrix_aio
+# Make sure to edit the transport address assigned by your router.
+board = telemetrix_uno_r4_wifi_aio.TelemetrixUnoR4WiFiAio(
+    transport_address='192.168.2.118')
+
+try:
+    # start the main function
+    loop.run_until_complete(my_app(board))
+except KeyboardInterrupt:
+    try:
+        loop.run_until_complete(board.shutdown())
+    except:
+        pass
+    sys.exit(0)
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/template_wifi_threaded/index.html b/template_wifi_threaded/index.html new file mode 100644 index 0000000..472da85 --- /dev/null +++ b/template_wifi_threaded/index.html @@ -0,0 +1,1076 @@ + + + + + + + + + + + + + + + + + + + + + + WIFI Threaded - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

WIFI Threaded

+ +

Here, we need to instantiate the class passing in the IP address assigned by your +router. This parameter enables the WIFI transport.

+
import sys
+import time
+
+# IMPORT THE API
+from telemetrix_uno_r4.wifi.telemetrix_uno_r4_wifi import telemetrix_uno_r4_wifi
+
+# INSTANTIATE THE API CLASS
+# Make sure to edit the transport address assigned by your router.
+
+board = telemetrix_uno_r4_wifi.TelemetrixUnoR4WiFi(transport_address='192.168.2.118')
+try:
+    # WRITE YOUR APPLICATION HERE
+except:
+    board.shutdown()
+
+
+
+
+
+


+

+

Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/venv/index.html b/venv/index.html new file mode 100644 index 0000000..29fb6ec --- /dev/null +++ b/venv/index.html @@ -0,0 +1,1058 @@ + + + + + + + + + + + + + + + + + + + + + + Create A Python Virtual Environment - The Telemetrix User's Guide For The Arduino UNO R4 Minima And WIFI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+ + +
+ +
+ + + + + + +
+
+ + + +
+
+
+ + + + +
+
+
+ + + +
+
+
+ + + +
+
+
+ + + +
+
+ + + + +

Create A Python Virtual Environment

+ +

When using Telemetrix, it is highly recommended that you work within a Python virtual +environment.

+

A virtual environment isolates your project from other projects. +Packages installed into a virtual environment are confined to your +current project and will not affect or change packages used by other projects. +Please refer to this article +or the Python documentation.

+

If you are using the latest version of Ubuntu and Debian Linux, you are +required +to use a virtual environment.

+


+Copyright (C) 2023 Alan Yorinks. All Rights Reserved.

+ + + + + + +
+
+ + +
+ +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file