Barcode Printer Issues

I am attempting to send a string to a barcode printer. I found two scripts, at the end of this post, on the forum.

The first successfully prints the barcode the first time it is run, but does nothing the second time it runs. Restarting the printer allows printing one more barcode.

The second script does not do anything; no errors, no printer output.

If anyone can tell me how to get script 1 to print labels each time it runs, or how to get script 2 to work at all, or has a better solution, I would be very grateful!!!

Script 1---------------------------------------

strMessage="""
P
E2;F2
H0;o5,5;d3,PART NUMBER FORMAT
B1;o10,10;i1;d0,13
R
E2
F1123
“”"

#================

Import Socket Library

#================
import socket

#================

Get Printer IP and Port

#================
strIP = ‘192.168.123.87’
port=9100

#================

Send Data to Printer

#================
updSocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
updSocket.connect((strIP,port))
updSocket.sendall(strMessage)
updSocket.close

Script 2---------------------------------------

strMessage="""
P
E2;F2
H0;o5,5;d3,PART NUMBER FORMAT
B1;o10,10;i1;d0,13
R
E2
F1123
“”"

#================

Import Socket Library

#================
import socket

#================

Get Printer IP and Port

#================
strIP = ‘192.168.123.87’
port=9100

#================

Send Data to Printer

#================
import system
udpSocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
udpSocket.sendto(strMessage,(strIP,port))

In script 1, I added “()” to the socket.close so that it is socket.close() now and all is well…