Array Help
eagletalontim
Posts: 1,399
This is following my power meter logger project..... I am attempting to store the date and time and a generated number in an array then when it is called for by my computer program, it will dump all the information to the computer for processing. Once all the information is sent to the computer, the array is cleared and the "pointer" is reset back to 0. I am trying to find the most efficient way to do this but am having a huge brain fart at the current moment
The process so far is....
When the Prop boots up, it will default to January 1, 2012 at 12:00AM (0101121200).
When the computer program starts up, it sends a serial signal to the PROP to update it's date and time to the computer's system time.
Every 2 seconds, the computer program requests other information from the PROP to simply display on the screen for user information purposes.
Every hour, the PROP dumps the Watt Hours Used into an Array which should be stored something like ("0929121628:1234", "next one", "another one")... Not sure if this is the best way.
At every top of the hour, the computer program sends a signal to the PROP to collect the Array data stored at the current time. Each array element is broken down and stored on my off site server's database.
If the information was successfully update on the offsite server, the Array is reset and the system time is sent back to the PROP to "sync" the time again.
The whole cycle is restarted over again.
My question is about the long array value that needs to be stored.... Since an example value would be "0929121628:1234", would the array variable be a LONG or WORD or something else?
Or....
Is there a better way to do the process above?
The process so far is....
When the Prop boots up, it will default to January 1, 2012 at 12:00AM (0101121200).
When the computer program starts up, it sends a serial signal to the PROP to update it's date and time to the computer's system time.
Every 2 seconds, the computer program requests other information from the PROP to simply display on the screen for user information purposes.
Every hour, the PROP dumps the Watt Hours Used into an Array which should be stored something like ("0929121628:1234", "next one", "another one")... Not sure if this is the best way.
At every top of the hour, the computer program sends a signal to the PROP to collect the Array data stored at the current time. Each array element is broken down and stored on my off site server's database.
If the information was successfully update on the offsite server, the Array is reset and the system time is sent back to the PROP to "sync" the time again.
The whole cycle is restarted over again.
My question is about the long array value that needs to be stored.... Since an example value would be "0929121628:1234", would the array variable be a LONG or WORD or something else?
Or....
Is there a better way to do the process above?
Comments
http://www.parallaxsemiconductor.com/an003
There's an EEPROM datalogging section in the PEK sticky.
I don't blame you for not wanting to make your program more complicated than needed for now.
As far as storing "00", it depends on what you mean by "00".
If you want them to be two ASCII zero characters (48), then it wouldn't fit in a single byte. Bytes are used to store characters (one byte per chardacter). Based on your earlier posts, it looks like you want to store your data as ASCII characters. This will require one byte for each digit.
I know there are several threads discussing ASCII characters versus normal variable numbers. I'll try to find some of them and post links here.
not sure how but something like this : AddData(string(Time_Count_Month & Time_Count_Day & Time_Count_Year & Time_Count_Hours & Time_Count_Minutes & Time_Count_Hours & ":" & pulseCount))
I don't know how to "add" variables together to make a string. Example :
Variable1 := 12
Variable2 := 34
Ouput = Variable1 & Variable2
' 1234
Let say you have a byte and the byte equals 0x41 or 65. By the way, 0x41 is hexadecimal notation, in Spin it's $41. So you have this number 65 but what does is mean? Well, it can mean 65 units to the right of 0. It can also mean the character A.
A long time ago in a galaxy far far away... someone said how the heck do I send an "A" so the guy on the other end of this wire understands I mean "A".
Alakazam! American Standard Code for Information Interchange (ASCII)
http://en.wikipedia.org/wiki/ASCII
I believe you are struggling with the concept of character encoding.
BTW, ASCII is not the only encoding scheme but very common.
However, if you simply want to convey two integers then no need to encode the values.
From what I understand (or think I understand) :
Bit = 0 or 1
Byte = 0 to 255
Long = Not sure
Word = 65000 or something like that. (max size from SX28 experience)
String = Text (NA Variable type on Prop)
In PHP, to append to a string you would do this :
Variable1 = "01";
Variable2 = "23";
Ouput = Variable1 . Variable2;
echo Output
This would output on the screen : 0123 with the leading zero. I have yet to figure out how to bring together 2 variables in Spin like this. Since I am working with VB6, I have limitations to what I can send and receive from the PROP when it comes to long variables, but sending multiple variables all at once slows down the VB program which makes it "hang" for a split second. This is why I went to using Arrays to store the pulse count from the meter every hour. I could easily loop through the arrays and send each value to the VB program then clear the array once all values were sent successfully. The problem I have run into is saving the values to an array and tying them to a specific time. I need to do this incase my computer is not on and the software is not pulling information for a period of time. One other way I have thought of doing this is to have a multi-dimensional array so I can store 2 values per pointer.... Example :
myArray[0][0] := DayOfValue
myArray[0][1] := TimeOfValue
myArray[0][2] := pulseCount
Since VB6 has the DatePart("y", Now) ability which outputs what number day it is in the year (1 to 365), I could store the DayOfValue as a number between 1 and 365. Not sure how it does on leap years though.
I don't think you really need to worry about storing your data as character strings. I'd think you'd be better off storing them as a byte, word or long and just let the serial driver convert them when it's time to send them to the PC.
The "dec" method will convert the variable to ASCII characters for you. You may need to find a serial object that has a zero padding option. Tim Moore's four port serial object has zero padding.
Come to find out, I cannot use multi dimensional arrays in Spin the way i figured http://forums.parallax.com/showthread.php?99888-Multi-dimensional-arrays-in-Propeller
Could someone help me on understanding on how it can be achieved in Spin? I don't quite understand the posts in that thread above or how they are supposed to work. I was hoping to have an array with 255 possible pointers and 3 addition dimensions per pointer...if that makes any sense.
If this cannot be achieved, I have also found this thread : http://forums.parallax.com/showthread.php?124308-Newb-question-Append-to-a-variable&highlight=append+variable
I can apparently merge variables together which would allow me to make the array something like this : myArray("DayOfYear:Time_Counter_Hours:pulseCount", "next one saved.....")
I think the variable append method may be a better method in the long run since I could simply store the "varAll" to the EEPROM for long term storage.
So I am confused on how you can get the "max variable value" based on the variable type (Byte, Long, Word). If a Long is 16 Bits and a Bit is 1 or 0, then I supposed the max value for a long is 1,111,111,111,111,111 (16ea 1's)? Sorry to sound so much like a newb, but this is one thing I just can't quite grasp.... Just like in school, I failed pre-algebra twice till I had a teacher who said the right thing and everything clicked
The first demo posted will handle a jagged string.
This demo will handle an integer name value collection.