public void InitializeController() { //SimpleIOClass.ConfigureMCP2200(0xFF, 115200, 0, 0, false, false, false, false); if (!SimpleIOClass.IsConnected()) { SimpleIOClass.InitMCP2200(VendorID, ProductID); } }
public bool SetAllPortState(byte ctrlState) { bool retVal = SimpleIOClass.WritePort((uint)ctrlState); if (retVal) { _ioStateMap = ctrlState; } return(retVal); }
public unsafe void GetAllPortState(ref byte portState) { uint states = 0; if (SimpleIOClass.ReadPort(&states)) { _ioStateMap = (byte)states; } portState = _ioStateMap; }
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); }
public byte[] ReadEEPROM() { byte[] retVal = new byte[256]; for (int i = 0; i < 256; i++) { retVal[i] = (byte)SimpleIOClass.ReadEEPROM((uint)i); } return(retVal); }
public ICtrl SetController(uint controllerNumber) { int curController = SimpleIOClass.GetSelectedDevice(); if (SimpleIOClass.SelectDevice(controllerNumber) == 0) { return(_controllers[(int)controllerNumber]); } else { return(_controllers[curController]); } }
public bool WriteEEPROM(uint address, byte value) { int retVal = SimpleIOClass.WriteEEPROM(address, value); if (retVal == 0) { return(true); } else { return(false); } }
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); } }
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); }
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); } }
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); }
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); }
public byte ReadEEPROM(byte address) { return((byte)SimpleIOClass.ReadEEPROM((uint)address)); }
public uint GetConnectedControllerCount() { return(SimpleIOClass.GetNoOfDevices()); }
public byte GetAllPortStates() { return((byte)SimpleIOClass.ReadPortValue()); }
public uint GetCurrentControllerID() { return((uint)SimpleIOClass.GetSelectedDevice()); }
public ICtrl GetCurrentController() { return(_controllers[SimpleIOClass.GetSelectedDevice()]); }
public string GetControllerInfo() { return(SimpleIOClass.GetDeviceInfo((uint)SimpleIOClass.GetSelectedDevice())); }