I wrote the following C# codes to read from my SFP device:
csharp
Console.Write("\n Enter the address to be read: ");
var ReadAddrText = Console.ReadLine();
byte[] SerBuf = new byte[30];
byte[] SerBufa = new byte[30];
byte Addr;
Addr = Convert.ToByte(ReadAddrText, 16);
SerBuf[0] = 0x56; // Command for Devices with 1 address byte
SerBuf[1] = 0xA1; // 24C32 I2C address + low bit set to indicate its a read operation
SerBuf[2] = 0xA2; // 24C32 high byte of internal address to read from
SerBuf[3] = 0xF0; // 24C32 low byte of internal address to read from
SerBuf[4] = 8; // number of bytes to read
comport.Write(SerBuf, 0, 5); // send the read command to the serial port
while (comport.BytesToRead < 16) ; // wait for data to arrive from the EEPROM
int bytes = comport.BytesToRead;
Console.WriteLine(" Bytes to be read: {0}", bytes);
comport.Read(SerBufa, 0, Addr); // get the 8 data bytes
Console.WriteLine("\n Origial received(fir): {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15}", SerBufa[0], SerBufa[1], SerBufa[2], SerBufa[3], SerBufa[4], SerBufa[5], SerBufa[6], SerBufa[7], SerBufa[8], SerBufa[9], SerBufa[10], SerBufa[11], SerBufa[12], SerBufa[13], SerBufa[14], SerBufa[15]);
The problem is that I got the same results whatever I changed the internal reading addresses.
running results: 57 57 13 10 57 57 13 10 57 57 13 10 57 57 13 10
Does anyone know what's wrong with it?
Thanks,
Dennis
EDIT: Code blocks added =>
This post has been edited by PsychoCoder: 2 Jun, 2008 - 11:32 AM