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 = 2; //const Int32 I2C_Slave_Add = 0x46; //must be 0x40, 0x44 or 0x46 //---------------------- private const string FILE_PATH = "D:\\MidTankPressurelog.txt"; int adc_configuration(uint I2C_Slave_Add,uint channel ) { StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); stubI2CWriteBytesRequest.I2CId = I2C_ID; stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add; UInt32 uInt32 = new UInt32(); stubI2CWriteBytesRequest.BytesTWrite.Add(0x00);//Byte 0 to write stubI2CWriteBytesRequest.BytesTWrite.Add(channel);//Byte 1 to Write, must be 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02 or 0x01 for different channels stubI2CWriteBytesRequest.BytesTWrite.Add(0x80);//Byte 2 to Write var response = stubManager.Run(stubI2CWriteBytesRequest); return 1; } int adc_set_for_read_temp(uint I2C_Slave_Add) { StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); stubI2CWriteBytesRequest.I2CId = I2C_ID; stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add; UInt32 uInt32 = new UInt32(); stubI2CWriteBytesRequest.BytesTWrite.Add(0x02);//Byte 0 to write var response = stubManager.Run(stubI2CWriteBytesRequest); return 1; } int adc_read_temp(uint I2C_Slave_Add) { StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest(); stubI2CReadBytesRequest.I2CId = I2C_ID; stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add; stubI2CReadBytesRequest.NumberOfBytesToRead = 2; // Number of bytes to read var response1 = stubManager.Run(stubI2CReadBytesRequest); for(int i=0; i(stubI2CWriteBytesRequest); return 1; } int adc_read_ch(uint ID, uint I2C_Slave_Add) { StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest(); stubI2CReadBytesRequest.I2CId = I2C_ID; stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add; stubI2CReadBytesRequest.NumberOfBytesToRead = 2; // Number of bytes to read var response1 = stubManager.Run(stubI2CReadBytesRequest); uint temph=0; uint templ=0; uint temp; double calc; double calc1; double calc2; double calc3; double calc4; for(int i=0; i