// Constructor, make OpenTrackData with values from OpenTrack public OpenTrackData(int LocalPort, int ReceiveTimeout = 5000) { this.X = this.Y = this.Z = this.Yaw = this.Pitch = this.Roll = 0; this.bLastReceiveSucceed = false; this.UDPClient = null; this.Callback = null; this.ReceiveOpenTrackData(LocalPort, ReceiveTimeout); }
// Constructor, make OpenTrackData from provided array of bytes public OpenTrackData(byte[] bytes) { this.X = this.Y = this.Z = this.Yaw = this.Pitch = this.Roll = 0; this.bLastReceiveSucceed = false; this.UDPClient = null; this.Callback = null; this.SetOpenTrackData(bytes); }
// Default constructor, makes OpenTrackData from provided values public OpenTrackData(double x = 0, double y = 0, double z = 0, double yaw = 0, double pitch = 0, double roll = 0) { this.X = x; this.Y = y; this.Z = z; this.Yaw = yaw; this.Pitch = pitch; this.Roll = roll; this.bLastReceiveSucceed = false; this.UDPClient = null; this.Callback = null; }
// Async function, start receiving, fires Callback function when receive was properly finished public void ReceiveOpenTrackDataAsync(OpenTrackDataCallback Callback, int LocalPort, int ReceiveTimeout = 5000) { this.Callback = Callback; this.bLastReceiveSucceed = false; try { UDPClient = new UdpClient(LocalPort); UDPClient.Client.ReceiveTimeout = ReceiveTimeout; } catch (Exception /* e*/) { //Console.WriteLine(e.ToString()); } try { UDPClient.BeginReceive(new AsyncCallback(OnDataReceived), null); } catch (Exception /* e*/) { //Console.WriteLine(e.ToString()); } }