Hi Christian,
It's ok, I have some Java background, so reading it in C# should not be a
big problem to me, just that I need to digest it and think in VB way, hehe.
Thanks for the great sharing, do you mean that you create generic class for
each of the possible scanner that you are going to use, by loading the
respective DLL library depending on the parameter passed in to the class?
Currently they are getting dolphin barcode reader/scanner and they have
purchased them in bulk, but I do see your points here on catering for the
change of barcode reader, so am I right to say that you also installed the
Symbol SDK too? Is it safe to say that if both of them are using the same
model/type of scanner, I would only need one SDK?
Thank you.
Regards,
Jenson
--
:: Vision is Power ::
:
Hi Jenson,
I've made various solutions involving bar code scanning in the past. A
problem that I encountered the first time I made such a solution was
that I was stupid enough to think that my customer would just use one
kind of device (Intermec at the time). So I used the Intermec SDK
directly in my application. At the end of the project, the customer
said that they got a really offer from Symbol and decided to go for
Symbol instead. And this gave me problems of course because I had to
change quite a lot of code, which also meant that we had to do a lot
of testing... again!
Anyway, my first advice is to create a generic bar code scanner
library that contains a generic interface and separate libraries
that implement the interface for each bar code scanner. You'll
probably end up have 2 or more bar code scanner or something like
this:
BarcodeScanner.dll ---> contains the interface
SymbolScanner.dll ---> implements the interface in BarcodeScanner.dll
IntermecScanner.dll ---> implements the interface in
BarcodeScanner.dll
..
...
.... and so on...
The way I normally create a generic library is that load a Type name
string as my interface. Let's say I called my interface
IBarcodeScanner. I'll then create a class called BarcodeReader(), in
the constructor of BarcodeReader() I load my scanner as
IBarcodeScanner and I create a property { get; } to access my scanner
instance. I would do something like:
private IBarcodeScanner instance;
public BarcodeReader(string typeName) {
Type type = Type.GetType(typeName);
if (type == null) {
throw new TypeLoadException("Unable to get type");
} else {
instance = (IBarcodeScanner)Activator.CreateInstance(type);
if (instance == null) {
throw new TypeLoadException("Unable to load type as
IBarcodeScanner");
}
}
}
public IBarcodeScanner Scanner {
get { return instance; }
}
For example we try to create the SymbolScanner.dll, we just make a new
class library project and have a reference to our BarcodeScanner
project. the main class in SymbolScanner should implement
IBarcodeScanner.
Example:
public Scanner : IBarcodeScanner {
...
..
.
}
For using the barcode scanner, just create an instance of the
BarcodeScanner and pass the Type name of SymbolScanner (or whatever).
The type name would use the format "[NAMESPACE].[CLASS NAME],
[ASSEMBLY NAME]". Of course you should avoid hard coding the string,
put it in a Config file that you can change easily.
Something like this will around 2 days to make including complete
testing.
Good luck on your project
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com