Shop OBEX P1 Docs P2 Docs Learn Events
Reading and Writing Bytes using Array's — Parallax Forums

Reading and Writing Bytes using Array's

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-02-20 03:59 in Propeller 1
Good morning all,

Can someone lead me to some examples or a good read on arrays. I need to be able to read 3 bytes of data from " datain[noparse][[/noparse] 2] " , multiply the first byte * 100, the second * 10 and the 3rd *1. I then need to add these togather and save the result in a varible to pass to another method.

Thanks for the help,
JMLStamp2p

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-19 20:31
    You need to explain a few things first:

    1) What's " datain[noparse][[/noparse] 2] "?

    2) What do you mean by "read 3 bytes of data"?

    3) When you talk about multiplying by powers of 10, do you mean that the data is a series of 3 ASCII digits (characters)?

    Have you looked at the Extended FullDuplexSerial object from the Object Exchange? This has routines to do this sort of thing. These routines all assume that the string of characters ends with a return character, but they can be easily changed.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-02-19 21:14
    Hello Mike,
    ...............................................................
    I'm using the declaration below, please let me know if this is wrong.

    VAR
    Byte datain[noparse][[/noparse] 2] '3 element Byte Array, location 0, 1 & 2

    Will this array hold 3 "bytes" ?
    What I am trying to do is this: I am entering 3 numbers via a 4 by 4 matrix keypad that
    outputs ASCII. I am doing a conversion in the code so that the number shows up on my serial display as "three digits" DEC. I would like to enter "0 - 999" and read this number in an array or save it in a varible. When I have this number intered, example: "123" I then push the "A" button on the keypad to jump to a method that will transmit the number out the serial port. I am simply trying to take the first number in the Array * 100, 2nd *10 and the third number *1 to transform the number into "One Hundred tenty three" DEC. I am currently using FullDuplexSerial and the full thread is under "Need help with the following code" about half way down the first page of the Propeller forum.
    You have helped me a couple of days ago with a version of "rxStr" that worked well.
    I can currently enter the number via the keypad, have it show up on the serial display in DEC digits. When I push the "A" button on the Keypad it jumps to a method and transmits a "test" byte out the port and also moves the cursor to the next line so that I can input the next "3 digit number". I need an example of how to read the number that is entered into the array and use that number to decrement a counter and turn on an output. If you would would take a look at the complete code listed and give me your advice.it would be greatly appreciated.

    JMLStamp2p
  • hippyhippy Posts: 1,981
    edited 2008-02-20 01:15
    PRI HandleNumber | value
      value = ( DigitValue(0) * 100 ) + ( DigitValue(1) * 10 ) + DigitValue(2)
      AnotherMethod( value )
    
    PRI DigitValue( index )
      result := datain[noparse][[/noparse] index ] & $0F
    
    PRI AnotherMethod( value )
    
    



    You may have to swap DigitValue(0),(1),(2) the other way round depending how you are storing your bytes.
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-20 01:20
    ... and make the dataIn long enough: "2" just means "2"
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-02-20 03:59
    Thanks guys,

    I will work with this example and get back with you on any questions that I have.

    JMLStamp2p
Sign In or Register to comment.