Client Class
Previous Top Next

Client Class
QuatView includes a TCP client class that can be used by other dot net applications to send quaternion data to the QuatView server.  This class encapsulates all the functionality that is necessary for communicating with QuatView over a TCP network connection.  The class is named QuatViewClient, and it is provided in the DLL file named QuatViewClient.dll that is located in the QuatView installation directory.  The user simply adds a reference to this DLL file to use this class in a Visual Studio project.  The class is contained within the namespace called NRC_QuatViewClient. So any C# client application will also need a corresponding "using NRC_QuatViewClient" statement to make use of the class.  A description of the class properties, methods, and events is given below. 

QuatViewClient Properties

IPEndPoint ServerIP
Stores server IP address and port number
string TransmitFilePath
Path to the quaternion file to be transmitted
int TransmitDelay
The delay time between transmissions
string ErrorMsg
Readonly.  Client error message.
string StatusMsg
Readonly.  Client status message
QuatMessage CurrentMessage
Readonly.  Current message being transmitted.
int NumMessagesSent
Readonly.  Value that indicates the number of messages transmitted.
bool IsConnected
Readonly.  Flag that indicates if a connection has been made. 
bool IsTransmitting
Readonly.  Flag that indicates if transmission is in progress.

QuatViewClient Methods

bool Connect(IPEndPoint serverAddress)
Establishes connection to QuatView server.  Returns true on success.
bool Connect()
Establishes connection to QuatView server.  Returns true on success.
bool Disconnect()
Disconnects from QuatView server.  Returns true on success.
bool TransmitFileStart(string FilePath)
Begins quaternion file transmission.  Returns true on success.
bool TransmitFileStart()
Begins quaternion file transmission.  Returns true on success.
bool TransmitFileStop()
Stops quaternion file transmission.  Returns true on success.
bool TransmitQuaternion(cQuaternion quatOut)
Transmits a single quaternion object.  Returns true on success. 

Events

event TransmitEvent(object sender, TransmitEventArgs eventArgs)
This event fires after every quaternion message transmission.

The QuatViewClient class incorporates several other classes and enumerations that warrant further description.  Those are the QuatMessage, cQuaternion, and TransmitEventArgs classes and the TransmitMsgType enumeration.  The QuatMessage class is used to store the quaternion messages that are sent to the QuatView server.  The TransmitEventArgs class is used to store the event data for the TransmitEvent event.  This class has a single field that stores the message type. The TransmitMsgType enumeration listed below gives the various message types. The message type is transmitted in the state number field of the QuatMessage class. If the state number field has a positive number then that field indicates the state number.  But if this field is negative then it indicates the message type.  This is how commands such as stop and disconnect as well as error conditions are sent to the server. 
The cQuaternion class is the class that stores the quaternion components and does all the mathematical calculations related to quaternions, vectors, Euler angles, and rotation matrices.  This class source code and documentation are available separately upon request as described here

QuatMessage Class Listing
[Serializable]
public class QuatMessage
{
      public uint Num;   // state number or message code if negative
      public double Time;  // time
      public double q0,q1,q2,q3; // quaternion

      public QuatMessage()
      {
            Num = 0;
            Time = 0.0;
            q0 = 1.00;
            q1 = 0.00;
            q2 = 0.00;
            q3 = 0.00;
      }
}


TransmitEventArgs Class Listing
public class TransmitEventArgs : EventArgs
{
   public TransmitMsgType MsgType;

   public TransmitEventArgs()
   {
      // set the default type
      MsgType = TransmitMsgType.Sent;
   }

   public TransmitEventArgs(TransmitMsgType msgType)
   {
      MsgType = msgType;
   }
}


TransmitMsgType Enumeration
public enum TransmitMsgType
{
      Sent       =  0,  // message was sent
      StopUser   = -1,  // premature stop (user commanded)
      StopError  = -2,  // premature stop (error condition)
      StopEnd    = -3,  // normal stop at end of playback file
      Disconnect = -4,  // disconnect
};


The procedure for using the QuatViewClient class is to first call one of the connect methods to establish the connection and then call one of the transmit start methods to transmit a quaternion history file or a single quaternion.  The user can subscribe to the TransmitEvent event to receive notification whenever a transmission has occurred.  When the input file or list of quaternions to transmit has ended the user can then call the TransmitFileStop method.  This leaves the QuatView server in a connected state and ready for another new quaternion data stream to start.  Or, if there is no more data to transmit, the user can call the Disconnect method which will terminate the connection to the QuatView server so that other clients may then connect. 
The QuatViewClient class currently supports only a single file format: five tab delimited columns with the time in column 1 and the quaternion in columns 2 through 4.  Other file formats can be easily added in the future, if needed.