/// <summary> /// Send commnad /// </summary> /// <returns></returns> public bool SendCommand(string message, out string result) { bool res = false; //if wasn't connected earlier, connect again if (ProgramSocket == null) { EstablishConnection(); } Logging.AddLog("PHD2 sending comand: " + message, LogLevel.Debug); //Send command string output = SocketServerClass.SendToServer(ProgramSocket, message, out Error); if (Error >= 0) { Thread.Sleep(200); //Read response string output2 = SocketServerClass.ReceiveFromServer(ProgramSocket, out Error); Logging.AddLog("PHD2_SendCommand: server response = " + output2, LogLevel.Debug, Highlight.Error); //Parse response Handle_PHD_Response(output2, out result); //Check if (!LastCommand_Result) { Error = -1; ErrorSt = LastCommand_Message; Logging.AddLog("PHD2 command failed: " + LastCommand_Message + "]", LogLevel.Debug, Highlight.Error); } else { Error = 0; ErrorSt = ""; Logging.AddLog("PHD2 command succesfull", LogLevel.Debug); res = true; } } else { result = ""; Logging.AddLog("PHD2 send command error: " + ErrorSt, LogLevel.Debug, Highlight.Error); } return(res); }
/// <summary> /// Send commnad through Socket Interface /// </summary> /// <returns></returns> public bool SendCommand(string CommandString, out string result) { bool res = false; //if wasn't connected earlier, connect again if (ProgramSocket == null) { if (!EstablishConnection()) { Logging.AddLog("Failed to connect to " + LogPrefix, LogLevel.Activity, Highlight.Error); result = ""; return(false); } } Logging.AddLog(LogPrefix + " sending comand: " + CommandString, LogLevel.Debug); ////////////////// //Send command ////////////////// string output = SocketServerClass.SendToServer(ProgramSocket, CommandString, out Error); //Release socket if (ProgramSocket != null && Error != 0) { ProgramSocket.Shutdown(SocketShutdown.Both); ProgramSocket.Close(); ProgramSocket = null; } if (Error >= 0) { //Wait a bit Thread.Sleep(300); ////////////////// //Read response ////////////////// string output2 = SocketServerClass.ReceiveFromServer(ProgramSocket, out Error); //Check if (output2 == null || output2 == String.Empty) { Error = -1; ErrorSt = LastCommand_Message; result = ""; Logging.AddLog(LogPrefix + " command failed: " + LastCommand_Message + "]", LogLevel.Debug, Highlight.Error); } else { Error = 0; ErrorSt = ""; result = output2; Logging.AddLog(LogPrefix + " command succesfull", LogLevel.Debug); res = true; } } else { result = ""; Logging.AddLog(LogPrefix + " send command error: " + ErrorSt, LogLevel.Debug, Highlight.Error); } return(res); }