/// <summary> /// Connect method. /// </summary> /// <param name="ip"> Ip for connection </param> /// <param name="port"> Port for connection </param> public void connect(string ip, int port) { this.telnetClient.connect(ip, port); if (telnetClient.isConnected() == true) { isConnected = true; } }
/* * The method set the all values by the command values it gets and by using the telnet * client, and if there is any kind of prolbem in the command sending, the method return 1. * for evrey single value that we need to set, we send to the server "set" command and * then "get" command, reed the feedback from the server and check if the values are equals */ public int SetAllValues(Command command) { try { if (telnetClientHandler.isConnected()) { string tmp = ""; telnetClientHandler.write("set /controls/flight/aileron " + String.Format("{0:0.##}", command.Aileron) + "\r\n"); telnetClientHandler.write("get /controls/flight/aileron" + "\r\n"); tmp = telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Aileron != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/engines/current-engine/throttle " + String.Format("{0:0.##}", command.Throttle) + "\r\n"); telnetClientHandler.write("get /controls/engines/current-engine/throttle" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Throttle != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/flight/elevator " + String.Format("{0:0.##}", command.Elevator) + "\r\n"); telnetClientHandler.write("get /controls/flight/elevator" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Elevator != double.Parse(tmp)) { return(1); //notOk } } telnetClientHandler.write("set /controls/flight/rudder " + String.Format("{0:0.##}", command.Rudder) + "\r\n"); telnetClientHandler.write("get /controls/flight/rudder" + "\r\n"); tmp = this.telnetClientHandler.read(); if (tryToConvert(tmp) == true) { if (command.Rudder != double.Parse(tmp)) { return(1); //notOk } } } return(0); //Ok } catch { throw new Exception("Could not read / write"); //notOk } }
public bool isClientConnected() { return(client != null && client.isConnected()); }