简体   繁体   中英

pywinusb Write to HID magstripe card encoder

I've been tasked to create a (very tightly time constrained) tkinter application that can read and write ISO-7811 spec'd magnetic cards for a POC. I'm using the MSR605x encoder that complies to the standard mentioned.

So far I've been able to set the encoder into read mode and read back a card swipe using feature reports and setting the needed raw data commands.

I'm unable to get the encoder into write mode by sending the specified control commands and the data blob I want written to the card using feature reports. As I understand it the device dictates the report types it can interface with. The device in question specifies two: output and feature.

I attempted output reports with no luck. Ideally I'd prefer the device to use a COM port and not HID but there seems no way around that.

Is there a different library that i could try or am I missing something with my implementation?

This is some documentation I found for the device: http://carddevicestore.com/files/msr605_user_manual.pdf

I've added my scratch code. Any insights would be greatly appreciated.

import pywinusb.hid as hid
import time
def sample_handler(data):
    print("Raw data: {0}".format(data))

filter = hid.HidDeviceFilter(vendor_id=0x0801, product_id=0x0003)
devices = filter.get_devices()

if devices:
    device = devices[0]
    print "success"

device.open()
device.set_raw_data_handler(sample_handler)
out_report = device.find_feature_reports()[0]

cmd = (0x00,
0x1B,
0x61,
0x1B,
0x65,
0x1B,
0x61,
0x1B,
0x77,
0x1B,
0x73,
0x1B,
0x01,
0x41,
0x42,
0x43,
0x31,
0x32,
0x33,
0x1B,
0x02,
0x31,
0x32,
0x33,
0x34,
0x35,
0x1B,
0x03,
0x31,
0x32,
0x33,
0x34,
0x35,
0x3F,
0x1C
)
buffer = [0x00] * 65
i = 0
for x in cmd:
    buffer[i] = x
    i += 1

print buffer
out_report.set_raw_data(buffer)
out_report.send()
count = 0
while device.is_plugged() and count < 10:
    time.sleep(0.5)
    count += 1

device.close()

I figured out which control characters to send it. Still only using the feature report. This translates to ;3=3? on track two of a mag strip.

cmd = (0x00,
0x1B,
0x61,
0x1B,
0x77,
0x1B,
0x73,
0x1B,
0x02,
0x33,
0x3D,
0x33,
0x3F,
0x1C,
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM