1
Vote

Arduino properties not populating after a board connect

description

I am successfully connecting to my UNO and setting PWM values to dim an LED and this works but after I have connected the following Arduino class/instance properties do not appear to be correctly populated:

IsConnected
FirmataName
FirmataMajorVersion
FirmataMinorVersion

I tried to sleep to see if it was a timing thing but that had no effect. I looked at the source but I don't quite follow how these are populated. Are these known to work? Am I doing something wrong? I am pasting some of my code below. Thanks!
namespace FirmataControl
{
    public partial class Form1 : Form
    {
        protected Arduino arduino;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Get a list of serial port names. 
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                comPortsComboBox.Items.Add(port);
            }
            if (ports.Length < 1)
            {
                comPortsComboBox.Text = "None";
                connectBtn.Enabled = false;
            }
            else
            {
                comPortsComboBox.SelectedIndex = 1;
                connectBtn.Enabled = true;
            }
        }

        private void connectBtn_Click(object sender, EventArgs e)
        {
            using (this.arduino = new Arduino(comPortsComboBox.Text))
            {
                if (true) //this.arduino.IsConnected
                {
                    labelStatus.Text = "Board connected on " + this.arduino.PortName + " running " +
                       this.arduino.FirmataName + " version " + this.arduino.FirmataMajorVersion + "." + this.arduino.FirmataMinorVersion;
                    this.arduino.DigitalPins[3].SetPinMode(PinMode.Pwm);
                    this.arduino.DigitalPins[5].SetPinMode(PinMode.Pwm);
                    this.arduino.DigitalPins[6].SetPinMode(PinMode.Pwm);
                    this.arduino.DigitalPins[9].SetPinMode(PinMode.Pwm);
                    this.arduino.DigitalPins[10].SetPinMode(PinMode.Pwm);
                    this.arduino.DigitalPins[11].SetPinMode(PinMode.Pwm);
                }
            }
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            this.arduino.DigitalPins[3].SetPinValue(trackBar1.Value);
            numericUpDown1.Value = trackBar1.Value;
        }

    }
}

comments