Wiegand Mode

Top  Previous  Next

In the Wiegand mode the serial port is able to receive the data directly from any Wiegand device, such as card reader and also output the data in the Wiegand format, as if it was a card reader itself. Wiegand interface is popular in the security, access control, and automation industry.

Standard Wiegand data transmission is shown below. There are two data lines- W0 and W1. Negative pulse on the W0 line represents data bit 0. Negative pulse on the W1 line represents data bit 1. There is no standard Wiegand timing, so pulse widths as well as inter-gap widths wary greatly between devices. Averagely, pulse width is usually in the vicinity of 100uS (microseconds), while the inter-pulse gap is usually around 20-100ms (milliseconds).

There is no explicit way to indicate the end of transmission. Receiving device either counts received bits (if it knows how many to expect) or assumes the transmission to be over when the time since the last pulse on the W0 or W1 line exceeds certain threshold, for example, ten times the expected inter-pulse gap.



The serial port outputs Wiegand data through W0out and W1out lines and receives the data via W0&1in and W1in lines. "W0&1in" means that the signal on this input must be a logical AND of W0 and W1 output lines of attached Wiegand device (see below for details). Your application should not attempt to work with W0out and W1out outputs directly through the io object when the serial port is in the Wiegand mode.



Please, remember that depending on the platform you may be required to correctly configure some or all of your serial port's lines as inputs or outputs through the io.enabled property of the io object. Additionally, you may have the freedom of re-mapping certain serial port lines to different I/O pins of the device if required. For more information, refer to your device's platform documentation (for example, EM1000's is here).

How the serial port sends and receives raw Wiegand data

There are many Wiegand data formats currently in use. These formats define how "raw" data bits are processed and converted into actual data. Typically, there are 2 parity bits- one at the beginning, and another one at the end of Wiegand data. Parity calculation, however, varies from format to format. Additionally, the length of Wiegand output is not standardized.

All this makes it impossible for the serial port object to verify incoming Wiegand data, i.e. check the data length and calculate the checksum. Instead, this task is delegated to your application while the serial object only receives raw data. Similarly, before sending out Wiegand data your application needs to prepare this data in the desired format- the serial object itself will output any data stream.

How the Wiegand data is stored in the RX and TX buffers of the serial port

When in the Wiegand mode, each data byte in the TX or RX buffer of the serial port represents one bit of Wiegand data. This bit is recorded in the least significant bit position of each data byte in the buffer. For your application's convenience, when the serial port receives Wiegand bit stream, it adds an offset of 30Hex to each data bit. Therefore, the data recorded into the RX buffer can only consist of bytes 30H and 31H. These correspond to ASCII characters '0' and '1'. This way, when your application reads RX buffer contents into a string variable the data will  be "readable" without any additional conversion (ASCII characters with codes 0 and 1 would not be "readable").

When the serial port outputs Wiegand data, it only takes bit 0 of each byte in the TX buffer. Other bits can contain any data. You can, for instance, put a string of ASCII characters '0' and '1' into the TX buffer and these will be correctly interpreted as data bits 0 and 1. This, again, is convenient for your BASIC application.

How the serial port transmits Wiegand data

Wiegand data output timing is fixed and your application cannot change it. Data pulses are 100uS wide and inter-pulse gaps are 2mS wide.

How the serial port receives Wiegand data

You already know that W0&1in input of the serial port must receive a logical AND of W0 and W1 output of attached Wiegand device. A simple AND gate will do the job (figure A below). Actually, NOR-AND gates are more popular and these can be used too (figure B). In case you are building a product that will also accept clock/data input, you may need to control whether the W0&1in input should receive a logical AND of two lines, or just one of the lines. Schematic diagram C uses an additional I/O line of the device to control this. When the control line is HIGH the W0&1in input receives a logical AND of both W0 and W1 lines, when the control line is LOW, the W0&1in input receives just the signal from the W0 line. Four gates are required for this, so you will get away with using a single 74HC00 IC.




The serial port does not require an incoming Wiegand data stream to adhere to any strict timing. The port is simply registering high-to-low transitions on the W0&1in line. When such transition is detected, the port checks the state of W1 line. If the line is HIGH, data bit 0 is registered, when the line is low, data bit 1 is registered.

The end of Wiegand transmission is identified by timeout- the serial port has a special property for that, called "intercharacter delay" (see Serial Settings). Another property- "auto-close"- can be used to disable the serial port after the delay has been encountered. This way, when the Wiegand output is over the port will be disabled and no further data will enter the port until you re-enable it.