Сервер для сбора данных с термодатчиковых модулей
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user