par Janet Albers | Mis à jour le : 01/13/2016 | Commentaires : 16
Une fois que vous stockez des mesures et d'autres données dans vos tables de centrales d'acquisition de données, comment voulez-vous accéder à ces données pour effectuer des opérations dans votre programme CRBasic ? Où pouvez-vous obtenir l'accès à vos données ? Cet article explique comment vous pouvez utiliser une syntaxe CRBasic spéciale pour simplifier le codage de votre programme pour accéder à vos données et effectuer diverses opérations.
En règle générale, les programmes écrits pour les centrales d'acquisition de Campbell Scientific utilisent une ou plusieurs tables de données pour stocker des mesures, des calculs et des états de variable. Les lignes d'une table de données sont appelés enregistrements, et les colonnes sont appelés champs.
Les tableaux dans lesquels les enregistrements de données sont stockées sont définies par les instructions DataTable()/EndTable, ainsi que par des instructions de traitement de sortie. Voici un exemple de ce type de définition :
Une fois les données stockées dans des tables, vous pouvez y accéder en utilisant une syntaxe spéciale CRBasic qui suit la forme suivante : TableName.FieldName. Cette syntaxe accède à la valeur stockée dans un champ spécifique d'un enregistrement d'une table spécifique. En option, vous pouvez ajouter la syntaxe avec un index des noms de domaine et enregistrer en retour en utilisant ce format : TableName.FieldName (FieldName Index, Records Back).
Note : Lorsque Records Back = 1, vous accédez à l'enregistrement le plus récent.
Cet exemple montre comment utiliser la syntaxe CRBasic afin de prendre certaines données (température maximale de l'air d'hier), qui sont stockées dans une table de données, et de l'écrire dans une variable Public nomée YesterdayMaxAirTemp. Pour faire cela utiliser la syntaxe YesterdayMaxAirTemp = Daily.AirTemp_Max, où Daily est le nom de la table TableName, et AirTemp_Max est le FieldName.
Votre instruction DataTable() pourrait ressembler à ceci:
En outre, pour calculer la variation de la température moyenne de l'air au cours des sept jours précédents, votre expression ressemblerait à ceci :
AirTempDiff = Daily.AirTemp_Avg(1,1) – Daily.AirTemp_Avg(1,7)
Vous pouvez trouver de plus amples informations sur d'autres syntaxes destinées aux tables de données, ainsi que des exemples de programmation, dans l'éditeur CRBasic. Suivez ces étapes pour accéder à cette rubrique :
J'espère que cet article vous a aidé à découvrir un des moyens pour accéder à vos données. En utilisant la syntaxe de CRBasic pour simplifier votre codage, vous devriez être en mesure d'accéder et d'utiliser facilement vos données stockées. Si vous avez des questions ou des commentaires, n'hésitez de les faire partager en postant ci-dessous vos remarques.
Traduction du bureau France de Campbell Scientific.
Commentaires
Ira | 01/13/2016 at 10:43 AM
A subtle, but important distinction to note is that FieldName doesn't necessarily equate to the variable name, which is illustrated in the examples above. The programmer should be cognizant of whether "_Max", "_Min", "_Avg" or another appendage is necessary to completely describe the FieldName.
Curt_Ingram | 01/15/2016 at 10:03 PM
I absolutely love the blogs that you post Janet! Keep it up :)
jra | 01/18/2016 at 08:17 AM
Right Ira. A variable name often is part of the FieldName but they are not (usually) the same.
Thanks Curt! Let me know if you have suggestions for other topics.
Curt_Ingram | 02/22/2016 at 08:30 PM
Janet, I would love a writeup on how to "properly" program events based on monthy or yearly change. For example, I would like my datalogger to keep up with monthly kWhr usage. For this to work for me now, I have to remember to reset to 0 each month (which I never do) :)
jra | 02/23/2016 at 08:53 AM
Hi Curt! Starting with OS 28 the TimeIntoInterval() and DataInterval() instructions have a MONTH option. A line in your program, after your CallTable(), like this:
If TimeIntoInterval (0,1,Mon) Then Total_kWhr = 0
should do the trick.
The MONTH option is a little different than our other intervals. When using MONTH as the interval, the TIME INTO parameter is in seconds. Here’s a link to the change log description https://www.campbellsci.com/revisions?dl=103&sval=month
If you are using an older operating system the technique in this forum post: https://www.campbellsci.com/forum?forum=1&l=thread&tid=726 uses RealTime() to accomplish the same thing.
I hope that helps.
Let me know what other questions you have.
Curt_Ingram | 02/29/2016 at 09:01 AM
Yay! Thanks Janet!
minida28 | 02/27/2020 at 02:44 PM
Hi Janet,
I work a lot with data coming from serial or modbus. And often time, the data I received already have their own "real" timestamp. If I call the datatable to store those data, I endup having a datatable with inaccurate timestamp.
Is there a way so that when I call the data table to store the readings, I can instruct the datatable to use the "real" timestamp coming with the data, and not using the timestamp from the scan?
Thanks Janet, really appreciate your enlightenment in advance.
jra | 02/27/2020 at 03:36 PM
Your datatable will always store timestamps and record numbers. You have more control over your data files when using the TableFile() instruction. https://help.campbellsci.com/crbasic/cr1000x/#instructions/tablefile.htm Take a look at, and test, the Options available. Start with Option 10 (TOA5, Header, Record#).
Or, from the LoggerNet Connect window you can use Custom Collect. In the Format Options area clear the "Include Timestamp" check box.
I hope that helps.
Makada | 05/05/2020 at 03:46 AM
Hi Janet,
May i ask you the following?:
When i use the "Tablename.fieldname" expression, for example "minute_avg_WS_kph = Table1.WS_KPH_S_WVT(1,1) , and have public data from it, "public minute_avg_WS_kph", then the actual value from the table1 "WS_KPH_S_WVT" is the same as the public minute_avg_WS_kph. So far so good.
But as soon as i make a sample data from the "public minute_avg_WS_kph" in table1, " Sample(1,minute_avg_WS_kph,IEEE4,False)", the output from the sample data from table 1 is one minute late (table1 is a one minute table) compared to the same data from the Table1.WS_KPH_S_WVT ...
With kind regards,
Mark
jra | 05/05/2020 at 12:20 PM
Thanks for your question Mark. This is being answered on our User Forum https://www.campbellsci.com/forum?forum=1&l=thread&tid=16306
JLomas | 07/14/2020 at 10:12 AM
Hello Janet, I have a very basic question. I have multiple sensors recording data to a single DataTable. If I modify this table, eg. adding more sensors, will I lose some data? The more general question would be: which criteria should I use when creating DataTables? Everything that requieres the same recording period should go together? I understand that DataInterval helps me saving space related with timestamps, but I'm worried about "safety" when modifying DataTables. Thanks in advance.
jra | 07/14/2020 at 10:47 AM
JLomas - always collect data before making changes to the program. You will lose data on the data logger but not data that has already been copied to your computer.
The best way to store data depends on how you are going to use it. If it makes it easier for you to do your job to store everything with the same record period in one table then that's what you should do. If it makes it easier for you to do your job to have all data of one type (for example all temperatures) in a table then you can do that; and put all, for example water levels, in another table.
Does that help?
bassel | 02/27/2021 at 06:28 AM
Hi .. I'm Basel .. Can I open a program that already exists on thedatalogger RC1000 by Loggernet .. The program is later CR1 .. And can I modify in the parameters .. Example: Modify the unit of measurement of wind speed from km to m.
Thank you
jra | 03/01/2021 at 07:41 AM
Based - yes, you should use the CRBasic editor (included with LoggerNet) to make changes to the program. For more information see this tutorial. To change the units of a measurement you will likely need to change the multipler and offset in the measurement instruction. Also see the manual for that sensor.
scg8 | 04/27/2021 at 07:20 AM
Hi,
Thank you very much for the blog. I would like to ask, in my case, I have a TDR200 connected to a CR1000x, I need to send the data by RS232, however, being data frames of more or less 10,000 fields, it arrives incomplete. Do you have any idea how I can improve this?
Public OutStringCable1$ As String * 65535
***
TDR Code and Datatables
***
GetRecord (OutStringCable1$,Cable_1,1)
'Send it out the serial port
SerialOut (COMRS232,OutStringCable1$,"",0,10000)
jra | 05/10/2021 at 09:04 AM
scg8 - Thank you for your question. To provide you with the best technical support for your application, please visit https://www.campbellsci.com/contact#dir to find your local Campbell Scientific office.
Please log in or register to comment.