Wiegand Input
Jumpkick
Posts: 19
Is anyone familiar with designing some software to·read the Wiegand protocol?·I have purchased a Basic Stamp Discovery Kit (USB) with a BS2 microcontroller.
I have tried the following:
I have DATA0 in input0, DATA1 in input1.
serialData VAR Byte
SHIFTIN IN0, IN1&IN0, MSBPRE, [noparse][[/noparse]serialData]
I get different bytes when an actual card is read, but the bytes are never consistent with something that I would consider being a valid Facility Code and Card Number.
Can someone please help?
I have tried the following:
I have DATA0 in input0, DATA1 in input1.
serialData VAR Byte
SHIFTIN IN0, IN1&IN0, MSBPRE, [noparse][[/noparse]serialData]
I get different bytes when an actual card is read, but the bytes are never consistent with something that I would consider being a valid Facility Code and Card Number.
Can someone please help?
Comments
The problem is that the weigand device provides that clock and the BS2 SHIFTIN command the BS2 provides the clock.
Using some kind of external "helper" chip you could probably do it.
I have read wiegand the the SX chip using SX/B.
Wiegand format:
Both DATA0 and DATA1 are normally high.
IF DATA0 goes low for about 40uSec then a 0 is clocked in.
IF DATA1 goes low for about 40uSec then a 1 is clocked in.
There is about 2mSec between pulses.
With one of the faster stamps you might be able to pull it off, but putting a diode and cap on each of the lines to act as a "pulse stretcher" so the stamp has a chance to see the low pulse.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
Post Edited (Bean (Hitt Consulting)) : 2/10/2006 4:46:37 PM GMT
I'll try to find the code for you.
[noparse][[/noparse]edit]
This is probably not the place to be posting SX/B code. Maybe one of the moderators will move the thread if they feel so inclined.
This is NOT a complete program, just a snippet to show reading wiegand data.
Sorry about all the comments too [noparse];)[/noparse]
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
Post Edited (Bean (Hitt Consulting)) : 2/10/2006 5:39:38 PM GMT
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
'
' IO Pins
'
DATA0 VAR RA.0
DATA1 VAR RA.1
GREENLED VAR RC.7
'
' Variables
'
dataBit VAR Bit
bitcnt VAR Byte
byteCnt VAR Byte
rfid VAR Byte (3)
bitCnt = 255 ' Skip first parity bit
byteCnt = 0
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
GOTO Main
Main:
'Check Low On Data0
IF Data1 = 0 THEN
'Wait For High On Data1
dataBit = 1
DO
LOOP UNTIL Data1 = 1
ELSE
'Wait For High On Data0
dataBit = 0
DO
LOOP UNTIL Data0 = 1
ENDIF
'Check For Parity Bit
IF bitCnt <> 255 THEN
rfid(byteCnt) = rfid(byteCnt) << 1
rfid(byteCnt).0 = dataBit
ENDIF
'Increase Bit Count
INC bitCnt
'8 Bits = 1 Byte
IF bitCnt = 8 THEN
bitCnt = 0
INC byteCnt
ENDIF
'Check For Required 3 Bytes
IF byteCnt < 3 THEN
LOW GREENLED
ELSE
HIGH GREENLED
byteCnt = 0
ENDIF
GOTO Main
I did some work with Wiegand code from a proximity card reader with a BS2 or BS2sx . Its not a pretty thing to work with, but in the end it did the trick. I wrote it down for safe keeping, now just have to find it.
Seems to me, the card reader would let you select whether the output was sent in async serial ( RS-232) or synchronous where you supplied a clock pulse. The serial version is what I used, 2400 baud, I think.
Will get back to you.
Tom
Is seems you missed the first 3 lines of code right after "ReaderWait:"
This keeps the program from continuing unless one of data lines is low.
Your code is shifting in a "0" on every loop through the code.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
OK, found my notes from 2002.
1. It was an HID RF proximity card reader.
2. The Wiegand code output could be set to either serial or sync. I used serial.
3. I tested it at 4800 on a BS2 and 9600 on a BS2sx. Just used SERIN to watch for CR or LF. Then, the next burst is grabbed as STR in an 18 byte array. I think the leading zeros were constant so they could also be used as a WAIT parameter inthe SERIN.
4. As an example, card number 31926 sends a string that looks like this:
00 00 04 D6 F9 6C 3F CR LF
step 1: throw away CR and LF ( carriage return and line feed)
step 2: the next pair ( 3F ) is the checksum and can also be disregarded , unless you really want the gymnastics to crunch it on the fly.
step 3: the next two pairs are the card number ( F9 6C ), sort of. F9 6C = 63852
step 4: take the value of those two pairs and divide by 2
step 5: card number is 31926
the 04 and D6 are facility numbers, which I didn't need to decode.
Hope this helps.
Tom
IF Data0 = 1 THEN
IF Data1 = 1 THEN
GOTO Main
ENDIF
ENDIF
But even with that the LED blinks green rather spontaneously. I was able to hook my reader to another manufacturers panel and it worked just fine so I don't know what is going on.
Stamptrol:
I am unable to use a serial interface per a requirement for the product. It has to be able to read Wiegand inputs. [noparse]:([/noparse]
Can you attach your complete program. I'll look at it.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
· Try this code.
· Make sure you have the ground wire connected between the reader and the SX.
·
· If the reader is operating from the same power source as the SX then it should be okay.
· If the reader is operating from a seperate supply then you need to connect the ground wires together.
· Other than that just connect the DATA0 and DATA1 wires to the SX pins. You might want to use a 1K resistor just to protect the pin.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
Post Edited (Bean (Hitt Consulting)) : 2/15/2006 6:20:33 PM GMT
You'll need three wires between the SX and reader: DATA0, DATA1, and GROUND.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
When you swipe a tag the WATCH window should show the siteID and the cardID for that tag.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
005-56164
Yields:
225 1 118
??
You should get 5 for siteID and 56164 for cardID. Not sure what's going on there.
Do you get the same values everytime ?
Do you have another card ? What values to you get for it ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
005-56166
005-56164
005-56170
Try setting them to zero before the routine maybe they are just not getting updated.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
siteid = rfid(0)
cardid(0) = rfid(2)
cardid(1) = rfid(1)
I can't seem to figure out the other two formats that I am dealing with. I am stumped right now as to how to program the SX to identify which format and properly return the siteID and cardID.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There's nothing a good wack with a hammer won't fix
Darn I let the white smoke out again