Ejemplo n.º 1
0
        internal static bool DisableRTS()
        {
            if (SerialPortRTS == null)
            {
                Trace.WriteLine("DisableRTS SerialPortRTS == null");
                return(false);
            }

            if (!SerialPortRTS.IsOpen)
            {
                SerialPortRTS.Open();
            }

            if (SerialPortRTS.RtsEnable)
            {
                SerialPortRTS.RtsEnable = false; // RTS disable 供電
                Trace.WriteLine("Set RTS Disable.");
                Thread.Sleep(300);
            }
            else
            {
                CloseRTSPort();
                return(true);
            }

            RetryCount = 0;
            while (!IsCharging)
            {
                RetryCount++;
                if (RetryCount > 20)
                {
                    CloseRTSPort();
                    return(false);
                }
                else
                {
                    Thread.Sleep(300);
                    Trace.WriteLine("Can't switch RTS Pin to Disable (AC In).");
                    SerialPortRTS.RtsEnable = false; // RTS disable 供電
                }
            }
            CloseRTSPort();
            return(true);
        }
Ejemplo n.º 2
0
        internal static bool EnableRTS()
        {
            if (SerialPortRTS == null)
            {
                Trace.WriteLine("EnableRTS SerialPortRTS == null");
                return(false);
            }

            if (!SerialPortRTS.IsOpen)
            {
                SerialPortRTS.Open();
            }

            if (!SerialPortRTS.RtsEnable)
            {
                SerialPortRTS.RtsEnable = true; // RTS enable 斷電
                Trace.WriteLine("Set RTS Enable.");
                Thread.Sleep(300);
            }
            else
            {
                return(true);
            }

            RetryCount = 0;
            while (IsCharging)
            {
                RetryCount++;
                if (RetryCount > 20)
                {
                    return(false);
                }
                else
                {
                    Thread.Sleep(300);
                    Trace.WriteLine("Can't switch RTS Pin to Enable (AC Out).");
                    SerialPortRTS.RtsEnable = true; // RTS enable 斷電
                }
            }
            return(true);
        }