Exemple #1
0
        //-------------------------------------------------------------------------------------------------//

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

            Logfile.WriteCalled(this.logLevel, 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.dcDriveMut = new DCDriveMut(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(this.logLevel, STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }
Exemple #2
0
        //-------------------------------------------------------------------------------------------------//

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

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            bool success = false;

            this.lastError = null;

            try
            {
                //
                // Open a connection to the specified IP address and port number
                //
                this.tcpClient = new TcpClient(this.ipaddr, this.ipport);
                success        = true;
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                this.lastError = STRERR_UnableToOpenNetworkConnection + this.ipaddr + ":" + this.ipport.ToString();
            }

            if (success == true)
            {
                this.tcpClient.ReceiveTimeout = this.receiveTimeout;
                this.modbusIpMaster           = ModbusIpMaster.CreateTcp(tcpClient);
            }

            this.connectionOpen = success;

            string logMessage = STRLOG_Success + success.ToString();

            Logfile.WriteCompleted(this.logLevel, STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }