public string ReceiveMessageIDX2(BufferD buffer, int[] idxSample) { string message = ""; if (buffer.socket.connect(buffer.host, buffer.port)) { try { float[,] data = buffer.socket.getFloatData(idxSample[0], idxSample[1]); for (int i = 0; i < buffer.nChans; i++) // 300 { if (!float.IsNaN(data[0, i]) & data[0, i] < keyAlphabet.Length) // extra safety check { message += keyAlphabet[(int)data[0, i]]; } else { break; } } buffer.socket.disconnect(); } catch (System.Net.Sockets.SocketException) { } } return(message); }
static public void PutDataThread2(BufferD buffer, float[,] dataToPut) { new System.Threading.Thread(() => // Create a new Thread { if (buffer.socket.connect(buffer.host, buffer.port)) { buffer.socket.putData(dataToPut); //buffer[idx].socket.disconnect(); } }).Start(); // Start the Thread }
public void FlushBuffer(BufferD buffer) { if (buffer.socket.connect(buffer.host, buffer.port)) { try { buffer.socket.flushData(); } catch (System.Net.Sockets.SocketException) {} buffer.socket.disconnect(); } }
void SkipMessageBacklog(BufferD buffer) { lastReadIndex[buffer.i] = -1; if (buffer.socket.connect(buffer.host, buffer.port)) { try { buffer.hdr = buffer.socket.getHeader(); lastReadIndex[buffer.i] = buffer.hdr.nSamples; } catch (System.Net.Sockets.SocketException) {} buffer.socket.disconnect(); } }
public void ConnectToRemoteBuffer(BufferD buffer) { new Thread(() => // Create a new Thread { while (true & isGameRunning) // needs to terminate so socket can be accessed by main thread, otherwise will lock the main thread, presumably on connect; needs to shut down on game termination or will run forever { //Debug.Log("/////////////////////////////////////////////////////////" + buffer.name + " " + buffer.host + ": " + buffer.port + ". ConnectToRemoteBuffer(BufferD buffer)"); if (buffer.socket.connect(buffer.host, buffer.port)) { isBufferOpen[buffer.i] = true; break; } else { isBufferOpen[buffer.i] = false; } Thread.Sleep(100); // be nice } }).Start(); // Start the Thread }
public void StartBuffer(BufferD buffer) { if (!IsBufferRunning(buffer)) { Debug.Log("attempting start..."); string cmdTest = "/k cd " + BufferConfig.Direct.realtimeHack + " & buffer.exe " + buffer.host + " " + buffer.port + " -&"; System.Diagnostics.Process.Start("CMD.exe", cmdTest); } if (buffer.socket.connect(buffer.host, buffer.port)) { try { // ----- populate header (necessary if hosted) buffer.hdr = buffer.socket.getHeader(); buffer.hdr.nChans = buffer.nChans; buffer.hdr.dataType = DataType.FLOAT32; buffer.socket.putHeader(buffer.hdr); } catch (System.Net.Sockets.SocketException) {} buffer.socket.disconnect(); } }
public bool IsBufferRunning(BufferD buffer) { bool isBufferRunning = false; var proc = new System.Diagnostics.Process { StartInfo = new System.Diagnostics.ProcessStartInfo // get process by window name - super dodge - also cannot run directly from unity { FileName = BufferConfig.Direct.fileName, Arguments = buffer.host + " " + buffer.port, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.Start(); string line = ""; while (!proc.StandardOutput.EndOfStream) { line = proc.StandardOutput.ReadLine(); } if (line == "False") { isBufferRunning = false; } else if (line == "True") { isBufferRunning = true; } else { isBufferRunning = false; } return(isBufferRunning); }
public float GetStatus(BufferD buffer) { float status = float.NaN; if (buffer.socket.connect(buffer.host, buffer.port)) { try { Header hdr = buffer.socket.getHeader(); float[,] data = new float[, ] { }; if (hdr.nSamples > 0) { data = buffer.socket.getFloatData(hdr.nSamples - 1, hdr.nSamples - 1); status = data[0, 0]; //Debug.Log(data[0, 0]); } buffer.socket.disconnect(); } catch (System.Net.Sockets.SocketException) { } } return(status); }
public string ReceiveMessageLast(BufferD buffer) { string message = ""; if (buffer.socket.connect(buffer.host, buffer.port)) { try { buffer.hdr = buffer.socket.getHeader(); if (buffer.hdr.nSamples == 0) { return(message); } //Debug.Log(buffer.hdr.nSamples); float[,] data = buffer.socket.getFloatData(buffer.hdr.nSamples - 1, buffer.hdr.nSamples - 1); for (int i = 0; i < buffer.nChans; i++) // 300 { if (!float.IsNaN(data[0, i]) & data[0, i] < keyAlphabet.Length) // extra safety check { message += keyAlphabet[(int)data[0, i]]; } else { break; } } //Debug.Log(message); buffer.socket.disconnect(); } catch (System.Net.Sockets.SocketException) { } } return(message); }