using System; using System.Collections.Generic; using System.Linq; using System.Text; using ElmoMotionControlComponents.Drive.EASComponents; using System.Threading; using System.Net; using ElmoMotionControlComponents.Drive.EASComponents.UploadsAndDownloads; namespace DriveDotNetDownloadTxtParameters { 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 Parameters file path:"); string filePath = Console.ReadLine(); StartDownloadParameters(filePath); mre.WaitOne(); Console.ReadLine(); } static void StartDownloadParameters(string filePath) { IDriveErrorObject err; Console.WriteLine("Would you like to filter parameters according to drive personality? 1. Yes, 2. No"); bool filterParams = (int.Parse(Console.ReadLine()) == 1); DownloadTxtSettings settings = new DownloadTxtSettings(); settings.StopOnError = false; if (filterParams) { settings.FilterParametersByPersonality = true; string path = null; Console.WriteLine("Type Personality file path:"); path = Console.ReadLine(); IDriveErrorObject errorObject; if (communication.CreatePersonalityModel(path, out errorObject)) Console.WriteLine("Personality Model was created!"); else { if (errorObject == null) Console.WriteLine("Cannot create Personality Model"); else Console.WriteLine("Cannot create Personality Model. " + errorObject.ToString()); } } else settings.FilterParametersByPersonality = false; IUploadDownloadModel model = communication.DownloadTxtParameters(filePath, 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.CANCELED: { Console.WriteLine("CANCELED"); mre.Set(); break; } case OPERATION_STATUS.FAILED: { Console.WriteLine("FAILED"); Console.WriteLine(model.Description); break; } case OPERATION_STATUS.PROGRESSED: { Console.Write("."); break; } } } } }