[Newbies] Timer in Morph
Herbert König
herbertkoenig at gmx.net
Sat Feb 6 12:12:34 UTC 2010
Hi Garret,
i can only guess here but i would use one Serial port and keep it open
all the time.
GR> readColor
GR> | s n |
GR> n := SerialPort new.
GR> n baudRate: 9600.
GR> n openPort: 7.
What happens if the port is opened in the middle of a transmitted
Byte? I will take the first rising edge of the signal as a start bit.
GR> s := n readString asInteger.
GR> Transcript show: s; cr.
GR> s := s - 46 * (1/60).
GR> self color: (Color r:s g:s b:s).
GR> n close.
GR> and it works almost fine. But there is a bug. Time to time I
GR> receive only a part of value, for example I am receiving: 56 55 56
GR> 55 5 6 55 ... 102 103 101
GR> 103 100 102 1 1 0 102 102. Those one-digit values are truly
GR> false and it looks like the mistake in receiving.
The example I constructed might account for this error
GR> How can I
GR> synchonize sending and receiving? Or do I have to use other method
GR> of SerialPort? Thanks.
Depends strongly on what you can do on your microcontroller. And I
hope your infrared is not involved in the serial communication. If you
use a Serial to USB converter we have another candidate for errors.
Assuming the serial ports buffer is big enough to collect all data
while you're not listening, I would:
- Open the port maybe when the Morph is created
- in the step method read a string (or ByteArray)
- only use the last received Character or Byte.
- close the port on deleting the morph.
If that doesn't help come back with a more detailed description of
your setup and the problem. Can you afford to loose data? Can you
influence what is sent from the microcontroller?
--
Cheers,
Herbert
More information about the Beginners
mailing list