Shop OBEX P1 Docs P2 Docs Learn Events
display value from another object — Parallax Forums

display value from another object

charleyshfcharleyshf Posts: 165
edited 2011-03-13 19:27 in Propeller 1
Hello,

I've been working on an object that basically controls a motor controller, now what I have done so far is I am creating another object to get results from the motor controller object, I am not getting the results that I thought I would.

From the motor controller object:
PUB GetBattery | i
    serial.RXflush
    serial.tx(128)
    serial.tx(24)
      repeat i from 0 to 2
           x[i] := Serial.rx  'receive 3 characters
 
      x[3] := 0          'set last character to zero to mark end of string
      Return  x

The new object I am working on I am trying to get the above x result by doing the following:
PST.Dec(MOTOR.GetBattery)

Like I said above the result is not what I expected at all. I'd appreciate any help

thanks

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-03-13 15:33
    if x[0] := 0 and x[1] := 1 and x[2] := 2

    Then
    Return X returns 0 or x[0]

    Is x[0] that the index you expect?
  • charleyshfcharleyshf Posts: 165
    edited 2011-03-13 15:40
    Hi Mike,,

    x[0] is the index that I am trying to get, however the result is always 0, the result is always a different number(voltage monitor on the motor controller)
    Mike G wrote: »
    if x[0] := 0 and x[1] := 1 and x[2] := 2

    Then
    Return X returns 0 or x[0]

    Is x[0] that the index you expect?
  • Mike GMike G Posts: 2,702
    edited 2011-03-13 16:02
    How is X defined as bytes?
    Why do you do this x[3] := 0?
    What is in X[0] a number or a string?
  • charleyshfcharleyshf Posts: 165
    edited 2011-03-13 16:12
    I have x defined as byte x[2] now
    the x[3] was because the motor controller is controlled by serial and in the beginning I was just using a single object to display the results of commands that I sent to the motor controller via PST(so the last byte had to be 0) now that I have motor controller as it's own object I am trying to get another object to display the value by using:
    PST.Dec(MOTOR.GetBattery)

    My old code for this method looked like this:
    PUB GetBattery | i
        serial.RXflush
        serial.tx(128)
        serial.tx(24)
          repeat i from 0 to 2
               x[i] := Serial.rx   'receive 3 characters
          x[3] := 0          'set last character to zero to mark end of string
          PST.Str(String("First = "))
          PST.Dec (x[0])
          PST.Str(string(13,"Second = "))
          PST.Dec(x[1])
          PST.Str(string (13,"Third = "))
          PST.Dec (x[2])
          PST.NewLine
        PST.Str(String(13,"End",13))
    

    the x[0] I thought was the result of what serial.rx got for each byte
    Mike G wrote: »
    How is X defined as bytes?
    Why do you do this x[3] := 0?
    What is in X[0] a number if a string?
  • charleyshfcharleyshf Posts: 165
    edited 2011-03-13 16:23
    I just figured it out, I should of had:
    Result := x[0] <<8 |x[1]
          Return Result
    

    Sorry about that, I think I was trying to add the bytes together....
  • Mike GMike G Posts: 2,702
    edited 2011-03-13 16:41
    Ah... I was wondering what the other bytes were for.
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-03-13 19:27
    Going to the original code post. GetBattery builds a string of length 3. PST.Dec wants an integer for its argument. Try PST.str(Motor.GetBattery)

    John Abshier
Sign In or Register to comment.