public void Connect(NatNetConnectionType connType, IPAddress localAddress, IPAddress serverAddress, UInt16 serverCommandPort = NatNetConstants.DefaultCommandPort, UInt16 serverDataPort = NatNetConstants.DefaultDataPort, IPAddress multicastAddress = null) { ThrowIfDisposed(); sNatNetClientConnectParams initParams = new sNatNetClientConnectParams { ConnectionType = connType, ServerCommandPort = serverCommandPort, ServerDataPort = serverDataPort, LocalAddress = localAddress.ToString(), ServerAddress = serverAddress.ToString(), MulticastAddress = multicastAddress == null ? null : multicastAddress.ToString() }; NatNetError result; result = NatNetLib.NativeMethods.NatNet_Client_Connect(m_clientHandle, ref initParams); NatNetException.ThrowIfNotOK(result, "NatNet_Client_Connect failed."); result = NatNetLib.NativeMethods.NatNet_Client_GetServerDescription(m_clientHandle, out m_serverDesc); NatNetException.ThrowIfNotOK(result, "NatNet_Client_GetServerDescription failed."); ServerAppVersion = new Version( m_serverDesc.HostAppVersion[0], m_serverDesc.HostAppVersion[1], m_serverDesc.HostAppVersion[2], m_serverDesc.HostAppVersion[3]); Connected = true; }
public NatNetServerDiscovery(IEnumerable <string> knownServerAddresses = null) { m_nativeCallbackHandler = ServerDiscoveredNativeThunk; if (knownServerAddresses == null) { NatNetError result = NatNetLib.NativeMethods.NatNet_CreateAsyncServerDiscovery(out m_discoveryHandle, m_nativeCallbackHandler); NatNetException.ThrowIfNotOK(result, "NatNet_CreateAsyncServerDiscovery failed."); if (m_discoveryHandle == IntPtr.Zero) { throw new NatNetException("NatNet_CreateAsyncServerDiscovery returned null handle."); } } else { NatNetError result = NatNetLib.NativeMethods.NatNet_CreateAsyncServerDiscovery(out m_discoveryHandle, m_nativeCallbackHandler, IntPtr.Zero, false); NatNetException.ThrowIfNotOK(result, "NatNet_CreateAsyncServerDiscovery failed."); foreach (string serverAddress in knownServerAddresses) { result = NatNetLib.NativeMethods.NatNet_AddDirectServerToAsyncDiscovery(m_discoveryHandle, serverAddress); NatNetException.ThrowIfNotOK(result, "NatNet_AddDirectServerToAsyncDiscovery failed."); } result = NatNetLib.NativeMethods.NatNet_StartAsyncDiscovery(m_discoveryHandle); NatNetException.ThrowIfNotOK(result, "NatNet_StartAsyncDiscovery failed."); } }
public void RemoteTrigger(string command) { ThrowIfDisposed(); // TODO: MarshalAs... NatNetError retval = NatNetLib.NativeMethods.SendMessage(command); NatNetException.ThrowIfNotOK(retval, "NatNet_Client RemoteTrigger failed."); }
public NatNetError Request(string request, out IntPtr pResponse, out Int32 pResponseLenBytes, Int32 timeoutMs = 1000, Int32 numAttempts = 1) { ThrowIfDisposed(); NatNetError retval = NatNetLib.NativeMethods.NatNet_Client_Request(m_clientHandle, request, out pResponse, out pResponseLenBytes, timeoutMs, numAttempts); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_Request failed."); return(retval); }
public void Disconnect() { ThrowIfDisposed(); if (Connected) { NatNetError retval = NatNetLib.NativeMethods.NatNet_Client_Disconnect(m_clientHandle); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_Disconnect failed."); Connected = false; } }
public NatNetClient(NatNetConnectionType connectionType) { NatNetError retval = NatNetLib.NativeMethods.NatNet_Client_Create(out m_clientHandle, connectionType); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_Create failed."); if (m_clientHandle == IntPtr.Zero) { throw new NatNetException("NatNet_Client_Create returned null handle."); } // This ensures the reverse P/Invoke delegate passed to the native code stays alive. m_nativeFrameReceivedHandler = FrameReceivedNativeThunk; retval = NatNetLib.NativeMethods.NatNet_Client_SetFrameReceivedCallback(m_clientHandle, m_nativeFrameReceivedHandler); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_SetFrameReceivedCallback failed."); }
public Int32 RequestInt32(string request, Int32 timeoutMs = 1000, Int32 numAttempts = 1) { ThrowIfDisposed(); IntPtr responsePtr; Int32 responseLen; NatNetError result = NatNetLib.NativeMethods.NatNet_Client_Request(m_clientHandle, request, out responsePtr, out responseLen, timeoutMs, numAttempts); NatNetException.ThrowIfNotOK(result, "NatNet_Client_Request failed."); if (responseLen != Marshal.SizeOf(typeof(Int32))) { throw new NatNetException("Response has incorrect length"); } Int32[] responseArray = { Int32.MinValue }; Marshal.Copy(responsePtr, responseArray, 0, 1); return(responseArray[0]); }
public void Connect(IPAddress localAddress, IPAddress serverAddress, UInt16 serverCommandPort = NatNetConstants.DefaultCommandPort, UInt16 serverDataPort = NatNetConstants.DefaultDataPort, IPAddress multicastAddress = null) { ThrowIfDisposed(); sNatNetClientConnectParams initParams = new sNatNetClientConnectParams { LocalAddress = localAddress.ToString(), ServerAddress = serverAddress.ToString(), ServerCommandPort = serverCommandPort, ServerDataPort = serverDataPort, MulticastAddress = multicastAddress == null ? null : multicastAddress.ToString() }; NatNetError retval = NatNetLib.NativeMethods.NatNet_Client_Connect(m_clientHandle, ref initParams); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_Connect failed."); Connected = true; }
public DataDescriptions GetDataDescriptions() { ThrowIfDisposed(); IntPtr pDataDescriptions; NatNetError retval = NatNetLib.NativeMethods.NatNet_Client_GetDataDescriptionList(m_clientHandle, out pDataDescriptions); NatNetException.ThrowIfNotOK(retval, "NatNet_Client_GetDataDescriptions failed."); sDataDescriptions dataDescriptions = (sDataDescriptions)Marshal.PtrToStructure(pDataDescriptions, typeof(sDataDescriptions)); // Do a quick first pass to determine the required capacity for the returned lists. Int32 numMarkerSetDescs = 0; Int32 numRigidBodyDescs = 0; Int32 numSkeletonDescs = 0; Int32 numForcePlateDescs = 0; for (Int32 i = 0; i < dataDescriptions.DataDescriptionCount; ++i) { sDataDescription desc = dataDescriptions.DataDescriptions[i]; switch (desc.DescriptionType) { case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_MarkerSet: ++numMarkerSetDescs; break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_RigidBody: ++numRigidBodyDescs; break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_Skeleton: ++numSkeletonDescs; break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_ForcePlate: ++numForcePlateDescs; break; } } // Allocate the lists to be returned based on our counts. DataDescriptions retDescriptions = new DataDescriptions { MarkerSetDescriptions = new List <sMarkerSetDescription>(numMarkerSetDescs), RigidBodyDescriptions = new List <sRigidBodyDescription>(numRigidBodyDescs), SkeletonDescriptions = new List <sSkeletonDescription>(numSkeletonDescs), ForcePlateDescriptions = new List <sForcePlateDescription>(numForcePlateDescs), }; // Now populate the lists. for (Int32 i = 0; i < dataDescriptions.DataDescriptionCount; ++i) { sDataDescription desc = dataDescriptions.DataDescriptions[i]; switch (desc.DescriptionType) { case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_MarkerSet: sMarkerSetDescription markerSetDesc = (sMarkerSetDescription)Marshal.PtrToStructure(desc.Description, typeof(sMarkerSetDescription)); retDescriptions.MarkerSetDescriptions.Add(markerSetDesc); break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_RigidBody: sRigidBodyDescription rigidBodyDesc = (sRigidBodyDescription)Marshal.PtrToStructure(desc.Description, typeof(sRigidBodyDescription)); retDescriptions.RigidBodyDescriptions.Add(rigidBodyDesc); break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_Skeleton: sSkeletonDescription skeletonDesc = (sSkeletonDescription)Marshal.PtrToStructure(desc.Description, typeof(sSkeletonDescription)); retDescriptions.SkeletonDescriptions.Add(skeletonDesc); break; case (Int32)NatNetDataDescriptionType.NatNetDataDescriptionType_ForcePlate: sForcePlateDescription forcePlateDesc = (sForcePlateDescription)Marshal.PtrToStructure(desc.Description, typeof(sForcePlateDescription)); retDescriptions.ForcePlateDescriptions.Add(forcePlateDesc); break; } } return(retDescriptions); }