[Newbies] Timer in Morph
boloomka at gmail.com
Sat Feb 6 20:55:53 UTC 2010
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*
On Sat, Feb 6, 2010 at 9:24 PM, Garret Raziel <boloomka at gmail.com> wrote:
> Thanks, but I have done it with opening port in initialization, but it
> didn't help. And I have tried to change it to reading a byteArray and it
> didn't help too. Here is the monticello package of my class. I'll try to do
> something with my arduino too.
> On Sat, Feb 6, 2010 at 7:30 PM, Yoshiki Ohshima <yoshiki at vpri.org> wrote:
>> At Fri, 5 Feb 2010 18:56:43 +0100,
>> Garret Raziel wrote:
>> > 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
>> > 56 55 5 6 55 ... 102 103 101
>> > 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
>> > synchonize sending and receiving? Or do I have to use other method of
>> SerialPort? Thanks.
>> It appears that data is sent in variable length format; i.e., a
>> value less than 10 is one byte, less than 100 is two bytes, and less
>> than 256 is three bytes. If so, the receiving side cannot know truely
>> the beginning and end of data, unless both sides truly synchronous,
>> but Squeak cannot do it, especially through Morphic's #step method.
>> The best way is to change the protocol so that either you send each
>> value in one byte, without rendering it to string, and Squeak side
>> read them in bulk but process them one by one. Alternatively, you can
>> add an "end marker" (any character other than '0' to '9') at the end
>> of each data and have Squeak look for it.
>> Let us say you take the first approach, things are quite simple;
>> In your #step (or #readColor) method, write something like:
>> | buffer value aSerialPort |
>> aSerialPort := ...
>> buffer := aSerialPort readByteArray.
>> buffer size = 0 ifTrue: [^ self].
>> s := buffer last.
>> Transcript show: s; cr.
>> s := s - 46 * (1/60).
>> self color: (Color r:s g:s b:s).
>> (For changing color, doing so many times in one #step doesn't make
>> sense, as only the last value is visible so here you can discard other
>> I didn't think you need to open the port every time you try to read
>> it. But certainly it is easier to code that way.
>> -- Yoshiki
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners