>
> At 10:00 PM 8/1/2007, 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.
>
> It would help if you indicated exactly what "strings" you plan on
> sending. I don't imagine you'll be sending single character
commands forever.
>
>
> >In C, there is a specific function for this called atoi, but I
can't
> >find anything like it in the OOPic manual.
>
> There isn't anything like it. You'll have to roll your own.
>
>
> >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
>
> I take it you're echoing the characters back to the PC here?
>
>
> > End If
> > A = B
>
> That will (sometimes) grab the NEXT character from the serial port
> and put it in A.
>
>
> > 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.
>
> You need to convert from ASCII characters to numeric values. You
> need an atoi...
>
>
> >Any thoughts?
>
> Sure. It looks like you want to send '0' or '1' to turn the DIO1
off or on.
>
> a = 0
> do
> if b.received then
> c = b // copy rcvd character to c (declare c as a byte
variable)
> b = c // echo character back to PC
>
> // set a to zero or one
>
> a = c - 48 // '0' = ASCII code #48, '1' = ASCII code #49
> end if
> loop
>
>
> You'll have to clean that up for whatever OOPic "language" you're
> using (BASIC?)
>
> I imagine you'd like to do more than just toggle a single DIO1 - so
> what's next?
>
>
> ...Andy
>
Thanks guys,
Your answers were quite helpful. Believe it or not, I really DO just
want to toggle a switch on and off via my PC LOL. In this case its a
switch for a light on a moving object I'm trying to track. A webcam
takes a picture with the light on and then off, and I use this
information to track position, movement, etc. As long as the object
moves slow enough, the oSerial object will work. Later on, I might
have to get smarter (heaven forbid).
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:
No comments:
Post a Comment