Ejemplo n.º 1
0
        public void InitializeController()
        {
            //SimpleIOClass.ConfigureMCP2200(0xFF, 115200, 0, 0, false, false, false, false);

            if (!SimpleIOClass.IsConnected())
            {
                SimpleIOClass.InitMCP2200(VendorID, ProductID);
            }
        }
Ejemplo n.º 2
0
        public bool SetAllPortState(byte ctrlState)
        {
            bool retVal = SimpleIOClass.WritePort((uint)ctrlState);

            if (retVal)
            {
                _ioStateMap = ctrlState;
            }

            return(retVal);
        }
Ejemplo n.º 3
0
        public unsafe void GetAllPortState(ref byte portState)
        {
            uint states = 0;

            if (SimpleIOClass.ReadPort(&states))
            {
                _ioStateMap = (byte)states;
            }

            portState = _ioStateMap;
        }
Ejemplo n.º 4
0
        public bool WriteEEPROM(byte[] value)
        {
            int retVal = 0;

            for (int i = 0; i < 256; i++)
            {
                retVal += SimpleIOClass.WriteEEPROM((uint)i, value[i]);
            }

            return(retVal == 0);
        }
Ejemplo n.º 5
0
        public byte[] ReadEEPROM()
        {
            byte[] retVal = new byte[256];

            for (int i = 0; i < 256; i++)
            {
                retVal[i] = (byte)SimpleIOClass.ReadEEPROM((uint)i);
            }

            return(retVal);
        }
Ejemplo n.º 6
0
        public ICtrl SetController(uint controllerNumber)
        {
            int curController = SimpleIOClass.GetSelectedDevice();

            if (SimpleIOClass.SelectDevice(controllerNumber) == 0)
            {
                return(_controllers[(int)controllerNumber]);
            }
            else
            {
                return(_controllers[curController]);
            }
        }
Ejemplo n.º 7
0
        public bool WriteEEPROM(uint address, byte value)
        {
            int retVal = SimpleIOClass.WriteEEPROM(address, value);

            if (retVal == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        public void InitializeAll()
        {
            SimpleIOClass.InitMCP2200(VendorID, ProductID);

            _deviceCount = SimpleIOClass.GetNoOfDevices();

            for (uint i = 0; i < _deviceCount; i++)
            {
                _controllers.Add(new DIO8_MCP22(i));

                _controllers[(int)i].InitializeController();
                _controllers[(int)i].Interrupt += new ICtrl_PortStateChanged(DIO8_MCP22_Manager_Interrupt);
            }
        }
Ejemplo n.º 9
0
        public void SetPortMode(uint port, CtrlMode mode)
        {
            if (mode == CtrlMode.Output)
            {
                _ioModeMap = (byte)(_ioModeMap & ~PortMask[port]);
            }
            else
            {
                _ioModeMap |= PortMask[port];
            }

            SimpleIOClass.ConfigureIO(_ioModeMap);
            SimpleIOClass.WritePort(_ioStateMap);
        }
Ejemplo n.º 10
0
        private void PollingThreadProc()
        {
            WaitHandle[] waits      = new WaitHandle[] { _pollFlag, _quitFlag };
            int          waitResult = WaitHandle.WaitAny(waits);

            if (waitResult != 0)
            {
                return;
            }

            long[] _portDebounce = new long[8];
            GetAllPortState(ref _ioStateMap);
            _ioModeMap = GetAllPortModes();

            while (!_quitFlag.WaitOne(0))
            {
                if (_pollFlag.WaitOne(25))
                {
                    byte curStates = (byte)SimpleIOClass.ReadPortValue();

                    if (curStates != _ioStateMap)
                    {
                        DateTime now = DateTime.Now;

                        for (uint i = 0; i < 8; i++)
                        {
//                            if ((_ioModeMap & PortMask[i]) > 0 && (_ioStateMap & PortMask[i]) != (curStates & PortMask[i]))
                            if ((_ioStateMap & PortMask[i]) != (curStates & PortMask[i]))
                            {
                                if (now.Ticks - _portDebounce[i] > DEBOUNCE_MIN_TICKS)
                                {
                                    FirePollEvent(i, ((_ioStateMap & PortMask[i]) == PortMask[i]) ? CtrlState.High : CtrlState.Low);
                                }
#if DEBUG
                                Trace.WriteLine(string.Format("Firing Input Poll Event Port {0}, State {1}", i, ((_ioStateMap & PortMask[i]) == PortMask[i]) ? CtrlState.High : CtrlState.Low));
#endif
                            }
                        }

                        _ioStateMap = curStates;
                    }
                }

                Thread.Sleep(10);
            }
        }
Ejemplo n.º 11
0
        public void SetPortState(uint port, CtrlState state)
        {
            if ((_ioModeMap & PortMask[port]) == PortMask[port])
            {
                throw new ArgumentException("Port must be in output state to be set.", "port");
            }

            if (state == CtrlState.High)
            {
                _ioStateMap |= PortMask[port];
            }
            else
            {
                _ioStateMap &= (byte)~PortMask[port];
            }

            SimpleIOClass.WritePort(_ioStateMap);
        }
Ejemplo n.º 12
0
        public CtrlState GetPortState(uint port)
        {
            CtrlState retVal = CtrlState.Floating;

            if ((_ioModeMap & PortMask[port]) != PortMask[port])
            {
                throw new ArgumentException("Port must be in input state to be read.", "port");
            }

            int stateVal = SimpleIOClass.ReadPortValue();

            if (stateVal == 0x8000)
            {
                throw new Exception("Error reading port values");
            }
            else
            {
                _ioStateMap = (byte)stateVal;
                retVal      = ((_ioStateMap & PortMask[port]) == PortMask[port]) ? CtrlState.High : CtrlState.Low;
            }

            return(retVal);
        }
Ejemplo n.º 13
0
 public byte ReadEEPROM(byte address)
 {
     return((byte)SimpleIOClass.ReadEEPROM((uint)address));
 }
Ejemplo n.º 14
0
 public uint GetConnectedControllerCount()
 {
     return(SimpleIOClass.GetNoOfDevices());
 }
Ejemplo n.º 15
0
 public byte GetAllPortStates()
 {
     return((byte)SimpleIOClass.ReadPortValue());
 }
Ejemplo n.º 16
0
 public uint GetCurrentControllerID()
 {
     return((uint)SimpleIOClass.GetSelectedDevice());
 }
Ejemplo n.º 17
0
 public ICtrl GetCurrentController()
 {
     return(_controllers[SimpleIOClass.GetSelectedDevice()]);
 }
Ejemplo n.º 18
0
 public string GetControllerInfo()
 {
     return(SimpleIOClass.GetDeviceInfo((uint)SimpleIOClass.GetSelectedDevice()));
 }