Shop OBEX P1 Docs P2 Docs Learn Events
Reading and writing an Array Problem. — Parallax Forums

Reading and writing an Array Problem.

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-03-04 23:36 in Propeller 1
Hello All, Please see attached "Spin" file for complete code and comments.
In my "Recieved_Data" method I am not reading and writing my array "datain[noparse][[/noparse] 3]" correctly. The Recieved_Data method is sending the numbers out the port and I can see them on my reciever end·via my LCD. The problem with my Recieved_Data method is this:

1) After recieving 3 bytes it should transmit the values in locations (0,1 & 2) in the "datain"·array to the LCD. The problem is that they are not sent to the LCD until the 2nd set of "3" bytes are recieved.

2) When they are sent to the LCD, 3 numbers appear on my LCD in the correct location but 2 out of 3 numbers are from the last set sent. And 1 number is from the first set sent.

Its looks as though I am not reading and writing the array in the correct manner.·If someone can look at the whole code and give me some advice it would be greatly appreciated.

PS: I have tried changing the number of array elements all the way up to 20
and it does not make a difference.

Regards,
JMLStamp2p
···
···

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-02-29 20:32
    JMLStamp,
    the main reason for the misbehavior is this line
     Success := (cog := cognew (Recieved_Data(3,@datain),@Stack_2) + 1)
    


    You are using @datain for inputing from the keyboard as well as inputting the data string

    I assume you wanted to use
    datain_2
    here, as this not used otherwise, and looks suitable.

    But Received_Data will not work very well. Think a little bit of ehat happens after "num_of_nums" characters have been received..

    Also, I should suggest that you re-write your program totally, as it is not fun to read, and will be difficult to maintain even in this early stage.

    Post Edited (deSilva) : 2/29/2008 8:38:40 PM GMT
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-02-29 22:33
    DeSilva,
    The reason I did this is because the data entered by the Keypad and stored in the array is used for Timer countdown varibles. These varibles are going to have to be sent also from a remote location to control the same timers and hense storing them in "datain". The array is "Global" is it not ? Values will not be enterred by the Keypad and the tranciever at the same time and therefore no data will be "butting heads".
    What exactly do you mean by:
    But Received_Data will not work very well. Think a little bit of ehat happens after "num_of_nums" characters have been received..
    When I enter 3 numbers via the Keypad the array pointer is reset to "0". When the Tranciever recieves 3 numbers and stores them in datain it should just overwrite the old data in the array, should it not ?
    Thanks for the help,
    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-01 17:08
    Mike & deSilva,

    The attached Spin file is a "Working" model of my "Remote Control
    Spin Program" to date.

    This·Object when finished will be able to send and recieve data between 2 Props via a "RF" link. They will be able to write to each others data arrays
    and Display the results as they happen on an Matrix Orbital LK204-25. This
    is a Smart LCD with programmable general purpose outputs and has debouncing circuits for the Keypad built in.

    The problem with the array was that I was saving the data in the array as a "dec" value and using data.tx when transmitting the bytes to the remote Prop. When I changed it to "data.dec" I started getting the correct ASCII values showing on my LCD with respect to the digits on my Keypad 1,2,3,4,ect. I also started recieving 3 numbers in the correct locations. It's kinda funny, sometimes when I look at this stuff for a long time it starts running togather. I was praying this morning, GOD give me the understanding to do this and it was like one window started opening after another and now it seems like everything that I have tried to do up to this point is working. The Recieved_data· method is running in it's own Cog as you can see by the attached file. It was important for it to do this because my program needed to be able to handle input from the Keypad even when the Recieved_data method was accepting data in the port. I still have a wy to go but wanted to thank you both for your continued help.

    Regards,
    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-03-04 23:36
    Jeff, my latest code is attached. Please reply to JMLStamp2p@aol.com when you get a chance to look at it.
    Thanks,
    JMLStamp2p
Sign In or Register to comment.