/// <summary> /// CBUSのIOポートを操作する /// </summary> /// <param name="bits"></param> public void SetCBusBit(CBUSBit bits) { if (!IsOpen()) { throw new InvalidOperationException("Connection is not opened yet."); } if (eeprom == null) { throw new InvalidOperationException("CBUS is not configured yet."); } // ビットマスク作成 byte mask = 0b00000000; if (eeprom.Cbus0 == FT_CBUS_OPTIONS.FT_CBUS_IOMODE) { mask = 0b00010000; if (bits.cbus0) { mask |= 0b0001; } } if (eeprom.Cbus1 == FT_CBUS_OPTIONS.FT_CBUS_IOMODE) { mask |= 0b00100000; if (bits.cbus1) { mask |= 0b0010; } } if (eeprom.Cbus2 == FT_CBUS_OPTIONS.FT_CBUS_IOMODE) { mask |= 0b01000000; if (bits.cbus2) { mask |= 0b0100; } } if (eeprom.Cbus3 == FT_CBUS_OPTIONS.FT_CBUS_IOMODE) { mask |= 0b10000000; if (bits.cbus3) { mask |= 0b1000; } } // ビット操作 ftdi.SetBitMode(mask, 0x20); }
/// <summary> /// CBUSのIOポートを読込む /// </summary> /// <returns></returns> public CBUSBit GetCBusBit() { if (!IsOpen()) { throw new InvalidOperationException("Connection is not opened yet."); } if (eeprom == null) { throw new InvalidOperationException("CBUS is not configured yet."); } // ビット読込み byte ret = 0; ftdi.GetPinStates(ref ret); // CBUSBit作成 CBUSBit bits = new CBUSBit(false, false, false, false); if ((ret & 0b00000001) == 0b00000001) { bits.cbus0 = true; } if ((ret & 0b00000010) == 0b00000010) { bits.cbus1 = true; } if ((ret & 0b00000100) == 0b00000100) { bits.cbus2 = true; } if ((ret & 0b00001000) == 0b00001000) { bits.cbus3 = true; } return(bits); }