Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public bool Connect()
        {
            try
            {
                byte[] bytStatus = new byte[1];
                int    num       = MXIO_CS.MXEIO_Init();
                switch (MXIO_CS.MXEIO_E1K_Connect(Encoding.UTF8.GetBytes(this.ipAddress), this.port, this.timeOut, this.hConnection, Encoding.UTF8.GetBytes(this.password)))
                {
                case 0:
                    switch (MXIO_CS.MXEIO_CheckConnection(this.hConnection[0], this.timeOut, bytStatus))
                    {
                    case 0:
                        return(true);

                    case 0x7d1:
                    case 0xfa2:
                        MXIO_CS.MXEIO_Exit();
                        break;
                    }
                    return(false);

                case 0x7d1:
                case 0xfa2:
                    MXIO_CS.MXEIO_Exit();
                    break;
                }
                return(false);
            }
            catch (Exception exception)
            {
                CLog.WriteErrLogInTrace(string.Format("在连接IOLogik时出错,{0}", exception.Message));
                return(false);
            }
        }
Ejemplo n.º 3
0
        public override void Open()
        {
            int ret;

            Manager.Logger.Log(LogLevel.INFO, "IP address: {0}", IP);
            Manager.Logger.Log(LogLevel.INFO, "Port: {0}", Port);

            // Ping.
            Ping      ping = new Ping();
            PingReply rep;

            rep = ping.Send(IP, (int)Manager.Timeout);
            if (rep.Status != IPStatus.Success)
            {
                throw new MXIOException("Cannot reach the IO module.");
            }

            // Connect.
            int[] conn = new int[1];
            ret = MXIO_CS.MXEIO_E1K_Connect(Encoding.UTF8.GetBytes(IP), Port, Manager.Timeout, conn, new byte[0]);
            if (ret != MXIO_CS.MXIO_OK)
            {
                throw new MXIOException("MXEIO_E1K_Connect failed: {0}.", ret);
            }
            this.connection = conn[0];

            // Check connection.
            byte[] bytCheckStatus = new byte[1];
            ret = MXIO_CS.MXEIO_CheckConnection(connection, Manager.Timeout, bytCheckStatus);
            if (ret != MXIO_CS.MXIO_OK)
            {
                throw new MXIOException("MXEIO_CheckConnection failed: {0}.", ret);
            }
            if (bytCheckStatus[0] != MXIO_CS.CHECK_CONNECTION_OK)
            {
                string msg;
                switch (bytCheckStatus[0])
                {
                case MXIO_CS.CHECK_CONNECTION_FAIL:
                    msg = "fail";
                    break;

                case MXIO_CS.CHECK_CONNECTION_TIME_OUT:
                    msg = "timeout";
                    break;

                default:
                    msg = "unknown: " + bytCheckStatus[0];
                    break;
                }
                throw new MXIOException("MXEIO_CheckConnection status failed: {0}.", msg);
            }
        }
Ejemplo n.º 4
0
 public VmIOReaderHome()
 {
     uiContext = SynchronizationContext.Current;
     DIs       = new ObservableCollection <DigitalInput>();
     Relays    = new ObservableCollection <Relay>();
     SetupHTTPClient();
     ret = MXIO_CS.MXEIO_Init();
     ret = MXIO_CS.MXEIO_E1K_Connect(System.Text.Encoding.UTF8.GetBytes(IpAddress), Port, Timeout, hConnection, System.Text.Encoding.UTF8.GetBytes(Password));
     testDelay();
     DIs.Insert(0, new DigitalInput()
     {
         diIndex  = 0,
         diMode   = 0,
         diStatus = 0
     });
     DIs.Insert(1, new DigitalInput()
     {
         diIndex  = 0,
         diMode   = 0,
         diStatus = 0
     }); DIs.Insert(0, new DigitalInput()
     {
         diIndex  = 0,
         diMode   = 0,
         diStatus = 0
     });
     DIs.Insert(1, new DigitalInput()
     {
         diIndex  = 1,
         diMode   = 0,
         diStatus = 0
     });
     Relays.Insert(0, new Relay()
     {
         relayIndex             = 0,
         relayStatus            = 0,
         relayCurrentCount      = 0,
         relayCurrentCountReset = 0,
         relayMode       = 0,
         relayTotalCount = 0
     });
     Relays.Insert(1, new Relay()
     {
         relayIndex             = 1,
         relayStatus            = 0,
         relayCurrentCount      = 0,
         relayCurrentCountReset = 0,
         relayMode       = 0,
         relayTotalCount = 0
     });
     //StartDIListenerThread();
 }
Ejemplo n.º 5
0
        private int CreateIoHandle()
        {
            ret = MXIO_CS.MXEIO_E1K_Connect(System.Text.Encoding.UTF8.GetBytes(ioLogicIP), ioLogicPortNo, ioLogicTimeout, hConnection, System.Text.Encoding.UTF8.GetBytes(Password));
            MXEIO_Error.CheckErr(ret, "MXEIO_E1K_Connect");
            if (ret == MXIO_CS.MXIO_OK)
            {
                tbCommunication.AppendText("MXEIO_E1K_Connect Success.\r\n");
            }
            else
            {
                tbCommunication.AppendText("MXEIO_E1K_Connect FAILED!!!.\r\n");
            }

            return(ret);
        }
Ejemplo n.º 6
0
        private void CheckConnection(bool attemptReconnect)
        {
            // Check Connection
            Connected = false;

            byte[]     checkStatus = new byte[1];
            MoxaStatus status      = (MoxaStatus)MXIO_CS.MXEIO_CheckConnection(_hConn[0], _timeout, checkStatus);

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

            if (checkStatus[0] == MXIO_CS.CHECK_CONNECTION_OK)
            {
                Connected = true;
                return;
            }

            if (attemptReconnect)
            {
                status = (MoxaStatus)MXIO_CS.MXEIO_E1K_Connect(_ipAddress, _port, _timeout, _hConn, _password);
                if (status == MoxaStatus.Ok)
                {
                    if (Logging)
                    {
                        Log.Trace(IOComponent.Instance.Name).Warn(this.ToString(), "Connection to Moxa ioLogic1200 device restored.");
                    }

                    return;
                }
            }

            switch (checkStatus[0])
            {
            case MXIO_CS.CHECK_CONNECTION_FAIL:
                throw new IOException(this, String.Format("Connection failed to Moxa ioLogic1200 device '{0}'.", Name));

            case MXIO_CS.CHECK_CONNECTION_TIME_OUT:
                throw new IOException(this, String.Format("Connection timed-out to Moxa ioLogic1200 device '{0}'.", Name));

            default:
                throw new IOException(this, String.Format("Unknown connection failure ({1}) to Moxa ioLogic1200 device '{0}'.", Name, checkStatus[0]));
            }
        }
Ejemplo n.º 7
0
        private void eXX_DO_Write(string IPAddr, UInt16 Port, UInt32 Timeout, byte Channel, uint Value, int ModuleType)
        {
            Int32[] hConnection = new Int32[16];
            string  Password    = "";
            int     ret         = 0;

            try
            {
                this.myLog.LogAlert(AlertType.System, this.id.ToString(), this.GetType().ToString(), "e1K_DO_Write()", "IPAddr = " + IPAddr.ToString(), "system");
                int init = MXIO_CS.MXEIO_Init();

                if ((MXIO_ModuleType)ModuleType == MXIO_ModuleType.E1212)
                {
                    ret = MXIO_CS.MXEIO_E1K_Connect(System.Text.Encoding.UTF8.GetBytes(IPAddr), Port, Timeout, hConnection, System.Text.Encoding.UTF8.GetBytes(Password));
                    ret = MXIO_CS.E1K_DO_Writes(hConnection[0], Channel, 1, Value);
                    MXIO_CS.MXEIO_Disconnect(hConnection[0]);
                }
                else if ((MXIO_ModuleType)ModuleType == MXIO_ModuleType.E2210)
                {
                    byte bytSlot = 0;
                    ret = MXIO_CS.MXEIO_Connect(System.Text.Encoding.UTF8.GetBytes(IPAddr), Port, Timeout, hConnection);
                    ret = MXIO_CS.DO_Writes(hConnection[0], bytSlot, Channel, 1, Value);
                    MXIO_CS.MXEIO_Disconnect(hConnection[0]);
                }

                MXIO_CS.MXEIO_Exit();

                if (ret != 0)
                {
                    this.myLog.LogAlert(AlertType.Error, this.id.ToString(), this.GetType().ToString(), "e1K_DO_Write()",
                                        "Error code, ret = " + ret.ToString(), "system");
                }
            }
            catch (Exception ex)
            {
                this.myLog.LogAlert(AlertType.Error, this.id.ToString(), this.GetType().ToString(), "e1K_DO_Write()",
                                    ex.ToString(), "system");
            }
        }