示例#1
0
            /// <summary>
            /// Recver.Perform() 実行中ではない -> 即例外
            /// 別の Sender 送信中 -> 終わるまで待つ。
            /// </summary>
            /// <param name="message"></param>
            public void Send(byte[] message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException();
                }

                _m.Set((int)M_INDEX.Sender, true);

                try
                {
                    // Recver.Perform() 実行中かどうか検査
                    {
                        if (
                            _m.TrySet((int)M_INDEX.Sync_0) &&
                            _m.TrySet((int)M_INDEX.Sync_1) &&
                            _m.TrySet((int)M_INDEX.Sync_2)
                            )
                        {
                            throw new Exception("recver is not running");
                        }

                        _m.Set((int)M_INDEX.Sync_0, false);
                        _m.Set((int)M_INDEX.Sync_1, false);
                        _m.Set((int)M_INDEX.Sync_2, false);
                    }

                    this.SendBit(true, true);

                    for (int index = 0; index < message.Length; index++)
                    {
                        for (int bit = 1 << 7; bit != 0; bit >>= 1)
                        {
                            if ((message[index] & bit) != 0)
                            {
                                this.SendBit(false, true);
                            }
                            else
                            {
                                this.SendBit(true, false);
                            }
                        }
                    }
                    this.SendBit(false, false);
                    this.SendBit(false, false);
                    this.SendBit(false, false);
                }
                finally
                {
                    _m.Clear();
                }
            }
示例#2
0
            /// <summary>
            /// 別の Recver 受信中 -> 即例外
            /// </summary>
            public void Perform()
            {
                if (_recver == null)
                {
                    throw new ArgumentNullException();
                }

                if (_m.TrySet((int)M_INDEX.Recver) == false)
                {
                    throw new Exception("already Perform() running");
                }

                try
                {
                    for (; ;)
                    {
                        this.RecvBit(0, 1, 2);
                        this.RecvBit(1, 2, 0);
                        this.RecvBit(2, 0, 1);

                        if (2000 <= _elapsed)
                        {
                            _elapsed -= 2000;

                            if (_recver.Interlude() == false)
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    _m.Clear();
                }
            }