/// <summary> /// Streams samples from LAN-XI modules. Assumes that sockets have been set up properly and connected. /// </summary> public static void Stream() { // Socket is connected and everything is ready to go. Run until the desired number of samples have been received for all input channels. while (samplesReceived[0, 0] < samples_to_receive || samplesReceived[0, 1] < samples_to_receive || samplesReceived[0, 2] < samples_to_receive || samplesReceived[0, 3] < samples_to_receive || samplesReceived[1, 0] < samples_to_receive || samplesReceived[1, 1] < samples_to_receive || samplesReceived[1, 2] < samples_to_receive || samplesReceived[1, 3] < samples_to_receive) { // In this example modules are handled in turns. This assumes that sample rate / message size is equal for all modules. for (int i = 0; i < NumberOfModules; i++) { StreamingHeader streamingHeader = ReadHeader(i); ReadMessage(i, (int)streamingHeader.dataLength, streamingHeader.messageType); } } }
/// <summary> /// Sets up socket communication /// </summary> public static void ConnectSocketAndStream(string address, UInt16 port) { // Connect to the streaming port on the LAN-XI module IPEndPoint remoteEP = new IPEndPoint(Dns.GetHostAddresses(address)[0], port); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect(remoteEP); // Socket is connected and everything is ready to go. Run until the desired number of samples have been received. while (samplesReceived[0] < samples_to_receive || samplesReceived[1] < samples_to_receive || samplesReceived[2] < samples_to_receive || samplesReceived[3] < samples_to_receive) { StreamingHeader streamingHeader = ReadHeader(); ReadMessage((int)streamingHeader.dataLength, streamingHeader.messageType); } }
/// <summary> /// Sets up socket communication /// </summary> public static void ConnectSocketAndStream(string address, UInt16 port) { // Connect to the streaming port on the LAN-XI module IPEndPoint remoteEP = new IPEndPoint(Dns.GetHostAddresses(address)[0], port); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect(remoteEP); sock.ReceiveTimeout = testTime; var stopwatch = new Stopwatch(); stopwatch.Start(); long elapsedTime = 0; // Socket is connected and everything is ready to go. Run until the desired number of samples have been received. // while (samplesReceived[0] < samples_to_receive || samplesReceived[1] < samples_to_receive || samplesReceived[2] < samples_to_receive /*|| samplesReceived[3] < samples_to_receive*/) while (elapsedTime < (testTime)) { StreamingHeader streamingHeader = ReadHeader(); if (streamingHeader.messageType == 11) { //CheckCanDataTimeStamp(streamingHeader.timestamp, streamingHeader.timestampFamily); ReadCanMessage((int)streamingHeader.dataLength, streamingHeader.messageType); } else { ReadMessage((int)streamingHeader.dataLength, streamingHeader.messageType, streamingHeader.timestamp); } elapsedTime = stopwatch.ElapsedMilliseconds; for (int i = 0; i < outputSamples.Count(); i++) { outputSamples[i].Clear(); } } stopwatch.Stop(); }
public void ConnectSocketAndStream() { // Connect to the input streaming port on the LAN-XI module IPEndPoint remoteInputEP = new IPEndPoint(Dns.GetHostAddresses(address)[0], inputPort); inputSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); inputSocket.Connect(remoteInputEP); // Set up and connect output sockets (1 per channel) outputSockets = new Socket[2]; for (int i = 0; i < 2; i++) { IPEndPoint remoteOutputEP = new IPEndPoint(Dns.GetHostAddresses(address)[0], outputPorts[i]); outputSockets[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); outputSockets[i].Connect(remoteOutputEP); } // Socket is connected and everything is ready to go. Run until the desired number of samples have been received. while (samplesReceived[0] < samples_to_receive || samplesReceived[1] < samples_to_receive || samplesReceived[2] < samples_to_receive || samplesReceived[3] < samples_to_receive) { StreamingHeader streamingHeader = ReadHeader(); ReadMessage((int)streamingHeader.dataLength, streamingHeader.messageType); } }