I am using the following code to extract information from the the Card Number and Facility code using a USB Smartcard reader. It works great in Script Console but wont find any devices (i.e. Index out of bounds on cardTerminal = terminalList.get(0)) when I load it into an onStartup event script for a text box. Do I need to move the script to a different part of the perspective session or is there no way to access peripheral devices from perspective?
from javax import smartcardio
terminalFactory = TerminalFactory.getDefault()
cardTerminals = terminalFactory.terminals()
terminalList = cardTerminals.list()
cardTerminal = terminalList.get(0)
cardTerminal.waitForCardPresent(0)
card = cardTerminal.connect("*")
card_string = str(card)
channel = card.getBasicChannel();
aid = b'\xA0\x05\xA1\x03\x80\x01\x04'
apdu = smartcardio.CommandAPDU(0xFF, 112, 7, 107, aid, 256)
r = channel.transmit(apdu)
data = r.getData()
bytedata = []
bitstring = ""
for i in range(4):
if data[i+3] < 0:
bitstring = bitstring + "{0:b}".format(256+data[i+3]).zfill(8)
else:
bitstring = bitstring + "{0:b}".format(data[i+3]).zfill(8)
FC = int(bitstring[1:9],2)
CN = int(bitstring[12:25],2)