Exemplo n.º 1
0
        /// <summary>
        /// データ受信を通知するイベントです。
        /// </summary>
        /// <param name="sender">発生元オブジェクト</param>
        /// <param name="e">イベントデータ</param>
        private void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int rcvlen = 0;

            labelRecive.BackColor = backColors.ReciveOn;
            Application.DoEvents();

            // Mutexの所有権を得る - ∞秒待つ
            mutex.WaitOne(-1, false);

            // 受信
            try
            {
                rcvlen = comPort.Read(reciveBuffer, reciveBufferDataLength, reciveBuffer.Length - reciveBufferDataLength);

                // 受信データサイズを更新
                reciveBufferDataLength += rcvlen;
            }
            catch
            {
            }

            // Mutexの所有権を解放
            mutex.ReleaseMutex();

            if (reciveBufferDataLength == 0)
            {
                // 受信データなし
                labelRecive.BackColor = backColors.ReciveOff;
                Application.DoEvents();
                return;
            }

            // 受信通知イベント
            RecivedEventArgs eArgs = new RecivedEventArgs();

            eArgs.DataCount = reciveBufferDataLength;
            eArgs.FreeCount = reciveBuffer.Length - reciveBufferDataLength;
            if (dataDump == true)
            {
                LogPrint("Status[RCV:" + eArgs.DataCount.ToString() + ",FREE:" + eArgs.FreeCount.ToString() + "]");
            }
            if (Recived != null)
            {
                // ハンドラが設定されていたらイベント発生
                CallRecivedEvent(this, eArgs);
            }

            if (reciveBuffer.Length - reciveBufferDataLength < 1)
            {
                labelRecive.BackColor = backColors.BufferFull;
                LogPrint("受信バッファがいっぱいです");
            }
            else
            {
                labelRecive.BackColor = backColors.ReciveOff;
            }
            Application.DoEvents();
        }
 private void Connection_OnRecived(object sender, RecivedEventArgs recivedEventArgs)
 {
     if (recivedEventArgs.Buffer.Length > 0)
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             //System.Threading.Thread.Sleep(100);
             //await DisplayAlert("Notify", recivedEventArgs.Buffer.ToArray()[0].ToString(), "Close");
             //editorTransmit.Text = recivedEventArgs.Buffer.ToArray()[0].ToString();
             _reciving          = true;
             stepperDigit.Value = recivedEventArgs.Buffer.ToArray()[0];
             _reciving          = false;
         });
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// データ受信イベントを発生させます。
        /// </summary>
        /// <param name="sender">発生元オブジェクト</param>
        /// <param name="e">イベントデータ</param>
        private void CallRecivedEvent(object sender, RecivedEventArgs e)
        {
            if (InvokeRequired)
            {
                // 別スレッドから呼び出された場合
                object[] param = { sender, e };
                Invoke(new CallRecivedEventDelegate(CallRecivedEvent), param);
                return;
            }

            try
            {
                Recived(sender, e);
            }
            catch
            {
            }
        }
 private void _reciver_OnRecived(object sender, RecivedEventArgs recivedEventArgs)
 {
     RaiseRecivedEvent(recivedEventArgs.Buffer);
 }