Ejemplo n.º 1
0
        /// <summary>
        /// Сохранить таблицу калибровки в файл
        /// </summary>
        /// <param name="table">Таблица калибровки, которую необходимо сохранить</param>
        /// <param name="eprom">Виртуальный eprom устройства</param>
        public void SaveCalibrationTableToDevice(CalibrationTable table, Eprom eprom)
        {
            try
            {
                int[] Indices = { 0x0400, 0x0430, 0x0460, 0x0490, 0x04C0, 0x04F0, 0x0520, 0x0550 };
                foreach (int index in Indices)
                {
                    if (eprom.GetByte(index) == table.Name)
                    {
                        string protectStart = "@JOB#000#" + string.Format("{0:X2}", platformIO.Options.Device) +
                            platformIO.Options.ProtectionStart + "$";
                        platform.SendPacket(new Packet(protectStart, DateTime.Now, null));

                        for (int line = 0; line < calibrationTableCountLines; line++)
                        {
                            int offset = index + (line * 16);

                            int pageNumber = (int)(offset / 256);
                            int offsetPage = (int)(offset % 256);

                            string data = string.Empty;
                            for (int byteIndex = 0; byteIndex < calibrationLineByteCount; byteIndex++)
                            {
                                data += string.Format("{0:X2}", eprom.GetByte(offset++));
                            }

                            platformIO.Write(platformIO.Options.Device, pageNumber, offsetPage, 16, data);
                            switch (platformIO.LastOperation)
                            {
                                case ResultOperation.Succes:

                                    if (eSaveCompleteReadEpromLine != null) eSaveCompleteReadEpromLine(this, new EventArgs());
                                    break;

                                case ResultOperation.Timeout:

                                    if (eSaveTimeoutReadEpromLine != null) eSaveTimeoutReadEpromLine(this, new EventArgs());
                                    return;

                                case ResultOperation.MorePopit:

                                    if (eSaveMorePopitReadEpromLine != null) eSaveMorePopitReadEpromLine(this, new EventArgs());
                                    return;

                                default:

                                    return;
                            }
                        }
                    }
                }
            }
            finally
            {
                string protectEnd = "@JOB#000#" + string.Format("{0:X2}", platformIO.Options.Device) +
                    platformIO.Options.ProtectionEnd + "$";
                platform.SendPacket(new Packet(protectEnd, DateTime.Now, null));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Сохраняет таблицу калибровки в указанный eprom
        /// </summary>
        /// <param name="table">Таблица калибровки, которую необходимо сохранить</param>
        /// <param name="eprom">Eprom в который необходимо сохранить таблицу калибровки</param>
        public void SaveCalibrationTableToFile(CalibrationTable table, Eprom eprom)
        {
            int[] Indices = { 0x0400, 0x0430, 0x0460, 0x0490, 0x04C0, 0x04F0, 0x0520, 0x0550 };
            foreach (int index in Indices)
            {
                if (eprom.GetByte(index) == table.Name)
                {
                    byte size = (byte)(table.Parameters.Count * 4);
                    eprom.SetByte(index + 3, size);

                    int offset = index + 4;
                    foreach (Parameter parameter in table.Parameters)
                    {
                        eprom.SetByte(offset++, (byte)(parameter.Physical >> 8));
                        eprom.SetByte(offset++, (byte)parameter.Physical);

                        eprom.SetByte(offset++, (byte)(parameter.Calibrated >> 8));
                        eprom.SetByte(offset++, (byte)parameter.Calibrated);
                    }
                    if (table.Parameters.Count < 11)
                    {
                        eprom.SetByte(offset++, 0xff);
                        eprom.SetByte(offset++, 0xff);

                        eprom.SetByte(offset++, 0xff);
                        eprom.SetByte(offset++, 0xff);
                    }
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Возвращяет таблицу калибровки
        /// </summary>
        /// <param name="eprom">EPROM устройства из которого необходимо извлеч данные</param>
        /// <param name="CalibrationParameterName">Имя калибровочного параметра</param>
        /// <returns>Таблица калибровки</returns>
        public LastError GetCalibrationTable(Eprom eprom, CalibrationTableHandle calibrationHandle)
        {
            int[] Indices = { 0x0400, 0x0430, 0x0460, 0x0490, 0x04C0, 0x04F0, 0x0520, 0x0550 };
            foreach (int index in Indices)
            {
                if (eprom.GetByte(index) == calibrationHandle.Name)
                {
                    byte size = eprom.GetByte(index + 3);
                    CalibrationTable table = new CalibrationTable(calibrationHandle.Name, size);

                    int offset = index + 4;         // смещение по которому начинаются калибровочные значения
                    if ((size % 4) != 0) return LastError.Error;

                    for (int i = 0; i < size / 4; i++)
                    {
                        byte[] physical = new byte[2];
                        byte[] calibrated = new byte[2];

                        physical[1] = eprom.GetByte(offset++);
                        physical[0] = eprom.GetByte(offset++);

                        calibrated[1] = eprom.GetByte(offset++);
                        calibrated[0] = eprom.GetByte(offset++);

                        Parameter param = new Parameter();

                        param.Physical = (ushort)BitConverter.ToInt16(physical, 0);
                        param.Calibrated = (ushort)BitConverter.ToInt16(calibrated, 0);

                        table.Parameters.Add(param);
                    }
                    calibrationHandle.CalibrationTable = table;
                    return LastError.Success;
                }
            }
            return LastError.Error;
        }