public async Task <Command.Response> sendCommand(Command cmd) { if (await initConnection()) { try { string cmdString = cmd.getCommandString() + "\r"; if (_useAuth && _pjKey != "") { cmdString = getMD5Hash(_pjKey + _passwd) + cmdString; } byte[] sendBytes = Encoding.ASCII.GetBytes(cmdString); _stream.Write(sendBytes, 0, sendBytes.Length); byte[] recvBytes = new byte[_client.ReceiveBufferSize]; int bytesRcvd = _stream.Read(recvBytes, 0, (int)_client.ReceiveBufferSize); string returndata = Encoding.ASCII.GetString(recvBytes, 0, bytesRcvd); returndata = returndata.Trim(); cmd.processAnswerString(returndata); return(cmd.CmdResponse); } finally { closeConnection(); } } return(Command.Response.COMMUNICATION_ERROR); }
public Command.Response sendCommand(Command cmd) { if(initConnection()) { try { string cmdString = cmd.getCommandString() + "\r"; if (_useAuth && _pjKey != "") cmdString = getMD5Hash(_pjKey + _passwd) + cmdString; byte[] sendBytes = Encoding.ASCII.GetBytes(cmdString); _stream.Write(sendBytes, 0, sendBytes.Length); byte[] recvBytes = new byte[_client.ReceiveBufferSize]; int bytesRcvd = _stream.Read(recvBytes, 0, (int)_client.ReceiveBufferSize); string returndata = Encoding.ASCII.GetString(recvBytes, 0, bytesRcvd); returndata = returndata.Trim(); cmd.processAnswerString(returndata); return cmd.CmdResponse; } finally { closeConnection(); } } return Command.Response.COMMUNICATION_ERROR; }