-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathProgram.cs
56 lines (46 loc) · 1.67 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
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using System;
using System.Diagnostics;
using System.Threading;
using nanoFramework.Hardware.Stm32;
namespace Stm32BackupMemory.TestApp
{
public class Program
{
public static void Main()
{
Debug.WriteLine($"The backup memory has {BackupMemory.Size} bytes.");
// write a byte array
uint testBufferPosition = 5;
byte[] testBuffer = new byte[] { 0xFA, 0xCE, 0xBE, 0xEF, 0xFA, 0xCE, 0xBE, 0xEF };
BackupMemory.WriteBytes(testBufferPosition, testBuffer);
// read back the byte array
byte[] readBackBuffer = new byte[testBuffer.Length];
BackupMemory.ReadBytes(testBufferPosition, readBackBuffer);
if(readBackBuffer.GetHashCode() != testBuffer.GetHashCode())
{
Debug.WriteLine("Array read from backup memory is different than what was written.");
}
else
{
Debug.WriteLine("Buffer comparison check!");
}
// write an Int64
uint testInt64Position = 15;
Int64 testInt64 = 9876543210;
BackupMemory.WriteInt64(testInt64Position, testInt64);
if (BackupMemory.ReadInt64(testInt64Position) != testInt64)
{
Debug.WriteLine("Int64 read from backup memory is different than what was written.");
}
else
{
Debug.WriteLine("Int64 comparison check!");
}
Thread.Sleep(Timeout.Infinite);
}
}
}