protected int parseConfFileHeader(string fileName, LTRM_ComercialRef Refrence)
        {
            int retCode = -1;

            if (File.Exists(fileName) == false)
            {
                //MessageBox.Show("File Doesn't exist");
                return(retCode);
            }
            StreamReader   confFile   = new StreamReader(fileName);
            confFileHeader fileHeader = new confFileHeader();

            //read header line not data from this line
            string strLine = confFile.ReadLine();
            int    pos     = strLine.IndexOf(";");

            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            string strTmpC = strLine.Substring(0, pos);
            string strTmpD = strLine.Substring(pos + 1);

            string cRatings = strTmpD.Substring(4, 2);

            if (cRatings == "08")
            {
                if (Refrence != LTRM_ComercialRef.LTMR_08)
                {
                    confFile.Close();
                    return(retCode);
                }
            }
            else if (cRatings == "27")
            {
                if (Refrence != LTRM_ComercialRef.LTMR_27)
                {
                    confFile.Close();
                    return(retCode);
                }
            }
            else if (cRatings == "10")//100
            {
                if (Refrence != LTRM_ComercialRef.LTMR_100)
                {
                    confFile.Close();
                    return(retCode);
                }
            }
            else
            {
                confFile.Close();
                return(retCode);
            }
            fileHeader.comRef = strTmpD;

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC = strLine.Substring(0, pos);
            strTmpD = strLine.Substring(pos + 1);
            fileHeader.serialNumber = strTmpD;

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC            = strLine.Substring(0, pos);
            strTmpD            = strLine.Substring(pos + 1);
            fileHeader.kuFwVer = strTmpD;

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC            = strLine.Substring(0, pos);
            strTmpD            = strLine.Substring(pos + 1);
            fileHeader.kcFwVer = strTmpD;

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC = strLine.Substring(0, pos);
            strTmpD = strLine.Substring(pos + 1);
            fileHeader.confRegLen = Convert.ToInt32(strTmpD);

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC = strLine.Substring(0, pos);
            strTmpD = strLine.Substring(pos + 1);
            fileHeader.customStartIndex = Convert.ToInt32(strTmpD);

            strLine = confFile.ReadLine();
            pos     = strLine.IndexOf(";");
            if (pos <= 0)
            {
                Console.WriteLine("Wrong File Formate");
                confFile.Close();
                return(retCode);
            }
            strTmpC = strLine.Substring(0, pos);
            strTmpD = strLine.Substring(pos + 1);
            fileHeader.customRegLen = Convert.ToInt32(strTmpD);

            ltmrConfigFile[(int)Refrence].fileHeader = fileHeader;
            retCode = 0;
            confFile.Close();

            return(retCode);
        }
Exemple #2
0
        /* Read LTMR configuration including host configuration register and
         * custom logic file over Modbus serial line(HMI Port) */
        private void readLTMRConfiguration(deviceEntry dEntry)
        {
            ushort modbusStartAddress;
            ushort numberofRegister;

            byte[]          data     = new byte[512];
            UInt16[]        regVal   = new UInt16[120];
            int             index    = 0;
            confFileFormate confData = new confFileFormate();

            //Register Address 540-599, 600-699,800-898,1250-1269,3000-3087,3088-3119)
            confFileHeader bHeader = new confFileHeader();

            bHeader.comRef  = dEntry.comRef;
            bHeader.kcFwVer = dEntry.kcVer;
            bHeader.kuFwVer = dEntry.kuVer;

            modbusSlaveInfo sInfo = new modbusSlaveInfo();

            sInfo.slaveIPAdd = dEntry.deviceIP;
            sInfo.slaveUid   = 1;
            sInfo.tcpPortId  = 502;
            mbAccess.setSlaveInfo(sInfo);

            mbAccess.readModbusRegister(70, 5, regVal);

            bHeader.serialNumber = regVal[0].ToString() + regVal[1].ToString() + regVal[2].ToString() + regVal[3].ToString() + regVal[4].ToString();
            // confData.fileHeader = bHeader;
            confData.fileData = new confData[20480];

            modbusStartAddress = 540;
            numberofRegister   = 60;

            if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
            {
                for (int i = 0; i < numberofRegister; i++)
                {
                    confData.fileData[i].regAdd = (ushort)(modbusStartAddress + i);
                    confData.fileData[i].regVal = (ushort)(regVal[i]);
                }

                index = index + numberofRegister;
                modbusStartAddress = 600;
                numberofRegister   = 100;
                //if (comm.Read(ViewModelConstants.NodeNumber, modbusStartAddress, numberofRegister, ref data) == true)
                if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
                {
                    //confFile.Write("  Main Setting     " + " \n");
                    for (int i = 0; i < numberofRegister; i++)
                    {
                        confData.fileData[index + i].regAdd = (ushort)(modbusStartAddress + i);
                        confData.fileData[index + i].regVal = (ushort)(regVal[i]);
                    }

                    index = index + numberofRegister;
                    modbusStartAddress = 800;
                    numberofRegister   = 99;
                    //if (comm.Read(ViewModelConstants.NodeNumber, modbusStartAddress, numberofRegister, ref data) == true)
                    if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
                    {
                        for (int i = 0; i < numberofRegister; i++)
                        {
                            confData.fileData[index + i].regAdd = (ushort)(modbusStartAddress + i);
                            confData.fileData[index + i].regVal = (ushort)(regVal[i]);
                        }
                        index = index + numberofRegister;
                        modbusStartAddress = 1250;
                        numberofRegister   = 20;
                        //if (comm.Read(ViewModelConstants.NodeNumber, modbusStartAddress, numberofRegister, ref data) == true)
                        if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
                        {
                            for (int i = 0; i < numberofRegister; i++)
                            {
                                confData.fileData[index + i].regAdd = (ushort)(modbusStartAddress + i);
                                confData.fileData[index + i].regVal = (ushort)(regVal[i]);
                            }
                            index = index + numberofRegister;
                            modbusStartAddress = 3000;
                            numberofRegister   = 88;
                            // if (comm.Read(ViewModelConstants.NodeNumber, modbusStartAddress, numberofRegister, ref data) == true)
                            if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
                            {
                                for (int i = 0; i < numberofRegister; i++)
                                {
                                    confData.fileData[index + i].regAdd = (ushort)(modbusStartAddress + i);
                                    confData.fileData[index + i].regVal = (ushort)(regVal[i]);
                                }
                                index = index + numberofRegister;
                                modbusStartAddress = 3088;
                                numberofRegister   = 32;
                                // if (comm.Read(ViewModelConstants.NodeNumber, modbusStartAddress, numberofRegister, ref data) == true)
                                if (mbAccess.readModbusRegister(modbusStartAddress, numberofRegister, regVal) == 0)
                                {
                                    for (int i = 0; i < numberofRegister; i++)
                                    {
                                        confData.fileData[index + i].regAdd = (ushort)(modbusStartAddress + i);
                                        confData.fileData[index + i].regVal = (ushort)(regVal[i]);
                                    }
                                    index = index + numberofRegister;
                                }
                            }
                        }
                    }
                }
            }
            bHeader.confRegLen       = index;
            bHeader.customStartIndex = index;
            confData.fileHeader      = bHeader;

            /* check Operating mode before starting uploading custom logic file*/
            //((modbusStartAddress, numberofRegister, regVal) == 0)
            if (mbAccess.readModbusRegister(540, 1, regVal) == 0)
            {
                /* Custom logic file will present if Reg(540)>255 else no custom logic file hance ignore reading it*/
                if (regVal[0] > 255)
                {
                    bHeader.customRegLen = readLTMRLogicFile(ref confData);
                }
            }

            confData.fileHeader = bHeader;
            string confFileName = dEntry.deviceIP.Replace('.', '_');

            confFileName = confFileName + "_conf.csv";
            writeConfFile(confData, confFileName);
            //MessageBox.Show("backup Completed");
        }