diff options
Diffstat (limited to 'Software/Stubs Collection/stubs/Scripts/Assemblies/ArcHead/Write Arc head eeprom.cs')
| -rw-r--r-- | Software/Stubs Collection/stubs/Scripts/Assemblies/ArcHead/Write Arc head eeprom.cs | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/Software/Stubs Collection/stubs/Scripts/Assemblies/ArcHead/Write Arc head eeprom.cs b/Software/Stubs Collection/stubs/Scripts/Assemblies/ArcHead/Write Arc head eeprom.cs new file mode 100644 index 000000000..8d0056de2 --- /dev/null +++ b/Software/Stubs Collection/stubs/Scripts/Assemblies/ArcHead/Write Arc head eeprom.cs @@ -0,0 +1,146 @@ +using System; +using System.Text; +using System.Linq; +using System.Drawing; +using System.Diagnostics; +using System.Windows.Forms; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; +using Tango.PMR.Stubs; +using Tango.Stubs; + +//---------------------- +const Int32 I2C_ID = 3; //MCU_I2C3 +const Int32 TCA9548A_address = 0xE2; +const Int32 I2C_Slave_Add = 0xA0; // //eeprom address - 32kByte +int Head_Mux_Channel_ID = 4; //Head MUX channel +//---------------------- + +const Int32 SerialNum = 0x01; + + +int enable_channel(int Channel_ID) +{ + uint Const_temp = 0x01; + + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = TCA9548A_address; + + Const_temp = Const_temp << Channel_ID; + stubI2CWriteBytesRequest.BytesTWrite.Add(Const_temp); + + var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); + + return 1; +} + + +int WriteFlatEpprom(uint I2C_Slave_Add) +{ + uint Page=0; + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add; + + UInt32 uInt32 = new UInt32(); + stubI2CWriteBytesRequest.BytesTWrite.Add(0);//Byte 0 to write + stubI2CWriteBytesRequest.BytesTWrite.Add(Page);//Byte 0 to write + //-------------------------------------------------------------- + + stubI2CWriteBytesRequest.BytesTWrite.Add(0x33); //header + stubI2CWriteBytesRequest.BytesTWrite.Add(0xcc); + stubI2CWriteBytesRequest.BytesTWrite.Add(0xaa); + stubI2CWriteBytesRequest.BytesTWrite.Add(0x55); + + //stubI2CWriteBytesRequest.BytesTWrite.Add(0x04);//HEAD_TYPE_STAPLE_SPUN + + var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); + Thread.Sleep(100); + + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add; + + UInt32 uInt32 = new UInt32(); + stubI2CWriteBytesRequest.BytesTWrite.Add(92);//Byte 0 to write + stubI2CWriteBytesRequest.BytesTWrite.Add(Page);//Byte 0 to write + //-------------------------------------------------------------- + + stubI2CWriteBytesRequest.BytesTWrite.Add(0x20); //flat + stubI2CWriteBytesRequest.BytesTWrite.Add(0x00); + stubI2CWriteBytesRequest.BytesTWrite.Add(0x00); + stubI2CWriteBytesRequest.BytesTWrite.Add(0x00); + + //stubI2CWriteBytesRequest.BytesTWrite.Add(0x04);//HEAD_TYPE_STAPLE_SPUN + + var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); + Thread.Sleep(100); + + + + + + return 1; +} + +int adc_set_for_read_ch(uint I2C_Slave_Add, uint Page) +{ + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add; + + + UInt32 uInt32 = new UInt32(); + stubI2CWriteBytesRequest.BytesTWrite.Add(0);//Byte 0 to write + stubI2CWriteBytesRequest.BytesTWrite.Add(Page);//Byte 0 to write + + var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); + + return 1; +} + +int adc_read_ch(uint I2C_Slave_Add) +{ + StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest(); + stubI2CReadBytesRequest.I2CId = I2C_ID; + stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add + 1; + stubI2CReadBytesRequest.NumberOfBytesToRead = 10; // Number of bytes to read + + var response1 = stubManager.Run<StubI2CReadBytesResponse>(stubI2CReadBytesRequest); + uint temph=0; + + for(int i=0; i<stubI2CReadBytesRequest.NumberOfBytesToRead;i++) + { + temph=response1.ReadBytes[i]; + stubManager.WriteHex(temph,2); + } + + return 1; +} + + +public void OnExecute(StubManager stubManager) +{ + + //enable_all_channel(); + enable_channel(Head_Mux_Channel_ID); // Chanel 0-7 => Disp0enser 0-7 + + for (int i = 0; i<1; i++) + { + + WriteFlatEpprom(I2C_Slave_Add); + Thread.Sleep(10); //Sleep for 5 milli. - must! otherwise read 0xff (See data sheet ) + + stubManager.Write("\nPage 0x00 #"); + stubManager.Write(i); + stubManager.Write("\t- The Buffer is: "); + adc_set_for_read_ch(I2C_Slave_Add, 0x00); + //Thread.Sleep(1); //Sleep for 10 milli. + adc_read_ch(I2C_Slave_Add); + + Thread.Sleep(1000); + + } +}
\ No newline at end of file |
