Can some one help me translate the following line of code from a Basic Stamp BS2 to GC Basic? I have tried everything imaginable with no luck. I am trying to read a number transmitted in ASCII at 1200 baud and then convert it to a decimal number. The decimal number will be a word not a byte.
SERIN SI, 17197, [DEC sData]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Very little information to go on. Literally it would be: SerReceive(1,sData)? But you need to add code for word variables, and ascii to decimal procedure.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I guess I should be more concise. My questions probably ought to be as follows. What should the InitSer command look like for the line of code I mentioned? Also, how do I convert from ASCII to decimal? Say the ASCII of sData was "255",
how could I make it a decimal value of 255? Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The only thing being read from the serial port will be a number from 0 to 1023 and it will always be in ASCII format. There will never be any other characters. I can read the output on a computer terminal and have been to told these numbers are in ASCII format. I will need to configure the InitSer command to receive the way a computer terminal works. I guess that will be something like this to receive at 1200 baud?
InitSer (1, r1200, 1, 8, 1, none, normal)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To read the number, you'll need to read a character at a time from the serial port using SerReceive. You can put these into an array, starting at location 1. Once you get an ASCII character that is not a number, such as null or CR, put the total length into location 0 of the array, and pass it too the above function. If the array was called StringIn, you'd call the function like this:
OutNo = GetDecimal(StringIn())
(As you may have guessed from above, strings in GCBASIC are just arrays. Element 0 contains the length of the string and the rest of the elements hold the characters.)
If you need help writing or debugging code to do any of that, just say so.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can some one help me translate the following line of code from a Basic Stamp BS2 to GC Basic? I have tried everything imaginable with no luck. I am trying to read a number transmitted in ASCII at 1200 baud and then convert it to a decimal number. The decimal number will be a word not a byte.
SERIN SI, 17197, [DEC sData]
Very little information to go on. Literally it would be: SerReceive(1,sData)? But you need to add code for word variables, and ascii to decimal procedure.
I guess I should be more concise. My questions probably ought to be as follows. What should the InitSer command look like for the line of code I mentioned? Also, how do I convert from ASCII to decimal? Say the ASCII of sData was "255",
how could I make it a decimal value of 255? Thanks.
For help with the InitSer command, refer to this help page: http://gcbasic.sourceforge.net/help/initser.htm
Here is a function you can use to convert from ASCII to decimal:
Function GetDecimal(InData As String) As Word
Dim PlaceVal As Word
InLen = InData(0)
GetDecimal = 0
PlaceVal = 1
For Temp = InLen to 1 Step -1
GetDecimal = GetDecimal + (InData(Temp) - 48) * PlaceVal
PlaceVal = PlaceVal * 10
Next
End Function
I'm not sure exactly what is going to be read from the serial port, so I can't really help there except to recommend the SerReceive command.
Hugh:
Thanks for the function. I will give it a try.
The only thing being read from the serial port will be a number from 0 to 1023 and it will always be in ASCII format. There will never be any other characters. I can read the output on a computer terminal and have been to told these numbers are in ASCII format. I will need to configure the InitSer command to receive the way a computer terminal works. I guess that will be something like this to receive at 1200 baud?
InitSer (1, r1200, 1, 8, 1, none, normal)
The InitSer command looks fine.
To read the number, you'll need to read a character at a time from the serial port using SerReceive. You can put these into an array, starting at location 1. Once you get an ASCII character that is not a number, such as null or CR, put the total length into location 0 of the array, and pass it too the above function. If the array was called StringIn, you'd call the function like this:
OutNo = GetDecimal(StringIn())
(As you may have guessed from above, strings in GCBASIC are just arrays. Element 0 contains the length of the string and the rest of the elements hold the characters.)
If you need help writing or debugging code to do any of that, just say so.