Skip to content

Commit 15d0052

Browse files
authored
Merge pull request #14 from 1a2m3/1a2m3-patch-20220215
20220220 update
2 parents f4c0c28 + a4b4194 commit 15d0052

File tree

13 files changed

+1590
-922
lines changed

13 files changed

+1590
-922
lines changed

src/SpdReaderWriter/Example.cs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,13 @@ class Example {
1010
/// <summary>
1111
/// Serial port settings
1212
/// </summary>
13-
public static Device.SerialPortSettings readerSettings = new Device.SerialPortSettings(
13+
public static SerialDevice.SerialPortSettings readerSettings = new SerialDevice.SerialPortSettings(
1414
// Baud rate
1515
115200,
1616
// Enable DTR
1717
true,
1818
// Enable RTS
1919
true,
20-
// Data bits
21-
8,
22-
// Handshake
23-
Handshake.None,
24-
// New line
25-
"\n",
26-
// Parity
27-
Parity.None,
28-
// Stop bits
29-
StopBits.One,
30-
// Use event handler
31-
true,
3220
// Response timeout (sec.)
3321
10);
3422

@@ -42,7 +30,7 @@ class Example {
4230
/// </summary>
4331
public static void Example_BasicUse() {
4432
// Initialize the device
45-
Device myDevice = new Device(readerSettings, portName);
33+
SerialDevice myDevice = new SerialDevice(readerSettings, portName);
4634
//myDevice.Connect();
4735

4836
// Test if the device responds (optional)
@@ -59,7 +47,7 @@ public static void Example_BasicUse() {
5947
myDevice.SpdSize = Ram.SpdSize.DDR4;
6048

6149
// The device can also be initialized in one line, like so:
62-
Device myOtherDevice = new Device(readerSettings, portName, 80, Ram.SpdSize.DDR4);
50+
SerialDevice myOtherDevice = new SerialDevice(readerSettings, portName, 80, Ram.SpdSize.DDR4);
6351

6452
// Read first byte at offset 0
6553
byte firstByte = Eeprom.ReadByte(myDevice, 0);
@@ -84,7 +72,7 @@ public static void Example_BasicUse() {
8472
/// Test an unreachable device to make sure all functions properly return false
8573
/// </summary>
8674
public static void Example_TestNonConnectableDevice() {
87-
Device UnreachableDevice = new Device(readerSettings,"COM666");
75+
SerialDevice UnreachableDevice = new SerialDevice(readerSettings,"COM666");
8876
UnreachableDevice.I2CAddress = 0x50;
8977
if (UnreachableDevice.IsConnected) {
9078
// This won't be reached
@@ -97,12 +85,12 @@ public static void Example_TestNonConnectableDevice() {
9785
/// </summary>
9886
public static void Example_TestRealDevice() {
9987
// Test a real device
100-
Device RealDevice = new Device(readerSettings, portName);
88+
SerialDevice RealDevice = new SerialDevice(readerSettings, portName);
10189
RealDevice.Test(); //true
10290
RealDevice.Scan(); //{ 80 }
10391

10492
// Test a real device
105-
Device MyReader = new Device(readerSettings, portName, 0x50, Ram.SpdSize.DDR4);
93+
SerialDevice MyReader = new SerialDevice(readerSettings, portName, 0x50, Ram.SpdSize.DDR4);
10694
MyReader.Test(); //true
10795
}
10896

@@ -111,8 +99,8 @@ public static void Example_TestRealDevice() {
11199
/// </summary>
112100
public static void Example_DuplicateRam() {
113101
// Copy SPD contents from one DIMM to another
114-
Device source = new Device(readerSettings, "COM1", 80, Ram.SpdSize.DDR4);
115-
Device destination = new Device(readerSettings, "COM4", 82, source.SpdSize);
102+
SerialDevice source = new SerialDevice(readerSettings, "COM1", 80, Ram.SpdSize.DDR4);
103+
SerialDevice destination = new SerialDevice(readerSettings, "COM4", 82, source.SpdSize);
116104

117105
for (ushort i = 0; i < (int)source.SpdSize; i++) {
118106
Eeprom.WriteByte(destination, i, Eeprom.ReadByte(source, i));
@@ -131,17 +119,17 @@ public static void Example_DuplicateRam() {
131119
/// </summary>
132120
public static void Example_FixCRC() {
133121

134-
Device MyReader = new Device(readerSettings, portName, 0x52, Ram.SpdSize.DDR4);
122+
SerialDevice MyReader = new SerialDevice(readerSettings, portName, 0x52, Ram.SpdSize.DDR4);
135123

136124
// Read first 126 bytes
137125
byte[] spdHeader = Eeprom.ReadByte(MyReader, 0, 126);
138126

139127
// Calculate CRC
140-
ushort crc = Spd.Crc16(spdHeader, 0x1021);
128+
ushort crc = Data.Crc16(spdHeader, 0x1021);
141129

142130
// Get LSB (byte 127) and MSB (byte 128)
143-
byte CrcLsb = (byte)(crc & 0xff); // CRC LSB at 0x7e for 0-125 range or @ 0xfe for 128-253 range
144-
byte CrcMsb = (byte)(crc >> 8); // CRC MSB at 0x7f for 0-125 range or @ 0xff for 128-253 range
131+
byte CrcLsb = (byte)(crc & 0xFF); // CRC LSB at 0x7E for 0-125 range or @ 0xFE for 128-253 range
132+
byte CrcMsb = (byte)(crc >> 8); // CRC MSB at 0x7F for 0-125 range or @ 0xFF for 128-253 range
145133

146134
// Compare calculated CRC against SPD data
147135
if (Eeprom.ReadByte(MyReader, 0x7e, 1)[0] == CrcLsb && Eeprom.ReadByte(MyReader, 0x7f, 1)[0] == CrcMsb) {
@@ -153,16 +141,16 @@ public static void Example_FixCRC() {
153141
Eeprom.UpdateByte(MyReader, 0x7e, CrcLsb);
154142
Eeprom.UpdateByte(MyReader, 0x7f, CrcMsb);
155143
}
156-
// Note: you'll have to do the same for 128-253 range, checksum bytes are 0xfe and 0xff
144+
// Note: you'll have to do the same for 128-253 range, checksum bytes are 0xfe and 0xFF
157145
}
158146

159147
/// <summary>
160-
/// Erase SPD contents (fill with 0xff's)
148+
/// Erase SPD contents (fill with 0xFF's)
161149
/// </summary>
162150
public static void Example_EraseSPD() {
163-
Device MyReader = new Device(readerSettings, portName, 0x50, Ram.SpdSize.DDR4);
151+
SerialDevice MyReader = new SerialDevice(readerSettings, portName, 0x50, Ram.SpdSize.DDR4);
164152
for (ushort i = 0; i <= (int)MyReader.SpdSize; i++) {
165-
Eeprom.UpdateByte(MyReader, i, 0xff);
153+
Eeprom.UpdateByte(MyReader, i, 0xFF);
166154
Console.WriteLine(i.ToString());
167155
}
168156
}
@@ -172,7 +160,7 @@ public static void Example_EraseSPD() {
172160
/// </summary>
173161
public static void ScanRange() {
174162

175-
Device myDevice = new Device(readerSettings, "COM8");
163+
SerialDevice myDevice = new SerialDevice(readerSettings, "COM8");
176164

177165
bool[] _probes = new bool[128];
178166

src/SpdReaderWriter/Program.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4-
using System.IO.Ports;
54
using SpdReaderWriterDll;
6-
using SerialPortSettings = SpdReaderWriterDll.Device.SerialPortSettings;
5+
using SerialPortSettings = SpdReaderWriterDll.SerialDevice.SerialPortSettings;
76

87
namespace SpdReaderWriter {
98
class Program {
@@ -94,30 +93,18 @@ static void ParseCommand(string[] args) {
9493
// Setup
9594
SerialPortSettings readerSettings = new SerialPortSettings(
9695
// Baud rate
97-
115200,
96+
baudRate: 115200,
9897
// Enable DTR
99-
true,
98+
dtrEnable: true,
10099
// Enable RTS
101-
true,
102-
// Data bits
103-
8,
104-
// Handshake
105-
Handshake.None,
106-
// New line
107-
"\n",
108-
// Parity
109-
Parity.None,
110-
// Stop bits
111-
StopBits.One,
112-
// Use event handler
113-
true,
100+
rtsEnable: true,
114101
// Response timeout (sec.)
115-
10);
102+
responseTimeout: 10);
116103

117104
// Find
118105
if (mode == "/find") {
119106
// Find
120-
string[] devices = new Device(readerSettings).Find();
107+
string[] devices = new SerialDevice(readerSettings).Find();
121108
if (devices.Length > 0) {
122109
foreach (string portName in devices) {
123110
Console.WriteLine($"Found Device on Serial Port: {portName}\n");
@@ -139,15 +126,15 @@ static void ParseCommand(string[] args) {
139126
throw new Exception("Port name should start with \"COM\" followed by a number.");
140127
}
141128

142-
Device reader = new Device(readerSettings, portName);
129+
SerialDevice reader = new SerialDevice(readerSettings, portName);
143130

144131
if (!reader.Connect()) {
145132
throw new Exception($"Could not connect to the device on port {portName}.");
146133
}
147134

148-
if (reader.GetFirmwareVersion() < SpdReaderWriterDll.Settings.MINVERSION) {
149-
throw new Exception($"The device on port {portName} requires its firmware to be updated.");
150-
}
135+
//if (reader.GetFirmwareVersion() < SpdReaderWriterDll.Settings.MINVERSION) {
136+
// throw new Exception($"The device on port {portName} requires its firmware to be updated.");
137+
//}
151138

152139
//if (!reader.Test()) {
153140
// throw new Exception($"The device on port {portName} does not respond.");
@@ -172,7 +159,7 @@ static void ParseCommand(string[] args) {
172159
// Test reversible write protection capabilities
173160
if (mode.StartsWith("/") && mode.EndsWith("writeprotection")) {
174161

175-
if (reader.GetRamTypeSupport() < Ram.BitMask.DDR2) {
162+
if (reader.GetRamTypeSupport() < Ram.BitMask.DDR3) {
176163
throw new Exception("Your device does not support write protection features.");
177164
}
178165

@@ -202,7 +189,7 @@ static void ParseCommand(string[] args) {
202189
reader.ResetAddressPins();
203190

204191
for (byte i = 0; i < block.Length; i++) {
205-
if (Eeprom.SetWriteProtection(reader, i)) {
192+
if (Eeprom.SetRswp(reader, i)) {
206193
Console.WriteLine($"Block {i} is now read-only");
207194
}
208195
else {
@@ -216,9 +203,9 @@ static void ParseCommand(string[] args) {
216203
// Disable write protection
217204
if (mode.StartsWith("/disable") || mode.StartsWith("/clear")) {
218205

219-
reader.PIN_SA1 = Pin.State.ON;
206+
reader.PIN_SA1 = SerialDevice.Pin.State.ON;
220207

221-
if (Eeprom.ClearReversibleWriteProtection(reader)) {
208+
if (Eeprom.ClearRswp(reader)) {
222209
Console.WriteLine("Write protection successfully disabled.");
223210
}
224211
else {
@@ -359,7 +346,7 @@ static void ParseCommand(string[] args) {
359346
}
360347

361348
if (mode == "/enablepermanentwriteprotection") {
362-
if (Eeprom.SetPermanentWriteProtection(reader)) {
349+
if (Eeprom.SetPswp(reader)) {
363350
Console.WriteLine($"Permanent write protection enabled on {reader.PortName}:{reader.I2CAddress}");
364351
}
365352
else {

0 commit comments

Comments
 (0)