using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SerialRelayLib;

namespace SerialRelayTest
{
    public partial class Form1 : Form
    {
        SerialRelay _sr = new SerialRelay();
        public Form1()
        {
            InitializeComponent();
            cbCommand.DataSource = Enum.GetNames(typeof(RelayCommand));
            cmbComSelect.DataSource = SerialRelay.GetPorts();
            cbChannels.SelectedIndex = 0;
            cbCommand.SelectedIndex = 2;
            cmbComSelect.SelectedIndex = -1;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            _sr.SendCommand((RelayCommand)Enum.Parse(typeof(RelayCommand), cbCommand.Text), cbChannels.SelectedIndex + 1);   
        }

        private void cmbComSelect_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (_sr.Open(cmbComSelect.Text))
                this.Text = cmbComSelect.Text + " open";
            else
                this.Text = _sr.LastError;

        }
    }
}
