Beispiel #1
0
            public Sender(string ident)
            {
                _n        = new Nectar2(ident);
                _evDoSend = new NamedEventPair();
                _th       = new Thread((ThreadStart) delegate
                {
                    while (_death == false)
                    {
                        byte[] message;

                        lock (SYNCROOT)
                        {
                            if (_messages.Count == 0)
                            {
                                message  = null;
                                _sending = false;
                            }
                            else
                            {
                                message  = _messages.Dequeue();
                                _sending = true;
                            }
                        }
                        if (message == null)
                        {
                            _evDoSend.waitForMillis(2000);
                        }
                        else
                        {
                            foreach (byte chr in message)
                            {
                                for (int bit = 0; bit < 8; bit++)
                                {
                                    if ((chr & (1 << bit)) != 0)
                                    {
                                        _n.set((E_INDEX)((int)E_INDEX.E_BIT_0 + bit));
                                    }
                                }

                                _n.get(E_INDEX.E_RECV);                                 // clear
                                _n.set(E_INDEX.E_SEND);

                                if (syncRecv() == false)                                 // ? 送信タイムアウト
                                {
                                    lock (SYNCROOT)
                                    {
                                        _messages.Clear();                                         // 全部失敗扱い。
                                    }
                                    break;
                                }
                            }
                        }
                    }
                });
                _th.Start();
            }
Beispiel #2
0
            public void Dispose()
            {
                if (_n != null)
                {
                    _death = true;

                    _th.Join();
                    _th = null;

                    _n.Dispose();
                    _n = null;
                }
            }
Beispiel #3
0
            public Recver(string ident, int delimiter = 0x00)
            {
                _n         = new Nectar2(ident);
                _delimiter = delimiter;
                _th        = new Thread((ThreadStart) delegate
                {
                    while (_death == false)
                    {
                        if (_n.get(E_INDEX.E_SEND, 2000))
                        {
                            int chr = 0x00;

                            for (int bit = 0; bit < 8; bit++)
                            {
                                if (_n.get((E_INDEX)((int)E_INDEX.E_BIT_0 + bit)))
                                {
                                    chr |= 1 << bit;
                                }
                            }

                            _n.set(E_INDEX.E_RECV);

                            if (chr == _delimiter)
                            {
                                byte[] message = _buff.ToArray();

                                lock (SYNCROOT)
                                {
                                    if (_messages.Count < BUFF_MAX)
                                    {
                                        _messages.Enqueue(message);
                                    }
                                }
                                _buff.Clear();
                            }
                            else
                            {
                                if (_buff.Count < MESSAGE_SIZE_MAX)
                                {
                                    _buff.Enqueue((byte)chr);
                                }
                            }
                        }
                    }
                });
                _th.Start();
            }
Beispiel #4
0
            public void Dispose()
            {
                if (_n != null)
                {
                    _death = true;
                    _evDoSend.set();

                    _th.Join();
                    _th = null;

                    _n.Dispose();
                    _n = null;

                    _evDoSend.Dispose();
                    _evDoSend = null;
                }
            }