#28044 laser-range-finder: some serial-spin-code into c-code
nomad
Posts: 276
hello,
i have some problems to convert spin-code into c-code for the simpleIDE.
-1) spin-code:
c-code:
- 2)
spincode:
c-code: From the elev lrf sf02
are the c-code correct or wrong ?
thanks for tips and hints
regards
nomad
i have some problems to convert spin-code into c-code for the simpleIDE.
-1) spin-code:
pst.Str(String("Waiting for LRF module..."))
waitcnt(clkfreq << 1 + cnt) ' Delay for 2 seconds to let the LRF module start-up
serial.Tx("U") ' Send character
repeat until serial.RxCheck == ":" ' When the LRF has initialized and is ready to go, it will send a single ':' ve it
pst.Str(String("Ready!", pst#NL, pst#NL)) ' Ready to go!
c-code:
serial* serLrf = serial_open(0, 1, 0, 115200);
print("Waiting for LRF-module...\n");
pause(2000);
writeChar(serLrf, 'U');
while(serial_rxChar(serLrf) == ':');
print("READY\n");
- 2)
spincode:
serial.Tx("R")
repeat until serial.RxCheck == "D"
repeat until serial.RxCheck == "="
repeat until serial.RxCheck == " "
range := serial.RxDec
c-code: From the elev lrf sf02
memset(s, 0, 6);
for (i = 0; i < 6; i++)
{
s = readChar(sf02);
if(s == '\r') break;
}
sscan(s, "%f", &dist);
are the c-code correct or wrong ?
thanks for tips and hints
regards
nomad
Comments
be changed to
The Spin is repeating UNTIL the received value == a desired value.
When using a WHILE statement in C you would repeat as long as the received value doesn't equal the desired value.
tom
.
In the second example the Spin code is transmitting "R" and then waiting until "D=" is received. It then reads an integer. The C code is very different; it's not sending anything or waiting for anything, and it's reading a floating point number.
BTW, are you aware of the spin2cpp tool? It can convert Spin to C or PASM, so it makes comparing Spin code with those other languages much easier. The spincvt GUI for spin2cpp is pretty easy to use, I think.
Eric
thanks for your answer
today i make it.
regards
nomad