Question

What should I done to enable my ASP.NET MVC app can "talk" to a card reader via a USB port? It worked with a desktop app and all I did was copy the dll file to a folder in the bin/Debug folder and do the necessary DllImport moves since it was written in C++ most likely. With this desktop app I could write to the card, read it, reset it, etc.

I did the same [copy the dlls into the bin folder and fully referenced the dll in one of the controllers] all to no avail. I realize the MVC app runs inside a browser, so how do I go about implementing this scenario? Can I use a web service to expose the functionality of the desktop app? I have pasted part of the code here.

public class FrontDeskController : Controller
{
    [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
    [DllImport(@"C:\Users\charles\Documents\Visual Studio     2012\Projects\hotels\MvcXsoftHotelApp\bin\Debug\LevelLock.dll")]
    private static extern short LV3_BeepOk();           // Sound of success

    [SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
    [DllImport(@"C:\Users\charles\Documents\Visual Studio 2012\Projects\hotels\MvcXsoftHotelApp\bin\Debug\LevelLock.dll")]
    private static extern short LV3_InitializeSystem(short LockType);
Was it helpful?

Solution 2

Finally, I found the answer. I am sure StackOverflow came in somewhere in the mix. I cannot quote the post or question now but I have all the links that enabled Silverlight run inside a browser but under trusted privileges. Now Silverlight can both run inside the browser and access the USB card reader hardware on the client PC. Here are the links

http://cureos.blogspot.com/2011/09/pinvoke-bundling-native-dlls-in.html?showComment=1393315645042#c1274996580196954353

https://github.com/cureos/nativedll/blob/master/NativeDllInvoker/NativeDllHelper.cs

http://www.mistergoodcat.com/post/Silverlight-5-Tidbits-Trusted-applications

http://msdn.microsoft.com/en-us/library/gg192793(v=vs.96).aspx

http://technet.microsoft.com/en-us/library/cc730989(WS.10).aspx

At least maf748's answer got me thinking in that direction. Thanks to the SO community!

OTHER TIPS

If Silverlight 4 is an option, you could create an out-of-browser application which would give you access to COM interop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top