Skip to content

Commit

Permalink
Add a sample and update sdk doc for NAPS2.Escl.Server
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Nov 28, 2023
1 parent 2041107 commit a82f567
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAPS2.Sdk.Samples/NAPS2.Sdk.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Import Project="..\NAPS2.Setup\targets\SdkUsers.targets" />

<ItemGroup>
<ProjectReference Include="..\NAPS2.Escl.Server\NAPS2.Escl.Server.csproj" />
<ProjectReference Include="..\NAPS2.Sdk\NAPS2.Sdk.csproj" />
<ProjectReference Include="..\NAPS2.Images.Gdi\NAPS2.Images.Gdi.csproj" />
</ItemGroup>
Expand Down
56 changes: 56 additions & 0 deletions NAPS2.Sdk.Samples/NetworkSharingSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using NAPS2.Escl.Server;
using NAPS2.Images.Gdi;
using NAPS2.Remoting.Server;
using NAPS2.Scan;

namespace NAPS2.Sdk.Samples;

public class NetworkSharingSample
{
public static async Task Server()
{
// NAPS2 can share scanners across the local network using the ESCL protocol with the NAPS2.Escl.Server package.
// On the server, you need to set up ScanServer with the device(s) to share.
// On the client, you just scan as usual using Driver.Escl.

using var scanningContext = new ScanningContext(new GdiImageContext());

// Get the device to share
var controller = new ScanController(scanningContext);
ScanDevice device = (await controller.GetDeviceList()).First();

// Set up the server (you'll need to reference NAPS2.Escl.Server to be able to create an EsclServer object).
using var scanServer = new ScanServer(scanningContext, new EsclServer());

// Register a device to be shared
scanServer.RegisterDevice(new SharedDevice
{
Name = device.Name,
Device = device,
Driver = Driver.Default
});

// Run the server until the user presses Enter
scanServer.Start();
Console.ReadLine();
scanServer.Stop();
}

public static async Task Client()
{
using var scanningContext = new ScanningContext(new GdiImageContext());
var controller = new ScanController(scanningContext);

// Find the shared device using Driver.Escl
ScanDevice device = (await controller.GetDeviceList(Driver.Escl)).First();

// Set up options using Driver.Escl
var options = new ScanOptions { Device = device, Driver = Driver.Escl };

// Do the scan
await foreach (var image in controller.Scan(options))
{
Console.WriteLine("Scanned a page!");
}
}
}
4 changes: 3 additions & 1 deletion NAPS2.Sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ NAPS2.Sdk is modular, and depending on your needs you may have to reference a di
- **[NAPS2.Sane.Binaries](https://www.nuget.org/packages/NAPS2.Sane.Binaries/)**
- For [using SANE drivers]() on Mac. (Linux has them pre-installed, and Windows isn't supported.)
- **[NAPS2.Tesseract.Binaries](https://www.nuget.org/packages/NAPS2.Tesseract.Binaries/)**
- For [running OCR](). (You can also use a separate Tesseract installation if you like.)
- For [running OCR](). (You can also use a separate Tesseract installation if you like.)
- **[NAPS2.Escl.Server](https://www.nuget.org/packages/NAPS2.Tesseract.Binaries/)**
- For [sharing scanners](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/NetworkSharingSample.cs) across the local network.

## Usage

Expand Down

0 comments on commit a82f567

Please sign in to comment.