Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Any way of using a Variable/Constant to set a Datatable name?


BenS Mar 9, 2012 10:02 AM

Hi All,

I would like to use a variable or constant to set the name of the datatable.

When using a Const or Public variable it just uses the name of the variable rather than the string assigned to it.

The application is using a file that is separate to the main program to set all constants for the logger configuration.

One of the settings is having a unique name for each loggers datatable. Having to go in to the main program to change the name of the datatable and where it is called would defeat the whole purpose.

Regards,

Ben


GTProdMgr Mar 9, 2012 04:59 PM

The name of the table has to be known at the time the program is compiled and executed, so there is no way to use a public variable to do this. However, I can see your point that you want to have multiple programs that are all essentially identical but use a different name for the output table.

The way to do this is with a constant declaration. Put the declaration of the constant at the very top of the program, and then declare the table with the constant name and make all of your calls or other references to the table through the constant name. That way you will only have to change the name of the table (for each different datalogger) in 1 line of the program (the first line of the program).

I tried this out just now with my CR1000 and OS Std24 and
it worked:

Const TABLNAME = "First"
Public PTemp, batt_volt


DataTable (TABLNAME,1,1000)
DataInterval (0,15,Sec,10)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable


BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (Batt_volt)

CallTable TABLNAME
NextScan
EndProg


GTProdMgr Mar 9, 2012 05:11 PM

I put these lines in a separate file called "Declare.CR1"
and sent it to the CPU: drive:

Const TABLNAME = "First"
Public PTemp, batt_volt

Then I changed the main program to be this:

Include "CPU:Declare.CR1"

DataTable (TABLNAME,1,1000)
DataInterval (0,15,Sec,10)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable


BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (Batt_volt)

CallTable TABLNAME
NextScan
EndProg

It still worked properly when using a separate file for the constant declaration.


BenS Mar 9, 2012 05:31 PM

Thanks very much I had tried before declaring the table name as a Const and didn't work.

Tried your code to see if it was something in my code, still didnt work.

Then checked the OS and was only 22 so updated to 24 and worked!

So was just the OS........lesson is always keep the OS updated.

Have a great weekend.


Sam Mar 11, 2012 01:26 AM

Maybe not always update the OS, but certainly always read the revision notes for new releases. Update if the new OS has a feature you want or fixes a bug that affects your program.

CR1000 OS revision history,
https://www.campbellsci.com/70_103
"86. Accept Constant strings to be used as TableNames in DataTable and CallTable."

Log in or register to post/reply in the forum.