Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:mervis-db:10-api [2017/07/13 17:24] m.kulvejt [C#] |
en:mervis-db:10-api [2021/04/08 13:04] (current) |
||
---|---|---|---|
Line 24: | Line 24: | ||
^GetVariableStatsAsync|Obsolete| | ^GetVariableStatsAsync|Obsolete| | ||
^CheckCredentials| | | ^CheckCredentials| | | ||
+ | |||
+ | ===== Object Properties ===== | ||
+ | * (UTC)TimeStamp - UTC time stamp of the record | ||
+ | * GoodThrough - UTC time stamp of the end of validity of particular record | ||
+ | * Interval - period of time (in seconds) when next value should be recorded | ||
+ | |||
===== Examples ===== | ===== Examples ===== | ||
Line 29: | Line 35: | ||
==== C# ==== | ==== C# ==== | ||
- | {{ : | + | {{ : |
+ | |||
+ | === Download === | ||
+ | |||
+ | |||
+ | {{ : | ||
+ | {{ : | ||
+ | |||
+ | === Code === | ||
<code csharp MervisDB_GetData_Example.cs> | <code csharp MervisDB_GetData_Example.cs> | ||
Line 37: | Line 52: | ||
using MervisDb_GetData_Example.MervisDbService; | using MervisDb_GetData_Example.MervisDbService; | ||
- | namespace MervisDb_GetData_Example | + | namespace MervisDb_GetData_Example |
+ | class Program { | ||
+ | static void Main(string[] args) { | ||
+ | // | ||
+ | // Demo of asynchronous methods. | ||
+ | // | ||
+ | var task = Task.Run(async() => { | ||
+ | // | ||
+ | // Create access to the real server. | ||
+ | // Without SSL connections, | ||
+ | // The client is automatically generated from the WSDL file available here: https:// | ||
+ | // | ||
+ | using(HistoryDbAccessClient client = new HistoryDbAccessClient(" | ||
+ | // Authentication credetials in the database. | ||
+ | | ||
+ | Name = " | ||
+ | }; | ||
+ | |||
+ | // Specification of the variables through Key-Value. | ||
+ | // Here we use 2 variables. | ||
+ | | ||
+ | new KeyValuePair[] { | ||
+ | new KeyValuePair { | ||
+ | Key = " | ||
+ | }, new KeyValuePair { | ||
+ | Key = " | ||
+ | } | ||
+ | }, | ||
+ | new KeyValuePair[] { | ||
+ | new KeyValuePair { | ||
+ | Key = " | ||
+ | }, new KeyValuePair { | ||
+ | Key = " | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | // From-To dates. The dates must be specified in the UTC time zone. | ||
+ | | ||
+ | | ||
+ | |||
+ | // Retrieving the data goes through cycling of values and variables. The server returns recommended values needed for the the next cycle. | ||
+ | int variableOffset = 0; // the offset of the variable | ||
+ | int variableCount = 10; // maximal number of variables returned in one request | ||
+ | int valueOffset; | ||
+ | int valueCount = 1000; // maximal values in on request | ||
+ | |||
+ | | ||
+ | |||
+ | do { | ||
+ | valueOffset = 0; | ||
+ | do { | ||
+ | // Execute the request. | ||
+ | var result = await client.GetDataAsyncAsync(credentials, | ||
+ | |||
+ | // Check the return code. " | ||
+ | if (!result.ReturnCode.StartsWith(" | ||
+ | Console.WriteLine(" | ||
+ | } | ||
+ | |||
+ | // Cycle through the data and print it out. | ||
+ | | ||
+ | Console.WriteLine(" | ||
+ | | ||
+ | }))); | ||
+ | |||
+ | foreach(var value in valRecord.Vals) { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | } | ||
+ | while (valueOffset != -1); | ||
+ | } | ||
+ | while (variableOffset != -1); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | | ||
+ | |||
+ | try { | ||
+ | task.Wait(); | ||
+ | } catch (Exception exc) { | ||
+ | Console.WriteLine(" | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | } | ||
+ | }</ | ||
+ | |||
+ | <code csharp MervisDB_SaveData_Example.cs> | ||
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Threading.Tasks; | ||
+ | using MervisDb_SaveData_Example.MervisDbService; | ||
+ | |||
+ | namespace MervisDb_SaveData_Example | ||
{ | { | ||
class Program | class Program | ||
Line 58: | Line 174: | ||
Credentials credentials = new Credentials { Name = " | Credentials credentials = new Credentials { Name = " | ||
- | // | + | // |
- | // Here we use 2 variables. | + | List< |
- | KeyValuePair[][] keys = new KeyValuePair[][] | + | |
- | { | + | |
- | new KeyValuePair[] | + | |
- | { | + | |
- | new KeyValuePair { Key= " | + | |
- | }, | + | |
- | new KeyValuePair[] | + | |
- | { | + | |
- | new KeyValuePair { Key= " | + | |
- | } | + | |
- | }; | + | |
- | // From-To dates. The dates must be specified in the UTC time zone. | + | DateTime |
- | DateTime | + | |
- | DateTime utcFrom = DateTime.UtcNow.AddDays(-1); | + | |
- | // | + | // |
- | int variableOffset = 0; // the offset of the variable | + | ValueRecord rec = new ValueRecord(); |
- | int variableCount = 10; // maximal number of variables returned | + | |
- | int valueOffset; | + | |
- | int valueCount | + | |
- | Console.WriteLine(" | + | rec.UtcTimeStamp = utcTimeStamp; |
- | + | rec.HistoryValueType = HistoryValueType.Double; // type of the value | |
- | do | + | rec.DoubleValue = 23.4; // value itself |
+ | rec.Interval = 60.0; // sampling period in seconds. When the difference of timestamps of subsequent values if greater than 1.1 multiple of the interval, the data should be considered incomplete. | ||
+ | rec.Keys = new KeyValuePair[] // | ||
{ | { | ||
- | valueOffset | + | new KeyValuePair { IsKey = true, Key = " |
- | do | + | new KeyValuePair { IsKey = true, Key = " |
- | { | + | new KeyValuePair |
- | // Execute the request. | + | new KeyValuePair { IsKey = false, Key = " |
- | var result | + | new KeyValuePair { IsKey = false, Key = "Name", Value = "Temperature"}, |
- | + | new KeyValuePair | |
- | // Check the return code. "0;OK" | + | new KeyValuePair { IsKey = false, Key = "Unit", |
- | if (!result.ReturnCode.StartsWith("0;")) { Console.WriteLine("Error on reading: {0}", | + | }; |
- | // Cycle through the data and print it out. | + | records.Add(rec); |
- | foreach | + | |
- | { | + | |
- | Console.WriteLine(" | + | |
- | foreach (var value in valRecord.Vals) | + | // Save data method returns the number of stored records |
- | { | + | int recordsSaved = await client.SaveDataAsync(credentials, records.ToArray()); |
- | Console.WriteLine(" | + | |
- | } | + | |
- | } | + | |
- | valueOffset = result.NextValueOffset; | + | Console.WriteLine(" |
- | variableOffset = result.NextVariableOffset; | + | |
- | } | + | |
- | while | + | |
- | } | + | |
- | while (variableOffset != -1); | + | |
} | } | ||
}); | }); | ||
Line 131: | Line 222: | ||
} | } | ||
} | } | ||
- | } | + | }</ |
- | + | ||
- | + | ||
- | </ | + | |
==== Matlab ==== | ==== Matlab ==== | ||
Line 158: | Line 245: | ||
<code matlab> | <code matlab> | ||
- | help MerbonDatabase.supported_function_name | + | help MervisDatabase.supported_function_name |
</ | </ | ||
=== Code === | === Code === | ||
- | MervisDB_GetData_example.m | ||
- | <code matlab> | + | |
+ | <code matlab | ||
% Instance of Mervis DB | % Instance of Mervis DB | ||
- | mervisDB = MerbonDatabase(' | + | mervisDB = MervisDatabase(' |
% Time interval definition | % Time interval definition | ||
Line 181: | Line 268: | ||
' | ' | ||
- | variable1 = MerbonDbVariable(varKeys1); % Create | + | variable1 = MervisDbVariable(varKeys1); % Create |
- | variable2 = MerbonDbVariable(varKeys2); | + | variable2 = MervisDbVariable(varKeys2); |
- | arrayOfVarKeys = [variable1; variable2]; % array of MerbonDbVariables | + | arrayOfVarKeys = [variable1; variable2]; % array of MervisDbVariables |
% help for function getData | % help for function getData | ||
- | help MerbonDatabase.getData | + | help MervisDatabase.getData |
% Download required data | % Download required data | ||
Line 198: | Line 285: | ||
==== PHP ==== | ==== PHP ==== | ||
- | MervisDB_GetData_example.php | + | === Code === |
- | <code php> | + | < |
<?php | <?php | ||
/* | /* |