Пример #1
0
        /// <summary>
        /// Записать выбранный eprom в устройство
        /// </summary>
        /// <param name="eprom">Eprom который необходимо записать</param>
        public void SetEprom(Eprom eprom)
        {
            for (int page = 1; page < 8; page++)
            {
                for (int line = 0; line < 16; line++)
                {
                    string data = Write(Options.Device, page, line * 16, 16, eprom[page - 1].Lines[line].ToString());
                    switch (lastOperation)
                    {
                    case ResultOperation.Succes:

                        if (eComplete != null)
                        {
                            eComplete(this, new EventArgs());
                        }
                        break;

                    default:

                        return;
                    }
                }
            }
            return;
        }
Пример #2
0
        /// <summary>
        /// Выполняет сохранение EPROM устройства в файл
        /// </summary>
        /// <param name="filePath">URI файла</param>
        /// <param name="eprom">EPROM устройства который необходимо сохранить</param>
        public void Save(string filePath, Eprom eprom)
        {
            XmlTextWriter writer = null;

            try
            {
                writer = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteStartElement("eprom");

                foreach (Page page in eprom.Pages)
                {
                    writer.WriteStartElement("page");
                    foreach (Line line in page.Lines)
                    {
                        writer.WriteElementString("line", line.ToString());
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (writer != null) writer.Close();
            }
        }
Пример #3
0
        /// <summary>
        /// Возврощает EPROM устройства с заданными страницами
        /// </summary>
        /// <param name="Pages">массив страниц, которые необходимо загрузить</param>
        /// <returns>EPROM устройства</returns>
        public Eprom GetEprom(int[] Pages)
        {
            if (Pages != null)
            {
                Eprom eprom = new Eprom();
                foreach (int pageNumber in Pages)
                {
                    if (pageNumber >= 1 && pageNumber <= 7)
                    {
                        for (int line = 0; line < 16; line++)
                        {
                            string data = Read(Options.Device, pageNumber, line * 16, 16);
                            switch (lastOperation)
                            {
                            case ResultOperation.Succes:

                                if (data.Length == 32)
                                {
                                    for (int i = 0; i < 16; i++)
                                    {
                                        string ch = data.Substring(i * 2, 2);
                                        eprom[pageNumber - 1][line * 16 + i] = byte.Parse(ch, NumberStyles.AllowHexSpecifier);
                                    }
                                    if (eComplete != null)
                                    {
                                        eComplete(this, new EventArgs());
                                    }
                                }
                                else
                                {
                                    throw new Exception("Произошла ошибка при чтении данных!");
                                }

                                break;

                            default:

                                return(null);
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Значение номера страницы не корректно");
                    }
                }
                return(eprom);
            }
            return(null);
        }
Пример #4
0
        /// <summary>
        /// Выполняет сохранение EPROM устройства в файл
        /// </summary>
        /// <param name="filePath">URI файла</param>
        /// <param name="eprom">EPROM устройства который необходимо сохранить</param>
        public void Save(string filePath, Eprom eprom)
        {
            StreamWriter writer = null;

            try
            {
                writer = new StreamWriter(filePath);

                int pageNumber = 0;
                int lineNumber = -1;

                foreach (Page page in eprom.Pages)
                {
                    pageNumber += 1;
                    lineNumber  = -1;

                    string pageString = string.Format("{0:d2}", pageNumber);
                    foreach (Line line in page.Lines)
                    {
                        lineNumber += 1;
                        string totalpageString = pageString + string.Format("{0:X}", lineNumber) + "0   ";

                        string lineStringValue = string.Empty;
                        foreach (var item in line.line)
                        {
                            lineStringValue += string.Format("{0:X2}", item) + " ";
                        }

                        writer.WriteLine(totalpageString + lineStringValue);
                    }
                    writer.WriteLine(" ");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Возврощает EPROM устройства(считывание выполняется в синхронном режиме)
        /// </summary>
        /// <returns>EPROM устройства</returns>
        public Eprom GetEprom()
        {
            Eprom eprom = new Eprom();

            for (int page = 1; page < 8; page++)
            {
                for (int line = 0; line < 16; line++)
                {
                    string data = Read(Options.Device, page, line * 16, 16);
                    switch (lastOperation)
                    {
                    case ResultOperation.Succes:

                        if (data.Length == 32)
                        {
                            for (int i = 0; i < 16; i++)
                            {
                                string ch = data.Substring(i * 2, 2);
                                eprom[page - 1][line * 16 + i] = byte.Parse(ch, NumberStyles.AllowHexSpecifier);
                            }
                            if (eComplete != null)
                            {
                                eComplete(this, new EventArgs());
                            }
                        }
                        else
                        {
                            throw new Exception("Произошла ошибка при чтении данных!");
                        }

                        break;

                    default:

                        return(null);
                    }
                }
            }
            return(null);
        }
Пример #6
0
        /// <summary>
        /// Выполняет сохранение EPROM устройства в файл
        /// </summary>
        /// <param name="filePath">URI файла</param>
        /// <param name="eprom">EPROM устройства который необходимо сохранить</param>
        public void Save(string filePath, Eprom eprom)
        {
            StreamWriter writer = null;
            try
            {
                writer = new StreamWriter(filePath);

                int pageNumber = 0;
                int lineNumber = -1;

                foreach (Page page in eprom.Pages)
                {
                    pageNumber += 1;
                    lineNumber = -1;

                    string pageString = string.Format("{0:d2}", pageNumber);
                    foreach (Line line in page.Lines)
                    {
                        lineNumber += 1;
                        string totalpageString = pageString + string.Format("{0:X}", lineNumber) + "0   ";

                        string lineStringValue = string.Empty;
                        foreach (var item in line.line) lineStringValue += string.Format("{0:X2}", item) + " ";

                        writer.WriteLine(totalpageString + lineStringValue);
                    }
                    writer.WriteLine(" ");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (writer != null) writer.Close();
            }
        }
Пример #7
0
        /// <summary>
        /// Записать выбранный eprom в устройство с заданными страницами
        /// </summary>
        /// <param name="eprom">Eprom который необходимо записать</param>
        /// <param name="Pages">Страницы которые необходимо записать</param>
        public void SetEprom(Eprom eprom, int[] Pages)
        {
            if (Pages != null)
            {
                foreach (int pageNumber in Pages)
                {
                    if (pageNumber >= 1 && pageNumber <= 7)
                    {
                        for (int line = 0; line < 16; line++)
                        {
                            string data = Write(Options.Device, pageNumber, line * 16, 16, eprom[pageNumber - 1].Lines[line].ToString());
                            switch (lastOperation)
                            {
                            case ResultOperation.Succes:

                                if (eComplete != null)
                                {
                                    eComplete(this, new EventArgs());
                                }
                                break;

                            default:

                                return;
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Значение номера страницы не корректно");
                    }
                }
                return;
            }
            return;
        }
Пример #8
0
        /// <summary>
        /// Загружает EPROM устройства из файла
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <returns>Загруженный EPROM устройства или же null, если загрузить EPROM не удалось</returns>
        public Eprom Load(string filePath)
        {
            try
            {
                Eprom eprom = new Eprom();
                using (StreamReader reader = new StreamReader(filePath))
                {
                    string line;
                    int page = 0, offset = 0;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Length == lineLenght)
                        {
                            string total = line.Substring(4).Replace(" ", string.Empty);
                            for (int i = 0; i < total.Length / 2; i++)
                            {
                                string sByte = total.Substring(i * 2, 2);
                                eprom[page][offset] = (byte)(int.Parse(sByte, NumberStyles.AllowHexSpecifier));
                                offset += 1;
                            }
                        }
                        else
                        {
                            offset = 0;
                            page += 1;
                        }
                    }
                    return eprom;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Пример #9
0
        /// <summary>
        /// Загружает EPROM устройства из файла
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <returns>Загруженный EPROM устройства или же null, если загрузить EPROM не удалось</returns>
        public Eprom Load(string filePath)
        {
            try
            {
                Eprom eprom = new Eprom();
                using (StreamReader reader = new StreamReader(filePath))
                {
                    string line;
                    int    page = 0, offset = 0;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Length == lineLenght)
                        {
                            string total = line.Substring(4).Replace(" ", string.Empty);
                            for (int i = 0; i < total.Length / 2; i++)
                            {
                                string sByte = total.Substring(i * 2, 2);
                                eprom[page][offset] = (byte)(int.Parse(sByte, NumberStyles.AllowHexSpecifier));
                                offset += 1;
                            }
                        }
                        else
                        {
                            offset = 0;
                            page  += 1;
                        }
                    }
                    return(eprom);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Пример #10
0
        /// <summary>
        /// Выполняет сохранение EPROM устройства в файл
        /// </summary>
        /// <param name="filePath">URI файла</param>
        /// <param name="eprom">EPROM устройства который необходимо сохранить</param>
        public void Save(string filePath, Eprom eprom)
        {
            XmlTextWriter writer = null;

            try
            {
                writer            = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteStartElement("eprom");

                foreach (Page page in eprom.Pages)
                {
                    writer.WriteStartElement("page");
                    foreach (Line line in page.Lines)
                    {
                        writer.WriteElementString("line", line.ToString());
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Записать выбранный eprom в устройство с заданными страницами
        /// </summary>
        /// <param name="eprom">Eprom который необходимо записать</param>
        /// <param name="Pages">Страницы которые необходимо записать</param>
        public void SetEprom(Eprom eprom, int[] Pages)
        {
            if (Pages != null)
            {
                foreach (int pageNumber in Pages)
                {
                    if (pageNumber >= 1 && pageNumber <= 7)
                    {
                        for (int line = 0; line < 16; line++)
                        {
                            string data = Write(Options.Device, pageNumber, line * 16, 16, eprom[pageNumber - 1].Lines[line].ToString());
                            switch (lastOperation)
                            {
                                case ResultOperation.Succes:

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

                                default:

                                    return;
                            }
                        }
                    }
                    else
                        throw new ArgumentException("Значение номера страницы не корректно");
                }
                return;
            }
            return;
        }
Пример #12
0
        /// <summary>
        /// Загружает EPROM устройства из файла
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <returns>Загруженный EPROM устройства или же null, если загрузить EPROM не удалось</returns>
        public Eprom Load(string filePath)
        {
            Eprom         eprom  = null;
            XmlTextReader reader = null;

            try
            {
                eprom  = new Eprom();
                reader = new XmlTextReader(filePath);

                int pageIndex = -1;
                int lineIndex = -1;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:

                        switch (reader.Name)
                        {
                        case "Page":

                            pageIndex += 1;
                            lineIndex  = -1;
                            break;

                        case "Value":

                            lineIndex += 1;
                            break;
                        }
                        break;

                    case XmlNodeType.Text:

                        string lineValue = reader.Value;
                        int    offset    = lineIndex * 16;

                        for (int i = 0; i < lineValue.Length / 2; i++)
                        {
                            string sByte = lineValue.Substring(i * 2, 2);
                            eprom[pageIndex][offset] = (byte)(int.Parse(sByte, NumberStyles.AllowHexSpecifier));
                            offset += 1;
                        }
                        break;

                    case XmlNodeType.EndElement:

                        break;
                    }
                }
                return(eprom);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Вычисляет CRC16 Eprom устройства
        /// </summary>
        /// <param name="eprom">Eprom устройства для которого необходимо вычислить контрольную сумму</param>
        /// <returns>Контрольная сумма</returns>
        public ushort CalculateCRC16(Eprom eprom)
        {
            ushort[] Crc16Table =
            {
                0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
                0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
                0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
                0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
                0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
                0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
                0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
                0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
                0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
                0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
                0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
                0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
                0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
                0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
                0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
                0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
                0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
                0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
                0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
                0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
                0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
                0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
                0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
                0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
                0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
                0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
                0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
                0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
                0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
                0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
                0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
                0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
            };

            ushort crc = 0xffff;
            for (int page = 0; page < 3; page++)
            {
                for (int offset = 0; offset < 256; offset++)
                {
                    crc = (ushort)((crc >> 8) ^ Crc16Table[(crc & 0xff) ^ eprom[page][offset]]);
                }
            }

            byte[] crc_bytes = BitConverter.GetBytes(crc);

            byte b = crc_bytes[1];
            crc_bytes[1] = crc_bytes[0];
            crc_bytes[1] = b;
            return BitConverter.ToUInt16(crc_bytes, 0);

            //return crc;
        }
Пример #14
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;
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Выполняет загрузку Eprom с файла
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <param name="format">Формат в котором сохранен Eprom</param>
        /// <returns></returns>
        public Eprom LoadEpromFromFile(string filePath, FileFormat format)
        {
            IEFLoader ldr = null;
            Eprom eprom = new Eprom();

            switch (format)
            {
                case FileFormat.EF1TXT:

                    ldr = platform.GetEFLoader(FileFormat.EF1TXT);
                    break;

                case FileFormat.EF2XMLOLD:

                    ldr = platform.GetEFLoader(FileFormat.EF2XMLOLD);
                    break;

                case FileFormat.EF2XML:

                    ldr = platform.GetEFLoader(FileFormat.EF2XML);
                    break;
            }
            eprom = ldr.Load(filePath);
            return eprom;
        }
Пример #16
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;
        }
Пример #17
0
        /// <summary>
        /// Возврощает EPROM устройства с заданными страницами
        /// </summary>
        /// <param name="Pages">массив страниц, которые необходимо загрузить</param>
        /// <returns>EPROM устройства</returns>
        public Eprom GetEprom(int[] Pages)
        {
            if (Pages != null)
            {
                Eprom eprom = new Eprom();
                foreach (int pageNumber in Pages)
                {
                    if (pageNumber >= 1 && pageNumber <= 7)
                    {
                        for (int line = 0; line < 16; line++)
                        {
                            string data = Read(Options.Device, pageNumber, line * 16, 16);
                            switch (lastOperation)
                            {
                                case ResultOperation.Succes:

                                    if (data.Length == 32)
                                    {
                                        for (int i = 0; i < 16; i++)
                                        {
                                            string ch = data.Substring(i * 2, 2);
                                            eprom[pageNumber - 1][line * 16 + i] = byte.Parse(ch, NumberStyles.AllowHexSpecifier);
                                        }
                                        if (eComplete != null) eComplete(this, new EventArgs());
                                    }
                                    else
                                        throw new Exception("Произошла ошибка при чтении данных!");

                                    break;

                                default:

                                    return null;
                            }
                        }
                    }
                    else
                        throw new ArgumentException("Значение номера страницы не корректно");
                }
                return eprom;
            }
            return null;
        }
Пример #18
0
        /// <summary>
        /// Записать выбранный eprom в устройство
        /// </summary>
        /// <param name="eprom">Eprom который необходимо записать</param>
        public void SetEprom(Eprom eprom)
        {
            for (int page = 1; page < 8; page++)
            {
                for (int line = 0; line < 16; line++)
                {
                    string data = Write(Options.Device, page, line * 16, 16, eprom[page-1].Lines[line].ToString());
                    switch (lastOperation)
                    {
                        case ResultOperation.Succes:

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

                        default:

                            return;
                    }
                }
            }
            return;
        }
Пример #19
0
        /// <summary>
        /// Возврощает EPROM устройства(считывание выполняется в синхронном режиме)
        /// </summary>
        /// <returns>EPROM устройства</returns>
        public Eprom GetEprom()
        {
            Eprom eprom = new Eprom();
            for (int page = 1; page < 8; page++)
            {
                for (int line = 0; line < 16; line++)
                {
                    string data = Read(Options.Device, page, line * 16, 16);
                    switch (lastOperation)
                    {
                        case ResultOperation.Succes:

                            if (data.Length == 32)
                            {
                                for (int i = 0; i < 16; i++)
                                {
                                    string ch = data.Substring(i * 2, 2);
                                    eprom[page - 1][line * 16 + i] = byte.Parse(ch, NumberStyles.AllowHexSpecifier);
                                }
                                if (eComplete != null) eComplete(this, new EventArgs());
                            }
                            else
                                throw new Exception("Произошла ошибка при чтении данных!");

                            break;

                        default:

                            return null;
                    }
                }
            }
            return null;
        }
Пример #20
0
        private void InitBlockCommonOptions(Block block, Eprom eprom)
        {
            for (int i = 0; i < 8; i++)
            {
                CmdOpros cmd = new CmdOpros();

                cmd.Address = eprom[0][0xf0 + i * 2];
                cmd.SizeBuffer = eprom[0][0xf0 + ((i * 2) + 1)];

                block.Cmds.Add(cmd);
            }
        }
Пример #21
0
        public void LoadFromFile(string filePath, HandleIO handle, FileFormat format)
        {
            IEFLoader ldr = platform.GetEFLoader(format);
            Eprom eprom = new Eprom();

            eprom = ldr.Load(filePath);
            if (eprom != null)
            {
                handle.Eprom = eprom;
                handle.VisionBlock = CreateBlock(eprom);

                if (handle.VisionBlock != null)
                {
                    handle.CRC16 = CalculateCRC16(eprom);
                    handle.ProgrammVersion = new Version(0, 0, 0, 0);
                }
            }
        }
Пример #22
0
        public void LoadDefault(HandleIO handle)
        {
            Eprom eprom = new Eprom(0x00);

            for (int by = 0; by < 256; by++)
            {
                eprom[0][by] = 0xff;
            }
            handle.Eprom = eprom;
            handle.VisionBlock = CreateBlock(eprom);

            handle.ProgrammVersion = new Version(0,0,0,0);
        }
Пример #23
0
        /// <summary>
        /// Инициализирует блок отображения
        /// </summary>
        /// <param name="eprom">Eprom устройства из которого необходимо выделить конфигурацию блока отображения</param>
        /// <returns>Блок отображения</returns>
        public Block CreateBlock(Eprom eprom)
        {
            Block block = new Block();
            for (int i = 0; i < 16; i++)
            {
                Indicator indicator = new Indicator();

                indicator.Jack = GetJackFromIndex(i + 1);

                indicator.Con = eprom[1][i * 16 + 0];
                indicator.Address = eprom[1][i * 16 + 1];

                indicator.Offset = eprom[1][i * 16 + 2];
                indicator.OffsetThr.TotalOffset = eprom[1][i * 16 + 3];

                indicator.OffsetPp.TotalOffset = eprom[1][i * 16 + 5];
                indicator.PointPosition = eprom[1][i * 16 + 6];

                switch (eprom[1][i * 16 + 7])
                {
                    case 1: indicator.IndicatorType = IndicatorType.Column32; break;
                    case 2: indicator.IndicatorType = IndicatorType.Column32Bipolar; break;
                    case 3: indicator.IndicatorType = IndicatorType.ThreeDigit; break;
                    case 4: indicator.IndicatorType = IndicatorType.FourDigit; break;
                    case 5: indicator.IndicatorType = IndicatorType.FiveDigit; break;
                    case 6: indicator.IndicatorType = IndicatorType.Clock; break;
                }

                byte[] factArray = new byte[4];
                byte[] CorrectoffsetArray = new byte[4];

                byte[] minArray = new byte[4];
                byte[] maxArray = new byte[4];

                for (int ind = 0; ind < 4; ind++)
                {
                    factArray[ind] = eprom[2][i * 16 + ind];
                    CorrectoffsetArray[ind] = eprom[2][(i * 16) + (ind + 4)];

                    minArray[ind] = eprom[2][(i * 16) + (ind + 8)];
                    minArray[ind] = eprom[2][(i * 16) + (ind + 12)];
                }

                float fact = BitConverter.ToSingle(factArray, 0);
                int correct = BitConverter.ToInt32(CorrectoffsetArray, 0);

                int min = BitConverter.ToInt32(minArray, 0);
                int max = BitConverter.ToInt32(maxArray, 0);

                indicator.Fact = fact;
                indicator.CorrectOffset = correct;

                indicator.Thr_MIN = min;
                indicator.Thr_MAX = max;

                block.Indicators.Add(indicator);
            }

            block.Address = eprom[0][0x18];
            block.Speed = eprom[0][0x10];
            block.TypeCRC = eprom[0][0x11];
            block.SpeedOpros = eprom[0][0xe0];

            InitBlockCommonOptions(block, eprom);
            return block;
        }
Пример #24
0
        /// <summary>
        /// Получить массив описателей калибровочных параметров
        /// </summary>
        /// <param name="eprom">EPROM устройства из которого необходимо извлеч данные</param>
        /// <returns>Массив описателй калибровочных параметров</returns>
        public CalibrationTableHandle[] CreateCalibrationTableHandles(Eprom eprom)
        {
            if (eprom != null)
            {
                CalibrationTableHandle[] handles = new CalibrationTableHandle[20];
                for (int index = 0; index < handles.Length; index++)
                {
                    int baseOffset = calibrationTableHandlesBaseOffset + (index * CalibrationTableHandle.SizeInTable);

                    byte name = eprom[calibrationTableHandlesPageNumber][baseOffset];
                    byte offset = eprom[calibrationTableHandlesPageNumber][baseOffset + 1];

                    handles[index] = new CalibrationTableHandle(name, offset);
                }
                return handles;
            }
            else
                throw new ArgumentNullException("eprom", "Не может принимать значение null");
        }
Пример #25
0
        /// <summary>
        /// Загружает EPROM устройства из файла
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <returns>Загруженный EPROM устройства или же null, если загрузить EPROM не удалось</returns>
        public Eprom Load(string filePath)
        {
            Eprom eprom = null;
            XmlTextReader reader = null;
            try
            {
                eprom = new Eprom();
                reader = new XmlTextReader(filePath);

                int pageIndex = -1;
                int lineIndex = -1;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:

                            switch (reader.Name)
                            {
                                case "page":

                                    pageIndex += 1;
                                    lineIndex = -1;
                                    break;

                                case "line":

                                    lineIndex += 1;
                                    break;
                            }
                            break;

                        case XmlNodeType.Text:

                            string lineValue = reader.Value;
                            int offset = lineIndex * 16;

                            for (int i = 0; i < lineValue.Length / 2; i++)
                            {
                                string sByte = lineValue.Substring(i * 2, 2);
                                eprom[pageIndex][offset] = (byte)(int.Parse(sByte, NumberStyles.AllowHexSpecifier));
                                offset += 1;
                            }
                            break;

                        case XmlNodeType.EndElement:

                            break;
                    }
                }
                return eprom;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }
Пример #26
0
        /// <summary>
        /// Выполняет загрузку Eprom устройства
        /// </summary>
        /// <returns>Загруженный Eprom устройства</returns>
        public Eprom LoadEprom()
        {
            int[] pages = { 4, 5, 7 };
            Eprom eprom = new Eprom();

            for (int page = 0; page < pages.Length; page++)
            {
                for (int line = 0; line < 16; line++)
                {
                    string data = platformIO.Read(platformIO.Options.Device, pages[page], line * 16, 16);
                    ResultOperation Result = platformIO.LastOperation;

                    switch (Result)
                    {
                        case ResultOperation.Succes:

                            if (data.Length == 32)
                            {
                                for (int i = 0; i < 16; i++)
                                {
                                    string ch = data.Substring(i * 2, 2);
                                    eprom[pages[page] - 1][line * 16 + i] = byte.Parse(ch, NumberStyles.AllowHexSpecifier);
                                }
                            }
                            else
                                throw new Exception("Произошла ошибка при передаче данных приложению!");

                            lock (sync) if (eCompleteReadEpromLine != null) eCompleteReadEpromLine(this, new EventArgs());
                            break;

                        case ResultOperation.Timeout:

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

                        case ResultOperation.MorePopit:

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

                        default:

                            return null;
                    }

                    Thread.Sleep(platformIO.Options.TimeoutBetweenAttemptsToReadWrite);
                    lock (sync)
                    {
                        if (toBreak)
                        {
                            toBreak = false;
                            return null;
                        }
                    }
                }
            }
            return eprom;
        }
Пример #27
0
        private void buttonLoadFromFile_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                IEFLoader ldr = null;
                switch (openFileDialog.FilterIndex)
                {
                    case 1:

                        ldr = app.GetEFLoader(FileFormat.EF1TXT);
                        break;

                    case 2:

                        ldr = app.GetEFLoader(FileFormat.EF2XMLOLD);
                        break;

                    case 3:

                        ldr = app.GetEFLoader(FileFormat.EF2XML);
                        break;
                }

                try
                {
                    eprom = ldr.Load(openFileDialog.FileName);
                    InitTabes(eprom);
                }
                catch (Exception)
                {
                    MessageBox.Show(this, "Не удалось загрузить файл. Возможно файл не соответствует формату или поврежден",
                        "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

            }
        }
Пример #28
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));
            }
        }
Пример #29
0
        public Eprom GetTables()
        {
            Eprom eprom = new Eprom();

            for (int i = 0; i < 7; i++)
            {
                DataGridView p = GetPage(i);
                if (p != null)
                {
                    for (int row = 0; row < 16; row++)
                    {
                        for (int col = 0; col < 16; col++)
                        {
                            if (p[col, row].Value != null && p[col, row].Value.ToString() != string.Empty)
                            {
                                eprom[i][col + row * 16] = (byte)int.Parse(p[col, row].Value.ToString(), System.Globalization.NumberStyles.AllowHexSpecifier);
                            }
                        }
                    }
                }
            }
            return eprom;
        }
Пример #30
0
        /// <summary>
        /// Сохраняет тблицу калибровки в файл
        /// </summary>
        /// <param name="filePath">Путь к файлу</param>
        /// <param name="table">Таблица калибровки, которую необходимо сохранить</param>
        /// <param name="eprom">Eprom в который необходимо сохранить данную таблицу калибровки</param>
        public void SaveEpromToFile(string filePath, CalibrationTable table, Eprom eprom)
        {
            IEFSaver svr = null;
            svr = platform.GetEFSaver(FileFormat.EF2XML);

            SaveCalibrationTableToFile(table, eprom);
            svr.Save(filePath, eprom);
        }
Пример #31
0
 // ----- загрузка EPROM с диска ----
 private void InitTabes(Eprom eprom)
 {
     int pageIndex = 0;
     foreach (Page page in eprom.Pages)
     {
         DataGridView p = GetPage(pageIndex++);
         if (p != null)
         {
             for (int row = 0; row < 16; row++)
             {
                 for (int col = 0; col < 16; col++)
                 {
                     int offset = col + row * 16;
                     p[col, row].Value = string.Format("{0:X2}", page[offset]);
                 }
             }
         }
     }
 }