# Accessing Peripheral Devices from Perspective Script

**URL:** <https://forum.inductiveautomation.com/t/accessing-peripheral-devices-from-perspective-script/81061>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [October 26, 2023, 10:59pm UTC](https://forum.inductiveautomation.com/t/accessing-peripheral-devices-from-perspective-script/81061 "2023-10-26T22:59:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawson\_Knight](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@Dawson\_Knight](https://forum.inductiveautomation.com/u/Dawson_Knight)\
**Post date:** [October 26, 2023, 10:59pm UTC](https://forum.inductiveautomation.com/t/accessing-peripheral-devices-from-perspective-script/81061/1 "2023-10-26T22:59:25Z")

</div>

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?

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 27, 2023, 12:42am UTC](https://forum.inductiveautomation.com/t/accessing-peripheral-devices-from-perspective-script/81061/2 "2023-10-27T00:42:27Z")

</div>

> [@Dawson\_Knight](#):
>
> no way to access peripheral devices from perspective?

This. Your script, in Perspective, is running on the gateway, and might find a smartcard plugged in there.

If you need this sort of thing, use Vision. It will work in a Vision client, because Vision runs UI scripts right in the client machine.

Sorry.
