I have had a look at some other topics involving setting up a TCP connection, and have managed to send some data to a label printer successfully.
Just trying to figure out the best and most reliable way to do it.
Printer is an Intermec PD43 label printer.
Using IPL commands to send data / commands to printer.
I have tried the following two methods:
1) Purely using Python scripting
Unfortunately I cant figure out why sometimes it works and sometimes it doesn’t (with no indication of an error).
def printLogLabels(data): # data - pyList of serial numbers to print. ie: [1000000321, 1000000123] import socket import sys scriptName = 'shared.production.printLogLabels ' log = system.util.getLogger("Script Debugger") tcp_ip = '192.168.44.198' tcp_port = 9101 try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((tcp_ip, tcp_port)) # Loop through data list and send print command for each serial number for item in data: MESSAGE = "<STX><ESC><E2<CAN><ETX><STX><ESC>F1<LF>" + str(item) + "<ETX><STX><ETB><ETX>" print MESSAGE s.send(MESSAGE) # end for s.close() return True except: shared.log.scriptError(scriptName + str(sys.exc_info())) return False # end try # end def
I’m wondering if there is some issue with socket connection that i need to check the status of somehow.
I read in an earlier topic that changing the tcp port and back again worked, which i have had some success with.
2) Ignition TCP Driver
I have also looked at using the Ignition TCP Driver to do the same thing, and have had some pretty good success with that.
I’ve been writing directly to the TCP Driver tag using:
try: for item in data: message = "<STX><ESC><E2<CAN><ETX><STX><ESC>F1<LF>" + str(item) + "<ETX><STX><ETB><ETX>" system.tag.write("Gisborne01/ProdSystems/IntermecPD43/Writable", message) # end for return True except: shared.log.scriptError(scriptName + str(sys.exc_info())) return False # end try
Is it better practise to use the method mentioned in this post when writing to TCP driver tags?
Should I be clearing the tag myself after every write? Seems like i don’t have to.
Also how can i detect errors with the connection? I don’t think i can use the Inactivity Timeout because i’m never actually receiving data from the source.
Pulling the Ethernet cable doesn’t seem to affect tag quality or device status.