Exemple #1
0
        public static void ReadConfig(ModbusServerConfig serverConfig, XmlReader reader)
        {
            serverConfig.IpAddress = reader["address"];
            int port;

            if (int.TryParse(reader["port"], out port))
            {
                serverConfig.Port = port;
            }
            int timeOut;

            if (int.TryParse(reader["timeout"], out timeOut))
            {
                serverConfig.TimeOut = timeOut;
            }
            int maxconnect;

            if (int.TryParse(reader["maxconnect"], out maxconnect))
            {
                serverConfig.MaxConnect = maxconnect;
            }
            int salveId;

            if (int.TryParse(reader["salveid"], out salveId))
            {
                serverConfig.SalveId = salveId;
            }
            serverConfig.SignalListFilePath = reader["signallist"];
        }
Exemple #2
0
 public bool OnInit()
 {
     _log.NormalLog(string.Format("ModbusServerHanderTask:Init=>Initing"));
     try
     {
         _config = ReaderXMLUtil.ReadXMLConfig <ModbusServerConfig>("../../../../conf/Configuration.xml", ModbusServerConfig.ReadConfig, "setup", "ModbusTCPServerHandlerTask")[0];
         if (_config.SignalListFilePath == "")
         {
             _log.ErrorLog("ModbusServerHanderTask Init fail: signal file path is null!");
             return(false);
         }
         _workbook = XmlSerialiaztion.XmlDeserial <XMLWorkbook>(_config.SignalListFilePath, _log);
         if (_workbook == default(XMLWorkbook))
         {
             _log.ErrorLog("ModbusServerHanderTask Init fail:Read signal file fail!");
             return(false);
         }
         _points = PointsCollcetCreate.CreateMoudbus(_workbook, _log);
         ModbusPointsRegister.Register(_points, _log);
         _timeout = new TimeOut("ModbusServerHanderTask", _config.TimeOut, _log);
         _server  = new ModbusTCPServer(new EthernetSetUp(_config.IpAddress, _config.Port), _timeout, _log, _config.MaxConnect, _config.SalveId, SocketServers.SocketServerType.SaeaServer);
         if (_server.Init())
         {
             _log.NormalLog(string.Format("ModbusServerHanderTask:Initing=>Inited"));
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         _log.ErrorLog(string.Format("ModbusServerHanderTask Init fail:{0}", e.Message));
         return(false);
     }
 }