27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
import os, json, time, struct, subprocess, re
|
|
from pathlib import Path
|
|
root=Path(__file__).resolve().parent
|
|
project=root.parents[1]
|
|
dll=project/'tmp/can1-test-20261002/pcan-basic/x64'
|
|
os.environ['PATH']=str(dll)+os.pathsep+os.environ['PATH']
|
|
handle=os.add_dll_directory(str(dll))
|
|
import can
|
|
cli=r'D:\STM32CubeCLT_1.19.0\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe'
|
|
results=[]
|
|
for rate in (250000,500000):
|
|
with can.Bus(interface='pcan',channel='PCAN_USBBUS1',bitrate=rate) as bus:
|
|
tag=rate+123
|
|
data=struct.pack('<HHI',1,1,tag)
|
|
errors=[]
|
|
for i in range(20):
|
|
try: bus.send(can.Message(arbitration_id=0x6a6,data=data,is_extended_id=False),timeout=.1)
|
|
except Exception as exc: errors.append(str(exc)); break
|
|
time.sleep(.1)
|
|
status=hex(bus.status())
|
|
r=subprocess.run([cli,'-c','port=SWD','mode=HOTPLUG','freq=1000','-r32','0x200002cc','128'],capture_output=True,timeout=15)
|
|
(root/f'probe_{rate}_ram.log').write_bytes(r.stdout+r.stderr)
|
|
result={'bitrate':rate,'tag':tag,'pcan_status':status,'send_errors':errors,'ram':r.stdout.decode(errors='replace')}
|
|
results.append(result)
|
|
print(json.dumps(result),flush=True)
|
|
(root/'link-probe.json').write_text(json.dumps(results,indent=2),encoding='utf-8')
|