コード例 #1
0
        private void ReceiveHands()
        {
            while (true)
            {
                if (leapControl)
                {
                    string data = "";
                    yarpPortHands.receivedData(out data);

                    if (data.Length > 2)
                    {
                        data = data.Substring(1, data.Length - 2); // remove first and last char from data, yarp puts the message in quotes ""
                    }
                    if (leapControl && data != null && data != "")
                    {
                        LRValues handsConfiguration = ComUtils.XmlUtils.Deserialize <LRValues>(data);
                        setHands(handsConfiguration);
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(500);
                }
            }
        }
コード例 #2
0
        private void Work()
        {
            while (true)
            {
                if (receive)
                {
                    string data = "";
                    yarpPortReceive.receivedData(out data);
                    data = data.Substring(1, data.Length - 2); // to remove quotes at beginning and end from received string
                    if (data != null && data != "")
                    {
                        frameCounter += 1;
                        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                               new Action(() => lblFrameReceived.Content = frameCounter));

                        ThreadPool.QueueUserWorkItem(ProcessData, data);
                    }
                }
            }
        }
コード例 #3
0
        RecognizedQRCode getInformationDB(Dictionary <string, ZXing.ResultPoint[]> dict)
        {
            RecognizedQRCode rec = new RecognizedQRCode();

            rec.ResolutionCam        = new ResolutionCam();
            rec.ResolutionCam.Width  = w.ToString();
            rec.ResolutionCam.Height = h.ToString();


            foreach (var s in dict)
            {
                //preparo l'informazione del soggetto con la posizione centrale del QRCode
                InfoQRCode inf = new InfoQRCode();
                inf.Positions = new List <Pos>();

                foreach (var v in s.Value)
                {
                    Pos p = new Pos();
                    p.X = v.X.ToString();
                    p.Y = v.Y.ToString();

                    inf.Positions.Add(p);
                }

                // verifico se già conosco il soggetto altrimenti interogo il database
                List <InfoQRCode> sub = SubjRecognition.InfoQRCode.FindAll(a => a.Message.Split('|')[1].Trim() == s.Key);
                if (sub.Count() == 0)
                {
                    //leggo lo status del database se è occupato attendo
                    string state = "";

                    do
                    {
                        yarpPortStatusDB.receivedData(out state);
                    }while (state != "Activo");

                    //apro le connessioni con il db
                    yarpPortCommandDB.openConnectionToDb(dataBaseCommand_OUT, dataBaseCommand_IN);
                    yarpPortReplyDB.openReceiverReplyDb(dataBaseReply_OUT, dataBaseReply_IN);

                    yarpPortCommandDB.sendData("SELECT * FROM subjects WHERE IdSubject=" + s.Key);
                    System.Threading.Thread.Sleep(400);

                    //attendo risposta
                    string reply = "";
                    do
                    {
                        yarpPortReplyDB.receivedData(out reply);
                    }while (reply == "");

                    //se non trovo nulla parte evento che gestire l'inserimento del nuovo soggetto
                    if (reply.Replace("\"", "") == "|")
                    {
                        InputDialog.InputDialog dialog2 = new InputDialog.InputDialog("Assign ID and Name to ", "", "");
                        if (dialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            if (dialog2.ResultText != "unknown")
                            {
                                yarpPortCommandDB.sendData("INSERT INTO subjects (IdSubject,Name,FirstTime) VALUE ('" + s.Key + "','" + dialog2.ResultText + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')");

                                System.Threading.Thread.Sleep(400);

                                reply = "";
                                do
                                {
                                    yarpPortReplyDB.receivedData(out reply);
                                }while (reply == "" || reply == "\"|\"");

                                inf.Message = "unknown";
                            }
                            else
                            {
                                inf.Message = dialog2.ResultText;
                            }
                        }
                        else
                        {
                            inf.Message = dialog2.ResultText;
                        }
                    }
                    else
                    {
                        inf.Message = reply.Replace("\"", "");
                    }



                    yarpPortCommandDB.Close();
                    yarpPortReplyDB.Close();

                    if (inf.Message != "unknown")
                    {
                        SubjRecognition.InfoQRCode.Add(inf);
                    }
                }
                else
                {
                    foreach (InfoQRCode info in sub)
                    {
                        if (info.Message[1] == s.Key[0])
                        {
                            inf.Message = info.Message;
                        }
                    }
                }

                Sub.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(delegate()
                {
                    Sub.Content = inf.Message;
                }));


                rec.InfoQRCode.Add(inf);
            }


            return(rec);
        }