WIA 2.0 Duplex scanning - c#

Since Vista, Windows is shipped with WIA 2.0 (wiaaut.dll).
According to the following KB article and many of my findings on various forums, duplex scanning is no longer possible using WIA 2.0. Yet, the article mentions the use of native WIA 2.0, what would make duplex scanning possible.
(https://support.microsoft.com/en-us/kb/2709992)
According to the WIA 2.0 documentation (https://msdn.microsoft.com/en-us/library/windows/desktop/ms630196(v=vs.85).aspx), duplex scanning is possible but using the new WIA_IPS_DOCUMENT_HANDLING_SELECT (3088) property.
My issues are:
I have no idea how to use native WIA, I suspect when using C# its just not possible.
I cant find a way to set the new WIA_IPS_DOCUMENT_HANDLING_SELECT property, as the property is not present in my wiaDevice properties. According to WiaDef.h, its property id is still 3088 and the only possible value is 0x400 (1024).
If anyone could help me (and I think many others) out on this, it would be much appreciated!
Greetings,
M.

After a few more hours of searching I found a clue in the following post.
https://stackoverflow.com/a/7580686/3641369
As I used a one-pass duplex scanner, both front and back sides where scanned at the same time. By setting the device properties (device properties, not item properties) Document_Handling_Select to 5 (Feeder + Duplex) and Pages to 1 and calling the transfer method 2 times, I finally got the font and back side of the scan.
Setting wiaDev.Properties["Document Handling Select"] = 5 specifies the use of the feeder and scanning duplex.
Setting wiaDev.Properties["Pages"] = 1 specifies that the scanner should keep 1 page in memory, this allowing to keep both front side and back side of the page in memory during 1 scan pass.
if (duplex)
{
wiaDev.Properties["Document Handling Select"].set_Value(5);
wiaDev.Properties["Pages"].set_Value(1);
}
Getting the Wia item and setting item properties such as color and dpi.
var item = wiaDev.Items[1];
item.Properties["6146"].set_Value((int)clr);
item.Properties["6147"].set_Value(dpi);
item.Properties["6148"].set_Value(dpi);
Then calling the transfer method twice returns two different images
var img = (ImageFile)wiaCommonDialog.ShowTransfer(item, FormatID.wiaFormatJPEG);
ImageFile imgduplex = null;
if(duplex)
imgduplex = (ImageFile)wiaCommonDialog.ShowTransfer(item, FormatID.wiaFormatJPEG);
Hope this helps someone!

Related

Image capturing via SNAPI.dll API for Symbol barcode scanner DS4208

I want to capture image via SNAPI API from Symbol (currently Zebra) barcode scanner, model DS4208 (we're also using another but compatible models from Zebra).
Barcode capturing/recognition works pretty well, but looks like SnapiDLL.SNAPI_SnapShot(hScanner) call don't work correctly: no WM_XFERSTATUS message received at all.
Here is small & simplified code snippet:
// Set image format
short[] parms = new short[2] { (short)SnapiParamIds.ImageFileType, (short)SnapiImageTypes.Jpeg };
var retCode = SnapiDLL.SNAPI_SetParameters(parms, 2, _devHandles[0]);
Debug.WriteLine($"SNAPI_SetParameters retCode={retCode}");
Application.DoEvents();
Thread.Sleep(50);
retCode = SnapiDLL.SNAPI_SnapShot(_devHandles[0]);
Debug.WriteLine($"SNAPI_SnapShot retCode={retCode}");
Application.DoEvents();
Thread.Sleep(50);
retCode = SnapiDLL.SNAPI_PullTrigger(_devHandles[0]);
Debug.WriteLine($"SNAPI_PullTrigger retCode={retCode}");
Application.DoEvents();
Thread.Sleep(50);
Return codes always 0 (i.e. no error), but no WM_XFERSTATUS message received by my message handler.
P.S. C# application from Zebra's SDK which is using CoreScanner driver and OCX, is working fine and able to capture images and video. But I'd like to avoid CoreScanner driver installation for some reasons; for barcode scanning small and simple SNAPI.dll works pretty fine, and I expect to get it work for image capturing too - probably, I'm doing something wrong...
P.P.S. Guys, please DO NOT COMMENT if you have NO EXPERIENCE WORKING WITH SYMBOL BARCODE SCANNERS & SNAPI, and CAN NOT PROVIDE a working snippet!
After contacting Zebra tech support (they are successors of Symbol/Motorola barcode scanner business), I figured out that the imaging/video functionality is broken in SNAPI.dll for the x64 OSes (but most of the rest API calls are working properly). Unfortunately, SNAPI isn't supported by Zebra anymore, and I should use Zebra's CoreScanner API. The good news is: this API is working fine, as it supposed to be. Not a very good news: I should use additional installation package from Zebra.

Windows 8.1 WPF application mixerSetControlDetails returns MMSYSERR_ERROR

Edit
After modifying the NAudio source code and a little debugging, I found that the mixerSetControlDetails function, which is called when I set the Value property, returns MMSYSERR_ERROR.
Is there a way to get further information about why mixerSetControlDetails failed?
I'm also open to other ways to accomplish same thing on C#.
Original
I have some code that computes energy in voice and sets the microphone boost level according to this computed value using NAudio. I have no problem reading audio samples but when I try to set microphone boost, the program gets stuck.
I have checked the issue on Windows 7, 8, and 8.1. The problem occurs only on Windows 8.1. Interestingly when I run the program on a virtual machine with Windows 8.1 it works as expected. Can this be a permission problem?
Here is the code for setting the boost value
foreach (MixerControl mixerControl in MixerLine.Controls)
{
if (mixerControl.ControlType == MixerControlType.Volume)
{
UnsignedMixerControl volumeControl = (UnsignedMixerControl)mixerControl;
volumeControl.Value = (uint) value;
}
}
Where MixerLine is created beforehand with this code.
MixerLine = new MixerLine((IntPtr) deviceID, 0, MixerFlags.WaveIn);
It seems the mixerSetControlDetails function returns MMSYSERR_ERROR randomly (at least I couldn't find a pattern). Actually it does set the new value, just ignore the exception, or if it does not set try setting the value again. The stuck behavior was about my program, irrelevant to this error.

Checking a monitor's power status from a .net managed application

I need to check if the power of a display/monitor (is it ON or OFF ?).
I've tried with WMI, using the Win32_DesktopMonitor and check the "Availability", but the value returned is always 3 (powered on), even when the monitor is physically turned off.
Now, looking at a few threads here on StackOverflow, there's one direction I'd like to follow and it's the use of IMSVidDevice Interface, but I have no clue how to use it.
I have this link http://msdn.microsoft.com/en-us/library/windows/desktop/dd694527(v=vs.85).aspx to start.
It talks about using segment.h and segment.idl. There's also the mention of msvidctl.h.
I found an MS Video Control 1.0 Type Library which seems to be what I'm looking for (it has an IMSVidDevice interface defined) but I can't figure out how to use this library.
var devices = new MSVidCtlLib.MSVidOutputDevices();
Console.WriteLine("Found {0} devices", devices.Count);
foreach (MSVidCtlLib.IMSVidOutputDevice dev in devices)
{
Console.WriteLine("{0}: {1} - {2}", dev.Name, dev.Status, dev.Power);
}
But the devices.count is always zero. I have two monitors on my dev box.
What am I missing ?

Playing Audio in .Net / C#

I'm an experienced MFC programmer of many years, who for the more recent years has been developing commercial apps in Objective C for Mac and iOS - I'm trying to get up to speed with .Net and C# (as I'm soon going to be required to convert one of my commercial apps from Mac to PC).
I've now worked my way through a couple of books and as an exercise to get more familiar with .Net (and C#) I've decided to have a go at converting one of my none commercial apps to .Net as a learning exercise and all is going well (interface is working, data structures all good) but I need to be able to play audio.
My Mac app generates audio from a series of mathematical formula - imagine a wave generator - not quite the same but similar. On the Mac I generate the audio as 16 bit signed raw audio, use Core Audio to setup audio output routing and then get a callback whenever a new buffer of audio is required for the audio routing (so I can generate the audio on the fly).
I need to do the same on the PC. Unfortunately I find MSDN documentation to be a case of "Can't see the wood for the trees" as there is such a vast amount of documentation. I can find classes that will let me load and play mp3/wav etc files, but I need to generate the audio realtime. Can anyone point me in the right direction to find something that will allow me to fill buffers on the fly as it plays them?
Thx
I have used this sample in several projects with good results. It is basically a .Net wrapper for Windows Waveform Audio API using P/Invoke.
Other choices:
NAudio
Sound Player class from .Net framework
I have created a class that can play audio given Stream derivate as an input. So if you are able to pack your sound-generator into the Stream compatible interface, it could be suitable for you.
How I did it - I used unmanaged waveOut* methods from old Windows multimedia API, and handled the playback from there.
Other options - that I am aware of - use waveOut directly, from this: http://windowsmedianet.sourceforge.net/ or write your own DirectShow source filter, but that might be too complicated, since it has to be written in c++.
If you are interested in giving my component a try, I can make it available to you at no charge, since I need it beta tested (I only used it in several of my projects).
EDIT:
Since there are 6 upvotes to the question, I am offering my component free of charge (if you find useful) here: http://dl.dropbox.com/u/10020780/SimpleAudioPlayer.zip
Maybe you can reflect on it :)
I use Audiere to accomplish this and find it works very well.
It's a C++ lib really, but there are a set of bindings available for C#.
For more info, see the question I asked.
You should have a look at FMOD which allows this kind of operation and much more. It is also cross platform which can be interested if you are also working on a mac.
Alvas.Audio has 3 audio players: Player
player.FileName = "123.mp3";
player.Play();
PlayerEx
public static void TestPlayerEx()
{
PlayerEx plex = new PlayerEx();
plex.Done += new PlayerEx.DoneEventHandler(plex_Done);
Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
IntPtr format = mr.ReadFormat();
byte[] data = mr.ReadData();
mr.Close();
plex.OpenPlayer(format);
plex.AddData(data);
plex.StartPlay();
}
static void plex_Done(object sender, DoneEventArgs e)
{
if (e.IsEndPlaying)
{
((PlayerEx)sender).ClosePlayer();
}
}
and RecordPlayer
public static void TestRecordPlayer()
{
RecordPlayer rp = new RecordPlayer();
rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged);
rp.Open(new Mp3Reader(File.OpenRead("in.mp3")));
rp.Play();
}
static void rp_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case RecordPlayer.StateProperty:
RecordPlayer rp = ((RecordPlayer)sender);
if (rp.State == DeviceState.Stopped)
{
rp.Close();
}
break;
}
}

What does it indicate when RasGetConnectStatus returns a value of 6?

I'm trying to query the RasStatus of a connection. When I call the RasGetConnectStatus method, it returns 6. I've not found that particular return value in any of the documentation that I've read.
Here are some of the pages that I've looked at:
http://www.cs.scranton.edu/~beidler/Ada/win32/win32-raserror.html
http://msdn.microsoft.com/en-us/library/aa920162.aspx
http://msdn.microsoft.com/en-us/library/bb530704(v=vs.85).aspx
I'm using C# and .net 4.0
Edit: The code that actually calls follows:
uint result;
RASCONNSTATUS rasconnstatus; // http://pinvoke.net/default.aspx/Structures/RASCONNSTATUS.html
// _handle is previously set to the hwnd of the ras connection
result = RASAPI.RasGetConnectStatus(_handle, out rasconnstatus);
return rasconnstatus;
When this returns, result == 6 and rasconnstatus.rasconnstate == 0
What I need to find out is why result == 6.
The easiest way to look up Win32 error codes is by looking at the header files directly in the Windows SDK. Most of them are in the WinError.h file in the include folder wherever you installed the Windows SDK. For the RAS specific errors (the result would be between 600 and 900) those are in the RasError.h file.
In the case of your result being 6, it's indicating ERROR_INVALID_HANDLE; which in RAS that means it didn't like the connection handle you passed to the function. In your code sample, that would be _handle.
By the way, you may want to look at using the DotRas project on CodePlex, it's a .NET wrapper around the RAS API. The particular method you're interested in would be RasConnection.GetConnectionStatus, it returns the data from that structure.
foreach (RasConnection conn in RasConnection.GetActiveConnections())
{
RasConnectionStatus status = conn.GetConnectionStatus();
// Do something useful.
}
The WinError.h file is also available online here: http://msdn.microsoft.com/en-us/library/ms819772.aspx
Hope that helps!
Here you should find your answer http://msdn.microsoft.com/en-us/library/aa920538.aspx this is the enum values of RASCONNSTATE returned by RasGetConnectStatus. The value 6 should equal to RASCS_AuthNotify and you will find this description:
An authentication event has occurred. If dwError is zero, this event will be immediately followed by one of the more specific authentication states following. If dwError is nonzero, authentication has failed, and the error value indicates why.
Maybe is related with some firewall rules that block the connection.
update the link is from windows mobile 6.5 documentation.
for the windows one this link.

Categories

Resources