Exemplo n.º 1
0
 private void SendALLFingersValue()
 {
     MainBoardSerial.Write(String.Format("@ALLF:{0},{1},{2},{3},{4},{5}#", interthread_ThumbValue.ToString().PadLeft(4, ' ')
                                         , interthread_IndexValue.ToString().PadLeft(4, ' ')
                                         , interthread_MiddleValue.ToString().PadLeft(4, ' ')
                                         , interthread_RingValue.ToString().PadLeft(4, ' ')
                                         , interthread_PinkyValue.ToString().PadLeft(4, ' ')
                                         , (interthread_ThumbValue + interthread_IndexValue + interthread_MiddleValue + interthread_PinkyValue + interthread_RingValue).ToString().PadLeft(3, '0')));
     dbg(String.Format("@ALLF:{0},{1},{2},{3},{4},{5}#", interthread_ThumbValue.ToString().PadLeft(4, ' ')
                       , interthread_IndexValue.ToString().PadLeft(4, ' ')
                       , interthread_MiddleValue.ToString().PadLeft(4, ' ')
                       , interthread_RingValue.ToString().PadLeft(4, ' ')
                       , interthread_PinkyValue.ToString().PadLeft(4, ' ')
                       , (interthread_ThumbValue + interthread_IndexValue + interthread_MiddleValue + interthread_PinkyValue + interthread_RingValue).ToString().PadLeft(4, '0')));
 }
Exemplo n.º 2
0
        public bool isConnected()
        {
            //int TimeoutCounter = 0;
            //if (SerialPortHandler.IsOpen == true)
            //{
            //    PINGFlag = false;
            //    dbg("Open OK .");
            //    SerialPortHandler.DiscardInBuffer();
            //    dbg("Step before sending ping.");
            if (MainBoardSerial.IsOpen == true)
            {
                MainBoardSerial.Write("PCPing#");
            }
            //    dbg("PingBoard");
            //    sw.Reset();
            //    sw.Start();
            //    while(PINGFlag == false && sw.ElapsedMilliseconds < 2000){}

            //    if (sw.ElapsedMilliseconds > 2000)
            //    {
            //        dbg("Ping TimeOut");
            //    }
            //    sw.Stop();
            //    if (PINGFlag == true)
            //    {
            dbg("PING OK !");
            ParseThread = new Thread(new ThreadStart(this.ParseBuffer));
            ParseThread.Start();
            return(true);
            //    }
            //    else
            //    {
            //        dbg("PingStatement Not Found,Ping string recieved :" + LastSerialData);
            //    }

            //    SerialPortHandler.Close();
            //    dbg("Serial Port has been closed , because the Hand didn't reply successfly");
            //    tabControl1.SelectedTab = tabPage1;
            //    return false;
            //}
            //else
            //{
            //    // ToolStripControlHost host = new ToolStripControlHost("HelloWorld");
            //    dbg("Serial Port is closed , please connect to hand first.");
            //}

            //return false;
        }
Exemplo n.º 3
0
        private void MainBoardSerial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            bool   SpecialCommand = false;
            string SerialRXData   = MainBoardSerial.ReadTo("#");

            if (SerialRXData == "PingOK#")
            {
                PINGFlag       = true;
                SerialRXData   = "";
                SpecialCommand = true;
                dbg("Special RX:" + SerialRXData);
            }
            if (SpecialCommand == false)
            {
                SerialQueue.Enqueue(SerialRXData);
                BufferWaitHandle.Set();
            }
        }
Exemplo n.º 4
0
        private void SendFingerData(int fingername, int fingervalue)
        {
            //Packet : FingerNumber,FingerDirection,FingerSpeedValue
            int TempDir = 0, TempSpeed = 0;

            if (fingervalue < 0)
            {
                TempDir = 1;
            }
            TempSpeed = (Math.Abs(fingervalue));
            // if(SerialPortHandler.IsOpen == true ) SerialPortHandler.Write("@SM:" + TempDir + "," + TempSpeed + "," + (TempDir+TempSpeed) + "#\r\n");
            //if (isConnected() == true)
            //{
            dbg(String.Format("Sending:{0},{1},{2},{3}#", TempDir.ToString().PadLeft(1, '0'), fingername.ToString().PadLeft(3), TempSpeed.ToString().PadLeft(3, '0'), (TempDir + TempSpeed + fingername).ToString().PadLeft(3, '0')));
            if (MainBoardSerial.IsOpen == true)
            {
                MainBoardSerial.Write(String.Format("@SM:{0},{1},{2},{3}#", TempDir.ToString().PadLeft(1, '0'), fingername.ToString().PadLeft(3), TempSpeed.ToString().PadLeft(3, '0'), (TempDir + TempSpeed + fingername).ToString().PadLeft(3, '0')));
            }
            //}
        }
Exemplo n.º 5
0
 private void cmd_connect_Click(object sender, EventArgs e)
 {
     dbg("Trying to connect ...");
     try
     {
         if (cmd_connect.Text == "Disconnect")
         {
             cmd_connect.Text = "Connect";
             MainBoardSerial.Close();
         }
         else
         {
             MainBoardSerial.BaudRate = 115200;
             if (MainBoardSerial.IsOpen == true)
             {
                 MainBoardSerial.Close();
             }
             MainBoardSerial.PortName = cmb_ports.Text;
             dbg("Just before connect ...");
             MainBoardSerial.Open();
             dbg("First stage of connection is OK ...");
             if (isConnected() == true)
             {
                 dbg("Connected to Bionic Hand");
                 dbg("Controller is ready...");
                 tabControl1.SelectedTab = tabPage2;
                 cmd_connect.Text        = "Disconnect";
             }
             else
             {
                 dbg("No Data from MCU");
             }
         }
     }
     catch (Exception ex)
     {
         dbg("Error in Connection : " + ex.Message);
     }
 }