|
60 | 60 | | Listen || IN | IN | IN | OUT | OUT | OUT | IN | OUT | OUT | |
61 | 61 | +--------++------+-----+-----+------+------+-----+-----+-----+-----+ |
62 | 62 |
|
63 | | -All lines use active low signalling. It probably would have made sense to invert the pins. |
64 | | -
|
65 | 63 | When a line is marked as an input, it should passively pull up the |
66 | 64 | line to 5v. Otherwise, the lines voltage should be dictatd by other |
67 | 65 | devices on the bus. |
@@ -334,20 +332,68 @@ async def write(self, message: GPIBMessage, data=bytes([0])): |
334 | 332 | ack = (await self.interface.read(1))[0] |
335 | 333 | assert GPIBMessage(ack) == GPIBMessage._Acknowledge |
336 | 334 |
|
337 | | - async def read(self, to_eoi=True): |
338 | | - await self.device.set_pulls(self.port_spec, high={pin.number for pin in self.listen_pull_high}) |
| 335 | + async def read(self, *, to_eoi=True): |
| 336 | + await self.interface.device.set_pulls(self.port_spec, high={pin.number for pin in self.listen_pull_high}) |
339 | 337 |
|
340 | 338 | eoi = False |
341 | 339 | while not eoi: |
342 | 340 | await self.interface.write(bytes([GPIBMessage.Listen.value])) |
343 | 341 | await self.interface.write(bytes([0])) |
344 | | - await self.interface.flush() |
345 | 342 |
|
346 | | - eoi = bool((await self.interface.read(1)).tobytes()[0] & 2) |
| 343 | + eoi = bool((await self.interface.read(1))[0] & 2) |
347 | 344 | if not to_eoi: |
348 | 345 | eoi = True |
349 | 346 |
|
350 | | - yield (await self.interface.read(1)).tobytes() |
| 347 | + yield (await self.interface.read(1)) |
| 348 | + |
| 349 | + async def send_to(self, address, data): |
| 350 | + await self.cmd_talk(address) |
| 351 | + await self.write(GPIBMessage.Data, data) |
| 352 | + await self.write(GPIBMessage.DataEOI, b'\n') |
| 353 | + await self.cmd_untalk() |
| 354 | + |
| 355 | + async def read_from(self, address, *, to_eoi=True): |
| 356 | + await self.cmd_listen(address) |
| 357 | + all = bytes([]) |
| 358 | + async for data in self.read(to_eoi=to_eoi): |
| 359 | + all += data |
| 360 | + |
| 361 | + return all |
| 362 | + |
| 363 | + async def iter_from(self, address, *, to_eoi=True): |
| 364 | + await self.cmd_listen(address) |
| 365 | + async for data in self.read(to_eoi=to_eoi): |
| 366 | + yield data |
| 367 | + |
| 368 | + async def cmd_talk(self, address): |
| 369 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.MTA.value | address])) |
| 370 | + |
| 371 | + async def cmd_untalk(self): |
| 372 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.UNT.value])) |
| 373 | + |
| 374 | + async def cmd_listen(self, address): |
| 375 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.MLA.value | address])) |
| 376 | + |
| 377 | + async def cmd_unlisten(self): |
| 378 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.UNL.value])) |
| 379 | + |
| 380 | + async def cmd_ppe(self, address): |
| 381 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.PPE.value | address])) |
| 382 | + |
| 383 | + async def cmd_ppd(self, address): |
| 384 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.PPD.value | address])) |
| 385 | + |
| 386 | + async def cmd_spe(self): |
| 387 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.SPE.value])) |
| 388 | + |
| 389 | + async def cmd_spd(self): |
| 390 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.SPD.value])) |
| 391 | + |
| 392 | + async def cmd_llo(self): |
| 393 | + await self.write(GPIBMessage.Command, bytes([GPIBCommand.LLO.value])) |
| 394 | + |
| 395 | + async def ifc(self): |
| 396 | + await self.write(GPIBMessage.InterfaceClear) |
351 | 397 |
|
352 | 398 |
|
353 | 399 | class GPIBControllerApplet(GlasgowApplet): |
@@ -430,14 +476,10 @@ def check_address(value): |
430 | 476 |
|
431 | 477 | async def interact(self, device, args, iface): |
432 | 478 | if args.command: |
433 | | - await iface.write(GPIBMessage.Command, bytes([GPIBCommand.MTA.value | args.address])) |
434 | | - await iface.write(GPIBMessage.Data, bytes(command.encode("ascii"))) |
435 | | - await iface.write(GPIBMessage.DataEOI, b'\n') |
436 | | - await iface.write(GPIBMessage.Command, bytes([GPIBCommand.UNT.value])) |
| 479 | + await iface.send_to(args.address, args.command.encode("ascii")) |
437 | 480 |
|
438 | 481 | if args.read_eoi: |
439 | | - await iface.write(GPIBMessage.Command, bytes([GPIBCommand.MLA.value | args.address])) |
440 | | - async for data in iface.read(True): |
| 482 | + async for data in iface.iter_from(args.address, to_eoi=True): |
441 | 483 | sys.stdout.buffer.write(data) |
442 | 484 | sys.stdout.buffer.flush() |
443 | 485 |
|
|
0 commit comments