Whether you are using .Net commercially, academically or just for your own edification, you will not use it for long before you will need to use Platform Invoke. P/Invoke is incredibly useful for calling into Win32 dlls for features not natively available in .Net. I recently ran into this while creating an internal tool for my employer. While I have worked on three separate major projects using .Net, I think this little app is more widely used than anything else I’ve done up to date. The hardest part of P/.Invoke is to the format of the dllimport correct. This reminds me of the days of VB when you needed to call into a VC++ dll. Yucky but necessary. Hopefully someone will take the initiative to post many of the signatures for public use. I have heard that Adam Nathan’s book on COM Interop includes many of these and I found this (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=f1dd70e4-c212-4a6f-bff7-c82e34c8836f) project on gotodotnet but much more could be done.
Well the project was to fulfill a need to generate card reads to an Access Control panel. This requires an understanding of the Wiegand Access Control Standard, and a way to send out pulses from the computer neither of which I knew. I found some elementary information on wiegand (http://www.nciaccessworld.com/literature/techBulletins/Td2058.pdf). But that was just one format. Here are some other formats I found online;
26 bit format with facility code
PAAAAAAAABBBBBBBBBBBBBBBBP
EXXXXXXXXXXXXX............
..............XXXXXXXXXXXO
P = Parity
A = Facility Code
B = Card Data
E = Even Parity
O = Odd Parity
X = Bit used in prity calculation
34 bit format with facility code
PAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBP
EXXXXXXXXXXXXXXXX.................
.................XXXXXXXXXXXXXXXXO
P = Parity
A = Facility Code
B = Card Data
E = Even Parity
O = Odd Parity
X = Bit used in parity calculation
. = Bit not used for parity calculation
35 bit format with facility code
PPAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBP
.EXX XX XX XX XX XX XX XX XX XX XX
.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.O
OXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
P = Parity
A = Facility Code
B = Card Data
E = Even Parity
O = Odd Parity
X = Bit used in parity calculation
. = Bit not used for parity calculation
37 bit format with facility code
PAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBP
EXXXXXXXXXXXXXXXXXX..................
..................XXXXXXXXXXXXXXXXXXO
P = Parity
A = Facility Code
B = Card Data
E = Even Parity
O = Odd Parity
X = Bit used in parity calculation
. = Bit not used for parity calculation
37 bit format without facility code
PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP
EXXXXXXXXXXXXXXXXXX..................
..................XXXXXXXXXXXXXXXXXXO
P = Parity
A = Card Data
E = Even Parity
O = Odd Parity
X = Bit used in parity calculation
. = Bit not used for parity calculation
I also started investigating using the serial port for sending out pulses and found some helpful code (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=3321cb13-03e0-42a5-8e0a-ea7c85952c6e) and my favorite (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=fcba7fc5-666e-4eb0-863f-0045b0c79ec7) stream-based implementation. But then I realized that the serial port did not offer me enough data lines out. After a thorough search for a .Net library for the parallel port, I finally settled on a Win32 implementation (with source) that I found here (http://www.internals.com) and wrapped it in a C# class.