Ejemplo n.º 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public I_ModbusTCP_NR()
        {
            this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
            this.backgroundWorker1.WorkerReportsProgress = true;
            this.backgroundWorker1.WorkerSupportsCancellation = true;
            this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
            this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
            this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);

            m_config_Modbus = new CONFG_Modbus_NR("config\\Modbus_NR.ini");
            sendRate = Convert.ToInt32(m_config_Modbus.m_SendRate * 1000);
            callAllRate = sendRate * 4;

            logfile = "log.txt";
            FileStream fs = new FileStream(logfile, FileMode.OpenOrCreate);
            fs.Close();

            sw = File.AppendText(logfile);
            sw.WriteLine("初始化成功!");
            sw.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public I_ModbusCOM_NR()
        {
            m_config_Modbus = new CONFG_Modbus_NR("config\\Modbus_NR.ini");
            sendRate =Convert.ToInt32( m_config_Modbus.m_SendRate * 1000);
            callAllRate = sendRate * 4;

            port1 = new SerialPort(m_config_Modbus.m_COM);
            port1.BaudRate = m_config_Modbus.m_BaudRate;//波特率
            port1.Parity = (Parity)m_config_Modbus.m_Parity;//奇偶校验位
            port1.DataBits = m_config_Modbus.m_DataBits;//数据位
            port1.StopBits =(StopBits)m_config_Modbus.m_StopBits;//停止位
            port1.Handshake =( Handshake)m_config_Modbus.m_Handshake;//控制协议

            logfile = "log.txt";
            FileStream fs = new FileStream(logfile, FileMode.OpenOrCreate);
            fs.Close();
            try
            {
                sw = File.AppendText(logfile);
                sw.WriteLine(DateTime.Now.ToString() + " 初始化成功!");
                sw.Close();
            }
            catch { }
        }