/// <summary>Send command to QTM server and get a command response</summary> /// <param name="command">Command to send</param> /// <returns>true if server does not reply with error packet</returns> public bool SendCommandExpectCommandResponse(string command, out string response) { if (SendString(command, PacketType.PacketCommand)) { PacketType packetType; while (ReceiveRTPacket(out packetType, true) > 0) { if (packetType == PacketType.PacketCommand) { response = mPacket.GetCommandString(); return(true); } if (packetType == PacketType.PacketError) { response = mPacket.GetErrorString(); mErrorString = mPacket.GetErrorString(); return(false); } } } response = "Command failed"; return(false); }
/// <summary>Create connection to server</summary> /// <param name="serverAddr">address to server</param> /// <param name="serverPortUDP">port to use if UDP socket is desired, set to 0 for automatic port selection</param> /// <param name="majorVersion">Major protocol version to use, default is latest</param> /// <param name="minorVersion">Minor protocol version to use, default is latest</param> /// <param name="port">base port for QTM server, default is 22222</param> /// <returns>true if connection was successful, otherwise false</returns> public bool Connect(string serverAddr, int serverPortUDP = -1, int majorVersion = Constants.MAJOR_VERSION, int minorVersion = Constants.MINOR_VERSION, int port = Constants.STANDARD_BASE_PORT) { Disconnect(); mMajorVersion = majorVersion; mMinorVersion = minorVersion; if (mMajorVersion > 1 || mMinorVersion > 7) { // Allow for 1.8 and above versions } else { mErrorString = "Protocol version of 1.8 or lower can not be used by the c# software development kit"; return(false); } PacketType packetType; port += 1; mPacket = new RTPacket(majorVersion, minorVersion); if (mNetwork.Connect(serverAddr, port)) { if (serverPortUDP >= 0) { mUDPport = (ushort)serverPortUDP; if (mNetwork.CreateUDPSocket(ref mUDPport, false) == false) { mErrorString = String.Format("Error creating UDP socket: {0}", mNetwork.GetErrorString()); Disconnect(); return(false); } } //Get connection response from server if (ReceiveRTPacket(out packetType) > 0) { if (packetType == PacketType.PacketError) { //Error from QTM mErrorString = mPacket.GetErrorString(); Disconnect(); return(false); } if (packetType == PacketType.PacketCommand) { string response = mPacket.GetCommandString(); if (response == "QTM RT Interface connected") { if (SetVersion(mMajorVersion, mMinorVersion, out response)) { string expectedResponse = String.Format("Version set to {0}.{1}", mMajorVersion, mMinorVersion); if (response == expectedResponse) { return(true); } else { mErrorString = "Unexpected response from server"; Disconnect(); return(false); } } else { //Error setting version mErrorString = "Error setting version of protocol"; Arqus.QTMNetworkConnection.QTMVersionSupported = false; Disconnect(); return(false); } } else { //missing QTM response mErrorString = "Missing response from QTM Server"; Disconnect(); return(false); } } } else { //Error receiving packet. mErrorString = String.Format("Error Recieveing packet: {0}", mNetwork.GetErrorString()); Disconnect(); return(false); } } else { if (mNetwork.GetError() == SocketError.ConnectionRefused) { mErrorString = "Connection refused, Check if QTM is running on target machine"; Disconnect(); } else { mErrorString = String.Format("Error connecting TCP socket: {0}", mNetwork.GetErrorString()); Disconnect(); } return(false); } return(false); }