[ucc] Magnetic Card Readers
Trent Lloyd
trent at ucc.gu.uwa.edu.au
Sat Nov 2 00:30:15 WST 2002
Hey Guys,
I have succesfully interfaced one of Dav's Card reader to my
computer by hooking it up to the game port (15pin, usually on
your sound card)
This is convienient because the game port provides a good 5v
power source which is exactly waht the card reader needs.
It seems to 'work' and my C code for it so far prints out things like
S00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001011111100111000001110100001000010011011010000101101101101010100001110011010110110101101000010110011010001000111100001000000001101100101100000000000000000000000
Clocks: 248
(Ive pasted my C code at the end)
This is basically 'S' means detected a card loaded, the bits are
a bitstream of the data and Clocks: 248 is the number of 'clocks
(i.e. data bits) that it detected
Linux does seem to have trouble keeping track of all of the data
bits, so I plan to get some AVR stuff hooked up to it and hopefully
thatl work better.
Interfacing was relatively easy, wiring
{1, 2, 4, 7, 10} - {+, DATA, GROUND, CLOCK, LOAD}
the numbners being the pins respective of the GAME port.
Total Cost: $1.60 (For the male 15pin sub D connector)
Hope this is interesting to some people :)
-- Trent
(note this is linux-only)
-- start C code --
#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
#include <string.h>
#define CLOCK 6
#define LOAD 5
#define DATA 4
int main(int argc, char *argv)
{
unsigned int data, clock, oldclock, rinp, load, bcount, clocks,
lcl;
char section;
ioperm(0x201, 1, 1);
ioperm(0x80, 1, 1);
oldclock = 0;
bcount = 0;
for(;;) {
rinp = ~(inb_p(0x201));
clock = !!(rinp & (1 << CLOCK));
load = !!(rinp & (1 << LOAD));
data = !!(rinp & (1 << DATA));
if (clock && !oldclock) {
printf("%i", data);
clocks++;
}
if (load && !lcl) { printf("S"); }
if (!load && lcl) { printf("\nClocks: %i\n", clocks);
clocks = 0;}
fflush(stdout);
lcl = load;
oldclock = clock;
}
}
-- end-
More information about the ucc
mailing list