Ejemplo n.º 1
0
        private void NewMethod(int index)
        {
            bytCount        = 1;
            bytStartChannel = (byte)(0 + index);
            Console.WriteLine("Start new update method");
            TimeSpan startTime = _timer.Elapsed;
            //Set Ch{0}~ch{1} DO Direction DO Mode value = ON
            UInt32 dwSetDOValue = (uint)(Relays[index].relayStatus == 0 ? 1 : 0);

            Console.WriteLine(dwSetDOValue);
            ret = MXIO_CS.E1K_DO_Writes(hConnection[0], bytStartChannel, bytCount, dwSetDOValue);
            Console.WriteLine(ret);
            if (ret == MXIO_CS.MXIO_OK)
            {
            }
            Console.WriteLine("End new update method");
            TimeSpan elapsedTime = _timer.Elapsed - startTime;

            Console.WriteLine("Elapsed time NEW: " + elapsedTime);
        }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to set the current value of the digital output bit (0 or 1) at the specified channel address to the specified value.
        /// Retries until successful or the max number of attempts is reached.
        /// </summary>
        /// <param name="channel">The channel address.</param>
        /// <param name="value">The set value (0 or 1).</param>
        /// <param name="attempt">The max number of retry attempts.</param>
        /// <exception cref="System.IO.IOException"></exception>
        public void SetDOBit(int channel, int value, int attempt)
        {
            /*
             * byte wordLength = (byte)GetDIOWordLength();
             *
             *
             * int startChannel = channel / wordLength;
             *
             * MoxaStatus status = (MoxaStatus)MXIO_CS.E1K_DO_Reads(_hConn[0], (byte)startChannel, wordLength, readValues);
             *
             * if (status != MoxaStatus.Ok)
             *  throw new IOException(this, String.Format("Could not read state before setting MOXA DO channel {0} ({1}).", channel, status));
             *
             * uint bitMask = (uint)1 << (channel % wordLength);
             *
             * if (value > 0)
             *  readValues[0] |= bitMask;
             * else if (value < 0)
             *  readValues[0] &= ~bitMask;
             */

            lock (_lock)
            {
                MoxaStatus status = (MoxaStatus)MXIO_CS.E1K_DO_Writes(_hConn[0], (byte)channel, (byte)1, (uint)value);

                if (status != MoxaStatus.Ok)
                {
                    CheckConnection(true);

                    if (attempt >= _retries)
                    {
                        throw new IOException(this, String.Format("Could not write to MOXA DO channel {0} after {1} retries ({2}).", channel, attempt, status));
                    }

                    SetDOBit(channel, value, attempt + 1);
                }
            }
        }
Ejemplo n.º 4
0
        public bool Do_Writes(byte channel, uint dwSetDOValue)
        {
            try
            {
                byte bytCount        = 1;
                byte bytStartChannel = channel;
                switch (MXIO_CS.E1K_DO_Writes(this.hConnection[0], bytStartChannel, bytCount, dwSetDOValue))
                {
                case 0:
                    return(true);

                case 0x7d1:
                case 0xfa2:
                    MXIO_CS.MXEIO_Exit();
                    break;
                }
                return(false);
            }
            catch (Exception exception)
            {
                CLog.WriteErrLogInTrace(string.Format("在设置IO端口状态时出错,{0}", exception.Message));
                return(false);
            }
        }
Ejemplo n.º 5
0
 public override void SetDigitalOutput(int output, bool value)
 {
     InvokeWithRetry("SetDigitalOutput", () => MXIO_CS.E1K_DO_Writes(connection, (byte)output, 1, (uint)(value ? 1 : 0)));
 }