using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using ElmoMotionControlComponents.Drive.EASComponents; using System.Net; using System.IO; using ElmoMotionControlComponents.Drive.EASComponents.Personality; using ElmoMotionControlComponents.Drive.EASComponents.UploadsAndDownloads; namespace DriveDotNetUploadPersonalityAndUploadTxtParameters { class Program { static IDriveCommunication communication; static ManualResetEvent mre = new ManualResetEvent(false); static void Main(string[] args) { Console.WriteLine("Which communication type do you need? 1. UDP, 2. USB, 3. RS232"); int result = int.Parse(Console.ReadLine()); IDriveCommunicationInfo commInfo = null; switch (result) { case 1: { Console.WriteLine("Please enter the drive IP address"); string ipAddress = Console.ReadLine(); Console.WriteLine("Please enter the host IP address"); string hostAddress = Console.ReadLine(); commInfo = DriveCommunicationFactory.CreateUDPCommunicationInfo(IPAddress.Parse(ipAddress), IPAddress.Parse(hostAddress)); Console.WriteLine("Established UDP communication for IP address " + ipAddress + ", host IP address: " + hostAddress); break; } case 2: { Console.WriteLine("Please enter COM port name"); string comPort = Console.ReadLine(); commInfo = DriveCommunicationFactory.CreateUSBCommunicationInfo(comPort); Console.WriteLine("Established USB communication for COM port " + comPort); break; } case 3: { Console.WriteLine("Please enter COM port name"); string comPort = Console.ReadLine(); Console.WriteLine("Please enter baud rate"); uint baudRate = uint.Parse(Console.ReadLine()); commInfo = DriveCommunicationFactory.CreateRS232CommunicationInfo(comPort, baudRate); Console.WriteLine("Established RS232 communication for COM port " + comPort + " and baud rate " + baudRate); break; } } IDriveErrorObject err; communication = DriveCommunicationFactory.CreateCommunication(commInfo); if (!communication.Connect(out err)) { Console.WriteLine(err); return; } Console.WriteLine("Please enter Personality file path:"); string personalityPath = Console.ReadLine(); try { communication.PersonalityModel = new DrivePersonalityModel(personalityPath); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); return; } StartUploadParameters(); mre.WaitOne(); Console.ReadLine(); } static void StartUploadParameters() { IDriveErrorObject err; UploadTxtSettings settings = new UploadTxtSettings(); settings.CreateFoEXml = false; settings.StopOnError = false; settings.LoadToRAM = false; settings.Filters.Add(new ParametersFilter("KG", ArrayFilterType.PartialUpload, 10, 50)); settings.Filters.Add(new ParametersFilter("ET", ArrayFilterType.DoNotUpload)); IUploadDownloadModel model = communication.UploadTxtParameters(Path.Combine(Environment.CurrentDirectory, "parametersTxt.gprm"), settings, out err); if (model == null) { Console.WriteLine(err); return; } model.OnStart += EventHandle; model.OnProgress += EventHandle; model.OnFinish += EventHandle; model.OnFailed += EventHandle; model.OnCancel += EventHandle; if (!model.Start(out err)) Console.WriteLine(err); } static void EventHandle(object sender, EventArgs e) { IUploadDownloadModel model = sender as IUploadDownloadModel; switch (model.OperationStatus) { case OPERATION_STATUS.STARTED: { Console.WriteLine("Started"); break; } case OPERATION_STATUS.FINISHED: { Console.WriteLine("FINISHED"); mre.Set(); break; } case OPERATION_STATUS.FAILED: { Console.WriteLine("FAILED"); Console.WriteLine(model.Description); break; } case OPERATION_STATUS.CANCELED: { Console.WriteLine("CANCELED"); break; } case OPERATION_STATUS.PROGRESSED: { Console.Write("."); break; } } } } }