Exemplo n.º 1
0
        public OpcMessage(Message message)
        {
            System.Console.WriteLine("Creating opc message instance.");

            CurrentCard = new DynoCard()
            {
                Id              = -1,
                Timestamp       = DateTime.Now,
                TriggeredEvents = false,
                PumpCard        = new PumpCard()
                {
                    Id              = -1,
                    CardType        = CardType.Pump,
                    FluidLoad       = 9500,
                    GrossStroke     = 150,
                    NetStroke       = 1200,
                    NumberOfPoints  = 200,
                    PumpFillage     = 77,
                    ScaledMaxLoad   = 19500,
                    ScaledMinLoad   = 7500,
                    Timestamp       = DateTime.Now,
                    CardCoordinates = new List <CardCoordinate>()
                },
                SurfaceCard = new SurfaceCard()
                {
                    Id              = -1,
                    CardType        = CardType.Surface,
                    StrokePeriod    = 150,
                    StrokeLength    = 1200,
                    NumberOfPoints  = 200,
                    ScaledMaxLoad   = 19500,
                    ScaledMinLoad   = 7500,
                    Timestamp       = DateTime.Now,
                    CardCoordinates = new List <CardCoordinate>()
                }
            };

            var messageBytes  = message.GetBytes();
            var messageString = Encoding.UTF8.GetString(messageBytes);

            if (!string.IsNullOrEmpty(messageString))
            {
                try
                {
                    var readingValues = JsonConvert.DeserializeObject <List <OpcNodeReading> >(messageString);
                    PopulateReadingValues(readingValues);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"An error occurred trying to populate/parse the values: {ex.Message}");
                    System.Console.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                Console.WriteLine("Empty opc message received.");
            }
        }
Exemplo n.º 2
0
        public static Message ToDeviceMessage(this DynoCard dynoCard)
        {
            Message dynoCardMessage = null;

            if (dynoCard != null)
            {
                var dynoCardBytes      = JsonConvert.SerializeObject(dynoCard);
                var dynoCardByteString = Encoding.UTF8.GetBytes(dynoCardBytes);
                dynoCardMessage = new Message(dynoCardByteString);
            }

            return(dynoCardMessage);
        }
Exemplo n.º 3
0
        public static async Task <DynoCard> ToDynoCard(this ModbusMessage modbus)
        {
            DynoCard dynoCard = new DynoCard()
            {
                SurfaceCard     = PopulateSurfaceCard(modbus.SurfaceCardRegisterValues),
                PumpCard        = PopulatePumpCard(modbus.PumpCardRegisterValues),
                TriggeredEvents = false
            };

            if (dynoCard.SurfaceCard != null)
            {
                dynoCard.Timestamp = dynoCard.SurfaceCard.Timestamp;
            }

            return(await Task.FromResult(dynoCard));
        }