|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading; |
| 4 | +using fgt_sdk; |
| 5 | +using fgt_sdk.Enums; |
| 6 | +using fgt_sdk.Structs; |
| 7 | + |
| 8 | +namespace Basic_Read_Sensor_Data |
| 9 | +{ |
| 10 | + class Program |
| 11 | + { |
| 12 | + /// <summary> |
| 13 | + /// This example shows how to retrieve a data from the sensor channel |
| 14 | + /// Hardware setup: One or more connected devices with sensor channel(s) or standalone sensor device(s). |
| 15 | + /// </summary> |
| 16 | + /// <param name="args"></param> |
| 17 | + static void Main(string[] args) |
| 18 | + { |
| 19 | + fgt_ERROR_CODE errCode; |
| 20 | + |
| 21 | + // Initialize session with all detected Fluigent instrument(s) |
| 22 | + // This step is optional, if not called session will be automatically created |
| 23 | + errCode = fgtSdk.Fgt_init(); |
| 24 | + |
| 25 | + if (errCode == fgt_ERROR_CODE.OK) |
| 26 | + { |
| 27 | + int sensorChannelsCount; |
| 28 | + // Get total number of initialized sensor channel(s) |
| 29 | + (errCode, sensorChannelsCount) = fgtSdk.Fgt_get_sensorChannelCount(); |
| 30 | + Console.WriteLine($"Status: {errCode} ### Total number of sensor channels detected: {sensorChannelsCount}"); |
| 31 | + |
| 32 | + List<(fgt_CHANNEL_INFO channelInfo, fgt_SENSOR_TYPE sensorType)> sensorChannelsInfo; |
| 33 | + // Get information about the connected sensor channel(s) |
| 34 | + (errCode, sensorChannelsInfo) = fgtSdk.Fgt_get_sensorChannelsInfo(); |
| 35 | + Console.WriteLine($"Status: {errCode} ### Retrieved information about {sensorChannelsInfo.Count} sensor channel(s)"); |
| 36 | + |
| 37 | + // Display the sensor(s) general information in console |
| 38 | + foreach (var channel in sensorChannelsInfo) |
| 39 | + { |
| 40 | + uint index = channel.channelInfo.Index; |
| 41 | + Console.WriteLine($"{Environment.NewLine} ### Index: {index}{Environment.NewLine}" + |
| 42 | + $" ### Device SN: {channel.channelInfo.DeviceSN}{Environment.NewLine}" + |
| 43 | + $" ### Firmware: {channel.channelInfo.Firmware}{Environment.NewLine}" + |
| 44 | + $" ### ID: {channel.channelInfo.IndexId}{Environment.NewLine}" + |
| 45 | + $" ### Type: {channel.channelInfo.InstrType}{Environment.NewLine}" + |
| 46 | + $" ### Sensor type: {channel.sensorType}{Environment.NewLine}"); |
| 47 | + |
| 48 | + string unit; |
| 49 | + // Retrieve the sensor unit |
| 50 | + (errCode, unit) = fgtSdk.Fgt_get_sensorUnit(index); |
| 51 | + Console.WriteLine($"Status: {errCode} ### Sensor {index} unit {unit}"); |
| 52 | + |
| 53 | + float pmin, pmax; |
| 54 | + // Get information about the sensor range |
| 55 | + (errCode, (pmin, pmax)) = fgtSdk.Fgt_get_sensorRange(index); |
| 56 | + Console.WriteLine($"Status: {errCode} ### Sensor {index} range from {pmin:0} to {pmax:0} {unit}"); |
| 57 | + |
| 58 | + float value; |
| 59 | + // Read sensor data |
| 60 | + for (int i = 0; i < 5; i++) |
| 61 | + { |
| 62 | + // Retrieve value from sensor |
| 63 | + (errCode, value) = fgtSdk.Fgt_get_sensorValue(index); |
| 64 | + Console.WriteLine($"Status: {errCode} ### Sensor {index} returned value {value:0.0} {unit}"); |
| 65 | + |
| 66 | + // Add a small delay between value read |
| 67 | + Thread.Sleep(200); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + Console.WriteLine($"Status: {errCode} ### Please make sure that your hardware setup matches this example's requirements and that all instruments are connected to the computer"); |
| 74 | + } |
| 75 | + |
| 76 | + fgtSdk.Fgt_close(); // Close session |
| 77 | + |
| 78 | + Console.WriteLine($"{Environment.NewLine}Close this console by pressing enter"); |
| 79 | + Console.ReadLine(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments