String data out from serial port
amerro
Posts: 3
Hi
I am very new to the Propeller chip and programming it so please bare with me;
What I am trying to do is take a line of text from the DAT Section and depending on the index within the loop is to what line of text is required from the DATA section and that line of text output via a serial link.
The following is part of code:
Pub Upset | codeout
If index => 1 and index < 8
index ++
SetSerout
LCD.str(string ??????? 'this is where I would place the line of code to Output indexed to "index"
else
index := 8
Pub SetSerout
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
Dat
StepNo byte "1 first step recover", '0
byte "2 second step over", 0
:
:
byte "8 last line of data ", 0
I have no problem with this line of code compiling:
LCD.str(string("some txt"))
or this line:
LCD.str(string(@StepNo))
but I am missing how to access the data to index it out according to the code in " PUB Upset."
Some help or direct me to a location which best explains the operation of string or indexind this data out would be much appreciated.
Many Thanks
I am very new to the Propeller chip and programming it so please bare with me;
What I am trying to do is take a line of text from the DAT Section and depending on the index within the loop is to what line of text is required from the DATA section and that line of text output via a serial link.
The following is part of code:
Pub Upset | codeout
If index => 1 and index < 8
index ++
SetSerout
LCD.str(string ??????? 'this is where I would place the line of code to Output indexed to "index"
else
index := 8
Pub SetSerout
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
Dat
StepNo byte "1 first step recover", '0
byte "2 second step over", 0
:
:
byte "8 last line of data ", 0
I have no problem with this line of code compiling:
LCD.str(string("some txt"))
or this line:
LCD.str(string(@StepNo))
but I am missing how to access the data to index it out according to the code in " PUB Upset."
Some help or direct me to a location which best explains the operation of string or indexind this data out would be much appreciated.
Many Thanks
Comments
I've found a library of string functions is very handy - http://forums.parallax.com/showthread.php?128779-KyeDOS-an-operating-system-for-the-Propeller and download the Kyedos zip and then inside that is a .spin method with pretty much all the string handling functions I can think of.
If stepno is a string, you could reserve some space in the VAR section with
byte stepno[80] ' reserves 80 bytes
Then use Kye's code to build strings, eg str.copy(string("Hello"),@stepno) ' moves "Hello" into the stepno array ready to do other things with this data
Strings still end up being complicated in Spin. In Basic you would just say
dim mystring(100) as string
and you then have an array that you can put 101 strings into. mystring(0)="Hello" mystring(1)= "World"
In Spin, as with C, you are 'closer to the metal', as it were. So you can have a list of data, and maybe you find that your longest string is 20 bytes, and the first element is "Hello" so you put that at location 0, and then you have "World" as the second element, so you put that at location 20, and so on. Then you can find your string with address := element n*20
But the above does waste memory space (as does the Basic example). So you could pack your strings in with no gaps. but then you need a routine to get the strings out again.
Or, keep it simple;
address = x
if address == 0
lcd.str(string("Hello"))
if address == 1
lcd.str(string("World"))
or put those in a Case statement.
There are a number of solutions. Maybe I'm not answering it fully. Can you explain a bit more what you want to do?
LCD.str(@StepNo)
string() simply formats a sting adding the final zero. You already have it.
Anyway either use a CASE or index stepno
@stepno is equivalent to @stepno[0]
next message will start at @stepno[n]
If you keep the messages of fixed size (adding zeros at the end..), you can index with @stepno[n*i] where n is message size (zero including) and i is the index, starting from zero...
Massimo
Either you are going to need count the nulls to find the offset from the first (i.e. [0]) element, or you will need to do fixed length strings and calculate as suggested by massimo.
All replys have further enlightened me to the process. I much prefer to have all the strings in DATA and execute from there.
I think Massmo has shown me the way and what I couldn't previously understand is the syntax to get the result as you have shown.
I can see several way and all have been helpful.
Is there some content other than the spin manual, which details the syntax required to get these outcomes.
Thanks
Peter
Take the following suggestions as a personal opinion.
Tha manual is quite good, but it is a reference manual. So starting from there is not so easy.
From the web site you can find other books. I have the Hydra manual, which in my opinion is a great guide about graphics, TV, double buffering and so on, even if you do not plan to make games.
Programming and Customizing... tackles some aspects in depth, is a very good book, but I'm not sure is the starting point. I don't have the other books so I cannot tell.
On the other hand there is a lot of stuff available on the web site. Check nuts and volts columns,
http://www.parallax.com/Resources/NutsVoltsColumns/TheSpinZone/tabid/781/Default.aspx
and http://www.parallax.com/tabid/832/Default.aspx for the documentation.
http://propeller.wikispaces.com/ has helpful stuff, too. Fro instance byte/word/long has been addressed. If you feel like that you can add and integrate it.
Then there is the object exchange. You can find not only cutting edge stuff, squeezing the last drop of computational power form the chip, but also a lot of useful code, great for learning and taking inspiration.
Some are well documented, others not, but in my experience it has been a good starting place.
Lastly this forum is probably the best resource available.
Have fun.
Massimo
http://www.gadgetgangster.com/tutorials.html
Massimo