Hi,
i want to exclude some configuration parameters, such as multiplier and offset in a seperate configuration file to keep it out from the original config file.
The idea is, if somebody has to change some multiplier or offsets of any sensor because of change of the sensors, he only has to edit the config file with the parameters.
My idea is:
config file with the programm
config file for sensors of anemometers
config file for sensors of windvanes
etc...
i tried a little with the filehandler.... but i haven't fine a good solution.......
if anybody has any good examples or solutions for this...would be great.
thanks in advance
Could you explain further what you mean by Config Files? Are you referring to the datalogger program files, DevConfig's configuration files, Split's (a post processing program) PAR file, or something else?
Dana W.
Hi,
i would like to exclude the multiplier and offset values in a seperate config file.
for example:
My CR3000 is running on cpu with programm.CR3
here i have the main programm written.
BeginProg
Scan(5,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'014A Wind Speed Sensor measurement WS_ms
PulseCount(WS_ms,1,1,2,1,multiplier,offset)
If WS_ms<0.457 Then WS_ms=0
'Call Data Tables and Store Data
CallTable(Table1)
CallTable(Table2)
NextScan
EndProg
in a new file calibration.ini, i want to store the multiplier and the offset values to change them only in a calibration config file so that i have not to search my whole programm.CR3 for this parameters.
I hope it is now better explained what i want to do :-)
The ConstTable facility can be used to declare constants in the program, then can be changed by various means. The program will recompile if any values are changed. E.g.,
ConstTable
multiplier = 1.2
offset = 0.03
EndConstTable
BeginProg
...
EndProg
Along with the ConstTable functionality that Kirving suggested, you could also:
* Use the CalFile instruction
* Use the Include instruction and put those values in a different program file
* Store a text file on the datalogger's CPU, USR, CRD, or USB drive and use FileRead to read the values back in to a variable
All of these are explained in the CRBasic help.
Regards,
Dana W.
Hi from Spain,
We are trying to do exactly the same thing as bsssc is proposing.
1- Having a main program where there is a subroutine that sets the multipliers and offsets for the different sensors.
2- Offsets and multipliers information is read from an external file, let's call it calibration.ini (i was thinking of a .csv file that could be prepared directly from a datasheet)
3- Subroutine is triggered: in case of re-start, in case user decides it and/or if calibration.ini changes.
The solution using FileOpen + FileRead or FileReadLine + FileClose seemed to us to be the desired one, we are in the design stage so we haven't tried this yet.
Constant solution implies a reset of the datalogger program, and, maybe I am wrong, implies the use of Device Configurator, i.e., serial cable on-site connection.
I haven't tried Include() but according to the manual it implies a recompilation of the program ==> reset.
We consider the config.ini solution to be the most elegant and practical, it allows an on-the-fly change of this parameters without reset. Our idea here is to control a network of weather stations with only one program that fits all and one config.ini that has all the sensor multipliers and offsets for the network. Using the stationName the program should get the appropiate multipliers and offsets from the config.ini file.
We will try with the File option but all help or other similar experiences would be mostly appreciated.
Regards and thanks in advance
* Last updated by: siarcida on 3/23/2011 @ 5:44 AM *
Use of the ConstTable would recompile the program. You can, however, change a ConstTable value using the datalogger's keyboard display (on-site) or using LoggerNet's terminal mode and the "C" command (see the CRBasic help).
If the Multiplier and Offset will remain constant after they are set for each site, and there are a finite list of multipliers and offsets that will be used, you might want to look at the example program in the CRBasic help for MenuRecompile, which allows you to set up the constant table values as picklists in a custom datalogger menu. This, however, would only be accessible via the datalogger's keyboard display (which might be OK if you'll be accomplishing this via on-site visits).
It may not be what you are looking for, but I thought I would point it out.
Dana W.
i'am just checking out the const function with filereadline command. if you have any demo example for a good solution may you could post it here ?!
I have found a solution, but i'm note really happy with that.
i read a ini file by "FileReadLine", but i want to read a CSV which looks like:
SensorName,serialnumber,Height,Offset,Multiplier,voltagerange
Anemometer,SN12345FFE6,20,0.04,0.02,5000
is this possible ?
now i just have read line by line in float. But i want to read also string too.
Format the variable you are putting the read values into as a string. Then use SplitStr to put each of the values in their own variable.
Dana W.
Hi Dana and bsssc
The latest solution you commented Dana, using SplitStr, is what we were trying out, though to no avail at the moment. Here is the code (variable names and csv file in Spanish but I guess it is easy to work out the purpose of them):
' ************
archivo = FileOpen("CPU:config_localizacion.csv","r",0)
FileRead(archivo, datosbrutos, 1500)
FileClose (archivo)
SplitStr(datos(), datosbrutos,",",252,0)
' **************
We've tried also with:
FileReadLine(archivo, datosbrutos, 1500)
We have troubles to understand the difference between FileRead and FileReadLine and also to use the lenght parameter in those, is lenght related to characters?, I guess so but I am not sure.
Also in the SplitStr we've changed the last parameter, since offsets and multipliers are numbers we've tried both with 0 and 3.
This is where we are at the moment, thanks for your time and responses.
PS: Regarding the keyboard display and constants, we considered it and our current program actually uses a constant table for multipliers and offsets but we'd rather use this system which would allow us to have only one program and one configuration file for the whole network.
BTW, here is a copy of part of the config file we are using:
Codigo_Estacion,Temp_Pendiente,Temp_Offset,HR_Pendiente,HR_Offset,Rad_Sensitivity,1000/Sensitivity,Anemometro_Pendiente,Anemometro_Offset,Direccion_Pendiente,Direccion_Offset,Pluviometro_Constante
501,0.1,-40,0.103,0,13.10,76.336,0.098,0,0.142,0,0.226
502,0.1,-40,0.1,0,15.00,66.667,0.098,0,0.142,0,0.200
503,0.1,-39.432,0.1,0,24.37,41.034,0.098,0,0.142,0,0.200
504,0.1,-40,0.1,0,23.04,43.403,0.098,0,0.142,0,0.199
505,0.1,-40,0.1,0,20.59,48.567,0.098,0,0.142,0,0.201
506,0.1,-40,0.1,0,22.76,43.937,0.098,0,0.142,0,0.236
Hi,
this is almost the same way which i would go too.
My config looks like:
Anemometer 01:
Name =AMSWB105
Slope =0.04596
Offset =0.0220
serial =66666666
calibrationnumber =12345678
i'am reading each line in an array, and now i have to split the string... but i have not yet found the best solution for that.....
Hi,
ok so far everything works with spliting etc. But now its a String value, how can i convert the strings into float or long ?
For example my configfile:
channel;name;serial;calibrationnumber;Offset;Multiplier;max_range;min_range;voltage
1;Anemometer1;123456ABC;CALIB1234578;0.0245;0.0456;;;
2;PRESSUARE1;5454SERIAL;;;;1000;1100;5
to calculate with the values i need the offset, multiplier, max_range, min_range and voltage as float....
bsssc,
The datalogger generally converts Strings to floats as needed. You usually don't need to do anything special. Are you getting compile errors? If you need to copy a string value into a float variable you can use a simple equality:
Public numval, strval as string
numval = strval
Does that help?
Janet
* Last updated by: Janet on 3/30/2011 @ 4:21 PM *
Hi, just to update our status, it seems we have found a way of doing it. Here is the code:
Contador = 1
archivo = FileOpen("CPU:Archivo_localizacion.csv","r",0)
Do
Do
readfile = FileRead(archivo, datosbrutos, 1)
If datosbrutos <> "," Then nombres(Contador) = nombres(Contador) + datosbrutos
Loop Until datosbrutos = ","
Contador = Contador + 1
Loop Until datosbrutos = ""
FileClose (archivo)
As you can see we are not using SplitStr but it works, at least with strings, with floats we are having some troubles that we are trying to address.
One thing we need to know is what special character is understood by the CRBasic as "Carriage return" I have tried with "\" and "\n" but it does not work. Any clues?
PS: Sorry about the lack of indentation that makes difficult to understand the code, this forum client eliminates it.
* Last updated by: siarcida on 3/31/2011 @ 2:43 AM *
Hi,
i dont know of a escape code for special characters in crbasic.
To append a special character to a string you would need to use the CHR() function.
example:
string_with_cr = some_string + CHR(13)
string_with_cr_and_lf = some_string + CHR(13) + CHR(10)
Hi Cunningham,
Thanks for the input, it works when creating strings but it doesn't for the task I want to do with it. I mean, I want the program to exit the loop when finding a carriage return.
The idea in the program:
-Initialize the counter
-- Open the file to read
---- Open loop1
------- Open loop2
----------- Read one character of the file
----------- If that character is not a comma or a carriage return then:
--------------- Add to the variable
------- If that character is a comma or a carriage return
------- then we have reached the end of the word so exit loop2
----- counter ++ (we are going to look for the next word)
---- If the readouts from the file are empty there are no more words so exit loop1
- Do whatever you want with the colection of words/values
* Last updated by: siarcida on 3/31/2011 @ 3:23 AM *
not sure if this is what you mean, but as i understand you need to check against CR.
Loop Until datosbrutos = CHR(13)
Not tested, but i think this should work.
Problem solved!, at least for the carriage return issue, in a CSV file new lines start with a Line Feed, represented by CHR(10).
Now working on the float thing, with a bit of luck today all this will be over.
PS: Cunningham, you were right the code I am using to exit the loop is: Loop Until datosbrutos = "," OR datosbrutos = CHR(10)
Problem was about the CHR(13) vs CHR(10), thank you very much for your time
* Last updated by: siarcida on 3/31/2011 @ 4:04 AM *
Hi,
our solution looks like:
Function Loadconfig(Filename As String * 30, NumberOfconfig As Long) As Boolean
FileHandle =FileOpen (ConfFilename,"r",0)
ReadFile= FileRead(FileHandle,ReadDest,7000)
FileClose (FileHandle)
SplitStr(config(1),ReadDest,";",700,6)
i open the function in the program.
But still there is a problem to calculate with the splitted string values.
for example i have:
config(1)=80
config(2)=20
value= config(1) + config(2)
the result is not "100", the result is "8020"
hi
this is clearly explained by your option "6"/HEADERFILTERCHARS in the splitstr function which would return the tokens as string.
you are _catenating_ strings instead of _adding_ numbers.
you still have to parse/convert the string-tokens to numbers
hi,
i know of option 6, but my config looks like:
channel;name;serial;calibrationnumber;Offset;Multiplier;max_range;min_range;voltage
1;Anemometer1;123456ABC;CALIB1234578;0.0245;0.0456;;;
2;PRESSUARE1;5454SERIAL;;;;1000;1100;5
and i need also the name and serial as string... or i have to split my arry twice in option6 and option2 or can i combinate it ?