Пример #1
0
        private void Open(DevicePortTcp tcp)
        {
            Ping      ping  = new Ping();
            PingReply reply = null;

            reply = ping.Send(tcp.Address, 1000);

            if (reply.Status != IPStatus.Success)
            {
                throw new IOException(this, String.Format("Failed to ping Moxa ioLogic1200 device '{0}' at {1}", Name, tcp));
            }

            _ipAddress = System.Text.Encoding.UTF8.GetBytes(tcp.Address.ToString());
            _password  = System.Text.Encoding.UTF8.GetBytes("");
            _port      = (ushort)tcp.Port;

            MoxaStatus status = (MoxaStatus)MXIO_CS.MXEIO_E1K_Connect(_ipAddress, _port, _timeout, _hConn, _password);

            if (status != MoxaStatus.Ok)
            {
                throw new IOException(this, String.Format("Failed to connect to Moxa ioLogic1200 device '{0}' at {1}", Name, tcp));
            }

            // Check Connection
            CheckConnection(false);
        }
Пример #2
0
        /// <summary>
        /// Opens a connection to this device using the device's specified <see cref="Port"/>.
        /// </summary>
        public void Open()
        {
            DevicePortTcp tcpPort = Port as DevicePortTcp;

            if (tcpPort == null)
            {
                DevicePortName namedPort = Port as DevicePortName;

                if (namedPort != null)
                {
                    tcpPort      = DevicePortTcp.FromString(namedPort.Name);
                    tcpPort.Port = _modbusPort;
                }
            }

            if (tcpPort != null)
            {
                tcpPort.Port = _modbusPort;
                Open(tcpPort);
                return;
            }

            throw new IOException(this, "Invalid TCP port specified for Moxa ioLogic 1200 controller.");
        }