forked from zhelnio/MPSSELight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpiTest.cs
70 lines (59 loc) · 1.73 KB
/
SpiTest.cs
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
65
66
67
68
69
70
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MPSSELight;
using System.Linq;
using MPSSELight.Mpsse;
using MPSSELight.Devices;
using MPSSELight.Protocol;
namespace MPSSELightTest
{
[TestClass]
public class SpiTest
{
[TestMethod]
public void OpenCloseTest()
{
using (MpsseDevice mpsse = new FT2232D("A"))
{
SpiDevice spi = new SpiDevice(mpsse);
}
}
[TestMethod]
public void LoopbackTest()
{
using (MpsseDevice mpsse = new FT2232D("A"))
{
SpiDevice spi = new SpiDevice(mpsse);
mpsse.Loopback = true;
byte[] tData = { 0x0A, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0xFF };
byte[] rData = spi.readWrite(tData);
Assert.IsTrue(tData.SequenceEqual(rData));
}
}
[TestMethod]
public void TransmitTest()
{
using (MpsseDevice mpsse = new FT2232D("A"))
{
SpiDevice spi = new SpiDevice(mpsse);
byte[] tData = { 0x0D, 0x01, 0x0F };
spi.write(tData);
}
}
[TestMethod]
public void LoopbackBigTest()
{
Random r = new Random();
const uint size = 60000;
using (MpsseDevice mpsse = new FT2232D("A"))
{
SpiDevice spi = new SpiDevice(mpsse);
mpsse.Loopback = true;
byte[] tData = new byte[size];
r.NextBytes(tData);
byte[] rData = spi.readWrite(tData);
Assert.IsTrue(tData.SequenceEqual(rData));
}
}
}
}