Hi there
I need to keep some variables from the configuration of my program, and I need to run it, but that will change in time. When I reprogram the logger values are lost and I have to put them on hand. I was wondering if I create a field in the status table (which is not affected with the reprogramming of a season!) And store my data there?
Or if you can do the same thing using another tipe of variables that are not deleted by reprogramming?
Have you looked at ConstTable/EndConstTable to see if it would satisfy your needs?
it doesnt because i need it a variavel that take the value of the variable in all scans (and the value varies), so that when i reprogram the station it starts with the last value that was measured.
* Last updated by: TaCaPica on 12/10/2010 @ 11:41 AM *
Hello TaCaPica,
Take a look at the PreserveVariables function and see if that will do what you want.
Also, look at Data/Read/Restore.
Yet another option might be to store a file on the CPU or USR drive, and read the values back in with a FileRead to populate the variables.
Regards,
Dana W.
Take a look at the CalFile instruction.
Regards,
Janet
In reference to Dana's last suggestion, here is one method you could use
'Purpose:
'Demonstrate how FileWrite and FileRead can be used to create
'a custom configuration file routine
Public Var01 '1st variable to be saved / restored
Public Var02 '2nd variable to be saved / restored
Public Var03 '3rd variable to be saved / restored
Public Save, Load 'flags to trigger saving / reading file, non-zero = true
Const FName = "USR:config.cfg" 'name of config file, write to USR, CRD, or USB drive
Dim FContent As String * 63 'content of config file, must be larger than actual content
Dim FHandle As Long 'used for file reference
Dim XMLRet 'code returned by XMLParse Sub
Sub XMLParse(Success As Float, Content As String * 63, XML As String * 127, Element As String * 31)
'XMLParse Subroutine
' Success = Return code
' * Value >= 1, Success, Start position of content within specified element.
' * -1, Tag open not found
' * -2, Tag open found, but tag close not found
'
' Content = Contents of XML Element Being Searched For, e.g. "350.21" for string provided below
' XML = XML Data To Be Searched, e.g. "<CO2>350.21</CO2><CRC>3067450353</CRC>"
' Element = Element tag to search for, not including "<" or ">". It is case sensitive., e.g. "CO2" for string example provided above
Dim TagO, TagC 'need pointers to begining and end of element content
Content = "" 'return empty string if unsuccessful
TagO = InStr (1,XML,"<" + Element + ">",4) 'beginning of element content
TagC = InStr (1,XML,"</" + Element + ">",2) 'end of element content
If TagO > 0 Then 'actually found tag open
If TagC > TagO Then 'found tag close and it is after tag open
Content = Trim(Mid (XML,TagO,TagC-TagO)) 'pull out the element content
Success = TagO 'success indicator is position of first character in element content
Else
Success = -2 'could not find tag close
EndIf
Else
Success = -1 'could not find tag open
EndIf
EndSub
BeginProg
'Set aside space for configuration file
SetStatus ("USRDriveSize","5000")
'Main Scan
Scan (1,Sec,0,0)
'Save / File Write
If Save Then
Save = 0
FContent = "<Var01>" + Var01 + "</Var01>" + _
"<Var02>" + Var02 + "</Var02>" + _
"<Var03>" + Var03 + "</Var03>"
SemaphoreGet (1) 'lock file resource
FHandle = FileOpen (FName,"w",0) 'open file
FileWrite (FHandle,FContent,0) 'write file
FileClose (FHandle) 'close file
SemaphoreRelease (1) 'release file resource
EndIf
'Load / File Read
If Load Then
Load = 0
SemaphoreGet (1) 'lock file resource
FHandle = FileOpen (FName,"r",0) 'open file
FileRead (FHandle,FContent,64) 'read file
FileClose (FHandle) 'close file
SemaphoreRelease (1) 'release file resource
Call XMLParse(XMLRet, Var01, FContent, "Var01") 'extract value
Call XMLParse(XMLRet, Var02, FContent, "Var02") 'extract value
Call XMLParse(XMLRet, Var03, FContent, "Var03") 'extract value
EndIf
NextScan
EndProg
* Last updated by: Sam on 12/10/2010 @ 8:44 PM *