Hello, I need help. I am developing a project with Scratch. This project consist in connect one plate (this plate have a microcontroler 8051) with Scratch. I get that the plate send signals to Scratch correctly, but now I will get that Scratch send signals to the plate. The plate is connect for a serial port. Anyone know what functions the source code I can use for to send signals. Thanks
Offline
Hi, rakel87,
Wow, 8051! It's a classic.
Are you familiar with Smalltalk? If so, browse SerialPort2 class. It manages serial port. You may find the source code that uses SerialPort2 in SensorBoardMorph class. It explains how to use serial port in Scratch.
Offline
Hello, Abi.
I'm not familiar with Smalltalk code. I would appreciate some guidance. I've been looking SensorBoardMorph class and I've not seen any request to send data. Can be used the two classes, the serial port i the SensorBoardMorph.
Thanks for the infomation
Offline
The key method is SensorBoardMorph>>processIncomingData. (This notation means "instance method 'processIncomingData' of 'SensorBoardMorph' class.")
buf _ port readByteArray.
This message expression means "receive data from the serial port as a bytearray and assign it to a temporary variable 'buf'".
port nextPut: 1.
This message expression means "send a byte value '1' to the serial port".
Anyway I recommend that you read a book about Squeak Smalltalk.
For example:
http://www.amazon.com/Squeak-Programming-Robots-Technology-Action/dp/1590594916
http://www.amazon.com/Squeak-Quick-ObjectLand-Gene-Korienek/dp/0201731142/
Last edited by abee (2011-04-21 08:04:03)
Offline
rakel87,
It is a difficult request. Because I don't know the protocol of your device.
However most simple code is as following.
| port buf |
port _ SerialPort2 new.
port openPortNamed: 'COM1' baud: 9600.
port nextPut: 1.
buf _ port readByteArray.
port close.
^ buf
I think there are no shortcuts to understanding Smalltalk. So you need to read the book.
BTW, I'm not Abi.
Last edited by abee (2011-04-27 00:53:47)
Offline