Exemplo n.º 1
0
        private void Connect()
        {
            SerialPortSettingsView serialPortSettingsView = new SerialPortSettingsView
            {
                Owner           = _parentWindow,
                DataContext     = _serialPortSettingsViewModel,
                MainStackPannel = { Background = (Brush)(new BrushConverter().ConvertFrom("#FFECEAEA")) }
            };

            if (serialPortSettingsView.ShowDialog() != true)
            {
                return;
            }
            if (!_serialPortSettingsViewModel.IsConnected)
            {
                return;
            }
            _port            = _serialPortSettingsViewModel.Port;
            PortIsOpen       = true;
            СonnectionStatus = $"Подключено: {_port.PortName} {_port.BaudRate} {_port.DataBits}{_port.Parity.ToString()[0]}{(int)_port.StopBits}";

            _slave           = ModbusSerialSlave.CreateRtu(1, _port);
            _slave.DataStore = _slaveDataStore;
            //TODO need to add data map of MTE device

            _slave.ModbusSlaveRequestReceived += OnModbusSlaveRequestReceived;
            _queriesCounter = 0;
            _slaveThread    = new Thread(_slave.Listen);
            _slaveThread.Start();
        }
Exemplo n.º 2
0
        public static void Serial()
        {
            using (var masterPort = new SerialPort("COM2"))
                using (var slavePort = new SerialPort("COM1"))
                {
                    // configure serial ports
                    masterPort.BaudRate = slavePort.BaudRate = 9600;
                    masterPort.DataBits = slavePort.DataBits = 8;
                    masterPort.Parity   = slavePort.Parity = Parity.None;
                    masterPort.StopBits = slavePort.StopBits = StopBits.One;
                    masterPort.Open();
                    slavePort.Open();

                    using (var slave = ModbusSerialSlave.CreateRtu(1, slavePort))
                    {
                        StartSlave(slave);

                        // create modbus master
                        using (var master = ModbusSerialMaster.CreateRtu(masterPort))
                        {
                            ReadRegisters(master);
                        }
                    }
                }
        }
        public void Open()
        {
            try
            {
                serialPort.Open();
                slave = ModbusSerialSlave.CreateRtu(slaveID, serialPort);

                logger.Info("Slave подключен");

                slave.DataStore = Modbus.Data.DataStoreFactory.CreateDefaultDataStore();
                slave.DataStore.DataStoreWrittenTo += new EventHandler <DataStoreEventArgs>(Modbus_DataStoreWriteTo);

                slave.DataStore.HoldingRegisters[1] = 0;
                logger.Info("Slave состояние" + slave.DataStore.HoldingRegisters[1]);

                //for (int i=0;i<100;i++)
                //{
                //    slave.DataStore.HoldingRegisters[i] = 0;
                //    Console.WriteLine(i);
                //}

                slave.Listen();
            }
            catch (Exception ex)
            {
                Logger   log   = LogManager.GetLogger("ModbusSerialSlave");
                LogLevel level = LogLevel.Error;
                log.Log(level, ex.Message);
            }
        }
Exemplo n.º 4
0
        //模拟器初始化
        public override void Simulator(int times, bool IsSystem)
        {
            SimulatorClose();
            if (_simularorserialPort == null)
            {
                InitSmSerialPort(ref _simularorserialPort);
            }
            SimulatorUpdateCycle = times;
            for (int i = 0; i < this.IODevices.Count; i++)
            {
                try
                {
                    ModbusSlave DeviceSlave = null;
                    if (Serial_PARA.ModbusType == ModbusType.ASCII)
                    {
                        DeviceSlave = ModbusSerialSlave.CreateAscii(byte.Parse(this.IODevices[i].IO_DEVICE_ADDRESS), _simularorserialPort);
                    }
                    else
                    {
                        DeviceSlave = ModbusSerialSlave.CreateRtu(byte.Parse(this.IODevices[i].IO_DEVICE_ADDRESS), _simularorserialPort);
                    }



                    slaves.Add(DeviceSlave);
                }
                catch (Exception emx)
                {
                    this.SimulatorAppendLog("创建设备模拟器失败 " + this.IODevices[i].IO_DEVICE_NAME + " " + emx.Message);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Simple Modbus serial RTU slave example.
        /// </summary>
        public async void StartModbusSerialRtuSlave()

        {
            using (SerialDevice slavePort = await SerialDevice.FromIdAsync("COM2"))

            {
                // configure serial port

                slavePort.BaudRate = 9600;

                slavePort.DataBits = 8;

                slavePort.Parity = SerialParity.None;

                slavePort.StopBits = SerialStopBitCount.One;



                byte unitId = 1;



                var adapter = new SerialPortAdapter(slavePort);

                // create modbus slave

                ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, adapter);

                slave.DataStore = DataStoreFactory.CreateDefaultDataStore();



                slave.ListenAsync().GetAwaiter().GetResult();
            }
        }
Exemplo n.º 6
0
        public void NModbusSerialRtuSlave_BonusCharacter_VerifyTimeout()
        {
            SerialPort masterPort = ModbusMasterFixture.CreateAndOpenSerialPort(ModbusMasterFixture.DefaultMasterSerialPortName);
            SerialPort slavePort  = ModbusMasterFixture.CreateAndOpenSerialPort(ModbusMasterFixture.DefaultSlaveSerialPortName);

            using (var master = ModbusSerialMaster.CreateRtu(masterPort))
                using (var slave = ModbusSerialSlave.CreateRtu(1, slavePort))
                {
                    master.Transport.ReadTimeout = master.Transport.WriteTimeout = 1000;
                    slave.DataStore = DataStoreFactory.CreateTestDataStore();

                    Thread slaveThread = new Thread(slave.Listen);
                    slaveThread.IsBackground = true;
                    slaveThread.Start();

                    // assert successful communication
                    Assert.AreEqual(new bool[] { false, true }, master.ReadCoils(1, 1, 2));

                    // write "bonus" character
                    masterPort.Write("*");

                    // assert successful communication
                    Assert.AreEqual(new bool[] { false, true }, master.ReadCoils(1, 1, 2));
                }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            using (SerialPort slavePort = new SerialPort("COM2"))
            {
                // configure serial port
                slavePort.BaudRate = 19200;
                slavePort.DataBits = 8;
                slavePort.Parity   = Parity.None;
                slavePort.Open();
                slavePort.StopBits = StopBits.One;

                byte unitId = 1;

                var adapter = new SerialPortAdapter(slavePort);
                // create modbus slave
                ModbusLib.Device.ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, adapter);
                slave.DataStore = DataStoreFactory.CreateDefaultDataStore();
                for (int i = 1; i < 21; i++)
                {
                    slave.DataStore.HoldingRegisters[i] = (ushort)i;
                    slave.DataStore.InputRegisters[i]   = (ushort)i;
                }
                slave.DataStore.CoilDiscretes[1] = true;
                slave.DataStore.CoilDiscretes[8] = true;
                slave.DataStore.CoilDiscretes[9] = true;

                slave.ListenAsync().GetAwaiter().GetResult();
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates hosted slave 2
 /// </summary>
 private static void CreateHostedSlave2()
 {
     Client2Port.Open();
     HostedSlave2           = ModbusSerialSlave.CreateRtu(1, Client2Port);
     HostedSlave2.DataStore = HostedSlave1.DataStore;
     HostedSlave2.ModbusSlaveRequestReceived += new EventHandler <ModbusSlaveRequestEventArgs>(HostedSlave2_Request_Event);
     SlavesCreated[1] = true;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates Hosted Slave 1
 /// </summary>
 public static void CreateHostedSlave1()
 {
     Client1Port.Open();
     HostedSlave1           = ModbusSerialSlave.CreateRtu(1, Client1Port);
     HostedSlave1.DataStore = Modbus.Data.DataStoreFactory.CreateDefaultDataStore(0, 0, 0, 65535);
     HostedSlave1.ModbusSlaveRequestReceived += new EventHandler <ModbusSlaveRequestEventArgs>(HostedSlave1_Request_Event);
     SlavesCreated[0] = true;
 }
        public NModbusSerialRtuMasterNModbusSerialRtuSlaveFixture()
        {
            SetupSlaveSerialPort();
            Slave = ModbusSerialSlave.CreateRtu(SlaveAddress, SlaveSerialPort);
            StartSlave();

            MasterSerialPort = CreateAndOpenSerialPort(DefaultMasterSerialPortName);
            Master           = ModbusSerialMaster.CreateRtu(MasterSerialPort);
        }
Exemplo n.º 11
0
        public override void Init()
        {
            base.Init();

            SetupSlaveSerialPort();
            Slave = ModbusSerialSlave.CreateRtu(SlaveAddress, SlaveSerialPort);
            StartSlave();

            MasterUsbPort = CreateAndOpenUsbPort(DefaultMasterUsbPortId);
            Master        = ModbusSerialMaster.CreateRtu(MasterUsbPort);
        }
Exemplo n.º 12
0
 private void ModbusWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         ModbusSerialSlave ms = ModbusSerialSlave.CreateRtu(1, modbusCom);
         ms.DataStore = dataStore;
         ms.Listen();
     }
     catch
     {
     }
 }
Exemplo n.º 13
0
        public void rtu_slave()
        {
            byte unitId = (byte)numericUpDown1.Value;

            // create modbus slave
            ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, rtu_port);

            slave.DataStore = DataStoreFactory.CreateDefaultDataStore();
            slave.ModbusSlaveRequestReceived += (obj, args) => { Console.WriteLine("[MODBUS SLAVE] I got it!!!"); };

            slave.Listen();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Simple Modbus serial RTU slave example.
        /// </summary>
        public static void StartModbusSerialRtuSlave()
        {
            using (SerialPort slavePort = new SerialPort("COM2"))
            {
                // configure serial port
                slavePort.BaudRate = 9600;
                slavePort.DataBits = 8;
                slavePort.Parity   = Parity.None;
                slavePort.StopBits = StopBits.One;
                slavePort.Open();

                byte unitId = 1;

                // create modbus slave
                ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, slavePort);
                slave.DataStore = DataStoreFactory.CreateDefaultDataStore();

                slave.Listen();
            }
        }
Exemplo n.º 15
0
 private void btOpenCOM_Click(object sender, EventArgs e)
 {
     comPort.PortName = cmbPort.Text;
     comPort.BaudRate = int.Parse(cmbBaud.Text);
     comPort.DataBits = int.Parse(cmbDataBit.Text);
     if (cmbParity.Text.Substring(0, 1) == "0")
     {
         comPort.Parity = Parity.None;
     }
     else if (cmbParity.Text.Substring(0, 1) == "1")
     {
         comPort.Parity = Parity.Odd;
     }
     else if (cmbParity.Text.Substring(0, 1) == "2")
     {
         comPort.Parity = Parity.Even;
     }
     if (cmbStopBit.Text == "0")
     {
         comPort.StopBits = StopBits.None;
     }
     else if (cmbStopBit.Text == "1")
     {
         comPort.StopBits = StopBits.One;
     }
     comPort.Open();
     slave = ModbusSerialSlave.CreateRtu(slaveID, comPort);
     slave.ModbusSlaveRequestReceived += new EventHandler <ModbusSlaveRequestEventArgs>(Modbus_Request_Event);
     slave.DataStore = Modbus.Data.DataStoreFactory.CreateDefaultDataStore();
     slave.DataStore.DataStoreWrittenTo += new EventHandler <DataStoreEventArgs>(Modbus_DataStoreWriteTo);
     btOpenCOM.Enabled  = false;
     btCloseCOM.Enabled = true;
     slave.Listen();
     timer1.Enabled = true;
     for (int i = 0; i < 60; i++)
     {
         reg30[i] = (ushort)i;
     }
     reg_init();
 }
Exemplo n.º 16
0
        /// <summary>
        /// Simple Modbus serial RTU slave example.
        /// </summary>
        public static void StartModbusSerialRtuSlave()
        {
            using (SerialPort slavePort = new SerialPort("COM2"))
            {
                // configure serial port
                slavePort.BaudRate = 9600;
                slavePort.DataBits = 8;
                slavePort.Parity   = Parity.None;
                slavePort.StopBits = StopBits.One;
                slavePort.Open();

                byte unitId = 1;

                // create modbus slave
                ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, slavePort);
                slave.DataStore = DataStoreFactory.CreateDefaultDataStore();

                slave.Listen();

                slave.ModbusSlaveRequestReceived += (obj, args) => { Console.WriteLine("[MODBUS SLAVE] I HAVE it!!!"); };
            }
        }
Exemplo n.º 17
0
        public static ModbusSlave CreateSlave(byte id, SerialPortAdapter adapter, SerialModBusMode type)
        {
            ModbusSlave slave = null;

            if (adapter != null)
            {
                switch (type)
                {
                case SerialModBusMode.Rtu:
                    slave = ModbusSerialSlave.CreateRtu(id, adapter);
                    break;

                case SerialModBusMode.Ascii:
                    slave = ModbusSerialSlave.CreateAscii(id, adapter);
                    break;

                default:
                    break;
                }
            }
            return(slave);
        }
Exemplo n.º 18
0
        /// <summary>
        /// This method creates a modbus slave on the desired port.
        /// </summary>
        /// <param name="commPort">
        /// The name for the slave serial port
        /// </param>
        /// <param name="baudRate">
        /// the serial port baud rate
        /// </param>
        /// <param name="dataStore">
        /// The data store object used for registers
        /// </param>
        public void initialize(string commPort, int baudRate, out DataStore dataStore)
        {
            //configure Modbus Slave
            SerialPort slavePort = new SerialPort(commPort);

            slavePort.BaudRate = baudRate;
            slavePort.DataBits = 8;
            slavePort.Parity   = Parity.None;
            slavePort.StopBits = StopBits.One;
            slavePort.Open();

            byte slaveId = 1;

            //create slave on seperate thread
            ModbusSlave slave = ModbusSerialSlave.CreateRtu(slaveId, slavePort);

            slave.DataStore = DataStoreFactory.CreateDefaultDataStore();
            dataStore       = slave.DataStore;
            Thread slaveThread = new Thread(new ThreadStart(slave.Listen));

            slaveThread.Start();
        }
Exemplo n.º 19
0
        public static void Slave(string selectedPort, string selectedBaudRate, string selectedParity, string selectedDataBits, string selectedStopBits)
        {
            int baudRate = int.Parse(selectedBaudRate);
            int dataBits = int.Parse(selectedDataBits);


            using (SerialPort slavePort = new SerialPort(selectedPort))
            {
                slavePort.BaudRate = baudRate;
                slavePort.DataBits = dataBits;
                SetParity(selectedParity, slavePort);
                SetStopBits(selectedStopBits, slavePort);
                slavePort.Open();

                slave           = ModbusSerialSlave.CreateRtu(1, slavePort);
                slave.DataStore = DataStoreFactory.CreateDefaultDataStore();
                slave.DataStore.DataStoreWrittenTo += new EventHandler <DataStoreEventArgs>(Modbus_DataStoreWriteTo);

                SetDefaultValue();

                slave.Listen();
            }
        }
Exemplo n.º 20
0
        void doStuff()
        {
            DataStore data52 = DataStoreFactory.CreateDefaultDataStore();
            Dictionary <byte, DataStore> map = new Dictionary <byte, DataStore>();

            byte unitID52 = 52;

            map.Add(unitID52, data52);
            string portname = "";

            if (InvokeRequired)
            {
                this.Invoke((MethodInvoker) delegate() { portname = comboBox1.SelectedItem.ToString(); });
            }


            using (SerialPort com = new SerialPort(portname, 9600, Parity.None, 8, StopBits.One))
            {
                com.Open();
                slave = ModbusSerialSlave.CreateRtu(map, com);
                //slave.stop = false;
                slave.Listen();
            }
        }
Exemplo n.º 21
0
        private static void ServerProc(object obj)
        {
            Plugin self = (Plugin)obj;

            /*try
             * {
             *
             *      IPAddress address = new IPAddress(new byte[] { 0, 0, 0, 0 });
             *
             *              // create and start the TCP slave
             *              TcpListener slaveTcpListener = new TcpListener(address, 502);
             *  slaveTcpListener.Start();
             *  ModbusSlave tcpSlave = ModbusTcpSlave.CreateTcp(self._unit_id, slaveTcpListener);
             *  tcpSlave.DataStore = self._ds;
             *
             *  tcpSlave.Listen();
             * }
             * catch (Exception e)
             * {
             *  Env.Current.Logger.LogError(e.Message);
             * } */
            while (true)
            {
                var         slavePort   = new SerialPort(self._comport);
                ModbusSlave serialSlave = null;
                try
                {
                    slavePort.BaudRate = self._baudrate;
                    slavePort.DataBits = 8;
                    slavePort.Parity   = Parity.None;
                    slavePort.StopBits = StopBits.One;
                    Env.Current.Logger.LogError(String.Format("try to open port {0}", self._comport));
                    slavePort.Open();

                    // create modbus slave
                    serialSlave           = ModbusSerialSlave.CreateRtu(self._unit_id, slavePort);
                    serialSlave.DataStore = self._ds;
                    serialSlave.Listen();
                }
                catch (Exception e)
                {
                    Env.Current.Logger.LogError(e.Message);
                    if (e is ThreadAbortException)
                    {
                        return;
                    }
                    if (e is System.IO.IOException)
                    {
                        return;
                    }

                    if (serialSlave != null)
                    {
                        serialSlave.Dispose();
                    }
                    slavePort.Close();

                    Thread.Sleep(2000);
                }
            }
        }
Exemplo n.º 22
0
        private void bt_slave()
        {
            BluetoothClient bt_client = null;
            string          BtAdress  = null;
            string          BtName    = null;

            try
            {
                bt_client = new BluetoothClient();
            }
            catch { MessageBox.Show("Bluetooth модуль не подключен!"); return; }

            while (BtAdress == null)
            {
                foreach (BluetoothDeviceInfo device in bt_client.DiscoverDevices(10, true, false, false, false))
                {
                    Console.WriteLine(device.DeviceName);
                    BtAdress = device.DeviceAddress.ToString();
                    BtName   = device.DeviceName;
                }

                Thread.Sleep(1000);
            }

            label10.Text = BtName;

            // Создаем последовательный порт, используя стороннее приложение btcom.exe

            Process a = Process.Start(Environment.CurrentDirectory + "\\btcom.exe", "-b\"" + BtAdress + "\" -c -s1101");

            a.WaitForExit();

            // Поиск названия созданного порта

            const string             Win32_SerialPort = "Win32_SerialPort";
            SelectQuery              q = new SelectQuery(Win32_SerialPort);
            ManagementObjectSearcher s = new ManagementObjectSearcher(q);
            object id = null;

            foreach (object cur in s.Get())
            {
                ManagementObject mo = (ManagementObject)cur;
                id = mo.GetPropertyValue("DeviceID");
                object pnpId = mo.GetPropertyValue("PNPDeviceID");
                Console.WriteLine("DeviceID:    {0} ", id);
                Console.WriteLine("PNPDeviceID: {0} ", pnpId);
                Console.WriteLine("");
            }

            //id = "COM2";

            if (id != null)
            {
                label11.BeginInvoke((MethodInvoker)(() => label11.Text = id.ToString()));

                int bd = 9600;
                comboBox5.BeginInvoke((MethodInvoker)(() => bd = int.Parse(comboBox5.SelectedItem.ToString())));

                // Открываем последовательный порт
                btSerialPort = new SerialPort(id.ToString(), bd);

                try
                {
                    //ModbusRtuMaster.OpenPort(btSerialPort);
                    btSerialPort.Open();

                    byte unitId = (byte)numericUpDown1.Value;

                    // create modbus slave
                    ModbusSlave slave = ModbusSerialSlave.CreateRtu(unitId, btSerialPort);
                    slave.DataStore = DataStoreFactory.CreateDefaultDataStore();
                    slave.ModbusSlaveRequestReceived += (obj, args) => { Console.WriteLine("[MODBUS SLAVE] I got it!!!"); };

                    Console.WriteLine("BT PORT IS OPEN!");

                    slave.Listen();
                }
                catch
                {
                    MessageBox.Show("Ошибка открытия порта!");
                }
            }
        }
Exemplo n.º 23
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form_ES_Modbus());

            //string portName = "COM3";
            //int baudRate = 9600;
            //byte slaveAddress = 1;
            //ushort startAddress = 7;
            //ushort numberOfPoints = 1;

            //var master = ModbusSerialMaster.CreateRtu(new System.IO.Ports.SerialPort(portName, baudRate));

            //while (true)
            //{
            //    Console.Write("\r{0}", master.ReadHoldingRegisters(slaveAddress, startAddress, numberOfPoints)[0]);
            //}

            {
                SerialPort serialPort = new SerialPort()
                {
                    PortName = "COM3",
                    BaudRate = 9600,
                    DataBits = 8,
                    Parity   = Parity.Even,
                    StopBits = StopBits.One
                };
                try
                {
                    serialPort.Open();
                }

                catch (IOException)
                {
                    Console.WriteLine("Не удалось подключиться к порту");
                }

                ModbusSerialMaster master = ModbusSerialMaster.CreateRtu(serialPort);
                byte slaveID = 1;

                SerialPort slaveSerialPort = new SerialPort()
                {
                    PortName = "COM3",
                    BaudRate = 9600,
                    DataBits = 8,
                    Parity   = Parity.Even,
                    StopBits = StopBits.One
                };
                ModbusSlave slave       = ModbusSerialSlave.CreateRtu(slaveID, slaveSerialPort);
                Thread      slaveThread = new Thread(new ThreadStart(slave.Listen));
                slaveThread.Start();

                ushort startAddress = 4;
                ushort numRegisters = 4;

                // Запись в один регистр

                //master.WriteSingleRegister(slaveID, 7, 4000);

                // Запись в несколько регистров НЕ РАБОТАЕТ

                //ushort[] data = { 4444, 3333, 1111, 2222};
                //master.WriteMultipleRegisters(slaveID, startAddress, data);

                // Чтение нескольких регистров

                ushort[] coils = master.ReadHoldingRegisters(slaveID, startAddress, numRegisters);

                for (int i = 0; i < numRegisters; i++)
                {
                    Console.WriteLine("Значение в регистре {0} = {1}", (int)startAddress + i, coils[i]);
                }

                //Console.Write("Для выхода нажмите любую клавишу...");
                //Console.ReadKey(true);
            }
        }
Exemplo n.º 24
0
        private void ButtonOpenRTUASCII_Click(object sender, EventArgs e)
        {
            SerPort = new SerialPort();

            if (!string.IsNullOrWhiteSpace(tbManualCOM.Text))
            {
                SerPort.PortName = tbManualCOM.Text;
            }
            else
            {
                SerPort.PortName = cbPort.SelectedItem.ToString();
            }

            SerPort.BaudRate  = Convert.ToInt32(cbBaud.SelectedItem.ToString());
            SerPort.Parity    = (Parity)cbParity.SelectedIndex;
            SerPort.DataBits  = Convert.ToInt32(cbDataBits.SelectedItem.ToString());
            SerPort.StopBits  = (StopBits)cbStopBits.SelectedIndex + 1;
            SerPort.Handshake = Handshake.None;
            SerPort.DtrEnable = true;
            SerPort.RtsEnable = true;

            try
            {
                SerPort.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            if (cbCommMode.SelectedIndex == 0)             //RTU
            {
                slave = ModbusSerialSlave.CreateRtu(unitID, SerPort);
            }
            else if (cbCommMode.SelectedIndex == 3)             //ASCIIoverRTU
            {
                slave = ModbusSerialSlave.CreateAscii(unitID, SerPort);
            }

            slave.ModbusSlaveRequestReceived += MasterRequests;
            slave.DataStore = dataStore;

            btnOpenRTUASCII.Enabled    = false;
            btnOpenRTUASCII.BackColor  = Color.Gainsboro;
            btnCloseRTUASCII.Enabled   = true;
            btnCloseRTUASCII.BackColor = Color.LightSteelBlue;
            btnRefresh.Enabled         = false;
            btnRefresh.BackColor       = Color.Gainsboro;

            cbPort.Enabled      = false;
            cbBaud.Enabled      = false;
            cbDataBits.Enabled  = false;
            cbParity.Enabled    = false;
            cbStopBits.Enabled  = false;
            cbCommMode.Enabled  = false;
            cbRowCount.Enabled  = false;
            tbManualCOM.Enabled = false;

            bckgndThread = new Thread(BckgndThreadTask)
            {
                IsBackground = true
            };
            bckgndThread.Start();
        }