public static void WriteI2CExampleAt24C16(string readerName) { try { var i2c = new Readers.AViatoR.Components.SynchronusI2C(); ISmartCardReader smartCardReader = Connect(readerName); if (!smartCardReader.IsConnected) { return; } // Write 1 byte to address 0x0000, AT24C16 card ushort address = 0x0000; byte numberOfBytesToWrite = 0x01; string data = "01"; string command = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data); string response = smartCardReader.Transmit(command); PrintData($"I2C Write {numberOfBytesToWrite} byte to address 0x{address:X6}", command, response, ""); // Write 10 bytes to address 0x0010, AT24C16 card address = 0x0010; numberOfBytesToWrite = 0x0A; data = "FFFFFFFFFFFFFFFFFFFF"; command = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data); response = smartCardReader.Transmit(command); PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, ""); // Write 32 bytes to address 0x0400, AT24C16 card // AT24C16 card has page size of 16 bytes so write operation need to be done twice address = 0x0400; numberOfBytesToWrite = 0x10; data = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; command = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data); response = smartCardReader.Transmit(command); PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, ""); // second part of write operation address += 16; numberOfBytesToWrite = 0x10; data = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; command = i2c.GetWriteCommandApdu(SynchronusI2C.MemorySize._2048, address, numberOfBytesToWrite, data); response = smartCardReader.Transmit(command); PrintData($"I2C Write {numberOfBytesToWrite} bytes starting from address 0x{address:X6}", command, response, ""); smartCardReader.Disconnect(CardDisposition.Unpower); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void ReadI2CExampleAt24C128(string readerName) { try { var i2c = new Readers.AViatoR.Components.SynchronusI2C(); ISmartCardReader smartCardReader = Connect(readerName); if (!smartCardReader.IsConnected) { return; } // Read 1 byte from address 0x0000 from AT24C128 card ushort address = 0x0000; byte bytesToRead = 0x01; string command = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead); string response = smartCardReader.Transmit(command); PrintData($"I2C Read {bytesToRead} byte from address 0x{address:X6}", command, response, ""); // Read 10 bytes from address 0x0010 from AT24C128 card address = 0x0010; bytesToRead = 0x0A; command = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead); response = smartCardReader.Transmit(command); PrintData($"I2C Read {bytesToRead} bytes starting from address 0x{address:X6}", command, response, ""); // Read 32 bytes from address 0x0400 from AT24C128 card address = 0x0400; bytesToRead = 0x20; command = i2c.GetReadCommandApdu(SynchronusI2C.MemorySize._16384, address, bytesToRead); response = smartCardReader.Transmit(command); PrintData($"I2C Read {bytesToRead} bytes starting from address 0x{address:X6}", command, response, ""); smartCardReader.Disconnect(CardDisposition.Unpower); } catch (Exception e) { Console.WriteLine(e.Message); } }