aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/I2C_DAC_MultiBytes.cs
blob: 009f5450c72f41e046da8790e29a0a5c6d933319 (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
59
60
61
62
63
64
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;

//----------------------
//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 =  2;
const Int32 I2C_Slave_Add = 0x98;
//----------------------

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(0x30);//Byte 0 to write
	stubI2CWriteBytesRequest.BytesTWrite.Add(0xff);//Byte 1 to Write
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x00);//Byte 2 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 = 3; // Number of bytes to read

	var response1 = stubManager.Run<StubI2CReadBytesResponse>(stubI2CReadBytesRequest);
	
	for(int i=0; i<stubI2CReadBytesRequest.NumberOfBytesToRead;i++)
	{
		stubManager.WriteLineHex(response1.ReadBytes[i],2);
	}

*/	
	
	
}