<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Yeah, that’s it. &nbsp;Cool - thanks Spencer!</div><br class=""><div class="">
<div class=""><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">—ss</div><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""></div><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">[ - ] &nbsp;<a href="http://www.scott-smallwood.com" class="">Scott Smallwood</a>&nbsp;- Associate Professor - University of Alberta &nbsp;[ - ]</div></div>
</div>
<div style=""><br class=""><blockquote type="cite" class=""><div class="">On Apr 18, 2019, at 11:03 PM, Spencer Salazar &lt;<a href="mailto:spencer.salazar@gmail.com" class="">spencer.salazar@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class="">Hey Scott,</div><div class=""><br class=""></div><div class="">Looks solid, but try checking if the ints[] array is null before the loop, or just put a null check in the loop condition. It shouldn’t normally be null but wouldn’t be surprised if it is occasionally.</div><div class=""><br class=""></div><div class="">Spencer</div><div class=""><br class="">On Apr 18, 2019, at 8:15 PM, Scott Smallwood &lt;<a href="mailto:ssmallwo@ualberta.ca" class="">ssmallwo@ualberta.ca</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div class="">Dear chuckians,</div><div class=""><br class=""></div><div class="">Not sure how many of you have messed with the serial objects - but I’m having a bit of a head-scratcher and wondered if anyone had any ideas about this.</div><div class=""><br class=""></div><div class="">I built a little box with one knob and one switch - which I’m planning to use as a master volume and mute switch for a multichannel audio installation that is running in Chuck.</div><div class=""><br class=""></div><div class="">The Arduino code is really basic:</div><div class=""><br class=""></div><div class="">—</div><div class=""><div class="">const int SwitchPin = 12;</div><div class="">const int VolPin = 0;</div><div class=""><br class=""></div><div class="">void setup()&nbsp;</div><div class="">{</div><div class="">&nbsp; //turn on serial communication</div><div class="">&nbsp; Serial.begin(57600);</div><div class=""><br class=""></div><div class="">&nbsp; //set switch pin and turn on pullup resistor</div><div class="">&nbsp; pinMode (SwitchPin, INPUT);</div><div class="">&nbsp; digitalWrite (SwitchPin, HIGH);</div><div class="">}</div><div class=""><br class=""></div><div class="">void loop()&nbsp;</div><div class="">{</div><div class=""><br class=""></div><div class="">&nbsp; Serial.print(digitalRead(SwitchPin));</div><div class="">&nbsp; Serial.print(' ');</div><div class="">&nbsp; Serial.println(analogRead(VolPin));</div><div class="">&nbsp; delay(50);</div><div class=""><br class=""></div><div class="">}</div></div><div class="">—</div><div class=""><br class=""></div><div class="">OK - so I first built a little Max patch to test it, which works flawlessly as far as I can tell.</div><div class=""><br class=""></div><div class="">I then wrote a little chuck script, based partially on one of Spencer’s examples. &nbsp;It simply grabs the data and prints it to the console.</div><div class=""><br class=""></div><div class="">It works great for awhile, but after a few minutes, it always crashes with an array-out-of-bounds exception:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: &quot;Andale Mono&quot;; color: rgb(40, 254, 20); background-color: rgba(0, 0, 0, 0.901961);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">NullPointerException: (array access) on line[35]</span></div></div><br class=""><div class="">I’m grabbing two ints, and looping through and printing them out. &nbsp;Why is the array size suddenly getting mucked up here? &nbsp; It’s intermittent, and sometimes doesn’t happen for several minutes, but always results in a crash eventually. &nbsp;Any ideas?? (chuck code below)</div><div class=""><br class=""></div><div class="">—</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class=""><span style="color: #94132e" class="">SerialIO</span>.list() @=&gt; <span style="color: #94132e" class="">string</span> list[];</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(148, 19, 46);" class="">SerialIO<span style="" class=""> cereal;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class="">//the name of my arduino box's serial port</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(81, 81, 81);" class="">"usbserial-12DP0657"<span style="" class=""> =&gt; </span><span style="color: #94132e" class="">string</span><span style="" class=""> port;</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class="">//number of serial device</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">-<span style="color: #de9210" class="">1</span>=&gt;<span style="color: #0433ff" class="">int</span> device;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class="">//loop through any ports and find the one with the right name</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class=""><span style="color: #0433ff" class="">for</span>(<span style="color: #de9210" class="">0</span>=&gt;<span style="color: #0433ff" class="">int</span> i; i &lt; list.cap(); i++)</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">{</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class=""><span style="" class="">&nbsp; &nbsp; </span>//check for correct port name</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; <span style="color: #0433ff" class="">if</span> (list[i].find(port) != -<span style="color: #de9210" class="">1</span>)</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; {&nbsp;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>//and assign the device number</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; &nbsp; &nbsp; i =&gt; device;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; <span style="color: #0433ff" class="">else</span>&nbsp;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; &nbsp; &nbsp; -<span style="color: #de9210" class="">1</span> =&gt; device;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">}</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class="">//open the serial port</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">cereal.open(device, <span style="color: #94132e" class="">SerialIO</span>.B57600, <span style="color: #94132e" class="">SerialIO</span>.ASCII);</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class="">//loop through and grab the serial port data</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(4, 51, 255);" class="">while<span style="" class="">(</span>true<span style="" class="">)</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">{</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; cereal.onInts(<span style="color: #de9210" class="">2</span>) =&gt; <span style="color: #0433ff" class="">now</span>;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; cereal.getInts() @=&gt; <span style="color: #0433ff" class="">int</span> ints[];</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; min-height: 17px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco; color: rgb(114, 158, 18);" class=""><span style="" class="">&nbsp; &nbsp; </span>//print out to console</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; <span style="color: #0433ff" class="">for</span>(<span style="color: #de9210" class="">0</span>=&gt;<span style="color: #0433ff" class="">int</span> i; i &lt; ints.cap(); i++) &nbsp; &nbsp;//&lt;- this is where the problem seems to happen</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; {</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0433ff" class="">chout</span> &lt;= ints[i] &lt;= <span style="color: #515151" class="">" "</span>;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">&nbsp; &nbsp; <span style="color: #0433ff" class="">chout</span> &lt;= <span style="color: #94132e" class="">IO</span>.newline();</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class="">}</div></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Monaco;" class=""><br class=""></div><div class=""><br class="webkit-block-placeholder"></div><div class="">
<div class=""><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">—ss</div><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""></div><div style="orphans: 2; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">[ - ] &nbsp;<a href="http://www.scott-smallwood.com/" class="">Scott Smallwood</a>&nbsp;- Associate Professor - University of Alberta &nbsp;[ - ]</div></div>
</div>
<br class=""></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">chuck-users mailing list</span><br class=""><span class=""><a href="mailto:chuck-users@lists.cs.princeton.edu" class="">chuck-users@lists.cs.princeton.edu</a></span><br class=""><span class=""><a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" class="">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">chuck-users mailing list<br class=""><a href="mailto:chuck-users@lists.cs.princeton.edu" class="">chuck-users@lists.cs.princeton.edu</a><br class="">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users<br class=""></div></blockquote></div><br class=""></body></html>