Basic stamp tokenizer
k lee
Posts: 8
I have tried to make a compiler with c# for the BS2 Basic Stamp. I was able
to get the Tokenizer working and the port control working but I do
not know what format to send the data down to the BS2 controller.
to get the Tokenizer working and the port control working but I do
not know what format to send the data down to the BS2 controller.
Comments
The Tokenizer documents describe how to download the tokenized program and it consists of a reset , Stamp identification and then writing the tokenized code to the Stamp's EEPROM.
Each write is an eighteen byte packet which consists of a 1 byte EEPROM address , 16 byte data and 1 byte checksum.
Here is an example of something I have used for the reset and the ID routines using VB
That is followed by the write routine , I believe I had a 50 mSec pause between each write , I'm not sure whether thats neccessary or not.
Jeff T.
Actually, I made reset and ID check program.
How can I make eighteen byte packet?
[noparse][[/noparse]Each write is an eighteen byte packet which consists of a 1 byte EEPROM address , 16 byte data and 1 byte checksum.]
do I have to send EEPROM data to BS2 controller?
I tryied to send Packetbuffer to BS2 controller.
give me a advice.
Jeff T.
·
Here is PBASIC code snippet that shows how to form the packet. That's right, one BASIC Stamp can be used to program another one. The formation of the packet would be the same in C#
You can find more information here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Packetbuffer is actual packet data to download to the BASIC stamp. and this data begins at element 0 and
constists of packets of 18 bytes each.
ELEMENT 0...17 : Packet number 1
...
ELEMENT 2286...2303 : Packet number 128
This means I should donwload packetbuffer to Basic stamp.
If it is correct, I have some question.
PBASIC program ;
' {$STAMP BS2}
' {$PORT COM3}
' {$PBASIC 2.5}
x var word
here:
for x = 1 to 100
pulsout 8, 500
pause 10
next
pause 500
for x = 1 to 100
pulsout 8, 1000
pause 10
next
pause 500
goto here
And I programmed c# as follows, it just download part, and Packetcount was 4;
unsafe void Compile_button_Click(object sender, EventArgs e)
{
bool ret;
TModuleRec tModRec = new TModuleRec();
string s = richTextBox1.Text;
tModRec.SourceSize = (int)(s.Length);
ret = tokenizer_compile(&tModRec, s, false, true, null);
MessageBox.Show(ret.ToString());
SerialPort SP = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
SP.Open();
SP.DtrEnable = true;
SP.BreakState = true;
Thread.Sleep(2);
SP.DtrEnable = false;
Thread.Sleep(36);
SP.BreakState = false;
Thread.Sleep(20);
SP.DiscardInBuffer();
SP.WriteLine("B");
SP.DiscardInBuffer();
SP.ReadLine();
Console.WriteLine(SP.ReadByte());
SP.WriteLine("S");
SP.DiscardInBuffer();
SP.ReadLine();
Console.WriteLine(SP.ReadByte());
SP.WriteLine("2");
SP.DiscardInBuffer();
SP.ReadLine();
Console.WriteLine(SP.ReadByte());
SP.WriteLine("0");
SP.DiscardInBuffer();
SP.ReadByte();
Console.WriteLine(SP.ReadByte());
byte[noparse]/noparse p0 = new byte[noparse][[/noparse]72];
for (i = 0; i < 72; i++)
{
richTextBox2.Text += "$" + System.Convert.ToString(tModRec.PacketBuffer, 16);
p0[noparse][[/noparse]i] += tModRec.PacketBuffer[noparse][[/noparse]i];
}
SP.Write(p0, 0, 18);
SP.DiscardInBuffer();
SP.ReadByte();
Console.WriteLine(SP.ReadByte());
SP.Write(p0, 18, 18);
SP.DiscardInBuffer();
SP.ReadByte();
Console.WriteLine(SP.ReadByte());
SP.Write(p0, 36, 18);
SP.DiscardInBuffer();
SP.ReadByte();
Console.WriteLine(SP.ReadByte());
SP.Write(p0, 54, 18);
SP.DiscardInBuffer();
SP.ReadByte();
Console.WriteLine(SP.ReadByte());
SP.WriteLine("0");
MessageBox.Show(SP.ReadExisting());
SP.Close();
}
motor dosn't work and console shows as follows;
190
173
206
0
64
232
51
Please, give me an advice.
Post Edited (k lee) : 9/28/2009 2:04:41 AM GMT