Skip to content

Commit

Permalink
fix: Switch from TWAIN to WIA as grpc failed in Windows service
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhouti committed Aug 29, 2023
1 parent b8db839 commit ce5549a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ dotnet clean
dotnet build -c Release
```

## Debug

To be able to attach the visual studio debugger on a running Windows Service, the project needs to be build in Debug and not release.

**Make sure to disable single file...**
```
dotnet build ScanServer.csproj -c Debug
```

Then create a Windows service **using cmd as administrator and not powershell** using the .exe in the debug file, make sure to stop the release server since they by default use the same port.
```
sc create ScanServerDebug binPath= "C:\Path\To\ScanServer\bin\Debug\net7.0\win-x64\ScanServer.exe" DisplayName= "Scan Server Debug" start= auto obj= "LocalSystem"
```

## Uninstall:

Expand Down
6 changes: 3 additions & 3 deletions ScanServer/Controllers/ScannerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ public async Task<ActionResult<List<ScanDevice>>> ListDevices()
// TODO based on env Var change driver
// TODO set 32 or 64 based on OS
//var devices = await _scanController.GetDeviceList(new ScanOptions { Driver = Driver.Twain, TwainOptions = { Dsm = TwainDsm.Old, Adapter = TwainAdapter.Legacy } });
var devices = await _scanController.GetDeviceList(Driver.Twain);
var devices = await _scanController.GetDeviceList();
return Ok(devices);
}

[HttpGet("scan/{deviceId}")]
public async Task<ActionResult> Scan([FromRoute] string deviceId)
{
_logger.LogDebug($"{nameof(Scan)}");
var devices = await _scanController.GetDeviceList(Driver.Twain);
var devices = await _scanController.GetDeviceList();
ScanDevice device = devices.Find(d => d.ID == deviceId);
if (device == null)
{
return NotFound();
}
var scannedImages = _scanController.Scan(new ScanOptions { Device = device, Driver = Driver.Twain, Dpi = 200 }).ToBlockingEnumerable().ToList();
var scannedImages = _scanController.Scan(new ScanOptions { Device = device, Dpi = 200 }).ToBlockingEnumerable().ToList();
if (scannedImages.Count == 0)
{
return NotFound();
Expand Down
2 changes: 0 additions & 2 deletions ScanServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using ScanServer.Controllers;
using System.Diagnostics;

ILogger<WebApplication> _logger;

var options = new WebApplicationOptions
{
Args = args,
Expand Down
4 changes: 3 additions & 1 deletion ScanServer/ScanServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<TargetFramework>net7.0</TargetFramework>
<OutputType>Exe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<PublishReadyToRun>true</PublishReadyToRun>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!--<DebugType>full</DebugType>-->
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,7 +21,7 @@

<PackageReference Include="NAPS2.Sdk" Version="0.1.0-alpha01" />
<PackageReference Include="NAPS2.Images.ImageSharp" Version="0.1.0-alpha01" />
<PackageReference Include="NAPS2.Images.Gdi" Version="0.1.0-alpha01" />
<PackageReference Include="NAPS2.Images.Gdi" Version="0.1.0-alpha01" />
<PackageReference Include="NAPS2.Sdk.Worker.Win32" Version="0.1.0-alpha01" />
</ItemGroup>

Expand Down

0 comments on commit ce5549a

Please sign in to comment.