Serial port com open failed

Hi,
I try to make screen for read UID number of and mifare card.
I put USB card-reader on my computer (the gateway is on a server) look for my port number (COM6) and try my code in the designer script console.

port_com = "COM6"
system.serial.configureSerialPort(
port=port_com,
bitRate = system.serial.BIT_RATE_9600
)
system.serial.openSerialPort(port_com)

try:
	
	uid = system.serial.readBytesAsString(port_com,12)
	print uid
	system.tag.writeAsync("[BorneChauffeur]test", uid) 
except Exception as e:
	print "Error in communication with %s: %s" % (port_com, str(e))
finally:
	#system.serial.closeSerialPort(port_com)
	print ""

This works perfectly!

If I try to put script on a button, it's tell me that he can't open port COM6.
I try many other way to open port COM but nothing work (session even, on startup...)

Have you got any idea?

thanks in advance.

You're using perspective. All those scripts are running on the gateway, not your client PC. You're not going to be able to access the client PC's COM port using Perspective most likely. You'll need Vision for that.

I bet if you put the reader on the server/gateway it may work with the button press.

A workaround with some fancy scripting and only if you're using a fixed set of machines might be to set up virtual COM ports on the server to link to a physical COM port on the client based on the IP address of the client. (I'm thinking if you have a master script on the server side that listens for requests sent from Perspective clients with the client IP (hopefully static) and then have a lookup for what virtual COM port to connect to for the reading of the card and pass the data back.)