示例#1
0
    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);
    }
示例#2
0
 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
 }
示例#3
0
 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();
     }
 }
示例#4
0
    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();
        }
    }
示例#5
0
    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
    }
示例#6
0
    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();
        }
    }
示例#7
0
    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);
    }
示例#8
0
    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);
    }
示例#9
0
    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);
    }