MCPcopy
hub / github.com/RUB-NDS/PRET / cmd

Method cmd

pcl.py:18–38  ·  view source on GitHub ↗
(self, str_send, fb=True)

Source from the content-addressed store, hash-verified

16 # --------------------------------------------------------------------
17 # send PCL command to printer, optionally receive response
18 def cmd(self, str_send, fb=True):
19 str_recv = "" # response buffer
20 token = str(random.randrange(2**8, 2**15) * -1) # -256..-32767
21 footer = c.ESC + "*s" + token + "X" # echo delimiter
22 # send command to printer device
23 try:
24 cmd_send = c.UEL + c.PCL_HEADER + str_send + footer + c.UEL
25 # write to logfile
26 log().write(self.logfile, c.ESC + str_send + os.linesep)
27 # sent to printer
28 self.send(cmd_send)
29 # use random token as delimiter for PCL responses
30 str_recv = self.recv("ECHO " + token + ".*$", fb)
31 # crop all PCL lines from received buffer
32 str_recv = re.sub(r"\x0d?\x0a?\x0c?PCL.*\x0a?", "", str_recv)
33 return str_recv
34
35 # handle CTRL+C and exceptions
36 except (KeyboardInterrupt, Exception) as e:
37 self.reconnect(str(e))
38 return ""
39
40 # --------------------------------------------------------------------
41 # remove functions not implemented in pcl

Callers 7

idlistMethod · 0.95
retrieve_dataMethod · 0.95
define_macroMethod · 0.95
delete_macroMethod · 0.95
do_infoMethod · 0.95
do_freeMethod · 0.95
do_selftestMethod · 0.95

Calls 5

logClass · 0.90
reconnectMethod · 0.80
writeMethod · 0.45
sendMethod · 0.45
recvMethod · 0.45

Tested by

no test coverage detected