This Forum is Dedicated For all The Object Oriented PIC Lovers .......... The concept behind OOPic is straight forward. Use preprogrammed multitasking Objects from a library of highly optimized Objects to do all the work of interacting with the hardware. Then write small scripts in Basic, C, or Java syntax styles to control the Objects. During operation, the Objects run continuously and simultaneously in the background while the scripts run in the foreground telling the objects what to do.

Wednesday, August 1, 2007

Re: [oopic] Converting a string value to a numeric value?

thetruth_as_i_seeit wrote:
> I'm trying to receive data to my OOPic R through a serial port
> connected to a laptop. I want to use this data to control objects
> from the OOPic but, in order to do that, I need to convert the string
> data that is coming from the serial port to numeric data.
>
> In C, there is a specific function for this called atoi, but I can't
> find anything like it in the OOPic manual.
>
> Just in case anybody wants to see it, here is my code ...
>
> Dim A As New oDIO1
> Dim B as New oSerial
>
> Sub Main()
> A.IOLine = 8
> A.Direction = cvOutput
> B.Baud = cv9600
> B.Operate = cvTrue
> A = 0
> Do
> If B.Received = cvTrue then
> B.Value = B.value
> End If
> A = B
> Loop
> End Sub
>
> Obviously, this doesn't work because B is not a zero or one in a
> numerical sense, and what I am picking up is ASCI code ... in other
> words a whole bunch of zeros and ones.
>
> Any thoughts?
>
>
>
>
>

I am assuming the value you are receiving with the oSerial object is an
ascii value. In which case the zero value that you sent from the PC will
be received as ascii 48

You could do this with a select case construct for example:-

Select Case B

Case 48: A = 0

Case 49: A =1

end select

or alternately:-

If B = 48 then A = 0
If B= 49 then A = 1


However the most effective way to communicate with the Oopic is by using
SCP commands. Read Chapter 16 of the manual for details.
With SCP you can write/read data to/from any object directly without
having any code resident on the Oopic.

Regards

Ian



Yahoo! Groups Links

<*> To visit your group on the web, go to:

http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:

http://groups.yahoo.com/group/oopic/join

(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

http://docs.yahoo.com/info/terms/

No comments: