Přidejte soubory projektu.

master
Jan Beníček 2023-11-22 17:24:01 +01:00
parent 4c80803656
commit 22cecc2650
3 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Device.Gpio" Version="3.1.0" />
</ItemGroup>
</Project>

View File

@ -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

57
RTD_8chanels_board.cs Normal file
View File

@ -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;
/// <summary>
/// Read Single Resistance
/// </summary>
/// <param name="stack">Level on Stack 0-7</param>
/// <param name="channel">Chanel on stack layer 1-8</param>
/// <returns>Resistance of selected element</returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="IOException"></exception>
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)
//{
//}
}
}