예제 #1
0
        /// <summary>
        /// Download One Paramter to the Drive
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="menuNumber"></param>
        /// <param name="parameterNumber"></param>
        /// <param name="parameterValue"></param>
        /// <param name="decimalPoints"></param>
        public void downloadParameter(String ipAddress, int menuNumber, int parameterNumber, int parameterValue, int decimalPoints)
        {
            BlockingCommsUser commsUser = new BlockingCommsUser();
            // Set the IP address using value from command Line
            CommsAddress address = new CommsAddress(IPAddress.Parse(ipAddress), 0);


            //ParameterValue Number = new ParameterValue(50);
            // Set the menu and parameter to write
            ECMPWriteRequest writeReq = new ECMPWriteRequest();

            ParameterIDAndValueAndDPs param = new ParameterIDAndValueAndDPs(new ParameterID(menuNumber, parameterNumber), new ParameterValue(parameterValue), decimalPoints);

            writeReq.Parameters.Add(param);

            // Set communication protocol
            T_STATUS State = commsUser.Go(Protocol.EthernetProtocol());

            ECMPWriteResponse response; // Define variable to recieve response

            //Execute the Write
            T_RESPONSE_STATUS Status = commsUser.Write(address, writeReq, out response);

            logger.Info("Download Status : " + Status);
            logger.Info("Response : " + response.OverallStatus.ToString());
        }
예제 #2
0
        public void saveParameterFile(IPAddress ipAddress)
        {
            //ParameterFile parameterFile = new ParameterFile();
            //parameterFile.SaveAs(@"C:\Temp\Demo2.parfile");

            BlockingCommsUser commsUser = new BlockingCommsUser();

            CommsAddress address = new CommsAddress(ipAddress, 4); //Changed to opt 4 to test option slot reading writing

            // Set communication protocol
            T_STATUS State = commsUser.Go(Protocol.EthernetProtocol());

            FileReadDiskMessageRequest readDiskReq = new FileReadDiskMessageRequest("/par/all", "C:\\test_par.bin");
            //FileReadDiskMessageRequest readDiskReq = new FileReadDiskMessageRequest("/par/macro", "C:\\test_macro.bin");
            //FileReadDiskMessageRequest readDiskReq = new FileReadDiskMessageRequest("/par/diff", "C:\\test_diff.bin");

            FileReadDiskMessageResponse response;
            T_RESPONSE_STATUS           Status = commsUser.FileReadDisk(address, readDiskReq, out response);

            logger.Info("Upload Status : " + Status);

            RawParameterFile rawParams = new RawParameterFile("C:\\test_par.bin");

            //RawParameterFile rawParams = new RawParameterFile("C:\\test_macro.bin");
            //RawParameterFile rawParams = new RawParameterFile("C:\\test_diff.bin");

            //ParameterSerialisationOptions serOpts = new ParameterSerialisationOptions();

            rawParams.ConvertToParameterFile("C:\\Demo4.parfile");
        }
            public override void Seed()
            {
                System.Diagnostics.Debug.Print("Seeding db");

                T_STATUS Active = new T_STATUS {
                    STATUS_ID = EStatus.Active, CREATEDON = DateTime.Now
                };
                T_STATUS Inactive = new T_STATUS {
                    STATUS_ID = EStatus.Inactive, CREATEDON = DateTime.Now
                };
                T_STATUS Deleted = new T_STATUS {
                    STATUS_ID = EStatus.Deleted, CREATEDON = DateTime.Now
                };

                STATUS.Add(Active);
                STATUS.Add(Inactive);
                STATUS.Add(Deleted);

                T_TABLE_A FirstA = new T_TABLE_A {
                    CREATEDON = DateTime.Now
                };
                T_TABLE_A SecondA = new T_TABLE_A {
                    CREATEDON = DateTime.Now
                };

                TABLE_A.Add(FirstA);
                TABLE_A.Add(SecondA);

                T_TABLE_C FirstC = new T_TABLE_C {
                    STATUS_ID = EStatus.Inactive, CREATEDON = DateTime.Now
                };
                T_TABLE_C SecondC = new T_TABLE_C {
                    STATUS_ID = EStatus.Active, CREATEDON = DateTime.Now
                };

                TABLE_C.Add(FirstC);
                TABLE_C.Add(SecondC);

                T_TABLE_B FirstB = new T_TABLE_B {
                    TABLE_A = FirstA, TABLE_C = FirstC, CREATEDON = DateTime.Now
                };
                T_TABLE_B SecondB = new T_TABLE_B {
                    TABLE_A = SecondA, TABLE_C = SecondC, CREATEDON = DateTime.Now
                };

                TABLE_B.Add(FirstB);
                TABLE_B.Add(SecondB);

                SaveChanges();
            }
예제 #4
0
        /// <summary>
        /// Upload One Parameter from the drive
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="menuNumber"></param>
        /// <param name="parameterNumber"></param>
        public void uploadParameter(String ipAddress, int menuNumber, int parameterNumber)
        {
            BlockingCommsUser commsUser = new BlockingCommsUser();

            // Set the IP address using value from command Line
            CommsAddress address = new CommsAddress(IPAddress.Parse(ipAddress), 0);

            ECMPReadRequest readReq = new ECMPReadRequest(18, 11);

            // Set communication protocol
            T_STATUS State = commsUser.Go(Protocol.EthernetProtocol());

            ECMPReadResponse  response;
            T_RESPONSE_STATUS Status = commsUser.Read(address, readReq, out response);

            logger.Info("Upload Status : " + Status);
            logger.Info("Response : " + response.ParameterValues.ToString());
        }
예제 #5
0
        public void downloadFile(IPAddress ipAddress, string filePath, DownloadType fileType)
        {
            try
            {
                BlockingCommsUser commsUser = new BlockingCommsUser();
                CommsAddress      address   = new CommsAddress(ipAddress, 0);

                // Set communication protocol
                T_STATUS State = commsUser.Go(Protocol.EthernetProtocol());

                if (State != T_STATUS.OK)
                {
                    logger.Error("Failed To Connect : Status Code : " + State.ToString());
                    return;
                }

                logger.Debug("Connected to Drive");

                string destination = null;
                switch (fileType)
                {
                case DownloadType.PARAMETERS:
                    //destination = "/par/all"; // can only read
                    destination = "par/macro";
                    break;

                case DownloadType.MACRO:
                    destination = "/par/macro";
                    break;

                case DownloadType.ONBOARD:
                    destination = "/sys/prog/user";
                    break;
                }

                string rawFilePath       = filePath;
                string parameterFilePath = filePath;

                if (fileType == DownloadType.PARAMETERS)
                {
                    //Change the parameter file into a macro file
                    XmlDocument doc = new XmlDocument();
                    doc.Load(filePath);
                    XmlNodeList aNodes = doc.SelectNodes("/ParameterFile");
                    if (aNodes.Count != 1)
                    {
                        //There should only be one node by this name
                        throw new Exception("ParameterFile Node missing, or incorrectly formated Paarmeter File");
                    }
                    if (aNodes[0].Attributes == null)
                    {
                        throw new Exception("ParameterFile Node incorrectly formated, missing Attributes");
                    }

                    if (aNodes[0].Attributes["type"] == null)
                    {
                        throw new Exception("ParameterFile Node incorrectly formated, missing type Attribute");
                    }
                    aNodes[0].Attributes["type"].Value = "Macro"; //Change the file to a macro file

                    parameterFilePath = Path.ChangeExtension(filePath, "tmp_par");

                    doc.Save(parameterFilePath);
                    if (!File.Exists(parameterFilePath))
                    {
                        throw new Exception("Error Processing Parameter File Save Macro");
                    }
                }

                if (fileType == DownloadType.PARAMETERS || fileType == DownloadType.MACRO)
                {
                    //Load the parameter file
                    ParameterFile parameterFile = new ParameterFile();
                    parameterFile.Load(parameterFilePath);

                    //convert the parameter file to a raw file for download
                    RawParameterFile rawParams = RawParameterFile.CreateFromParameterFile(parameterFile);

                    rawFilePath = parameterFilePath.Replace(Path.GetExtension(parameterFilePath), ".bin"); //Replace the original filename with the bin file
                    rawParams.Write(rawFilePath, true);
                    if (!File.Exists(rawFilePath))
                    {
                        logger.Error("Error writing intermediate raw file " + rawFilePath);
                        return;
                    }
                }

                FileWriteDiskMessageRequest writeDiskReq = new FileWriteDiskMessageRequest(rawFilePath, destination, FileWriteOptions.None);

                FileWriteDiskMessageResponse response;
                logger.Debug("Downloading File");
                T_RESPONSE_STATUS Status = commsUser.FileWriteDisk(address, writeDiskReq, out response);
                logger.Info("Download Complete");
                //logger.Info("Download Complete - Time Taken : " + response.TimeTaken + " Status : " + response.Status.ToString());

                if (Status != T_RESPONSE_STATUS.OK)
                {
                    logger.Error("Download Failed - Status: " + Status.ToString());
                }

                //Delete the intermediate raw file if created
                if (fileType == DownloadType.PARAMETERS || fileType == DownloadType.MACRO)
                {
                    File.Delete(rawFilePath);
                }
            } catch (Exception ex)
            {
                logger.Error("Execption : " + ex.ToString());
                return;
            }
        }