예제 #1
0
    public void Update()
    {
        if (buffer == null)
        {
            return;
        }
        buffer.AcquireReadLock();
        buffer.Read(dbuf);
        buffer.ReleaseReadLock();

        data.Parse(dbuf, 0);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (buffer == null)
        {
            return;
        }
        buffer.AcquireReadLock();
        buffer.Read(dbuf);
        buffer.ReleaseReadLock();

        data.Parse(dbuf, 0);

        Debug.Log(data.joints.rt_arm.left[0].ToString());

        /*
         * data [2] = (byte)((data [2]+1)%127);
         *
         *
         * buffer.AcquireWriteLock ();
         * buffer.Write<byte> (data);
         * buffer.ReleaseWriteLock ();*/
    }
예제 #3
0
        public Form1()
        {
            InitializeComponent();
            const int size   = 1024;
            const int length = 1024;
            int       value  = 1;

            richTextBox1.AppendText("Using Shared Memory");
            while (value <= 100)
            {
                try
                {
                    //using (var mmf = MemoryMappedFile.OpenExisting(args))
                    //{
                    using (var consumer = new SharedMemory.BufferReadWrite(name: "CountingBuffer"))
                    {
                        //MemoryMappedViewStream mmvStream = mmf.CreateViewStream(0, size);

                        //BinaryFormatter formatter = new BinaryFormatter();

                        //byte[] buffer = new byte[size];

                        //Message msg;
                        //richTextBox1.AppendText("found Counting file\n");

                        //while (mmvStream.CanRead)
                        //{
                        //	richTextBox1.AppendText("Reading mmvStream\n");

                        //	mmvStream.Read(buffer, 0, size);

                        //	msg = (Message)formatter.Deserialize(new MemoryStream(buffer));

                        //	DateTime now = DateTime.UtcNow;
                        //	long unixTime = ((DateTimeOffset)now).ToUnixTimeSeconds();

                        //	//if (msg.timestamp != unixTime)
                        //	//{
                        //	//	msg.count++;
                        //	//	richTextBox1.AppendText("Incrementing count: " + msg.count + "\n");
                        //	//}

                        //	//value = msg.count;

                        //	richTextBox1.AppendText("Count: " + msg.count);
                        //	richTextBox1.AppendText("Timestamp: " + msg.timestamp);

                        //	formatter.Serialize(mmvStream, msg);
                        //	mmvStream.Seek(0, System.IO.SeekOrigin.Begin);
                        //}
                        int  count;
                        long timestamp;
                        consumer.Read <int>(out count, 0);
                        consumer.Read <long>(out timestamp, 500);
                        richTextBox1.AppendText("Count: " + count.ToString() + ", timestamp: " + timestamp.ToString());
                    }
                }
                catch (Exception ex)
                {
                    richTextBox1.AppendText(ex.ToString());
                    value = 101;
                    break;
                }
            }
        }