blob: 58389a58c43fc711673ac139f51d5bb729d0271a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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.UI;
//----------------------
//I2C4:
// Switches address: 0xE0, 0xE4, 0xE3
//I2C3
// Switches address: 0xE0, 0xE4, 0xE3
// ADC address: 0x40, 0x44, 0x46
//I2C2
// DAC address: 0x98
// EEPROM address: 0xA0
//----------------------
const Int32 I2C_ID = 4;
const Int32 I2C_Slave_Add = 0xE0;
//----------------------
public void OnExecute(StubManager stubManager)
{
// --------------------- I2C write multibyte ---------------------
StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();
stubI2CWriteBytesRequest.I2CId = I2C_ID;
stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;
UInt32 uInt32 = new UInt32();
stubI2CWriteBytesRequest.BytesTWrite.Add(0x11);//Byte 0 to write
//stubI2CWriteBytesRequest.BytesTWrite.Add(0x22);//Byte 1 to Write
//and so on,add lines in order to add Bytes - max : 256
var response = stubManager.Run<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);
// --------------------- I2C Read multibyte ---------------------
StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest();
stubI2CReadBytesRequest.I2CId = I2C_ID;
stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add;
stubI2CReadBytesRequest.NumberOfBytesToRead = 1; // Number of bytes to read
var response1 = stubManager.Run<StubI2CReadBytesResponse>(stubI2CReadBytesRequest);
for(int i=0; i<stubI2CReadBytesRequest.NumberOfBytesToRead;i++)
{
stubManager.WriteLineHex(response1.ReadBytes[0],2);
}
}
|