Exemple #1
0
        // 受信データの処理
        private void executeRecvData(string data)
        {
            GPduinoEventArgs args = new GPduinoEventArgs();

            args.data = data;
            onReceived(this, args);
        }
/*
        // デバイス接続通知ハンドラ
        private void onConnect(object sender, GPduinoEventArgs e)
        {
            this.BeginInvoke((Action)(() => {
                string deviceName = e.data;
                textStatus.Text = "接続中: " + deviceName;
            }));
        }

        // デバイス切断通知ハンドラ
        private void onDisconnect(object sender, GPduinoEventArgs e)
        {
            this.BeginInvoke((Action)(() => {
                textStatus.Text = "未接続";
            }));
        }
*/
        // ネットワーク切断ハンドラ
        private void onClosed(object sender, GPduinoEventArgs e)
        {
            this.BeginInvoke((Action)(() => {
                isOpen = false;
                buttonOpen.Text = "開く";
            }));
        }
Exemple #3
0
 // 受信スレッド関数
 private void recvThreadFunc()
 {
     while (!toQuit)
     {
         try
         {
             //サーバーから送られたデータを受信する
             IPEndPoint remote = new IPEndPoint(IPAddress.Any, REMOTE_PORT);
             byte[]     buffer = udp.Receive(ref remote);
             // TODO
             // 受信したデータを変換
             string data = Encoding.ASCII.GetString(buffer);
             if (data == null)
             {
                 isOpen = false;
                 udp.Close();
                 GPduinoEventArgs args = new GPduinoEventArgs();
                 onClosed(this, args);
                 break;
             }
             // 受信した文字列の処理
             executeRecvData(data);
         }
         catch (SocketException)
         {
             ; // タイムアウト
         }
         catch (ObjectDisposedException)
         {
             isOpen = false;
             udp.Close();
             GPduinoEventArgs args = new GPduinoEventArgs();
             onClosed(this, args);
             break;
         }
     }
 }