Сервер для сбора данных с термодатчиковых модулей

This commit is contained in:
ftc
2021-04-10 14:41:43 +03:00
parent 087db98d98
commit bba851ae16
13 changed files with 653 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
namespace ESPServer
{
class RegistersContainer
{
private Dictionary<int, int> registers;
public RegistersContainer()
{
registers = new Dictionary<int, int>();
}
public int this[int address]
{
get
{
lock(registers)
{
if (registers.ContainsKey(address)) return registers[address];
return 0;
}
}
set
{
lock (registers)
{
registers[address] = value;
}
}
}
public void SetFloat(int address, float value)
{
byte[] bytes = BitConverter.GetBytes(value);
registers[address + 1] = (int)bytes[0] + (((int)bytes[1]) << 8);
registers[address] = (int)bytes[2] + (((int)bytes[3]) << 8);
}
}
}