Пример #1
0
        /// <summary>
        /// Set the PWM Speed. The speed can be between PWM_MIN and PWM_MAX
        /// </summary>
        public void SetPWM(Digital.DigitalPortEnum pwmPort, int speed)
        {
            if (!_ezb.IsConnected)
            {
                return;
            }

            if (speed > PWM_MAX)
            {
                speed = PWM_MAX;
            }
            else if (speed < PWM_MIN)
            {
                speed = PWM_MIN;
            }

            if (speed == 0)
            {
                StopPWM(pwmPort);

                return;
            }

            _pwmPositions[(int)pwmPort] = speed;
            _pwmReleased[(int)pwmPort]  = false;

            _ezb.sendCommand(EZB.CommandEnum.CmdSetPWMSpeed + (byte)pwmPort, new byte[] { (byte)speed });
        }
Пример #2
0
        /// <summary>
        /// Stop PWM.
        /// </summary>
        public void StopPWM(Digital.DigitalPortEnum pwmPort)
        {
            _pwmPositions[(int)pwmPort] = 0;
            _pwmReleased[(int)pwmPort]  = true;

            _ezb.sendCommand(EZB.CommandEnum.CmdSetPWMSpeed + (byte)pwmPort, new byte[] { (byte)0 });
        }
Пример #3
0
        /// <summary>
        ///  Get the value received from the HC-SR04 Ping Sensor
        /// </summary>
        public async Task <int> GetValue(Digital.DigitalPortEnum triggerPort, Digital.DigitalPortEnum echoPort)
        {
            int index = (int)triggerPort;

            if (lastRequest[index].AddMilliseconds(MinPoolTimeMS) > DateTime.Now)
            {
                return(lastValue[index]);
            }

            byte retVal = (await _ezb.sendCommand(1, EZB.CommandEnum.CmdHC_SR04 + (byte)triggerPort, (byte)echoPort))[0];

            lastValue[index]   = retVal;
            lastRequest[index] = DateTime.Now;

            return(retVal);
        }
Пример #4
0
        /// <summary>
        /// Send text over serial specified serial port at baud rate
        /// </summary>
        public void SendSerial(Digital.DigitalPortEnum digitalPort, BAUD_RATE_ENUM baudRate, byte[] byteArray)
        {
            if (!_ezb.IsConnected)
            {
                throw new Exception("Not connected");
            }

            foreach (byte [] bArray in Functions.Chunk(byteArray, 255))
            {
                List <byte> send = new List <byte>();

                send.Add((byte)baudRate);
                send.Add((byte)bArray.Length);
                send.AddRange(bArray);

                _ezb.sendCommand(EZB.CommandEnum.CmdSendSerial + (byte)digitalPort, send.ToArray());
            }
        }
Пример #5
0
 /// <summary>
 /// Return true if the specified pwm port is in a stopped state
 /// </summary>
 public bool IsPWMStopped(Digital.DigitalPortEnum pwmPort)
 {
     return(_pwmReleased[(int)pwmPort]);
 }
Пример #6
0
 /// <summary>
 /// Get the PWM
 /// </summary>
 public int GetPWM(Digital.DigitalPortEnum pwmPort)
 {
     return(_pwmPositions[(int)pwmPort]);
 }
Пример #7
0
 /// <summary>
 /// Send text over serial specified serial port at baud rate
 /// </summary>
 public void SendSerial(Digital.DigitalPortEnum digitalPort, BAUD_RATE_ENUM baudRate, char[] charArray)
 {
     SendSerial(digitalPort, baudRate, Encoding.UTF8.GetBytes(charArray));
 }
Пример #8
0
 /// <summary>
 /// Send text over serial specified serial port at baud rate
 /// </summary>
 public void SendSerial(Digital.DigitalPortEnum digitalPort, BAUD_RATE_ENUM baudRate, string text)
 {
     SendSerial(digitalPort, baudRate, text.Select(Convert.ToByte).ToArray());
 }