简体   繁体   English

pywinusb写入HID磁条卡编码器

[英]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. 我的任务是创建一个(非常受时间限制的)tkinter应用程序,该应用程序可以为POC读写ISO-7811规格的磁卡。 I'm using the MSR605x encoder that complies to the standard mentioned. 我正在使用符合上述标准的MSR605x编码器。

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. 我无法通过使用功能报告发送指定的控制命令和要写入卡的数据Blob来使编码器进入写入模式。 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. 理想情况下,我希望设备使用COM端口而不是HID,但似乎无法解决。

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 这是我为该设备找到的一些文档: 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? 这相当于; 3 = 3? on track two of a mag strip. 在磁条的第二磁道上。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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