Sign in

username:

password:



Not a member?

Search oopic



Search tips

Subscribe to oopic



Ads

Discussion Groups

Discussion Groups | | Strings & Manipulation

Strings & Manipulation - teh_gamr - May 19 16:32:23 2008

Hello all,

I've got a CMUcam tracking an object connected serially to an oopic.
The camera returns packets of type:
"T 125 52" where 125 and 52 are examples of the numbers I need,
followed by carriage return (ASCII 13).

What I need to do is take those two numbers and convert them from
ASCII to decimal or whatnot.

I can assign the number to an oBuffer object, but it's still in ASCII.
What to do next?

Thanks,
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )


Re: Strings & Manipulation - tinslwc - May 20 17:03:16 2008

Since you already have the information in the buffer, you need to
examine each digit and add them together with the correct multiplier.
You might have to get fancy to determine the number of digits. To get
the digit from ASCII to decimal, simply subtract 48 from the value and
there you go. Now start right to left and add the Right*(10^0) +
(Right-1)*10^1 + (Right-2)*(10^2)... Until you get to the left digit.
One possible method would be to find the space and then work backwards
from there adding the digit and the multiplier. If you need some help
with the code, let me know and I will try to help you.
--- In o...@yahoogroups.com, "teh_gamr" wrote:
>
> Hello all,
>
> I've got a CMUcam tracking an object connected serially to an oopic.
> The camera returns packets of type:
> "T 125 52" where 125 and 52 are examples of the numbers I need,
> followed by carriage return (ASCII 13).
>
> What I need to do is take those two numbers and convert them from
> ASCII to decimal or whatnot.
>
> I can assign the number to an oBuffer object, but it's still in ASCII.
> What to do next?
>
> Thanks,
>

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Strings & Manipulation - rtstofer - May 20 18:45:38 2008

--- In o...@yahoogroups.com, "tinslwc" wrote:
>
> Since you already have the information in the buffer, you need to
> examine each digit and add them together with the correct
multiplier.
> You might have to get fancy to determine the number of digits. To
get
> the digit from ASCII to decimal, simply subtract 48 from the value
and
> there you go. Now start right to left and add the Right*(10^0) +
> (Right-1)*10^1 + (Right-2)*(10^2)... Until you get to the left
digit.
> One possible method would be to find the space and then work
backwards
> from there adding the digit and the multiplier. If you need some
help
> with the code, let me know and I will try to help you.

Yes, you are going to have to do this the hard way. When you read
the 'T', you know to expect 2 numbers potentially starting with a
space (between T and the first number) ending in a space or some
combination of CR or LF.

So, when you detect the 'T', set both variables to 0. Now, as you
read the first digit, multiply the first variable by 10 and add in
the new digit (calculated as the ASCII val - '0'). Keep going, digit
by digit, until you encounter a space. Now start converting the
second number in the same manner until you get a space, CR or LF. In
fact, you should terminate conversion when you detect a non-digit,
regardless of what it is.

This should not require a buffer if you can act quickly enough on the
incoming chars. If not, go ahead an put the chars in a buffer and
work through the buffer from left to right as indicated above.

Richard

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Strings & Manipulation - teh_gamr - May 22 2:45:05 2008

Hello, thanks for your replies!

I managed to get it working for the first number only. The incoming
serial data looks like this:
"T 55
T 100
T 129" etc

Followed your advice and my code looks like below.
It's working perfectly. Now, the first number after the T is the x
position of the object being tracked, the second is confidence value
of the tracking (number of pixels or something).

I'll work on getting the second number later today, shouldn't be a
problem now that I got the first.
Do
LCD.Clear
LCD.Locate(0,0)
LCD.VString = Str$(xpos)
Delay = 300
Loop

End Sub
Sub serialReceive_Event_Code()

While(cmu.Received = cvTrue)
rxBuff.Value=cmu.Value

If rxBuff.Value = 13
processPacket()

rxBuff.Location=0
Else
rxBuff.Location = rxBuff.Location + 1
EndIf
Wend
End Sub

Sub processPacket()

rxBuff.Location = 2
c1 = rxBuff.Value
rxBuff.Location = 3
If (rxBuff.Value = 13)
a = 1

Else
c2 = rxBuff.Value

a=2
EndIf

If (a!=1)
rxBuff.Location = 4
If (rxBuff.Value = 13)
a = 2
Else
c3 = rxBuff.Value
a = 3
EndIf

EndIf
Delay = 300

c1 = c1 - 48
Select Case a
Case 1
xpos = c1

Case 2
c2 = c2 - 48
xpos = 10*c1 + c2
Case 3
c2 = c2 - 48
c3 = c3 - 48
xpos = 100*c1 + 10*c2 + c3
End Select

End Sub

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )