Showing posts with label Windows 7. Show all posts
Showing posts with label Windows 7. Show all posts

Friday, February 4, 2011

Read from Magtek card swipe reader in HID mode using libusb-win

This post deals with reading card swipe information from a Magtek USB Swipe Reader when set in HID mode. I used Visual Studio C++ Express Edition for a windows development environment. I installed libusb-win32 from http://www.libusb.org/wiki/libusb-win32
Create a C++ project in Visual studio, include the usb.h file and link the project with libusb.lib. Both of these are included in the libusb package.

The following can be used to read the card information-

// magtekusbhidcardswipe.cpp : Defines the entry point for the console application.
//
#include
#include

#include "stdafx.h"
#include "usb.h"

int _tmain(int argc, _TCHAR* argv[])
{
    struct usb_bus *busses;
    struct usb_bus *bus;
    struct usb_device *dev;
    int c, i, res;
    char data[337];
    char idata[10];

    usb_init();
    usb_find_busses();
    usb_find_devices();
    busses = usb_get_busses();
    for (bus = busses; bus; bus = bus->next) {

        for (dev = bus->devices; dev; dev = dev->next) {           
        if(dev->descriptor.idProduct == 2 && dev->descriptor.idVendor == 0x801) {
        printf("Product id: %04hx" ,dev->descriptor.idProduct);
        printf("Vendor id: %04hx \n" ,dev->descriptor.idVendor);
               
        usb_dev_handle *l_Handle = usb_open( dev);
        if( NULL == l_Handle ){
            printf( "usb_open(): no handle to device\n" );
        }
        res = usb_claim_interface(l_Handle, 0);
        if(res  < -EBUSY) {
            printf("Device interface not available to be claimed! \n");
            exit(0);
        }
        if(res < -ENOMEM) {
            printf("Insufficient Memory! \n");
            exit(0);
        }
        printf( "\nPlease swipe your card\n",res );
       
        res = usb_interrupt_read(l_Handle, 0x81, data, 337, -1);
        printf( "\nusb_interrupt_read %d \n",res ); 
       
        c=-1;
                //I am interested in only 10 characters in this range
        for(i=1;i<10;i++) {
            idata[++c] = data[i];
        }
        c=atoi(idata);
        printf( "\nMy data : %d\n",c);
       
        usb_release_interface(l_Handle, 0);            
        usb_close(l_Handle);
        }
       }
    }
    getchar();
    return 0;
}
 


Suggestions/improvements are welcome as always.



Tuesday, October 20, 2009

Windows - the Seventh

“And the SEVENTH angel poured out his vial into the air; and there came a great voice out of the temple of heaven, from the throne saying, It is DONE.” (Revelation 16 : 17)

The number 'Seven' has a lot of significance. There are seven days in a week and it was on the seventh day that the world was completed. 'Seven' symbolizes completeness or perfection. Perfection is only divine. At an earthly level, I would attribute seven to refinement. In that respect, Microsoft has achieved elegance with W7. A few things I like about W7 are:
1. The annoying UAC has become much more placid. Introduced in Vista, as a security measure, it turned out to irritate the users with its frequent pop-ups.
2. The boot performance is significantly faster. Windows 7 should have achieved a 15-sec boot up by the time it is up for final release.
3. W7 lets the users connect to wireless networks instantly with fewer clicks which will prove to be of lot of help, for users without much technical know-how.
4. The footprint of the OS is much lighter compared to Vista. It installs faster and occupies lesser space on the hard disk. Some of additional software like Windows Mail have been made optional downloads instead of default installations.
5. The new OS uses lesser battery power and is known to save energy by 20%. That is a very good news for netbook makers as, Windows 7 will prove to be the OS for netbooks, too.
6. There are some cool mouse gestures included: Aero Peek and Aero Shake. Aero Peek makes all the open windows transparent and lets the users peek through their desktop revealing hidden gadgets and icons while, Aero Shake lets the users minimize unnecessary windows from the desktop by shaking the required window.
7. The OS supports backward compatibility. Legacy applications can run in a Windows XP mode, inside of Window 7.

And, something I don't like about W7:
1. Microsoft failed to come up with a suitable strategy for integrating the cloud. With computing being the talk of the town, and Microsoft itself working on Azure, the Software as a Service(Saas) integration seems to have been lost in translation. Microsoft could have amalgamated its Live Mesh with Windows 7 for data backup.
2. W7 still lives on to the concept of one partition OS. I would have liked this to change. The data like Documents, Music, Pictures and other user settings should reside on a different partition than the OS itself. This would be of great value in case of a system crash or an OS reinstall.

Overall, W7 is a nice compact mixture of niceties and removes some of the nuisances of Vista.