forked from nanoframework/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
61 lines (49 loc) · 1.69 KB
/
Program.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
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using nanoFramework.TI.EasyLink;
using System;
using System.Diagnostics;
using System.Threading;
namespace EasyLink.Node
{
public class Program
{
static byte s_concentratorAddress = 0x00;
static byte s_nodeAddress = 0x33;
public static void Main()
{
EasyLinkController controller = new EasyLinkController(PhyType._5kbpsSlLr);
// need to initialize the EasyLink layer on the target before any operation is allowed
var initResult = controller.Initialize();
if (initResult == Status.Success)
{
var destinationAddress = new byte[] { s_concentratorAddress };
byte counter = 0;
while (true)
{
var packet = new TransmitPacket(
destinationAddress,
new byte[] { counter++ }
);
var txResult = controller.Transmit(packet);
if (txResult == Status.Success)
{
Debug.WriteLine($"Tx packet: {packet.Payload[0]}");
}
else
{
Debug.WriteLine($"Error when Tx'ing: {txResult}");
}
Thread.Sleep(3000);
}
}
else
{
Debug.WriteLine($"Failed to initialize SimpleLink. Error: {initResult}");
}
Thread.Sleep(Timeout.Infinite);
}
}
}