using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.IO; using ElmoMotionControlComponents.Drive.EASComponents; using System.Net; using System.ComponentModel; using ElmoMotionControlComponents.Drive.EASComponents.StatusRegister; namespace DriveDotNetGetAndParseDeviceStatusRegister { class Program { 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()); IDriveCommunication communication; IDriveCommunicationInfo commInfo = null; IDriveErrorObject errorObject; 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; } } try { IDriveErrorObject err; communication = DriveCommunicationFactory.CreateCommunication(commInfo); if (!communication.Connect(out err)) { Console.WriteLine(err); return; } string res; if (!communication.SendCommandAnalyzeError("sr", out res, out errorObject, 2000)) { Console.WriteLine("Failed to get Status Register from the drive. error = "+errorObject); return; } IStatusRegister sr = StatusRegisterFactory.CreateStatusRegister(communication.ProductInfo); if (!sr.AnalyzeRegister(res)) { Console.WriteLine("Failed to Analyze Status Register"); return; } foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(sr)) {//print all properties string name = descriptor.Name; object value = descriptor.GetValue(sr); Console.WriteLine("{0} = {1}", name, value); } } finally { Console.ReadKey(); } } } }