Example #1
0
        //-------------------------------------------------------------------------------------------------//

        public bool CreateConnection()
        {
            const string STRLOG_MethodName = "CreateConnection";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            bool success = false;

            try
            {
                this.tcpClient  = new TcpClient(this.machineIP, this.machinePort);
                this.master     = ModbusIpMaster.CreateTcp(this.tcpClient);
                this.acDrive    = new ACDrive(this.master);
                this.powerMeter = new PowerMeter(this.master);

                success        = true;
                this.lastError = null;
            }
            catch (Exception ex)
            {
                this.lastError = ex.Message;
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_Success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }
        //-------------------------------------------------------------------------------------------------//
        public bool CreateConnection()
        {
            const string STRLOG_MethodName = "CreateConnection";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            bool success = false;
            try
            {
                this.tcpClient = new TcpClient(this.machineIP, this.machinePort);
                this.master = ModbusIpMaster.CreateTcp(this.tcpClient);
                this.acDrive = new ACDrive(this.master);
                this.powerMeter = new PowerMeter(this.master);

                success = true;
                this.lastError = null;
            }
            catch (Exception ex)
            {
                this.lastError = ex.Message;
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_Success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return success;
        }
Example #3
0
        //-------------------------------------------------------------------------------------------------//
        public PLC(XmlNode xmlNodeEquipmentConfig, DriverMachine.KeepAliveCallback keepAliveCallback)
        {
            const string STRLOG_MethodName = "PLC";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            try
            {
                //
                // Initialise local variables
                //
                this.keepAliveCallback = keepAliveCallback;
                this.initialised = false;

                //
                // Initialise properties
                //
                this.lastError = null;
                this.connectionOpen = false;

                //
                // Get the IP address and port number to use
                //
                XmlNode xmlNodePLC = XmlUtilities.GetXmlNode(xmlNodeEquipmentConfig, Consts.STRXML_plc);
                XmlNode xmlNodeNetwork = XmlUtilities.GetXmlNode(xmlNodePLC, Consts.STRXML_network, false);
                this.ipaddr = XmlUtilities.GetXmlValue(xmlNodeNetwork, Consts.STRXML_ipAddr, false);
                IPAddress ipaddr = IPAddress.Parse(this.ipaddr);
                this.ipport = XmlUtilities.GetIntValue(xmlNodeNetwork, Consts.STRXML_ipPort);
                Logfile.Write(STRLOG_IPaddr + this.ipaddr.ToString() +
                    Logfile.STRLOG_Spacer + STRLOG_IPport + this.ipport.ToString());

                //
                // Get the network timeouts
                //
                XmlNode xmlNodeTimeouts = XmlUtilities.GetXmlNode(xmlNodeNetwork, Consts.STRXML_timeouts, false);
                this.receiveTimeout = XmlUtilities.GetIntValue(xmlNodeTimeouts, Consts.STRXML_receive);
                Logfile.Write(STRLOG_ReceiveTimout + this.receiveTimeout.ToString() + STRLOG_MilliSecs);

                //
                // Get Modbus slave identity
                //
                XmlNode xmlNodeModbus = XmlUtilities.GetXmlNode(xmlNodePLC, Consts.STRXML_modbus, false);
                this.slaveId = XmlUtilities.GetIntValue(xmlNodeModbus, Consts.STRXML_slaveId);
                Logfile.Write(STRLOG_ModbusSlaveId + this.slaveId.ToString());

                //
                // Get the flag to determine if equipment initialisation is required
                //
                this.doInitialise = XmlUtilities.GetBoolValue(xmlNodePLC, Consts.STRXML_doInitialise, false);
                Logfile.Write(STRLOG_DoInitialise + this.doInitialise.ToString());

                //
                // Get the time it takes to initialise
                //
                this.initialiseDelay = XmlUtilities.GetIntValue(xmlNodePLC, Consts.STRXML_initialiseDelay);

                //
                // Determine the logging level for this class
                //
                try
                {
                    this.logLevel = (Logfile.LoggingLevels)Utilities.GetIntAppSetting(STRLOG_ClassName);
                }
                catch
                {
                    this.logLevel = Logfile.LoggingLevels.Minimum;
                }
                Logfile.Write(Logfile.STRLOG_LogLevel + this.logLevel.ToString());

                this.syncMonitor = new SyncMonitor(this.ipaddr, this.ipport);
                this.syncMonitor.ReceiveTimeout = this.receiveTimeout;
                this.syncMonitor.SlaveId = this.slaveId;
                this.powerMeter = new PowerMeter(this.ipaddr, this.ipport);
                this.powerMeter.ReceiveTimeout = this.receiveTimeout;
                this.powerMeter.SlaveId = this.slaveId;
            }
            catch (Exception ex)
            {
                //
                // Log the message and throw the exception back to the caller
                //
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }