Connect to remote device: open
(self, arg, mode="")
| 202 | |
| 203 | # ------------------------[ open <target> ]--------------------------- |
| 204 | def do_open(self, arg, mode=""): |
| 205 | "Connect to remote device: open <target>" |
| 206 | if not arg: |
| 207 | arg = eval(input("Target: ")) |
| 208 | # open connection |
| 209 | try: |
| 210 | newtarget = arg != self.target |
| 211 | self.target = arg # set new target |
| 212 | self.conn = conn(self.mode, self.debug, self.quiet) |
| 213 | self.conn.timeout(self.timeout) |
| 214 | self.conn.open(arg) |
| 215 | print(("Connection to " + arg + " established")) |
| 216 | # hook method executed after successful connection |
| 217 | self.on_connect(mode) |
| 218 | # show some information about the device |
| 219 | if not self.quiet and mode != "reconnect": |
| 220 | sys.stdout.write("Device: ") |
| 221 | self.do_id() |
| 222 | print("") |
| 223 | # set printer default values |
| 224 | self.set_defaults(newtarget) |
| 225 | except Exception as e: |
| 226 | output().errmsg("Connection to " + arg + " failed", e) |
| 227 | self.do_close() |
| 228 | # exit if run from init function (command line) |
| 229 | if mode == "init": |
| 230 | self.do_exit() |
| 231 | |
| 232 | # wrapper to send data |
| 233 | def send(self, data): |