예제 #1
0
        private static SurfaceCard PopulateSurfaceCard(List <ModbusRegisterValue> registerValues)
        {
            if (registerValues == null || registerValues.Count == 0)
            {
                System.Console.WriteLine("Empty register values passed.");
                return(null);
            }

            System.Console.WriteLine("Parsing surface card.");
            SurfaceCard surfaceCard = new SurfaceCard()
            {
                CardCoordinates = new List <CardCoordinate>()
            };

            var timestampProp = ModbusMessage.SurfaceLayoutConfig.Timestamp;

            if (timestampProp != null)
            {
                int timestamp       = 0;
                var timeStampValues = GetValueArray(timestampProp.RegisterNumber, timestampProp.NumberOfRegisters, registerValues);

                if (timeStampValues != null && timeStampValues.Count > 1)
                {
                    short left  = (short)Int32.Parse(timeStampValues[0]);
                    short right = (short)Int32.Parse(timeStampValues[1]);

                    timestamp = left;
                    timestamp = (timestamp << 16);
                    timestamp = timestamp | (int)(ushort)right;
                }

                DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();
                surfaceCard.Timestamp = dateTime;
            }

            var maxLoadProp = ModbusMessage.SurfaceLayoutConfig.MaxLoad;

            if (maxLoadProp != null)
            {
                var maxLoadpValues = GetValueArray(maxLoadProp.RegisterNumber, maxLoadProp.NumberOfRegisters, registerValues);
                if (maxLoadpValues != null && maxLoadpValues.Count > 0)
                {
                    surfaceCard.ScaledMaxLoad = Int32.Parse(maxLoadpValues.First());
                }
            }

            var minLoadProp = ModbusMessage.SurfaceLayoutConfig.MinLoad;

            if (minLoadProp != null)
            {
                var minLoadValues = GetValueArray(minLoadProp.RegisterNumber, minLoadProp.NumberOfRegisters, registerValues);
                if (minLoadValues != null && minLoadValues.Count > 0)
                {
                    surfaceCard.ScaledMinLoad = Int32.Parse(minLoadValues.First());
                }
            }

            var strokeLengthProp = ModbusMessage.SurfaceLayoutConfig.StrokeLength;

            if (strokeLengthProp != null)
            {
                var strokeLengthValues = GetValueArray(strokeLengthProp.RegisterNumber, strokeLengthProp.NumberOfRegisters, registerValues);
                if (strokeLengthValues != null && strokeLengthValues.Count > 0)
                {
                    surfaceCard.StrokeLength = Int32.Parse(strokeLengthValues.First());
                }
            }

            var strokePeriodProp = ModbusMessage.SurfaceLayoutConfig.StrokePeriod;

            if (strokePeriodProp != null)
            {
                var strokePeriodValues = GetValueArray(strokePeriodProp.RegisterNumber, strokePeriodProp.NumberOfRegisters, registerValues);
                if (strokePeriodValues != null && strokePeriodValues.Count > 0)
                {
                    surfaceCard.StrokePeriod = Int32.Parse(strokePeriodValues.First());
                }
            }

            var numberOfPointsProp = ModbusMessage.SurfaceLayoutConfig.NumberOfPoints;
            int numberOfDataPoints = 0;

            if (numberOfPointsProp != null)
            {
                var numberOfPointsValues = GetValueArray(numberOfPointsProp.RegisterNumber, numberOfPointsProp.NumberOfRegisters, registerValues);
                if (numberOfPointsValues != null && numberOfPointsValues.Count > 0)
                {
                    //Get just the low byte of the value
                    numberOfDataPoints = Int32.Parse(numberOfPointsValues.First());
                    Console.WriteLine($"Number of surface points 16-bit value: {numberOfDataPoints}");

                    numberOfDataPoints = (int)(ushort)numberOfDataPoints;
                    Console.WriteLine($"Number of surface points 8-bit value: {numberOfDataPoints}");

                    surfaceCard.NumberOfPoints = numberOfDataPoints;

                    if (numberOfDataPoints == 0)
                    {
                        //If the number of detail points is 0, that's an indication we have bad data.
                        Console.WriteLine("Zero coordinates found. Returning null card.");
                        return(null);
                    }

                    List <CardCoordinate> cardCoordinates = new List <CardCoordinate>();
                    var pointArrayProperty = ModbusMessage.SurfaceLayoutConfig.Point;

                    for (int i = 0; i < surfaceCard.NumberOfPoints; i += pointArrayProperty.NumberOfRegisters)
                    {
                        var pointsArray = GetValueArray(pointArrayProperty.RegisterNumber + i, pointArrayProperty.NumberOfRegisters, registerValues);
                        if (pointsArray != null && pointsArray.Count > 1)
                        {
                            cardCoordinates.Add(new CardCoordinate()
                            {
                                Load     = Int32.Parse(pointsArray[0]),
                                Position = Int32.Parse(pointsArray[1])
                            });
                        }
                    }

                    surfaceCard.CardCoordinates = cardCoordinates;
                }
            }

            return(surfaceCard);
        }
예제 #2
0
파일: DynoCard.cs 프로젝트: Jman5451/jjkkkk
 public DynoCard()
 {
     SurfaceCard = new SurfaceCard();
     PumpCard    = new PumpCard();
 }