-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7799ffc
commit 846cbfb
Showing
10 changed files
with
1,077 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,59 @@ | ||
# spidriver-net | ||
An unofficial .NET SDK for the SPIDriver debugger | ||
|
||
|
||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/alandoherty/spidriver-net/master/LICENSE) | ||
[![GitHub issues](https://img.shields.io/github/issues/alandoherty/spidriver-net.svg?style=flat-square)](https://github.com/alandoherty/spidriver-net/issues) | ||
[![GitHub stars](https://img.shields.io/github/stars/alandoherty/spidriver-net.svg?style=flat-square)](https://github.com/alandoherty/spidriver-net/stargazers) | ||
[![GitHub forks](https://img.shields.io/github/forks/alandoherty/spidriver-net.svg?style=flat-square)](https://github.com/alandoherty/spidriver-net/network) | ||
[![GitHub forks](https://img.shields.io/nuget/dt/SPIDriver.svg?style=flat-square)](https://www.nuget.org/packages/SPIDriver/) | ||
|
||
</div> | ||
|
||
# spidriver | ||
|
||
An unofficial .NET library for [SPIDriver](https://spidriver.com/), allows for synchronous/asynchronous control of the device via the serial port. Open permissive MIT license with a dual-compliation for .NET Standard 2.0 and .NET Framework 4.6.1. | ||
|
||
![SPIDriver PCB](img/spidriver.jpg) | ||
|
||
## Getting Started | ||
|
||
[![NuGet Status](https://img.shields.io/nuget/v/SPIDriver.svg?style=flat-square)](https://www.nuget.org/packages/SPIDriver/) | ||
|
||
You can install the package using either the CLI: | ||
|
||
``` | ||
dotnet add package SPIDriver | ||
``` | ||
|
||
or from the NuGet package manager: | ||
|
||
``` | ||
Install-Package SPIDriver | ||
``` | ||
|
||
For assistance with the SPIDriver product itself you can view the [user guide](https://spidriver.com/spidriver.pdf) hosted on the official website. | ||
|
||
### Example | ||
|
||
You can find the example project `Example.CommandLine`, which demonstrates a CLI which implements all the features of the library. | ||
|
||
``` | ||
> connect | ||
Connected successfully | ||
> status | ||
Model: spidriver1 | ||
Serial Number: DO01JHMO | ||
Uptime: 01:56:22 | ||
Voltage: 5.203V | ||
Current: 0A | ||
Temperature: 32.6°C | ||
A: True | ||
B: True | ||
CS: True | ||
CRC: 0x0001 | ||
> writef airline.mp4 | ||
Wrote 1510004 bytes in 33.294s | ||
``` | ||
|
||
## Contributing | ||
|
||
Any pull requests or bug reports are welcome, please try and keep to the existing style conventions and comment any additions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29009.5 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpiDriver", "src\SpiDriver\SpiDriver.csproj", "{DB31321A-1176-45BA-B346-3E935C461B62}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7C86F419-D0FB-4251-AF6C-2C9194EA1C05}" | ||
ProjectSection(SolutionItems) = preProject | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EFCCC756-6E2D-4608-865D-5CE6B204C6F8}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.CommandLine", "samples\Example.CommandLine\Example.CommandLine.csproj", "{69010272-1995-4708-A354-CC8485F9109F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DB31321A-1176-45BA-B346-3E935C461B62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DB31321A-1176-45BA-B346-3E935C461B62}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DB31321A-1176-45BA-B346-3E935C461B62}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DB31321A-1176-45BA-B346-3E935C461B62}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{69010272-1995-4708-A354-CC8485F9109F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{69010272-1995-4708-A354-CC8485F9109F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{69010272-1995-4708-A354-CC8485F9109F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{69010272-1995-4708-A354-CC8485F9109F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{69010272-1995-4708-A354-CC8485F9109F} = {EFCCC756-6E2D-4608-865D-5CE6B204C6F8} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1AD50AD4-1933-4F12-BC76-14C291BA7587} | ||
EndGlobalSection | ||
EndGlobal |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\SpiDriver\SpiDriver.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using SpiDriver; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace Example.CommandLine | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] argv) { | ||
// the device | ||
Device device = null; | ||
|
||
// loop through accepting commands | ||
string line; | ||
|
||
while (true) { | ||
// read next line | ||
Console.Write("> "); | ||
line = Console.ReadLine().Trim(); | ||
|
||
// parse the line | ||
string[] components = line.Split(' '); | ||
string[] args = components.Length == 0 ? new string[0] : new string[components.Length - 1]; | ||
string cmd = components.Length == 0 ? null : components[0]; | ||
|
||
if (args.Length > 0) | ||
Array.Copy(components, 1, args, 0, args.Length); | ||
|
||
// ignore empty lines | ||
if (cmd == null) | ||
continue; | ||
|
||
// process command | ||
if (cmd.Equals("connect", StringComparison.CurrentCultureIgnoreCase)) { | ||
if (args.Length == 0) { | ||
Console.WriteLine("connect <port>"); | ||
continue; | ||
} | ||
|
||
try { | ||
device = new Device(args[0]); | ||
device.Connect(); | ||
Console.WriteLine("Connected successfully"); | ||
} catch (Exception ex) { | ||
Console.Error.WriteLine(ex.Message); | ||
} | ||
} else if (cmd.Equals("a", StringComparison.CurrentCultureIgnoreCase) || cmd.Equals("b", StringComparison.CurrentCultureIgnoreCase) | ||
|| cmd.Equals("cs", StringComparison.CurrentCultureIgnoreCase)) { | ||
// check device is connected | ||
if (device == null) { | ||
Console.WriteLine("Not connected to device"); | ||
continue; | ||
} | ||
|
||
// determine output | ||
Output output = Output.A; | ||
|
||
if (cmd.Equals("b", StringComparison.CurrentCultureIgnoreCase)) | ||
output = Output.B; | ||
else if (cmd.Equals("cs", StringComparison.CurrentCultureIgnoreCase)) | ||
output = Output.CS; | ||
|
||
try { | ||
if (args.Length == 0) { | ||
bool value = device.GetOutput(output); | ||
device.SetOutput(output, !value); | ||
Console.WriteLine($"{output}: {!value}"); | ||
} else { | ||
if (args[0].Equals("yes", StringComparison.CurrentCultureIgnoreCase) || args[0].Equals("on", StringComparison.CurrentCultureIgnoreCase)) { | ||
device.SetOutput(output, true); | ||
} else { | ||
device.SetOutput(output, false); | ||
} | ||
} | ||
} catch (Exception ex) { | ||
Console.Error.WriteLine(ex.Message); | ||
} | ||
} else if (cmd.Equals("status", StringComparison.CurrentCultureIgnoreCase)) { | ||
if (device == null) { | ||
Console.WriteLine("Not connected to device"); | ||
continue; | ||
} | ||
|
||
try { | ||
DeviceStatus status = device.GetStatus(); | ||
|
||
Console.WriteLine($"Model: {status.Model}"); | ||
Console.WriteLine($"Serial Number: {status.Serial}"); | ||
Console.WriteLine($"Uptime: {status.Uptime}"); | ||
Console.WriteLine($"Voltage: {status.Voltage}V"); | ||
Console.WriteLine($"Current: {status.Current}A"); | ||
Console.WriteLine($"Temperature: {status.Temperature}°C"); | ||
Console.WriteLine($"A: {status.A}"); | ||
Console.WriteLine($"B: {status.B}"); | ||
Console.WriteLine($"CS: {status.ChipSelect}"); | ||
Console.WriteLine($"CRC: 0x{status.Crc.ToString("x4")}"); | ||
} catch (Exception ex) { | ||
Console.Error.WriteLine(ex.Message); | ||
} | ||
} else if (cmd.Equals("writef", StringComparison.CurrentCultureIgnoreCase)) { | ||
string path = string.Join(' ', args); | ||
|
||
if (device == null) { | ||
Console.WriteLine("Not connected to device"); | ||
continue; | ||
} else if (args.Length == 0) { | ||
Console.WriteLine("No data in arguments"); | ||
continue; | ||
} else if (!File.Exists(path)) { | ||
Console.WriteLine("File does not exist"); | ||
continue; | ||
} | ||
|
||
// create stopwatch to time transfer | ||
Stopwatch stopwatch = new Stopwatch(); | ||
|
||
try { | ||
byte[] fb = File.ReadAllBytes(path); | ||
|
||
stopwatch.Start(); | ||
device.Write(fb, 0, fb.Length); | ||
|
||
Console.WriteLine($"Wrote {fb.Length} bytes in {Math.Round(stopwatch.Elapsed.TotalSeconds, 3)}s"); | ||
} catch (Exception ex) { | ||
Console.Error.WriteLine(ex.Message); | ||
} | ||
} else if (cmd.Equals("read", StringComparison.CurrentCultureIgnoreCase)) { | ||
int count = 0; | ||
|
||
if (device == null) { | ||
Console.WriteLine("Not connected to device"); | ||
continue; | ||
} else if (args.Length == 0) { | ||
Console.WriteLine("No data in arguments"); | ||
continue; | ||
} else if (!int.TryParse(args[0], out count)) { | ||
Console.WriteLine("Invalid count to read"); | ||
continue; | ||
} | ||
|
||
try { | ||
byte[] data = new byte[count]; | ||
device.Read(data, 0, data.Length); | ||
|
||
Console.WriteLine(BitConverter.ToString(data)); | ||
} catch (Exception ex) { | ||
Console.Error.WriteLine(ex.Message); | ||
} | ||
} else if (cmd.Equals("help", StringComparison.CurrentCultureIgnoreCase)) { | ||
Console.WriteLine("connect <port> - connect to serial port"); | ||
Console.WriteLine("a [on/off] - toggle or set A output"); | ||
Console.WriteLine("b [on/off] - toggle or set B output"); | ||
Console.WriteLine("cs [on/off] - toggle or set CS output"); | ||
Console.WriteLine("status - get device status"); | ||
Console.WriteLine("writef <path> - write file to SPI"); | ||
} else if (line != "quit" && line != "q" && line != "exit") { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.