/// <summary> /// Get description for TextChatStatus enum /// </summary> /// <param name="chatStatus"></param> /// <returns></returns> public static string GetMotorDescription(this MotorType motorType) { // get the field var field = motorType.GetType().GetField(motorType.ToString()); var result = GetDescriptionAttributeValue(field); return(string.IsNullOrWhiteSpace(result) ? motorType.ToString() : result); }
bool SetSerialPort(SerialPort serialPort, MotorType motorType) { bool result = false; try { //make sure in SCL mode serialPort.WriteLine("PM"); if (serialPort.ReadLine().Substring(3) != "2") { serialPort.WriteLine("PM2"); //CheckAck(); App.LogEntry.AddEntry("ST5 : Please power cycle the Motor Drive and try connecting again", true); return(false); } serialPort.WriteLine("PR5"); if (!CheckAck(serialPort)) { return(false); } serialPort.WriteLine("SKD"); //Stop and Kill if (!CheckAck(serialPort)) { return(false); } serialPort.WriteLine("MV"); string mvRead = serialPort.ReadLine(); try { SERVO_MOTOR_MODEL _model = (SERVO_MOTOR_MODEL)Convert.ToInt32(mvRead.Substring(4, 3));; } catch (Exception /*ex*/) { App.LogEntry.AddEntry("Unsupported Motor Drive", true); return(false); } App.LogEntry.AddEntry("ST5 Model/Revision: " + mvRead); serialPort.WriteLine("OP"); App.LogEntry.AddEntry("ST5 Option Board: " + serialPort.ReadLine()); serialPort.WriteLine("SC"); string response = serialPort.ReadLine().Substring(3); App.LogEntry.AddEntry("ST5 Status: 0x" + response); bool _motorEnabled = (Convert.ToInt32(response.Substring(3, 1)) % 2) == 1; bool _driveBusy = (Convert.ToInt32(response.Substring(2, 1)) % 2) != 0; serialPort.WriteLine("AC100"); if (!CheckAck(serialPort)) { return(false); } serialPort.WriteLine("DC100"); if (!CheckAck(serialPort)) { return(false); } result = true; } catch (Exception ex) { Console.WriteLine("Failed in SetSerialPort: " + motorType.ToString() + " exception: " + ex.Message); result = false; } return(result); }