Hardware Windows

Two computers, one scanner

I have an USB scanner I bought a while ago. It is attached to my computer and it is working fine. Occasionally my wife has to scan pictures for herself. She works on her computer but when she has to do some scanning I have to do the scanning for her even though she could scan the pictures by herself – if the scanner was attached to her computer. This sort of scanner doesn’t know client-server mode, they work directly on the computer where they are attached. I don’t mind scanning, but when you have work to do and 50 pages to scan it is an annoying process: feed the page, go through Acquire Image menu, save the result, etc.

One solution to the problem would be to manually switching scanner between the two computers. It isn’t very pleasant to crawl under the desks, pinpointing the right cable (among tenths of others), detaching it from one computer and attaching it to the other. And the reverse when the other person requires the scanner. Not an option for me since I am not a hardware specialist, I am a software developer after all and I refuse to solve the problems with hardware manipulation šŸ™‚

Perhaps I could use an USB switch of some sort, but then again, this solution would increase the amount of (USB) cables and the switch would have to be in the reach to operate and it will consume a bit of power.

So I went with USB over Network solution that enables the client-server scenario for USB devices. And not only scanners, the work with all sort of USB devices. Their solution is actually a redirection of USB data flow to network computers and the other way round. A server application has to be installed on the machine (Windows and Linux are supported) where the USB device is attached. Once this server application runs you can decide which USB device to share. In my case I’ll share the scanner:

USB over Network server, shared

(it states the name of the device before sharing: ScanJet bla bla)

Once the device is shared it isn’t available anymore to the host computer – USB over Network Server takes command of it. On the host computer you can still use a shared device in two ways: either you un-share it or you do it like you’d do it on client computers – install USB over Network Client. Once client is installed you have to add server’s address to the list of available servers. The thing communicates over port 33000 by default, so make sure your firewall lets the traffic through (you do have a firewall, right?). Once the connection with the server is established you are given the list of shared USB devices on that server. Just find the scanner, right click and select Attach.

USB over Network client

Server application shows that scanner is in now use:


That’s it. The client computer now sees the scanner as attached to it and you can use it as such. Note: you’ll need the device drivers installed on the client computer – remember, the client sees the device as attached to it. Actually, you need drivers installed only on computers where device is used, i.e. you won’t need drivers on the server if you don’t use the device there.

The drawback of this approach is the ownership of the device – only one client can own it at same time (you can specify whether new client can take possession of shared device even though somebody else is already using it).

Does it really work? With the version 3.4.6 I installed initially it didn’t work when the host computer was running Vista. However it worked if I run VMWare Workstation with Windows XP as guest OS and routing scanner from host to guest OS and from there through USB over Network. It was a temporary hack and an experiment. I notified the Fabulatech support, they acknowledge the problem and fixed it in the current version 3.5.1. Now it works just fine. While this way of sharing USB devices isn’t perfect it does elegantly solve issues when you want to share an USB device amongst many clients. It isn’t free, the server part is licensed based on the amount of the device you want to share while the client is free.


Providing syntax editor within a .net application

Many times I’ve incorporated some sort of scripting capabilities into my .net applications. Usually I’d let user to type in some C# code and then I’d take that code, compile it in memory in another AppDomain (to avoid memory hogging) and execute it when required. Or in other occasions I’d let user type some SQL code and later use it to execute a T-SQL command or against the database. The C# feature provides some challenges while the SQL feature is pretty straightforward. The weak point in both feature implementations is the lack of syntax coloring control or even better, intellisense, error underlining and other nice stuff we are used from Visual Studio. In other words if one wants to do it with style a proper syntax editor is required. Creating such a control by myself would be a complex task and without unlimited time at my disposition it’d be a mission impossible.

That’s why I’ve bought Actipro‘s Syntax Editor for WinForms (and no, other platforms aren’t supported right now, WPF being in development AFAIK). The core Syntax Editor is a huge beast in positive sense. It supports all sort of editor features one would expect. Its language definition is dynamic, meaning that you can create support for whatever language you want through an XML definition or, if you require additional features, through an add-on which is written in .net. You most probably won’t need to, because many definitions come out of the box, such as “Assembly, Batch files, C#, CSS, HTML, INI files, Java, JScript, Lua, MSIL, Pascal, Perl, PHP, PowerShell, Python, SQL, VB.NET, VBScript, and XML“, but it is nice to have an open definition.

If you are serious about providing editing support for either a .net language (C# and VB.NET) or XML language then you have an option to buy an add-on that extends the support even further. With such an add-on the Syntax Editor really starts to shine with IntelliPrompt, syntax error display, reflection and metadata cache of referenced assemblies, etc. Similar features are provided with XML add-on, once you provide matching XSD. I won’t go in the details since this stuff is all over Actipro‘s web pages. Worth to remember is the fact that both .net and XML add-on are a separate products. If you don’t want to buy them you are actually free to create such add-ons by yourself, too. There is even a sample of a simple add-on.

The learning curve is steep but there is documentation to help, a huge (but readable and good) sample that demonstrates various features and a responsive support forum. Support is good, they quickly fix the errors and include the fix in the next minor version. I actually stumbled upon few errors (no wonder there are error in such a big product) which were quickly fixed. If you are interested in what Actipro is doing or explanations you might check their blog as well.

All in all Syntax Editor is a feature rich, easy to use, flexible and expandable syntax editor worth looking at. It is actually very easy to use most important of its capabilities writing just a bunch of lines of code. If you are interested in the product then there is no better way than to check it by yourself – go download their time limited full trial version.

Ah, and here is Syntax Editor in action in my Righthand’s LLBLGenPro Query Studio (application in-development):


.net 3.5 DevExpress

Visual Studio, CodeRush and Silverlight 2

If your Visual Studio 2005 or 2008 freezes while creating a Silverlight project, or any other project then you might try switching off [CodeRush] add in. Yep, it causes Visual Studio to freeze when creating a shinny new Silverlight 2.0 application. I am sure that [DevEx] folks will fix the problem very soon but for the time being just start Visual Studio, go to Tools\Add-in Manager… and uncheck DevExpress Tools item (I guess that will be a hard step to [CodeRush] addicted people, but don’t worry, it is only temporal). You can run Silverlight project wizard now and you can re-enable [CodeRush] once the project is created.

The workaround and the fact that [CodeRush] is the culprit has been found in this thread.


XNA Game Studio: I could play video but I’d rather not

Did you ever try to play a video inside your DirectX application, or a newer XNA Game Studio? One could assume that this is a trivial task, right? WPF lets you play it, heck, even Silverlight has no problems playing video – it is a matter of setting a bunch of properties on a proper object and voila.

So, XNA (same goes for DirectX) shouldn't have problem playing videos, too. WRONG. Playing video in XNA is a tricky, difficult and  you don't know when you'll get an unmanaged exception. Every solution out there I saw is based on DirectShow COM thing (luckily, there is a .net wrapper for DirectShow at like i.e. XNA DirectShow Video Player. But don't think this is an excellent solution. Dealing with video is still very problematic – while I haven't yet tried the mentioned video player I tried some other similar solutions and none of them is rock solid.

The logical question would be: why doesn't [MS] support video playback in XNA natively (through whatever library as long as one doesn't have to deal with low level details)? Or better, playing video to texture would be more than enough. Didn't they think of it? Sure they did, there is even a very highly rated request at Connect. It is dated back to year 2006! After a week or two it has been marked as Closed – Postponed. That's it.

This issue begs for two questions:

  1. Is it really that difficult to add video to texture playback in XNA/DirectX?
  2. Why bother giving feedback to Connect at all?

I/We are not asking for some obscure feature after all. Having the video manipulation ability opens many interesting possibilities. Interestingly, video to texture playback was introduced with first versions of Managed DirectX library and soon after discarded, I guess because of bugs.

What gives? I guess we'll have to deal with that DirectShow directly in one way or another for a long time to come. Or pay a huge price to a 3rd party. Is there a third solution I am not aware of?

UPDATE [19.10.2008]: I just found Scurvy Media project on CodePlex that does play a subset of AVI video -> texture without messing with DirectShow. It looks quite promising. Perhaps the biggest drawback is lack of audio playback (not sure about this, looks like is roadmapped to next release).

.net 3.5 SQL

Minimum database permissions for using SqlDependency with SQL Server 2005

If you wonder what minimum permissions you need to use SqlDependency with SQL Server 2005 then look no further. This code project article definitely works and is the most complete one I’ve found. Note that setting minimum database permissions for notification isn’t exactly the easiest task on the planet. Actually through experimenting I’ve managed to create a service_queue in sys.objects that I couldn’t remove without restoring the database entirely (luckily I am using RedGate‘s SQL Backup 5 for backing up my databases – it makes the backup and restore process so easy, not to mention the encryption and compression capabilities).

Anyway, after restoring the database to the initial non-notification enabled point (clean state), I managed to apply proper minimum permissions following the mentioned article.

.net .net 3.5 DevExpress LLBLGenPro ORM Slovenia

Material from my "Making ORM applications more secure/Naredimo ORM aplikacije varnejŔe" presentation

I posted both slides and demo code from my "Making ORM applications more secure/Naredimo ORM aplikacije varnejše" presentation held at Bleeding Edge conference in Portorož on 1.10.2008.

The material is in Slovene language. Enjoy.