From 22cecc2650b4f8460b4325b39e242f9047ae24e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ben=C3=AD=C4=8Dek?= Date: Wed, 22 Nov 2023 17:24:01 +0100 Subject: [PATCH] =?UTF-8?q?P=C5=99idejte=20soubory=20projektu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libs_SequentMicrosystems.csproj | 13 ++++++++ Libs_SequentMicrosystems.sln | 25 +++++++++++++++ RTD_8chanels_board.cs | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 Libs_SequentMicrosystems.csproj create mode 100644 Libs_SequentMicrosystems.sln create mode 100644 RTD_8chanels_board.cs diff --git a/Libs_SequentMicrosystems.csproj b/Libs_SequentMicrosystems.csproj new file mode 100644 index 0000000..e3c6ea1 --- /dev/null +++ b/Libs_SequentMicrosystems.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Libs_SequentMicrosystems.sln b/Libs_SequentMicrosystems.sln new file mode 100644 index 0000000..c73830d --- /dev/null +++ b/Libs_SequentMicrosystems.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libs_SequentMicrosystems", "Libs_SequentMicrosystems.csproj", "{C3DEDD92-2AF1-448F-B500-2009E9EE88F5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C3DEDD92-2AF1-448F-B500-2009E9EE88F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3DEDD92-2AF1-448F-B500-2009E9EE88F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3DEDD92-2AF1-448F-B500-2009E9EE88F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3DEDD92-2AF1-448F-B500-2009E9EE88F5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {160033F0-C347-43EF-9B6A-D67DDFC7BF91} + EndGlobalSection +EndGlobal diff --git a/RTD_8chanels_board.cs b/RTD_8chanels_board.cs new file mode 100644 index 0000000..8b0ffa6 --- /dev/null +++ b/RTD_8chanels_board.cs @@ -0,0 +1,57 @@ +using System; +using System.Device.Gpio; +using System.Device.I2c; + + +namespace Libs_SequentMicrosystems +{ + public class RTDStackLevelReader + { + public readonly byte DEVICE_ADDRESS = 0x40; + public readonly byte RTD_RESISTANCE_ADD = 59; + + /// + /// Read Single Resistance + /// + /// Level on Stack 0-7 + /// Chanel on stack layer 1-8 + /// Resistance of selected element + /// + /// + public float Get(byte stack, byte channel) + { + if (stack < 0 || stack > 7) + throw new ArgumentException("Invalid stack level"); + + if (channel < 1 || channel > 8) + throw new ArgumentException("Invalid channel number"); + + float val = -273.15f; + + try + { + using (I2cDevice i2c = I2cDevice.Create(new I2cConnectionSettings(1, DEVICE_ADDRESS + stack))) + { + byte[] buffer = new byte[4]; + i2c.WriteByte((byte)(RTD_RESISTANCE_ADD + (4 * (channel - 1)))); + i2c.Read(buffer); + val = BitConverter.ToSingle(buffer, 0); + } + } + catch (IOException e) + { + throw new IOException($"Fail to communicate with the RTD card with message: \"{e.Message}\""); + } + + return val; + } + + + //public float[] GetStack(byte stack) + //{ + + //} + + + } +} \ No newline at end of file