Пример #1
0
        public bool SetModbusRtuSerialPort(SerialPort serialPort)
        {
            bool success = true;

            try
            {
                if (this.modbusRtu.TryOpenSerialPort(serialPort))
                {
                    Stop();
                    InitializeModbusRtu(serialPort);
                    SerialPorConfigerHelper.SaveSerialPortToConfigFile(serialPort);
                    Start();
                }
                else
                {
                    success = false;
                }
            }
            catch (Exception)
            {
                success = false;
            }

            Start();

            return(success);
        }
Пример #2
0
        private bool InitializeModbusRtuSerialPortFormConfigFile()
        {
            bool success = true;

            try
            {
                Stop();
                SerialPort serialPortFromConfigFile
                    = SerialPorConfigerHelper.GetSerialPortFormConfigFile();
                InitializeModbusRtu(serialPortFromConfigFile);
            }
            catch (Exception)
            {
                success = false;
            }
            Start();
            return(success);
        }