コード例 #1
0
ファイル: SysInt.cs プロジェクト: matrixitUser/matrix-mx
        public static SysInt Parse(byte[] data, int offset)
        {
            if (data == null || data.Length < 0xFF + offset)
            {
                return(null);
            }

            var result = new SysInt();

            DateTime curdate;
            var      dateTimeString = string.Format("{0}.{1}.{2} {3}:00:00",
                                                    ConvertHelper.BinDecToInt(data[offset + 1]), //day
                                                    ConvertHelper.BinDecToInt(data[offset + 2]), //mon
                                                    ConvertHelper.BinDecToInt(data[offset + 3]), //yr
                                                    ConvertHelper.BinDecToInt(data[offset + 0])  //hr
                                                    );

            DateTime.TryParse(dateTimeString, out curdate);
            result.date = curdate;

            result.Trab.Value[0] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x68, 4), 0);

            for (var sysch = 0; sysch < 4; sysch++)
            {
                result.IntV.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x08 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x38 + sysch * 4, 4), 0);
                result.IntM.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x18 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x48 + sysch * 4, 4), 0);
                result.IntQ.Value[sysch] =
                    BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0x28 + sysch * 4, 4), 0) +
                    BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x58 + sysch * 4, 4), 0);

                result.Tnar.Value[sysch] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x6c + sysch * 4, 4), 0);
                //result.Tmin.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x7c + sysch * 4, 4), 0);
                //result.Tmax.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x8c + sysch * 4, 4), 0);
                //result.Tdt.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0x9c + sysch * 4, 4), 0);
                //result.Ttn.Value[sysch] = BitConverter.ToInt32(GetReversed(data, offset + 0xac + sysch * 4, 4), 0);

                result.Rshv.Value[sysch] = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0xec + sysch * 4, 4), 0);

                for (int i = 0; i < 3; i++)
                {
                    result.T.Value[sysch * 3 + i] = (double)(BitConverter.ToInt16(ConvertHelper.GetReversed(data, offset + 0xc8 + (sysch * 3 + i) * 2, 2), 0)) / 100;
                    result.P.Value[sysch * 3 + i] = (double)(data[offset + 0xe0 + (sysch * 3 + i)]) / 100;
                }
            }

            return(result);
        }
コード例 #2
0
        public static T2K Parse(byte[] data, int offset)
        {
            if (data == null || data.Length < 0x2FF + offset)
            {
                return(null);
            }

            var result = new T2K();

            result.Systems = data[offset + 0];
            for (int i = 0; i < 12; i++)
            {
                result.Type_g[i] = (TypeG)data[offset + 0x01 + i];
                result.Type_t[i] = (TypeT)data[offset + 0x0c + i];
            }
            result.Net_num = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x78, 4), 0);
            result.Number  = BitConverter.ToInt32(ConvertHelper.GetReversed(data, offset + 0x7c, 4), 0);

            for (int i = 0; i < 4; i++)
            {
                result.Diam[i]       = BitConverter.ToInt16(ConvertHelper.GetReversed(data, offset + 0xc4 + i * 2, 2), 0);
                result.G_max[i]      = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xcc + i * 4, 4), 0);
                result.G_pcnt_max[i] = data[offset + 0xdc + i];
                result.G_pcnt_min[i] = data[offset + 0xe0 + i];
            }

            for (int i = 0; i < 2; i++)
            {
                result.F_max[i]  = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xe4 + i * 4, 4), 0);
                result.Weight[i] = BitConverter.ToSingle(ConvertHelper.GetReversed(data, offset + 0xec + i * 4, 4), 0);//??? 74? EC?
            }

            result.SysInt_copy = SysInt.Parse(data, offset + 0x200);
            for (int i = 0; i < 4; i++)
            {
                result.SysConN[i] = SysCon.Parse(data, offset + 0x600 + i * 0x20);
            }

            return(result);
        }
コード例 #3
0
        private IEnumerable <Data> ReadArchive(ArchiveType archiveType, IEnumerable <DateTime> dates)
        {
            var datas = new List <Data>();

            if (T2k == null)
            {
                return(null);
            }

            Show(string.Format("Чтение {0} архива", archiveType));

            if (GetVersion().Equals(DriverVersion))
            {
                foreach (var date in dates)
                {
                    Show(string.Format("Запрос даты {0:HH:mm dd.MM.yyyy}", date));
                    var answer = SendRequest(0x0d11, new byte[] { (byte)archiveType,
                                                                  archiveType == ArchiveType.Hourly? IntToBCD(date.Hour):(byte)0x00,
                                                                  archiveType != ArchiveType.Monthly? IntToBCD(date.Day):(byte)0x01,
                                                                  IntToBCD(date.Month),
                                                                  IntToBCD(date.Year - 2000) });

                    if (answer != null && answer.Length == 3)
                    {
                        var num = answer[1] << 8 | answer[2];
                        if (num == 0xFFFF)
                        {
                            Show("запись не обнаружена");
                        }
                        else
                        {
                            Show(string.Format("номер записи: {0} ({0:X})", num));
                            //Int64 addr = 0;
                            //var answer0 = SendRequest(0x0f03, new byte[] { 64, (byte)(addr >> 24), (byte)(addr >> 16), (byte)(addr >> 08), (byte)(addr) });
                            answer = new byte[256];
                            for (int i = 0; i < 4; i++)
                            {
                                var curanswer = SendRequest(0x0f03, new byte[] { 64, 0x00, ConvertHelper.ByteHigh(num), ConvertHelper.ByteLow(num) /*answer[1], answer[2]*/, (byte)(i * 0x40) }, 3333, 5);
                                if (curanswer == null || curanswer.Length != 65)
                                {
                                    Show("не удалось запросить запись, пропуск");
                                    answer = null;
                                    break;
                                }
                                Array.Copy(curanswer, 1, answer, 64 * i, 64);
                            }

                            if (answer != null)
                            {
                                var sysInt = SysInt.Parse(answer, 0);

                                if (T2k.Systems < 1 || T2k.Systems > 4)
                                {
                                    Show(string.Format("Некорректное число систем: {0}", T2k.Systems));
                                    return(null);
                                }

                                datas.Add(new Data(sysInt.Trab.Parameter, sysInt.Trab.MeasuringUnit, sysInt.date,
                                                   sysInt.Trab.Value[0]));
                                for (int sys = 0; sys < T2k.Systems; sys++)
                                {
                                    var systype = T2k.SysConN[sys].sysType;
                                    datas.Add(new Data(sysInt.IntV.Parameter, sysInt.IntV.MeasuringUnit, sysInt.date,
                                                       sysInt.IntV.Value[sys]));
                                    datas.Add(new Data(sysInt.IntM.Parameter, sysInt.IntM.MeasuringUnit, sysInt.date,
                                                       sysInt.IntM.Value[sys]));
                                    datas.Add(new Data(sysInt.IntQ.Parameter, sysInt.IntQ.MeasuringUnit, sysInt.date,
                                                       sysInt.IntQ.Value[sys]));
                                    datas.Add(new Data(sysInt.Tnar.Parameter, sysInt.Tnar.MeasuringUnit, sysInt.date,
                                                       sysInt.Tnar.Value[sys]));

                                    for (int i = 0; i < SysCon.GetChannelsPorT(systype); i++)
                                    {
                                        datas.Add(new Data(sysInt.T.Parameter, sysInt.T.MeasuringUnit, sysInt.date,
                                                           sysInt.T.Value[sys * 3 + i]));
                                        datas.Add(new Data(sysInt.P.Parameter, sysInt.P.MeasuringUnit, sysInt.date,
                                                           sysInt.P.Value[sys * 3 + i]));
                                    }

                                    datas.Add(new Data(sysInt.Rshv.Parameter, sysInt.Rshv.MeasuringUnit, sysInt.date,
                                                       sysInt.Rshv.Value[sys]));
                                }
                            }

                            //var answer0 = SendRequest(0x0f03, new byte[] { 64, 0x00, answer[1], answer[2], 0x00 });
                            //var answer1 = SendRequest(0x0f03, new byte[] { 64, 0x00, answer[1], answer[2], 0x40 });
                            //var answer2 = SendRequest(0x0f03, new byte[] { 64, 0x00, answer[1], answer[2], 0x80 });
                            //var answer3 = SendRequest(0x0f03, new byte[] { 64, 0x00, answer[1], answer[2], 0xC0 });
                        }
                    }
                    else
                    {
                        Show("ответ не получен");
                    }
                }
            }

            return(datas);
        }