11import logging
22import asyncio
3- import time
43
54from amaranth import *
65
76from ... import *
87
98from glasgow .simulation .assembly import SimulationAssembly
109from glasgow .gateware .ports import PortGroup
11- from . import GPIBControllerApplet , GPIBControllerInterface
10+ from . import GPIBControllerApplet , GPIBControllerInterface , GPIBStatus , GPIBMessage
11+
1212
1313logger = logging .getLogger (__name__ )
1414
@@ -17,39 +17,40 @@ class GPIBControllerAppletTestCase(GlasgowAppletV2TestCase, applet=GPIBControlle
1717 def test_build (self ):
1818 self .assertBuilds ()
1919
20-
21- # def talk_and_listen(self, iface):
22- # async def testbench(ctx):
23- # print(ctx)
24- # await iface.send_to(10, b'*IDN?')
25- # await iface.read_from(10)
26- # return testbench
27-
28- def listen_and_reply (self , iface ):
20+ def send_a_message (self , iface ):
2921 async def testbench (ctx ):
30- time .sleep (0.5 )
31- print (await iface .read_from (10 ))
32- await iface .send_to (10 , b'GLASGOW DIGITAL INTERFACE EXPLORER' )
22+ print ("hello from testbench" )
23+ # await iface.send_to(10, b'I')
24+ await iface .write (GPIBMessage .Data , b'I' )
25+ # await iface.write(GPIBMessage.Data, b'O')
26+ print ("message sent" )
3327 return testbench
3428
35-
36-
3729 def test_two_can_talk (self ):
3830 assembly = SimulationAssembly ()
3931 iface0 = GPIBControllerInterface (logger , assembly ,
40- dio = "A0:7" , eoi = "A8" , dav = "A9" , nrfd = "A10" , ndac = "A11" , srq = "A12" , ifc = "A13" , atn = "A14" , ren = "A15" )
41-
32+ dio = "A0:7" , eoi = "A8" , dav = "A9" , nrfd = "A10" , ndac = "A11" , srq = "A12" , ifc = "A13" , atn = "A14" , ren = "A15" )
4233 iface1 = GPIBControllerInterface (logger , assembly ,
43- dio = "B0:7" , eoi = "B8" , dav = "B9" , nrfd = "B10" , ndac = "B11" , srq = "B12" , ifc = "B13" , atn = "B14" , ren = "B15" )
34+ dio = "B0:7" , eoi = "B8" , dav = "B9" , nrfd = "B10" , ndac = "B11" , srq = "B12" , ifc = "B13" , atn = "B14" , ren = "B15" )
4435
45- for pin in range (0 ,16 ):
36+ # We skip IFC, ATN and REN, since they're always under the
37+ # control of the controller, and we're pretending one of the
38+ # controller isn't a controller....
39+ for pin in range (0 ,13 ):
4640 assembly .connect_pins ("A%i" % pin , "B%i" % pin )
4741
48- # assembly.add_testbench(self.talk_and_listen(iface0))
49- assembly .add_testbench (self .listen_and_reply (iface1 ))
42+ assembly .add_testbench (self .send_a_message (iface0 ))
5043
5144 async def do_it (ctx ):
52- await iface0 .send_to (10 , b'*IDN?' )
53- await iface0 .read_from (10 )
45+ import time
46+ time .sleep (0.1 )
47+ while True :
48+ response = b''
49+ async for data in iface1 .read (to_eoi = True ):
50+ response += data
51+ # print(data)
52+ # print("Talker:", GPIBStatus(await iface0._status.get()))
53+ # print("Listener:", GPIBStatus(await iface1._status.get()))
54+
5455
5556 assembly .run (do_it , vcd_file = "test.vcd" )
0 commit comments