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

namespace SLZ_4
{
    public partial class ConfigDevicePort : Form
    {
        public ConfigDevicePort()
        {
            InitializeComponent();

            refreshPort();
        }

        public void refreshPort()
        {
            CodePort.Items.Clear();
            string[] ports = System.IO.Ports.SerialPort.GetPortNames();
            CodePort.Items.AddRange(ports);
        }
        private void CodeCon_Click(object sender, EventArgs e)
        {
            FormMain.form.updateDevice(CodePort.Text, int.Parse(CodeBaud.Text));
            Config.saveDevParam(0);
            FormMain.form.addDevObj(0);
        }

        private void CodeRefresh_Click(object sender, EventArgs e)
        {
            refreshPort();
        }

        private void CodeBreak_Click(object sender, EventArgs e)
        {
            FormMain.form.deleteDevObj(0);
        }

        public void showDevInfo()
        {
            CodePort.Text = FormMain.form.arrDevParam[0].sDevAddr;
            CodeBaud.Text = FormMain.form.arrDevParam[0].iPort.ToString();

            if (FormMain.form.arrDevObj[0] != null)
            {
                CodeIsComm.Text = FormMain.form.arrDevObj[0].bStatus ? "已连接" : "未连接";
                CodeIsComm.BackColor = FormMain.form.arrDevObj[0].bStatus ? Color.Green : Color.Red;
            }
            else
            {
                CodeIsComm.Text = "未配置";
            }
        }
    }
}
