omni changes from last freiday

This commit is contained in:
Stoyan Zlatev
2023-11-01 08:40:26 +01:00
parent c7f63c1093
commit 11c2d2922d
119 changed files with 4985 additions and 2675 deletions
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
</configuration>
@@ -1,15 +0,0 @@
using OmniPlus.Connection.Events;
namespace OmniPlus.Connection.Contracts
{
public interface ISerialPortConnection
{
event SerialPortStateChangedEventHandler StateChanged;
void Write(SerialPortMessage message);
void Close();
void Open();
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Connection.Contracts
{
public interface ISerialPortReader
{
void Read(byte b);
}
}
@@ -1,19 +0,0 @@
namespace OmniPlus.Connection.Enums
{
public enum BaudRate
{
BaudRate300 = 300,
BaudRate600 = 600,
BaudRate1200 = 1200,
BaudRate2400 = 2400,
BaudRate4800 = 4800,
BaudRate9600 = 9600,
BaudRate19200 = 19200,
BaudRate38400 = 38400,
BaudRate57600 = 57600,
BaudRate115200 = 115200,
BaudRate230400 = 230400,
BaudRate460800 = 460800,
BaudRate921600 = 921600
}
}
@@ -1,10 +0,0 @@
namespace OmniPlus.Connection.Enums
{
public enum DataBits
{
DataBits5 = 5,
DataBits6 = 6,
DataBits7 = 7,
DataBits8 = 8
}
}
@@ -1,11 +0,0 @@
namespace OmniPlus.Connection.Enums
{
public enum SerialPortState
{
Closed,
Disposed,
PinChanged,
ErrorReceived,
Open
}
}
@@ -1,6 +0,0 @@
using OmniPlus.Connection.Enums;
namespace OmniPlus.Connection.Events
{
public delegate void SerialPortStateChangedEventHandler(SerialPortState state, string message);
}
@@ -1,193 +0,0 @@
using OmniPlus.Connection.Contracts;
using OmniPlus.Connection.Enums;
using OmniPlus.Connection.Events;
using System;
using System.IO;
using System.IO.Ports;
namespace OmniPlus.Connection
{
public abstract class SerialPortConnection : ISerialPortConnection
{
private event Action Read;
private event Action<string> Log;
private SerialPort serialPort;
private SerialPortState state;
protected bool reading;
protected SerialPortStream stream;
protected SerialPortOptions options;
protected SerialPortConnection()
=> this.options = new SerialPortOptions();
public event SerialPortStateChangedEventHandler StateChanged;
protected bool connected => this.state == SerialPortState.Open;
public void Close()
{
if (this.serialPort != null)
{
this.serialPort.DataReceived -= this.Port_DataReceived;
this.serialPort.Disposed -= this.Port_Disposed;
this.serialPort.ErrorReceived -= this.Port_ErrorReceived;
this.serialPort.PinChanged -= this.Port_PinChanged;
}
this.serialPort?.Close();
this.stream = null;
this.serialPort = null;
this.state = SerialPortState.Closed;
this.StateChanged?.Invoke(this.state, $"{this.options.PortName} closed.");
this.Read -= this.SerialPortConnection_Read;
this.Log -= this.SerialPortConnection_Log;
this.StateChanged -= this.SerialPortConnection_StateChanged;
}
public void Open()
{
this.Close();
try
{
var fileInfo = new FileInfo(this.options.LogFile);
fileInfo.Directory.Create();
File.AppendAllText(this.options.LogFile, string.Empty);
this.Log += this.SerialPortConnection_Log;
this.StateChanged += this.SerialPortConnection_StateChanged;
}
catch (Exception e)
{
this.state = SerialPortState.ErrorReceived;
Console.WriteLine($"[{this.state}] {this.options.PortName}: {e}");
}
try
{
this.stream = new SerialPortStream();
this.serialPort = new SerialPort
{
PortName = options.PortName,
BaudRate = (int)options.BaudRate,
DataBits = (int)options.DataBits,
Parity = options.Parity,
StopBits = options.StopBits,
RtsEnable = options.RtsEnabled,
DtrEnable = options.DtrEnabled
};
this.serialPort.DataReceived += this.Port_DataReceived;
this.serialPort.Disposed += this.Port_Disposed;
this.serialPort.ErrorReceived += this.Port_ErrorReceived;
this.serialPort.PinChanged += this.Port_PinChanged;
this.serialPort.Open();
this.state = SerialPortState.Open;
this.Read += this.SerialPortConnection_Read;
this.StateChanged?.Invoke(this.state, $"{this.options.PortName} opened"
+ $", {this.options.BaudRate}"
+ $", {this.options.DataBits}"
+ $", {this.options.Parity}"
+ $", {this.options.StopBits}");
}
catch (Exception e)
{
this.state = SerialPortState.ErrorReceived;
this.StateChanged?.Invoke(this.state, $"{this.options.PortName}: {e}");
this.Close();
}
}
public virtual void Write(SerialPortMessage message)
{
if (this.connected && message.Length > 0)
{
this.serialPort.Write(message, 0, message.Length);
}
this.Log?.Invoke($"TX: {BitConverter.ToString(message)}");
}
public virtual void Write(params byte[] message)
{
if (this.connected && message.Length > 0)
{
this.serialPort.Write(message, 0, message.Length);
}
this.Log?.Invoke($"TX: {BitConverter.ToString(message)}");
}
protected abstract void SerialPortConnection_Read();
private void Port_PinChanged(object sender, SerialPinChangedEventArgs args)
{
this.state = SerialPortState.PinChanged;
this.StateChanged?.Invoke(SerialPortState.PinChanged, $"{this.options.PortName} {args.EventType}.");
this.Close();
}
private void Port_ErrorReceived(object sender, SerialErrorReceivedEventArgs args)
{
this.state = SerialPortState.ErrorReceived;
this.StateChanged?.Invoke(SerialPortState.ErrorReceived, $"{this.options.PortName} {args.EventType}.");
this.Close();
}
private void Port_Disposed(object sender, EventArgs args)
{
this.state = SerialPortState.Disposed;
this.StateChanged?.Invoke(SerialPortState.Disposed, $"{this.options.PortName} disposed.");
this.Close();
}
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs args)
{
if (this.connected && sender is System.IO.Ports.SerialPort port && port.BytesToRead > 0)
{
var bytes = new byte[port.BytesToRead];
var lock_object = new object();
lock (lock_object)
{
port.Read(bytes, 0, port.BytesToRead);
}
this.stream.Append(bytes);
if (!this.reading)
{
this.Read?.Invoke();
}
this.Log?.Invoke($"RX: {BitConverter.ToString(bytes)}");
}
}
private void SerialPortConnection_Log(string message)
=> File.AppendAllText(this.options.LogFile, $"{message}{Environment.NewLine}");
private void SerialPortConnection_StateChanged(SerialPortState state, string message)
=> File.AppendAllText(this.options.LogFile, $"[{state}] {message}{Environment.NewLine}");
}
}
@@ -1,38 +0,0 @@
using System;
namespace OmniPlus.Connection
{
public abstract class SerialPortMessage
{
protected readonly byte[] bytes;
protected readonly byte[] payload;
protected readonly bool isResponse;
protected SerialPortMessage(byte[] bytes, bool response)
{
this.isResponse = response;
if (this.isResponse)
{
this.bytes = bytes;
this.payload = this.ParseMessage(bytes);
}
else
{
this.payload = bytes;
this.bytes = this.CreateMessage(bytes);
}
}
public int Length => this.bytes.Length;
public byte[] Payload => this.payload;
protected abstract byte[] CreateMessage(byte[] payload);
protected abstract byte[] ParseMessage(byte[] message);
public static implicit operator byte[](SerialPortMessage message)
=> message?.bytes ?? Array.Empty<byte>();
}
}
@@ -1,40 +0,0 @@
using OmniPlus.Connection.Enums;
using System.IO.Ports;
namespace OmniPlus.Connection
{
public class SerialPortOptions
{
public SerialPortOptions()
{
foreach (var portName in SerialPort.GetPortNames())
{
this.PortName = portName;
break;
}
this.BaudRate = BaudRate.BaudRate4800;
this.DataBits = DataBits.DataBits8;
this.Parity = Parity.None;
this.StopBits = StopBits.One;
}
public string PortName { get; set; }
public BaudRate BaudRate { get; set; } = BaudRate.BaudRate4800;
public Parity Parity { get; set; } = Parity.None;
public DataBits DataBits { get; set; } = DataBits.DataBits8;
public StopBits StopBits { get; set; } = StopBits.One;
public bool RtsEnabled { get; set; }
public bool DtrEnabled { get; set; }
public string LogFile { get; set; }
}
}
@@ -1,85 +0,0 @@
using System;
namespace OmniPlus.Connection
{
public class SerialPortStream
{
private readonly int minBufferLength;
private byte[] buffer;
private int dataLength;
public SerialPortStream(int minBufferLength = byte.MaxValue)
{
this.minBufferLength = minBufferLength;
this.buffer = new byte[this.minBufferLength];
}
public byte this[int index] => this.buffer[index];
public void Append(byte[] bytes)
{
var bytesLength = bytes?.Length ?? 0;
if (bytesLength <= 0)
{
return;
}
var lock_object = new object();
lock (lock_object)
{
if (this.dataLength + bytesLength > this.buffer.Length)
{
var buffer = new byte[this.buffer.Length * 2];
Array.Copy(this.buffer, 0, buffer, 0, this.dataLength);
}
this.dataLength += bytesLength;
Array.Copy(bytes, 0, this.buffer, this.dataLength, bytesLength);
}
}
public void CopyTo(byte[] destinationArray, int destinationIndex, int sourceIndex, int length)
{
var requiredBufferLength = sourceIndex + length;
if (destinationArray is null || destinationIndex < 0 || sourceIndex < 0 || requiredBufferLength > this.buffer.Length)
{
return;
}
Array.Copy(this.buffer, sourceIndex, destinationArray, destinationIndex, length);
}
public void Flush(int length)
{
var lock_object = new object();
lock (lock_object)
{
if (length <= 0 || this.dataLength - length <= 0)
{
this.buffer = new byte[this.minBufferLength];
}
else
{
var dataLength = this.dataLength - length;
var newBufferLength = this.minBufferLength;
while (newBufferLength <= dataLength)
{
newBufferLength *= 2;
}
var newBuffer = new byte[newBufferLength];
Array.Copy(this.buffer, dataLength, newBuffer, 0, dataLength);
}
}
}
}
}
-86
View File
@@ -1,86 +0,0 @@
using System;
namespace OmniPlus.Connections
{
public static class Extensions
{
/// <summary>
/// TODO: Test calculated crc
/// </summary>
/// <param name="message">The message for CRC16.</param>
/// <param name="start">The start index.</param>
/// <param name="length">The length from the start index.</param>
/// <returns>Two bytes array from the calculated CRC16 in LSB0.</returns>
public static byte[] CalculateCRC(this byte[] message, int start, int length)
{
var crc = 0xFFFF;
for (int i = 0; i < length; i++)
{
//copy data byte to lower word because of LSB will be XORed
var dataWord = (UInt16)(message[i] & 0x00FF);
for (var b = 0; b < 8; b++)
{
//test if CRC lowest bit is XORed set to one
if (0x0001 == ((crc ^ dataWord) & 0x0001))
{
crc >>= 1;
//apply generator polynomial
crc ^= 0x8408;
}
else
{
crc >>= 1;
}
dataWord >>= 1;
}
}
//var test = default(byte);
//var zeichen = default(byte);
//var crcSum = ushort.MaxValue;
//var messageLength = length - start;
//while (start < messageLength)
//{
// zeichen = message[start];
// start++;
// for (byte h = 0; h < 8; h++)
// {
// test = 0;
// if ((crcSum & 0x8000) != 0)
// {
// test = 0x80;
// }
// crcSum <<= 1;
// if (((zeichen & 0x80) ^ test) != 0)
// {
// crcSum ^= 0x1021;
// }
// zeichen <<= 1;
// }
//}
return BitConverter.GetBytes(crc);
}
public static byte[] CalculateCheckSum16(this byte[] bytes, int length)
{
ushort checksum = 0;
for (int i = 0; i < length; i++)
{
checksum += bytes[i];
}
return BitConverter.GetBytes(checksum);
}
}
}
@@ -1,92 +0,0 @@
namespace OmniPlus.Connections
{
using OmniPlus.Connection;
using OmniPlus.Connection.Enums;
using OmniPlus.Connections.Messages;
using System;
using System.IO.Ports;
using System.Threading;
public class IrdaConnection : SerialPortConnection
{
internal const byte MSG_START = 0x9B;
internal const byte MSG_OMNI2PC = 0x43;
internal const byte MSG_PC2OMNI = 0x33;
private event Action<IrdaMessage> messageReceived;
public IrdaConnection(string portName, string logFile = null)
{
this.options.PortName = portName;
this.options.BaudRate = BaudRate.BaudRate115200;
this.options.DataBits = DataBits.DataBits8;
this.options.Parity = Parity.None;
this.options.StopBits = StopBits.One;
this.options.LogFile = logFile ?? ".\\IrdaConnection.txt";
}
public byte[] Write(byte[] command, int timeout, int delay)
{
var ui1236Request = new UI1236Message(command);
var irdaRequest = new IrdaMessage(ui1236Request);
var responseBytes = Array.Empty<byte>();
var retriesCount = 3;
var received = false;
this.messageReceived += irdaResponse =>
{
var ui1236Response = new UI1236Message(irdaResponse.Payload, true);
responseBytes = ui1236Response.Payload;
received = true;
};
while (!received && retriesCount-- > 0)
{
this.Write(0x01, 0x01, 0x01, 0x01);
Thread.Sleep(1);
this.Write(irdaRequest);
// this.Write(0x9B, 0x33, 0x04, 0x0D, 0x05, 0x08, 0xFD, 0xC6, 0x01, 0xDD, 0x00, 0x3B, 0x1B);
var sleep = timeout;
while (!received && sleep >= 0)
{
sleep -= delay;
Thread.Sleep(delay);
}
}
return responseBytes;
}
protected override void SerialPortConnection_Read()
{
this.reading = true;
var message = default(byte[]);
var length = 0;
var start = 0;
while (true)
{
if (this.stream[start] == MSG_START)
{
length = this.stream[start + 2] * 2 + 5;
message = new byte[length];
this.stream.CopyTo(message, 0, start, length);
break;
}
start++;
}
this.messageReceived?.Invoke(message);
this.reading = false;
}
}
}
@@ -1,71 +0,0 @@
using OmniPlus.Connection;
using System;
using System.Linq;
using Xylem.Common.Utils.Crc16Ccitt;
namespace OmniPlus.Connections.Messages
{
public class IrdaMessage : SerialPortMessage
{
public const int MIN_LENGTH = 5;
public const int CRC_LENGTH = 2;
public IrdaMessage(byte[] bytes, bool response = false) : base(bytes, response)
{
}
public byte Start
{
get => this.bytes[0];
set => this.bytes[0] = value;
}
public byte Type
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public byte DataLength
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
protected override byte[] CreateMessage(byte[] payload)
{
var messageLength = payload.Length;
messageLength += messageLength % 2;
var index = 0;
var message = new byte[messageLength + MIN_LENGTH];
message[index++] = IrdaConnection.MSG_START;
message[index++] = IrdaConnection.MSG_PC2OMNI;
message[index++] = (byte)(messageLength / 2);
payload.CopyTo(message, index);
messageLength = message.Length;
var crc16 = BitConverter.GetBytes(Crc16Ccitt.CalculateReversedLsb8408(message.Skip(1).Take(message.Length - 3).ToArray()));
message[messageLength - 2] = crc16[1];
message[messageLength - 1] = crc16[0];
return message;
}
protected override byte[] ParseMessage(byte[] message)
{
var payloadLength = message.Length - MIN_LENGTH;
var payload = new byte[payloadLength];
Array.Copy(message, 3, payload, 0, payloadLength);
return payload;
}
public static implicit operator IrdaMessage(byte[] bytes)
=> new IrdaMessage(bytes, true);
}
}
@@ -1,4 +0,0 @@
namespace OmniPlus.Connections.Messages
{
public delegate byte[] MessageHandler(byte[] command, int timeout, int delay);
}
@@ -1,61 +0,0 @@
using OmniPlus.Connection;
using OmniPlus.Features.Enums;
using OmniPlus.Features.Types;
using System;
namespace OmniPlus.Connections.Messages
{
public class UI1236Message : SerialPortMessage
{
public const byte START_BYTE = 0x0D;
public const byte MIN_LENGTH = 0x05;
public const byte HEADER_BYTES = 0x03;
public UI1236Message(byte[] bytes, bool response = false) : base(bytes, response)
{
}
public byte Start => this.bytes[0];
public byte DataLength => this.bytes[1];
public Control Control => this.bytes[2];
public Status Status
=> this.isResponse
? (Status)this.bytes[3]
: Status.Completed;
protected override byte[] CreateMessage(byte[] payload)
{
var messageLength = payload.Length + MIN_LENGTH;
var message = new byte[messageLength];
var index = 0;
message[index++] = START_BYTE;
message[index++] = (byte)(payload.Length + HEADER_BYTES);
Control control = 0;
control.ReturnResponse = true;
message[index++] = control;
payload.CopyTo(message, index);
var checksum = message.CalculateCheckSum16(messageLength - 2);
message[messageLength - 2] = checksum[1];
message[messageLength - 1] = checksum[0];
return message;
}
protected override byte[] ParseMessage(byte[] message)
{
var payload = new byte[message.Length - MIN_LENGTH];
Array.Copy(message, 3, payload, 0, payload.Length);
return payload;
}
}
}
@@ -1,30 +0,0 @@
using OmniPlus.Connection;
using OmniPlus.Connection.Enums;
using System.IO.Ports;
namespace OmniPlus.Connections
{
public class UniProConnection : SerialPortConnection
{
public UniProConnection(string portName)
{
this.options.PortName = portName;
this.options.BaudRate = BaudRate.BaudRate2400;
this.options.DataBits = DataBits.DataBits8;
this.options.Parity = Parity.None;
this.options.StopBits = StopBits.One;
this.options.RtsEnabled = true;
}
public byte[] Write(byte[] command, int timeout, int delay)
{
throw new System.NotImplementedException();
}
protected override void SerialPortConnection_Read()
{
throw new System.NotImplementedException();
}
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct BatteryVoltage
{
public const byte BASE = 0xFD;
public const byte GET = 0xA9;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct BatteryVoltageMeasurementCalibrationFactors
{
public const byte BASE = 0xFD;
public const byte GET = 0xAA;
public const byte SET = 0xAB;
}
}
@@ -1,47 +0,0 @@
using OmniPlus.Features.Enums;
using System;
namespace OmniPlus.Features.DeviceSpecific
{
public struct CalibrationResults
{
private const byte FAILED = 0x01;
private const byte COMPLETED = 0x02;
private CalibrationResults(byte[] bytes)
{
this.Status = Status.UnknownCommand;
this.Completed = default(bool);
this.Rotations = default(ushort);
this.Dauer = default(uint);
if (bytes?.Length == 8)
{
this.Status = (Status)bytes[0];
this.Completed = bytes[1] == COMPLETED;
this.Rotations = BitConverter.ToUInt16(bytes, 2);
this.Dauer = BitConverter.ToUInt16(bytes, 4);
}
}
public Status Status { get; }
public bool Completed { get; }
public ushort Rotations { get; }
public uint Dauer { get; }
public static byte[] RequestResults => new byte[]
{
FactoryMeterChamberCalibrationTest.BASE,
FactoryMeterChamberCalibrationTest.SET,
FactoryMeterChamberCalibrationTest.VIEW,
};
public static implicit operator CalibrationResults(byte[] bytes)
=> new CalibrationResults(bytes);
}
}
@@ -1,27 +0,0 @@
using OmniPlus.Features.UI1236;
namespace OmniPlus.Features.DeviceSpecific
{
public struct ConfigurationParameters
{
public const byte BASE = 0xFD;
public const byte GET = 0xC7;
public const byte ALL = 0x01;
public ProgrammableID ProgrammableId { get; }
public FactoryID FactoryId { get; }
public NumberOfReadingDigits ReadingDigits { get; }
public Reading Reading { get; }
public OptionalUniDirectionalFields OptionalUniDirectionalFields { get; }
public AlarmPersistencePeriod AlarmPersistensePeriaod { get; }
public DataLogInterval DataLogInterval { get; }
public RegisterDeviceIDString DeviceIDString { get; }
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct DataLogData
{
public const byte BASE = 0xFD;
public const byte GET = 0x80;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct DataLogInterval
{
public const byte BASE = 0xFD;
public const byte SET = 0x7D;
public const byte GET = 0x7E;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct DisplayMode
{
public const byte BASE = 0xFD;
public const byte GET = 0x14;
public const byte SET = 0x15;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct EnabledLCDViews
{
public const byte BASE = 0xFD;
public const byte GET = 0x7B;
public const byte SET = 0x7C;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct EnabledPredefinedAlarms
{
public const byte BASE = 0xFD;
public const byte GET = 0x12;
public const byte SET = 0x13;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct ExtendedResolutionSetting
{
public const byte BASE = 0xFD;
public const byte GET = 0x28;
public const byte SET = 0x29;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct FactoryCalibration
{
public const byte BASE = 0xFD;
public const byte GET = 0x08;
public const byte SET = 0x09;
}
}
@@ -1,54 +0,0 @@
using OmniPlus.Features.Enums;
using System;
namespace OmniPlus.Features.DeviceSpecific
{
public struct FactoryMeterChamberCalibrationTest
{
public const byte BASE = 0xFD;
public const byte SET = 0x67;
public const byte VIEW = 0x01;
private FactoryMeterChamberCalibrationTest(byte[] bytes) : this()
{
this.Status = Status.UnknownCommand;
this.CalibrationState = default(CalibrationState);
this.Rotations = default(ushort);
this.Dauer = default(ushort);
if (bytes?.Length == 6)
{
this.Status = (Status)bytes[0];
this.CalibrationState = (CalibrationState)bytes[1];
this.Rotations = BitConverter.ToUInt16(bytes, 2);
this.Dauer = BitConverter.ToUInt16(bytes, 4);
}
}
public Status Status { get; set; }
public CalibrationState CalibrationState { get; set; }
public ushort Rotations { get; set; }
public ushort Dauer { get; set; }
public static implicit operator FactoryMeterChamberCalibrationTest(byte[] bytes)
=> new FactoryMeterChamberCalibrationTest(bytes);
public static implicit operator byte[] (FactoryMeterChamberCalibrationTest calibration)
{
var bytes = new byte[7];
bytes[0] = BASE;
bytes[1] = SET;
bytes[2] = (byte)(calibration.CalibrationState);
BitConverter.GetBytes(calibration.Rotations).CopyTo(bytes, 3);
BitConverter.GetBytes(calibration.Dauer).CopyTo(bytes, 5);
return bytes;
}
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct FactoryPulseTestMode
{
public const byte BASE = 0xFD;
public const byte SET = 0x1B;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct FactorySeal
{
public const byte BASE = 0xFD;
public const byte GET = 0x63;
public const byte SET = 0x64;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct FieldCalibration
{
public const byte BASE = 0xFD;
public const byte GET = 0x0A;
public const byte SET = 0x0B;
}
}
@@ -1,66 +0,0 @@
using OmniPlus.Features.Enums;
using OmniPlus.Features.Types;
using System;
namespace OmniPlus.Features.DeviceSpecific
{
public struct InputVolume
{
public const byte BASE = 0xFD;
public const byte GET = 0x02;
public const byte SET = 0x03;
private InputVolume(byte[] bytes) : this()
{
this.Status = Status.UnknownCommand;
this.MilliliterPerPulse = default(ushort);
this.FractionalPart = default(ushort);
this.MeterSize = default(byte);
this.MeterRange = default(byte);
if (bytes?.Length == 6)
{
this.Status = (Status)bytes[0];
this.MilliliterPerPulse = BitConverter.ToUInt16(bytes, 1);
this.MilliliterPerPulse = BitConverter.ToUInt16(bytes, 3);
this.MeterSize = bytes[5];
this.MeterRange = bytes[6];
}
}
public Status Status { get; }
public ushort MilliliterPerPulse { get; set; }
public ushort FractionalPart { get; set; }
public MeterSize MeterSize { get; set; }
public MeterRange MeterRange { get; set; }
public static byte[] GetCommand => new byte[] { BASE, GET };
public static implicit operator InputVolume(byte[] bytes)
=> new InputVolume(bytes);
public static implicit operator byte[] (InputVolume inputVolume)
{
var bytes = new byte[8];
bytes[0] = BASE;
bytes[1] = SET;
BitConverter.GetBytes(inputVolume.MilliliterPerPulse).CopyTo(bytes, 2);
BitConverter.GetBytes(inputVolume.FractionalPart).CopyTo(bytes, 4);
bytes[6] = inputVolume.MeterSize;
bytes[7] = inputVolume.MeterRange;
return bytes;
}
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct LCDSegmentTest
{
public const byte BASE = 0xFD;
public const byte SET = 0x62;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct LCDTimeout
{
public const byte BASE = 0xFD;
public const byte GET = 0x8B;
public const byte SET = 0x8C;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct LidState
{
public const byte BASE = 0xFD;
public const byte GET = 0xAC;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct LifeTimeMaxSensorPulsesperSecond
{
public const byte BASE = 0xFD;
public const byte GET = 0x22;
public const byte SET = 0x23;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct ManufacturingTestCommand
{
public const byte BASE = 0xFD;
public const byte SET = 0x65;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct ManufacturingTime
{
public const byte BASE = 0xFD;
public const byte GET = 0x39;
public const byte SET = 0x3A;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct OmniSize
{
public const byte BASE = 0xFD;
public const byte GET = 0xB7;
public const byte SET = 0xB8;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct OutputPulseSettings
{
public const byte BASE = 0xFD;
public const byte GET = 0x0E;
public const byte SET = 0x0F;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct PeriodicAlarmLogEntries
{
public const byte BASE = 0xFD;
public const byte GET = 0xC2;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct RebootCount
{
public const byte BASE = 0xFD;
public const byte GET = 0x55;
public const byte SET = 0x56;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct RegisterDeviceIDString
{
public const byte BASE = 0xFD;
public const byte GET = 0x26;
public const byte SET = 0x27;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct RegisterSetting
{
public const byte BASE = 0xFD;
public const byte GET = 0x24;
public const byte SET = 0x25;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct SecondsActive
{
public const byte BASE = 0xFD;
public const byte GET = 0x3D;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct SendFlexNetSerialCommands
{
public const byte BASE = 0xFD;
public const byte SET = 0x98;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct SendMultipleFlexNetSerialCommands
{
public const byte BASE = 0xFD;
public const byte SET = 0xA2;
}
}
@@ -1,63 +0,0 @@
using OmniPlus.Features.Enums;
using OmniPlus.Features.Types;
using System;
namespace OmniPlus.Features.DeviceSpecific
{
public struct SystemParameters
{
public const byte BASE = 0xFD;
public const byte GET = 0xC6;
private SystemParameters(byte[] bytes)
{
this.Status = Status.UnknownCommand;
this.BuildInfo = default(byte[]);
this.ManifacturingTime = default(uint);
this.SystemTime = default(uint);
this.RebootCount = default(byte);
this.VersionAndType = default(byte[]);
this.BytteryV = default(double);
this.BytteryADC = default(uint);
this.Sealed = default(bool);
if (bytes?.Length >= 60)
{
this.Status = (Status)bytes[0];
this.BuildInfo = bytes.Subarray(1, 16);
this.ManifacturingTime = BitConverter.ToUInt32(bytes, 17);
this.SystemTime = BitConverter.ToUInt32(bytes, 21);
this.RebootCount = bytes[25];
this.VersionAndType = bytes.Subarray(26, 27);
this.BytteryV = BitConverter.ToUInt16(bytes, 53) / 1000.0;
this.BytteryADC = BitConverter.ToUInt32(bytes, 55);
this.Sealed = bytes[59] == 1;
}
}
public Status Status { get; }
public ASCIIString BuildInfo { get; }
public TimeSinse20000101 ManifacturingTime { get; }
public TimeSinse20000101 SystemTime { get; }
public byte RebootCount { get; }
public ASCIIString VersionAndType { get; }
public double BytteryV { get; }
public uint BytteryADC { get; }
public bool Sealed { get; }
public static byte[] GetCommand
=> new byte[] { BASE, GET };
public static implicit operator SystemParameters(byte[] bytes)
=> new SystemParameters(bytes);
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct SystemTime
{
public const byte BASE = 0xFD;
public const byte GET = 0x10;
public const byte SET = 0x11;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct TestPulse
{
public const byte BASE = 0xFD;
public const byte SET = 0x66;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct TestTotalizerValue
{
public const byte BASE = 0xFD;
public const byte GET = 0x06;
public const byte SET = 0x07;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct TimeofFactorySeal
{
public const byte BASE = 0xFD;
public const byte GET = 0x05;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct TimeofInstallation
{
public const byte BASE = 0xFD;
public const byte GET = 0xBC;
public const byte SET = 0xBD;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.DeviceSpecific
{
public struct TriggerWatchdogReset
{
public const byte BASE = 0xFD;
public const byte SET = 0x8D;
}
}
@@ -1,9 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum CalibrationState : byte
{
OK = 0x00,
Failed = 0x01,
Completed = 0x02
}
}
@@ -1,234 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum DeviceCommands : byte
{
/// <summary>
/// Device specific
/// </summary>
Specific = 0xFD,
/// <summary>
///Available after seal: Yes
/// </summary>
GetInputVolumeValue = 0x02,
/// <summary>
///Available after seal: No
/// </summary>
SetInputVolumeValue = 0x03,
/// <summary>
///Available after seal: Yes
/// </summary>
GetTimeofFactorySeal = 0x05,
/// <summary>
///Available after seal: Yes
/// </summary>
GetTestTotalizerValue = 0x06,
/// <summary>
///Available after seal: Yes
/// </summary>
SetTestTotalizerValue = 0x07,
/// <summary>
///Available after seal: Yes
/// </summary>
GetFactoryCalibration = 0x08,
/// <summary>
///Available after seal: No
/// </summary>
SetFactoryCalibration = 0x09,
/// <summary>
///Available after seal: Yes
/// </summary>
GetFieldCalibration = 0x0A,
/// <summary>
///Available after seal: Yes
/// </summary>
SetFieldCalibration = 0x0B,
/// <summary>
///Available after seal: Yes
/// </summary>
GetOutputPulseSettings = 0x0E,
/// <summary>
///Available after seal: Yes
/// </summary>
SetOutputPulseSettings = 0x0F,
/// <summary>
///Available after seal: Yes
/// </summary>
GetSystemTime = 0x10,
/// <summary>
///Available after seal: Yes
/// </summary>
SetSystemTime = 0x11,
/// <summary>
///Available after seal: Yes
/// </summary>
GetEnabledPredefinedAlarms = 0x12,
/// <summary>
///Available after seal: Yes
/// </summary>
SetEnabledPredefinedAlarms = 0x13,
/// <summary>
///Available after seal: Yes
/// </summary>
GetDisplayMode = 0x14,
/// <summary>
///Available after seal: Yes
/// </summary>
SetDisplayMode = 0x15,
/// <summary>
///Available after seal: No
/// </summary>
SetFactoryPulseTestMode = 0x1B,
/// <summary>
///Available after seal: Yes
/// </summary>
GetLifeTimeMaxSensorPulsesperSecond = 0x22,
/// <summary>
///Available after seal: No
/// </summary>
SetLifeTimeMaxSensorPulsesperSecond = 0x23,
/// <summary>
///Available after seal: Yes
/// </summary>
GetRegisterSetting = 0x24,
/// <summary>
///Available after seal: No
/// </summary>
SetRegisterSetting = 0x25,
/// <summary>
///Available after seal: Yes
/// </summary>
GetRegisterDeviceIDString = 0x26,
/// <summary>
///Available after seal: No
/// </summary>
SetRegisterDeviceIDString = 0x27,
/// <summary>
///Available after seal: Yes
/// </summary>
GetExtendedResolutionSetting = 0x28,
/// <summary>
///Available after seal: Yes
/// </summary>
SetExtendedResolutionSetting = 0x29,
/// <summary>
///Available after seal: Yes
/// </summary>
GetManufacturingTime = 0x39,
/// <summary>
///Available after seal: No
/// </summary>
SetManufacturingTime = 0x3A,
/// <summary>
///Available after seal: Yes
/// </summary>
GetSecondsActive = 0x3D,
/// <summary>
///Available after seal: Yes
/// </summary>
Getrebootcount = 0x55,
/// <summary>
///Available after seal: No
/// </summary>
Setrebootcount = 0x56,
/// <summary>
///Available after seal: No
/// </summary>
SetLCDSegmentTest = 0x62,
/// <summary>
///Available after seal: Yes
/// </summary>
GetFactorySeal = 0x63,
/// <summary>
///Available after seal: No
/// </summary>
SetFactorySeal = 0x64,
/// <summary>
///Available after seal: Conditional
/// </summary>
ManufacturingTestCommand = 0x65,
/// <summary>
///Available after seal: Yes
/// </summary>
SetTestPulse = 0x66,
/// <summary>
///Available after seal: No
/// </summary>
FactoryMeterChamberCalibrationTest = 0x67,
/// <summary>
///Available after seal: Yes
/// </summary>
GetEnabledLCDViews = 0x7B,
/// <summary>
///Available after seal: Yes
/// </summary>
SetEnabledLCDViews = 0x7C,
/// <summary>
///Available after seal: Yes
/// </summary>
SetDataLogInterval = 0x7D,
/// <summary>
///Available after seal: Yes
/// </summary>
GetDataLogInterval = 0x7E,
/// <summary>
///Available after seal: Yes
/// </summary>
GetDataLogData = 0x80,
/// <summary>
///Available after seal: Yes
/// </summary>
GetLCDTimeout = 0x8B,
/// <summary>
///Available after seal: Yes
/// </summary>
SetLCDTimeout = 0x8C,
/// <summary>
///Available after seal: Yes
/// </summary>
TriggerWatchdogReset = 0x8D,
/// <summary>
///Available after seal: Yes
/// </summary>
SendFlexNetSerialCommands = 0x98,
/// <summary>
///Available after seal: Yes
/// </summary>
SendMultipleFlexNetSerialCommands = 0xA2,
/// <summary>
///Available after seal: Yes
/// </summary>
GetBatteryVoltage = 0xA9,
/// <summary>
///Available after seal: Yes
/// </summary>
GetBatteryVoltageMeasurementCalibrationFactors = 0xAA,
/// <summary>
///Available after seal: No
/// </summary>
SetBatteryVoltageMeasurementCalibrationFactors = 0xAB,
/// <summary>
///Available after seal: Yes
/// </summary>
GetLidState = 0xAC,
/// <summary>
///Available after seal: Yes
/// </summary>
GetMeterSize = 0xB7,
/// <summary>
///Available after seal: Yes
/// </summary>
SetMeterSize = 0xB8,
/// <summary>
///Available after seal: Yes
/// </summary>
GetTimeofInstallation = 0xBC,
/// <summary>
///Available after seal: No
/// </summary>
SetTimeofInstallation = 0xBD,
/// <summary>
///Available after seal: Yes
/// </summary>
GetPeriodicAlarmLogEntries = 0xC2
}
}
@@ -1,11 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum MeterRanges : byte
{
From1To2 = 0x00,
From3To4 = 0x01,
SixInch = 0x02,
EightInch = 0x03,
TenInch = 0x04,
}
}
@@ -1,14 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum MeterSizes : byte
{
Unknown = 0x00,
OneHalfIn = 0x05,
TwoIn = 0x06,
ThreeIn = 0x07,
FourIn = 0x08,
SixIn = 0x09,
EightIn = 0x0A,
TenIn = 0x0B,
}
}
@@ -1,139 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum PredefinedAlarms : byte
{
/// <summary>
/// Set when the unit is in a mode that is updating the firmware.
/// <para>
/// Trigger Condition: Alarm is set when the device begins to receive firmware image blocks.
/// It is marked as no longer occurring before executing the flasher app as the last part of a firmware upgrade.
/// Upon booting into the upgraded image, the alarm is in persistent state with start time associated with the reception of Load Start command
/// and stop time associated with the reception of Flash Start command.
/// If after loading the new image, the CRC fails, the Alarm condition is maintained until a Reset Firmware Image is received
/// or a new image is attempted to be loaded.
/// </para>
/// </summary>
UpgradeMode = 0x00,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// SevereHardwareFailure = 0x01,
/// <summary>
/// NV memory error alarm becomes active when an NV memory location fails a checksum check.
/// <para>
/// Alarm is triggered whenever a checksum check of any of the above modules and log entries fails.
/// </para>
/// </summary>
NVMemoryError = 0x02,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// DeadBattery = 0x03,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// EmptyPipe = 0x04,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// MagneticTamper = 0x05,
/// <summary>
/// Omni+ presently does not have the hardware capability to detect a cut or broken wire,
/// however the Alarm should be supported through the system so that once hardware is capable that no changes in the system have to be made to support the alarm.
/// <para>
/// Trigger Condition: Detection of a broken or cut wire going to the sensor.
/// </para>
/// </summary>
MeterDisconnectTamper = 0x06,
/// <summary>
/// Register has reached the end of its operational life.
/// <para>
/// Trigger Condition: For a 10 year battery device, Near End of Life alarm becomes active 10.5 years from date of manufacture or 9.5 years from Date of Activation whichever is less.
/// Alarm-specific additional data field indicates number of days remaining before meter reaches end-of-life. Alarm is updated once a day at midnight.
/// </para>
/// </summary>
NearEndOfLife = 0x07,
/// <summary>
/// NV memory error alarm becomes active when an NV memory location fails a checksum check.
/// <para>
/// Trigger Condition: For a 10 year battery device, End-of-life alarm becomes active 11 years from date of manufacture or 10 years from Date of Activation whichever is less.
/// Alarm-specific additional data field indicates number of days elapsed after meter reached end-of-life. Alarm is updated once a day at midnight.
/// </para>
/// </summary>
BeyondEndOfLife = 0x08,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// CommunicationsFailure = 0x09,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// CriticalHardwareWarning = 0x10,
/// <summary>
/// This is a one-shot alarm. Its start and stop time are the same. For that reason, this alarm is never reported as active. It persists for the persistence period.
/// <para>
/// Trigger Condition: Reboot alarm is triggered when the register has rebooted.
/// </para>
/// </summary>
Reboot = 0x11,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// EMFRange = 0x12,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// LowField = 0x13,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HighCurrent = 0x14,
/// <summary>
/// Update Interval: Battery voltage is measured every 15 minutes
/// <para>
/// Trigger Condition: Battery low voltage alarm becomes active when the battery voltage is below 2.7 V for an 4 consecutive 15 sample periods.
/// </para>
/// </summary>
LowPrimaryBattery = 0x15,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// LowSecondaryBattery = 0x16,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// GlideSlope = 0x17,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HighTemperature = 0x18,
/// <summary>
/// Reason for this alarm: uint32LE bitmap indicating which calibration factors/factory required parameters are missing:
/// Factory seal not set: bit 15 of the additional data.
/// <para>
/// Trigger Conditions: Configuration error alarm becomes active when factory seal is not set. Alarm is checked once an hour.
/// </para>
/// </summary>
ConfigError = 0x19,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// ActuatorFailure = 0x20,
/// <summary>
/// Not supported by OMNI+
/// </summary>
// HumiditySensorRead = 0x21
}
}
-47
View File
@@ -1,47 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum Status : byte
{
/// <summary>
/// Used by communication devices to indicate communication failure/timeout. Should not be used by a slave device implementing UI-1236.
/// </summary>
FailureOrTimeout = 0x00,
/// <summary>
/// Command complete, no errors
/// </summary>
Completed = 0x01,
/// <summary>
/// Error, unable to execute command
/// </summary>
UnableToExecute = 0x02,
/// <summary>
/// Error, unknown command
/// </summary>
UnknownCommand = 0x03,
/// <summary>
/// Error, unsupported control bit pattern
/// </summary>
UnsupportedControl = 0x04,
/// <summary>
/// Error, command blocked by factory seal. Added in version B1.23
/// </summary>
BlockedBySeal = 0x05,
/// <summary>
/// Frame received, no error
/// </summary>
FrameReceived = 0xFC,
/// <summary>
/// Message corrupt
/// </summary>
MessageCorrupt = 0xFD,
/// <summary>
/// Wait status
/// </summary>
Waiting = 0xFE,
/// <summary>
/// Used by communication devices to indicate unrecognized communication device command.
/// </summary>
UnrecognizedDevice = 0xFF
}
}
@@ -1,26 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum UI1203Units : byte
{
/// <summary>
/// Cubic meters
/// </summary>
M3 = 0x00,
/// <summary>
/// Cubic feets
/// </summary>
CF = 0x01,
/// <summary>
/// US gallons
/// </summary>
GAL = 0x04,
/// <summary>
/// Imperial gallons
/// </summary>
IGAL = 0x05,
/// <summary>
/// Acre feets
/// </summary>
AF = 0x06,
}
}
@@ -1,131 +0,0 @@
namespace OmniPlus.Features.Enums
{
public enum UI1236Commands : byte
{
/// <summary>
/// Available after seal: Yes
/// </summary>
GetFactoryID = 0x01,
/// <summary>
/// Available after seal: No
/// </summary>
SetFactoryID = 0x02,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetProgrammableID = 0x03,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetProgrammableID = 0x04,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetVersionAndType = 0x05,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetCustomerText = 0x07,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetCustomerText = 0x08,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetNumberOfReadingDigits = 0x09,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetNumberOfReadingDigits = 0x0A,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingUnits = 0x0B,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetReadingUnits = 0x0C,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetRateUnits = 0x0D,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetRateUnits = 0x0E,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingResolution = 0x0F,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetRateResolution = 0x11,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReading = 0x13,
/// <summary>
/// Note1: Conditional
/// </summary>
SetReadingPreset = 0x14,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetReadingMode = 0x15,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetReadingMode = 0x16,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetBuildInformation = 0x17,
/// <summary>
/// Available after seal: No
/// </summary>
SetBuildInformation = 0x18,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetMetrologyAlarmSettings1F = 0x1F,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetMetrologyAlarmSettings1F = 0x20,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetMetrologyAlarmSettings21 = 0x21,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetMetrologyAlarmSettings21 = 0x20,
/// <summary>
/// Available after seal: Yes
/// </summary>
ClearMetrologyAlarms = 0x22,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetAlarmPersistencePeriod = 0x25,
/// <summary>
/// Available after seal: Yes
SetAlarmPersistencePeriod = 0x26,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetOptionalUniDirectionalFields = 0x27,
/// <summary>
/// Available after seal: Yes
/// </summary>
SetOptionalUniDirectionalFields = 0x28,
/// <summary>
/// Available after seal: Yes
/// </summary>
GetUniDirectionalString = 0x29
}
}
@@ -1,22 +0,0 @@
namespace OmniPlus.Features.Types
{
using System;
using System.Text;
public struct ASCIIString
{
private readonly string value;
private ASCIIString(byte[] data)
=> this.value = Encoding.ASCII.GetString(data);
public override string ToString()
=> this.value;
public static implicit operator ASCIIString(byte[] data)
=> new ASCIIString(data ?? Array.Empty<byte>());
public static implicit operator byte[](ASCIIString asciiString)
=> Encoding.ASCII.GetBytes(asciiString.value ?? string.Empty);
}
}
-66
View File
@@ -1,66 +0,0 @@
namespace OmniPlus.Features.Types
{
public class Control
{
private readonly byte[] bits;
private Control(byte[] bits)
=> this.bits = bits;
public bool E0Encryption => this.bits[0] == 1;
public bool E1Encryption => this.bits[1] == 1;
public bool E2Encryption => this.bits[2] == 1;
public bool ReturnResponse
{
get => this.bits[3] == 1;
set => this.bits[3] = (byte)(value ? 1 : 0);
}
public bool NFNetwork => this.bits[4] == 1;
public bool MultipleCommands
{
get => this.bits[5] == 1;
set => this.bits[5] = (byte)(value ? 1 : 0);
}
public bool LongControl
{
get => this.bits[6] == 1;
set => this.bits[6] = (byte)(value ? 1 : 0);
}
public bool MultipleFrames
{
get => this.bits[7] == 1;
set => this.bits[7] = (byte)(value ? 1 : 0);
}
public static implicit operator Control(byte controlByte)
{
var bits = new byte[8];
for (int i = 0; i < 8; i++)
{
bits[i] = (byte)((controlByte >> i) & 1);
}
return new Control(bits);
}
public static implicit operator byte (Control control)
{
var @byte = default(byte);
for (int i = 0; i < 8; i++)
{
@byte ^= (byte)(control.bits[i] << i);
}
return @byte;
}
}
}
@@ -1,24 +0,0 @@
using OmniPlus.Features.Enums;
namespace OmniPlus.Features.Types
{
public struct MeterRange
{
private MeterRanges rangeId;
public MeterRange(MeterRanges rangeId)
=> this.rangeId = rangeId;
public static implicit operator MeterRange(byte rangeId)
=> new MeterRange((MeterRanges)rangeId);
public static implicit operator MeterRange(MeterRanges rangeId)
=> new MeterRange(rangeId);
public static implicit operator byte(MeterRange range)
=> (byte)range.rangeId;
public static implicit operator MeterRanges(MeterRange range)
=> range.rangeId;
}
}
@@ -1,24 +0,0 @@
using OmniPlus.Features.Enums;
namespace OmniPlus.Features.Types
{
public struct MeterSize
{
private MeterSizes sizeId;
public MeterSize(MeterSizes sizeId)
=> this.sizeId = sizeId;
public static implicit operator MeterSize(byte sizeId)
=> new MeterSize((MeterSizes)sizeId);
public static implicit operator MeterSize(MeterSizes sizeId)
=> new MeterSize(sizeId);
public static implicit operator byte(MeterSize size)
=> (byte)size.sizeId;
public static implicit operator MeterSizes(MeterSize size)
=> size.sizeId;
}
}
@@ -1,28 +0,0 @@
using System;
namespace OmniPlus.Features.Types
{
public struct TimeSinse20000101
{
private readonly uint seconds;
public TimeSinse20000101(uint seconds)
=> this.seconds = seconds;
public override string ToString()
{
DateTime dateTime = this;
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
public static implicit operator TimeSinse20000101(uint seconds)
=> new TimeSinse20000101(seconds);
public static implicit operator uint(TimeSinse20000101 time)
=> time.seconds;
public static implicit operator DateTime(TimeSinse20000101 time)
=> new DateTime(2000, 01, 01, 00, 00, 00, DateTimeKind.Utc).AddSeconds(time);
}
}
@@ -1,30 +0,0 @@
using System;
namespace OmniPlus.Features.Types
{
public static class TypesExtensions
{
public static byte[] Subarray(this byte[] sourceArray, int start, int length)
{
if (sourceArray is null)
{
throw new ArgumentNullException(nameof(sourceArray));
}
if (length <= 0)
{
throw new ArgumentException($"Invalid subarray length.");
}
var subarray = new byte[length];
var sourceL = sourceArray.Length;
if (sourceL >= length + start)
{
Array.Copy(sourceArray, start, subarray, 0, length);
}
return subarray;
}
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct AlarmPersistencePeriod
{
public const byte GET = 0x25;
public const byte SET = 0x26;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct BuildInformation
{
public const byte GET = 0x17;
public const byte SET = 0x18;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ClearMetrologyAlarms
{
public const byte SET = 0x22;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct CustomerText
{
public const byte GET = 0x07;
public const byte SET = 0x08;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct FactoryID
{
public const byte GET = 0x01;
public const byte SET = 0x02;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct MetrologyAlarmSettings1F
{
public const byte SET = 0x20;
public const byte GET = 0x1F;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct MetrologyAlarmSettings21
{
public const byte SET = 0x20;
public const byte GET = 0x21;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct NumberOfReadingDigits
{
public const byte GET = 0x09;
public const byte SET = 0x0A;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct OptionalUniDirectionalFields
{
public const byte GET = 0x27;
public const byte SET = 0x28;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ProgrammableID
{
public const byte GET = 0x03;
public const byte SET = 0x04;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct RateResolution
{
public const byte GET = 0x11;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct RateUnits
{
public const byte GET = 0x0D;
public const byte SET = 0x0E;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct Reading
{
public const byte GET = 0x13;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ReadingMode
{
public const byte GET = 0x15;
public const byte SET = 0x16;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ReadingPreset
{
public const byte SET = 0x14;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ReadingResolution
{
public const byte GET = 0x0F;
}
}
@@ -1,8 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct ReadingUnits
{
public const byte GET = 0x0B;
public const byte SET = 0x0C;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct UniDirectionalString
{
public const byte GET = 0x29;
}
}
@@ -1,7 +0,0 @@
namespace OmniPlus.Features.UI1236
{
public struct VersionAndType
{
public const byte GET = 0x05;
}
}
-147
View File
@@ -1,147 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{920435CC-ABDF-497A-9C34-1A8511F0CB56}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>OmniPlus</RootNamespace>
<AssemblyName>OmniPlus</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Connections\Messages\MessageHandler.cs" />
<Compile Include="Connections\UniProConnection.cs" />
<Compile Include="Connection\Contracts\ISerialPortConnection.cs" />
<Compile Include="Connection\Contracts\ISerialPortReader.cs" />
<Compile Include="Connection\Enums\BaudRate.cs" />
<Compile Include="Connection\Enums\SerialPortState.cs" />
<Compile Include="Connection\Events\SerialPortStateChangedEventHandler.cs" />
<Compile Include="Connection\SerialPortConnection.cs" />
<Compile Include="Connection\SerialPortMessage.cs" />
<Compile Include="Connection\SerialPortOptions.cs" />
<Compile Include="Connection\Enums\DataBits.cs" />
<Compile Include="Connection\SerialPortStream.cs" />
<Compile Include="Features\DeviceSpecific\BatteryVoltage.cs" />
<Compile Include="Features\DeviceSpecific\BatteryVoltageMeasurementCalibrationFactors.cs" />
<Compile Include="Features\DeviceSpecific\CalibrationResults.cs" />
<Compile Include="Features\DeviceSpecific\ConfigurationParameters.cs" />
<Compile Include="Features\DeviceSpecific\DataLogData.cs" />
<Compile Include="Features\DeviceSpecific\DataLogInterval.cs" />
<Compile Include="Features\DeviceSpecific\DisplayMode.cs" />
<Compile Include="Features\DeviceSpecific\EnabledLCDViews.cs" />
<Compile Include="Features\DeviceSpecific\EnabledPredefinedAlarms.cs" />
<Compile Include="Features\DeviceSpecific\ExtendedResolutionSetting.cs" />
<Compile Include="Features\DeviceSpecific\FactoryCalibration.cs" />
<Compile Include="Features\DeviceSpecific\FactoryMeterChamberCalibrationTest.cs" />
<Compile Include="Features\DeviceSpecific\FactoryPulseTestMode.cs" />
<Compile Include="Features\DeviceSpecific\FactorySeal.cs" />
<Compile Include="Features\DeviceSpecific\FieldCalibration.cs" />
<Compile Include="Features\DeviceSpecific\InputVolume.cs" />
<Compile Include="Features\DeviceSpecific\LCDSegmentTest.cs" />
<Compile Include="Features\DeviceSpecific\LCDTimeout.cs" />
<Compile Include="Features\DeviceSpecific\LidState.cs" />
<Compile Include="Features\DeviceSpecific\LifeTimeMaxSensorPulsesperSecond.cs" />
<Compile Include="Features\DeviceSpecific\ManufacturingTestCommand.cs" />
<Compile Include="Features\DeviceSpecific\ManufacturingTime.cs" />
<Compile Include="Features\DeviceSpecific\OmniSize.cs" />
<Compile Include="Features\DeviceSpecific\OutputPulseSettings.cs" />
<Compile Include="Features\DeviceSpecific\PeriodicAlarmLogEntries.cs" />
<Compile Include="Features\DeviceSpecific\RebootCount.cs" />
<Compile Include="Features\DeviceSpecific\RegisterDeviceIDString.cs" />
<Compile Include="Features\DeviceSpecific\RegisterSetting.cs" />
<Compile Include="Features\DeviceSpecific\SecondsActive.cs" />
<Compile Include="Features\DeviceSpecific\SendFlexNetSerialCommands.cs" />
<Compile Include="Features\DeviceSpecific\SendMultipleFlexNetSerialCommands.cs" />
<Compile Include="Features\DeviceSpecific\SystemParameters.cs" />
<Compile Include="Features\DeviceSpecific\SystemTime.cs" />
<Compile Include="Features\DeviceSpecific\TestPulse.cs" />
<Compile Include="Features\DeviceSpecific\TestTotalizerValue.cs" />
<Compile Include="Features\DeviceSpecific\TimeofFactorySeal.cs" />
<Compile Include="Features\DeviceSpecific\TimeofInstallation.cs" />
<Compile Include="Features\DeviceSpecific\TriggerWatchdogReset.cs" />
<Compile Include="Features\Enums\CalibrationState.cs" />
<Compile Include="Features\Enums\DeviceCommands.cs" />
<Compile Include="Features\Enums\MeterRanges.cs" />
<Compile Include="Features\Enums\MeterSizes.cs" />
<Compile Include="Features\Enums\Status.cs" />
<Compile Include="Features\Enums\PredefinedAlarms.cs" />
<Compile Include="Features\Enums\UI1203Units.cs" />
<Compile Include="Features\Enums\UI1236Commands.cs" />
<Compile Include="Features\Types\Control.cs" />
<Compile Include="Features\Types\MeterRange.cs" />
<Compile Include="Features\Types\MeterSize.cs" />
<Compile Include="Features\UI1236\AlarmPersistencePeriod.cs" />
<Compile Include="Features\UI1236\BuildInformation.cs" />
<Compile Include="Features\UI1236\ClearMetrologyAlarms.cs" />
<Compile Include="Features\UI1236\CustomerText.cs" />
<Compile Include="Features\UI1236\FactoryID.cs" />
<Compile Include="Features\UI1236\MetrologyAlarmSettings1F.cs" />
<Compile Include="Features\UI1236\MetrologyAlarmSettings21.cs" />
<Compile Include="Features\UI1236\NumberOfReadingDigits.cs" />
<Compile Include="Features\UI1236\OptionalUniDirectionalFields.cs" />
<Compile Include="Features\UI1236\ProgrammableID.cs" />
<Compile Include="Features\UI1236\RateResolution.cs" />
<Compile Include="Features\UI1236\RateUnits.cs" />
<Compile Include="Features\UI1236\Reading.cs" />
<Compile Include="Features\UI1236\ReadingMode.cs" />
<Compile Include="Features\UI1236\ReadingPreset.cs" />
<Compile Include="Features\UI1236\ReadingResolution.cs" />
<Compile Include="Features\UI1236\ReadingUnits.cs" />
<Compile Include="Features\UI1236\UniDirectionalString.cs" />
<Compile Include="Features\UI1236\VersionAndType.cs" />
<Compile Include="Connections\Messages\UI1236Message.cs" />
<Compile Include="Connections\IrdaConnection.cs" />
<Compile Include="Connections\Messages\IrdaMessage.cs" />
<Compile Include="Connections\Extensions.cs" />
<Compile Include="OmniRegister.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Features\Types\ASCIIString.cs" />
<Compile Include="Features\Types\TimeSinse20000101.cs" />
<Compile Include="Features\Types\TypesExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Utils\Crc16Ccitt\Crc16Ccitt.csproj">
<Project>{91DEF0C0-AA4F-40AE-8F18-CB717FDE7E7F}</Project>
<Name>Crc16Ccitt</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
-54
View File
@@ -1,54 +0,0 @@
using OmniPlus.Connections;
using OmniPlus.Connections.Messages;
using OmniPlus.Features.DeviceSpecific;
using OmniPlus.Features.Enums;
namespace OmniPlus
{
public class OmniRegister
{
private readonly string portName;
private readonly IrdaConnection irdaConnection;
private readonly UniProConnection uniProConnection;
private MessageHandler messageHandler;
public OmniRegister(string portName)
{
this.portName = portName;
this.irdaConnection = new IrdaConnection(portName);
this.uniProConnection = new UniProConnection(portName);
}
public void ActivateIrda()
{
this.uniProConnection?.Close();
this.irdaConnection?.Open();
this.messageHandler = this.irdaConnection.Write;
}
public void ActivateUniPro()
{
this.irdaConnection?.Close();
this.uniProConnection?.Open();
this.messageHandler = this.uniProConnection.Write;
}
public SystemParameters GetSystemParameters()
=> this.messageHandler?.Invoke(SystemParameters.GetCommand, 3000, 300);
public bool SetInputVolume(InputVolume inputVolume)
{
inputVolume = this.messageHandler?.Invoke(inputVolume, 3000, 300);
return inputVolume.Status == Status.Completed;
}
public FactoryMeterChamberCalibrationTest StartCalibration(FactoryMeterChamberCalibrationTest calibrationOptions)
=> this.messageHandler?.Invoke(calibrationOptions, 3000, 300);
public CalibrationResults GetCalibrationResults()
=> this.messageHandler?.Invoke(CalibrationResults.RequestResults, 3000, 300);
}
}
-30
View File
@@ -1,30 +0,0 @@
namespace OmniPlus
{
class Program
{
static void Main(string[] args)
{
var omniRegister = new OmniRegister("COM4");
omniRegister.ActivateIrda();
var systemParameters = omniRegister.GetSystemParameters();
//var inputVolumeSetted = omniRegister.SetInputVolume(new InputVolume
//{
// MilliliterPerPulse = 1500,
// FractionalPart = 500,
// MeterSize = MeterSizes.OneHalfIn,
// MeterRange = MeterRanges.From1To2,
//});
//var calibrationStart = omniRegister.StartCalibration(new FactoryMeterChamberCalibrationTest
//{
// CalibrationState = CalibrationState.OK,
// Rotations = 1000,
// Dauer = 10000
//});
//var calibration = omniRegister.GetCalibrationResults();
}
}
}
@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OmniPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OmniPlus")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("920435cc-abdf-497a-9c34-1a8511f0cb56")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]