示例#1
0
        void GetMotorTemp()
        {
            Task.Run(() =>
            {
                bool worked        = false;
                double temperature = 0;

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        temperature = MotorCom.GetTemp();

                        MotorCom.Close();

                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("unable to open comport for GetMotorTemp");
                        return;
                    }
                }

                if (worked)
                {
                    //TODO: handle dual humidities for MotorHumidityLbl
                    Action <double> update_action = (t) => { MotorBoardTempLbl.Content = "MOTOR BOARD TEMP: " + t.ToString("0.00") + "C/F?"; };
                    Dispatcher.BeginInvoke(update_action, temperature);
                }
            });
        }
示例#2
0
        void PingMotor()
        {
            //TODO: add gui for motor ping.
            Task.Run(() =>
            {
                bool worked = false;
                bool pinged = false;

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        pinged = MotorCom.Ping();

                        MotorCom.Close();

                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("unable to open comport for GetMotorTemp");
                        return;
                    }
                }

                if (worked)
                {
                    //if (pinged)
                    //Console.WriteLine("Motor ping success");
                }
            });
        }
示例#3
0
        void GetMotorHumidity()
        {
            Task.Run(() =>
            {
                bool worked     = false;
                double humidity = 0;

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        humidity = MotorCom.GetHumidity();

                        MotorCom.Close();

                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("unable to open comport for GetMotorHumidity");
                        return;
                    }
                }

                if (worked)
                {
                    //TODO: handle dual humidities for MotorHumidityLbl
                    //double MotorBoardHumidity = 0;
                    //double BmsBoardHumidity = 0;
                    Action <double> update_action = (h) => { MotorBoardHumidity = h; UpdateHumidityDisplay(); };
                    Dispatcher.BeginInvoke(update_action, humidity);
                }
            });
        }
示例#4
0
        void SetKey(bool key_on)
        {
            Task.Run(() =>
            {
                bool worked = false;

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        MotorCom.SetKey(key_on);

                        MotorCom.Close();
                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("failed to SetKey");
                    }
                }

                if (worked)
                {
                    Action <bool> update_action = (k) => { KeyLbl.Content = k ? "KEY ON" : "KEY OFF"; };
                    Dispatcher.BeginInvoke(update_action, key_on);
                }
            });
        }
示例#5
0
        /// <summary>
        /// Set motor Speed between 0 and 1.0.
        /// </summary>
        /// <param name="speed"></param>
        void SetSpeed(double speed)
        {
            Task.Run(() =>
            {
                bool worked = false;

                if (speed < 0)
                {
                    speed = 0;
                }

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        MotorCom.SetSpeed(speed);
                        MotorCom.Close();
                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("failed to SetSpeed");
                    }
                }

                if (worked)
                {
                    Action <double> update_action = (s) => { BoatSpeedLbl.Content = speed.ToString("0.00"); };
                    Dispatcher.BeginInvoke(update_action, speed);
                }
            });
        }
示例#6
0
        void SetDirection(MotorControllerCom.Direction direction)
        {
            Task.Run(() =>
            {
                bool worked = false;

                lock ( MotorLock )
                {
                    if (MotorCom.Open(MotorComPort))
                    {
                        MotorCom.SetDirection(direction);

                        MotorCom.Close();
                        worked = true;
                    }
                    else
                    {
                        Console.WriteLine("failed to SetDirection");
                    }
                }

                if (worked)
                {
                    string dir_string = "ERROR";
                    switch (direction)
                    {
                    case MotorControllerCom.Direction.Forward:
                        dir_string = "FORWARD";
                        break;

                    case MotorControllerCom.Direction.Reverse:
                        dir_string = "REVERSE";
                        break;

                    case MotorControllerCom.Direction.NoDirection:
                        dir_string = "NO DIRECTION";
                        break;
                    }

                    Action <MotorControllerCom.Direction> update_action = (d) => { UpdateDirection(d); };
                    Dispatcher.BeginInvoke(update_action, direction);
                }
            });
        }
示例#7
0
        void MotorBeep()
        {
            //todo: add this.


            lock (MotorLock)
            {
                if (MotorCom.Open(MotorComPort))
                {
                    MotorCom.Beep();

                    MotorCom.Close();
                }
                else
                {
                    Console.WriteLine("unable to open comport for MotorBeep");
                    return;
                }
            }
        }