public override void HomeAll() { // start the device polling device.StartPolling(250); // call GetMotorConfiguration on the device to initialize the DeviceUnitConverter object required for real world unit parameters MotorConfiguration motorSettings = device.GetMotorConfiguration(this.Config.Name); DCMotorSettings currentDeviceSettings = device.MotorDeviceSettings as DCMotorSettings; // display info about device DeviceInfo deviceInfo = device.GetDeviceInfo(); try { device.Home(60000); } catch (Exception ex) { this.LastError = string.Format("Failed to home device {0}\r\n{1}", this, ex.Message); } finally { device.StopPolling(); } }
static void Main(string[] args) { // get parameters from command line int argc = args.Count(); if (argc < 1) { Console.WriteLine("Usage = TDC_Console_net_managed [serial_no] [position: optional (0 - 1715200)] [velocity: optional (0 - 3838091)]"); Console.ReadKey(); return; } // get position int position = 250000; if (argc > 1) { position = int.Parse(args[1]); } // get velocity int velocity = 0; if (argc > 2) { velocity = int.Parse(args[2]); } // get serial no string serialNo = args[0]; try { // build device list InstrumentManager.BuildDeviceList(); } catch (Exception ex) { Console.WriteLine("Exception raised by BuildDeviceList {0}", ex); Console.ReadKey(); return; } // get available TCube DC Servos and check our serial number is correct string[] serialNumbers = InstrumentManager.GetDeviceListByType(83); if (!serialNumbers.Contains(serialNo)) { Console.WriteLine("{0} is not a valid serial number", serialNo); Console.ReadKey(); return; } // display info about device InstrumentManager.DeviceInfo di = InstrumentManager.GetDeviceInfo(serialNo); Console.WriteLine("Device {0} = {1}", di.SerialNumber(), di.Description()); // open device Console.WriteLine("Opening device {0}", serialNo); TCubeDCServo device = new TCubeDCServo(serialNo); short err = device.Open(); if (err != 0) { Console.WriteLine("Failed to open device {0}: error code = {1}", serialNo, err); Console.ReadKey(); return; } // register a callback function to receive device messages device.RegisterMessageCallback(new TCubeDCServo.CallbackDelegate(MessageWaitingCallback)); device.StartPolling(250); Thread.Sleep(500); device.EnableLastMsgTimer(true, 2000); // home the device Console.WriteLine("Homing device"); device.ClearMessageQueue(); device.Home(); if (!WaitForMessage(device, MotorMessageType, MotorHomed)) { return; } Console.WriteLine("Device Homed"); // if position is set if (position != 0) { // update velocity if required if (velocity != 0) { TCubeDCServo.VelocityParameters velPars = device.GetVelParams(); velPars.maxVelocity = velocity; device.SetVelParams(velPars); } // move to defined position Console.WriteLine("Moving Device to {0}", position); device.ClearMessageQueue(); device.MoveToPosition(position); if (!WaitForMessage(device, MotorMessageType, MotorMoved)) { return; } int newPos = GetPosition(device); Console.WriteLine("Device Moved to {0}({1})", newPos, position); } Console.ReadKey(); return; }