示例#1
0
        /// <summary>
        /// reads a byte from the specified port
        /// </summary>
        /// <param name="port">port address (2 bytes)</param>
        /// <returns>the data byte from the port</returns>
        public int Read(int port)
        {
            lock (portLock)
            {
                int ret = 0;
                for (int i = 0; i < ADDR_PINS.Length; i++)
                {
                    int j = 1 << i;
                    if ((port & j) > 0)
                    {
                        GPIO.SetPinLevel(ADDR_PINS[i], 1);
                    }
                    else
                    {
                        GPIO.SetPinLevel(ADDR_PINS[i], 0);
                    }
                }
                GPIO.SetPinLevel(IOR_PIN, 0);
                for (int i = 0; i < DATA_PINS.Length; i++)
                {
                    int pin = DATA_PINS[i];

                    bool level = GPIO.GetPinLevel(pin);
                    ret = level ? ret | (1 << i) : ret & ~(1 << i);
                }
                GPIO.SetPinLevel(IOR_PIN, 1);
                return(ret);
            }
        }
示例#2
0
        /// <summary>
        /// writes a byte to the specified port
        /// </summary>
        /// <param name="port">port address</param>
        /// <param name="data">port data</param>
        public void Write(int port, int data)
        {
            lock (portLock)
            {
                for (int i = 0; i < DATA_PINS.Length; i++)
                {
                    GPIO.SetPinDir(DATA_PINS[i], true);
                    int j = 1 << i;
                    if ((data & j) > 0)
                    {
                        GPIO.SetPinLevel(DATA_PINS[i], 1);
                    }
                    else
                    {
                        GPIO.SetPinLevel(DATA_PINS[i], 0);
                    }
                }
                for (int i = 0; i < ADDR_PINS.Length; i++)
                {
                    int j = 1 << i;
                    if ((port & j) > 0)
                    {
                        GPIO.SetPinLevel(ADDR_PINS[i], 1);
                    }
                    else
                    {
                        GPIO.SetPinLevel(ADDR_PINS[i], 0);
                    }
                }

                GPIO.SetPinLevel(IOW_PIN, 0);

                GPIO.SetPinLevel(IOW_PIN, 1);
                for (int i = 0; i < DATA_PINS.Length; i++)
                {
                    int pin = DATA_PINS[i];
                    GPIO.SetPinDir(pin, false);
                }
            }
        }