Wow, many thanks to all of you! Now it works! Problem was in sending partly in my arduino (I have sending it by println (print and then print newline) and not print and I have sending as a decimal, not byte) and partly in Squeak (where I am receiving it into string and using it by readString first asInteger). Now it works perfectly. Thanks again. *SOLVED*<br>

<br><div class="gmail_quote">On Sat, Feb 6, 2010 at 9:24 PM, Garret Raziel <span dir="ltr">&lt;<a href="mailto:boloomka@gmail.com">boloomka@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Thanks, but I have done it with opening port in initialization, but it didn&#39;t help. And I have tried to change it to reading a byteArray and it didn&#39;t help too. Here is the monticello package of my class. I&#39;ll try to do something with my arduino too.<div>

<div></div><div class="h5"><br>
<br><div class="gmail_quote">On Sat, Feb 6, 2010 at 7:30 PM, Yoshiki Ohshima <span dir="ltr">&lt;<a href="mailto:yoshiki@vpri.org" target="_blank">yoshiki@vpri.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


At Fri, 5 Feb 2010 18:56:43 +0100,<br>
<div>Garret Raziel wrote:<br>
&gt;<br>
&gt; and it works almost fine. But there is a bug. Time to time I receive only a part of value, for example I am receiving: 56 55<br>
&gt; 56 55 5 6 55 ... 102 103 101<br>
&gt; 103 100 102 1 1 0 102 102. Those one-digit values are truly false and it looks like the mistake in receiving. How can I<br>
&gt; synchonize sending and receiving? Or do I have to use other method of SerialPort? Thanks.<br>
<br>
</div>  It appears that data is sent in variable length format; i.e., a<br>
value less than 10 is one byte, less than 100 is two bytes, and less<br>
than 256 is three bytes.  If so, the receiving side cannot know truely<br>
the beginning and end of data, unless both sides truly synchronous,<br>
but Squeak cannot do it, especially through Morphic&#39;s #step method.<br>
<br>
  The best way is to change the protocol so that either you send each<br>
value in one byte, without rendering it to string, and Squeak side<br>
read them in bulk but process them one by one.  Alternatively, you can<br>
add an &quot;end marker&quot; (any character other than &#39;0&#39; to &#39;9&#39;) at the end<br>
of each data and have Squeak look for it.<br>
<br>
  Let us say you take the first approach, things are quite simple;<br>
In your #step (or #readColor) method, write something like:<br>
<br>
     | buffer value aSerialPort |<br>
     aSerialPort := ...<br>
     buffer := aSerialPort readByteArray.<br>
     buffer size = 0 ifTrue: [^ self].<br>
     s := buffer last.<br>
<div>     Transcript show: s; cr.<br>
     s := s - 46 * (1/60).<br>
     self color: (Color r:s g:s b:s).<br>
<br>
</div>(For changing color, doing so many times in one #step doesn&#39;t make<br>
sense, as only the last value is visible so here you can discard other<br>
values.)<br>
<br>
  I didn&#39;t think you need to open the port every time you try to read<br>
it.  But certainly it is easier to code that way.<br>
<font color="#888888"><br>
-- Yoshiki<br>
</font><div><div></div><div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org" target="_blank">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>