Replay UART
We highly encourage everyone to use our new Python package which is packed with features. This library is still supported, but is not recommended for new design.
The following script can be used to repeat UART streams captured and exported from Saleae Logic. After the capture is completed, export the Async Serial analyzer results as a csv file. You can follow this guide to export the file. The exported data should be in HEX-- Note that the base/radix of the exported data will match the current setting for display in the software.
Simply modify the parameters in lines 9-18 in the script below and then everything is ready to play back the file from the Binho Multi-Protocol USB Host Adapter.
For easy testing, here's an example export file from Saleae Logic that works with this script:
uart_9600.csv
2KB
Binary
1
from binhoHostAdapter import binhoHostAdapter
2
from binhoHostAdapter import binhoUtilities
3
4
from datetime import datetime, timedelta, time
5
import math
6
import csv
7
8
9
uartIndex = 0
10
uartBaudRate = 9600
11
uartDataBits = 8
12
uartParity = 'NONE'
13
uartStopBits = 1
14
uartEscapeString = "+++UART0"
15
16
captureExportFile = 'C:\\Users\\Batman\\Desktop\\LogicExports\\uart_9600.csv'
17
18
binhoCommPort = 'COM27'
19
20
21
# ---- No Need to Change Anything Below Here ----
22
23
print("Opening " + binhoCommPort + "...")
24
print()
25
26
# create the binhoHostAdapter object
27
binho = binhoHostAdapter.binhoHostAdapter(binhoCommPort)
28
29
print("Connecting to binho host adapter...")
30
print()
31
32
print("Connected!")
33
print()
34
binho.setLEDColor('YELLOW')
35
36
print("Setting UART bus parameters:")
37
print()
38
binho.setOperationMode(0, 'UART')
39
40
print('BaudRate: ' + str(uartBaudRate))
41
binho.setBaudRateUART(uartIndex, uartBaudRate)
42
43
print('Databits: ' + str(uartDataBits))
44
binho.setDataBitsUART(uartIndex, uartDataBits)
45
46
print('Parity Bit: ' + str(uartParity))
47
binho.setParityUART(uartIndex, uartParity)
48
49
print('Stop Bits: ' + str(uartStopBits))
50
binho.setStopBitsUART(uartIndex, uartStopBits)
51
52
binho.setEscapeSequenceUART(uartIndex, uartEscapeString)
53
54
print()
55
print("Computing USB Transit time...")
56
t0 = datetime.now()
57
binho.ping()
58
binho.ping()
59
binho.ping()
60
binho.ping()
61
binho.ping()
62
t1 = datetime.now()
63
64
avgUSBTxTime = (t1 - t0)/5
65
print('Average USB Tx Time = ' + str(avgUSBTxTime) + 's')
66
print()
67
68
69
print("Beginning Replay...")
70
print()
71
binho.beginBridgeUART(uartIndex)
72
73
with open(captureExportFile) as captureExport:
74
capture_reader = csv.reader(captureExport, delimiter=',')
75
rowCount = 0
76
77
startTime = datetime.now()
78
prevTimestamp = startTime
79
prevRowTime = 0
80
81
for row in capture_reader:
82
83
if rowCount == 0:
84
85
# These are the column headers, just advance to the next row
86
rowCount += 1
87
print('Row#\tTimestamp\t\t\t\tData')
88
89
else:
90
91
currRowTime = float(row[0])
92
payload = int(row[1], 16)
93
94
deltaTimems = (currRowTime - prevRowTime) * 1000
95
#deltaTimems = 0.125 * 1000
96
#print('DeltaT: ' + str(deltaTimems))
97
#print('computed delta: ' + str(timedelta(0,0,0,math.floor(deltaTimems))))
98
99
while (datetime.now() - prevTimestamp) < timedelta(0,0,0,math.floor(deltaTimems)):
100
#nothing, sleep does not have high enough resolution
101
# print('WAITING ' + str(datetime.now() - prevTimestamp))
102
pass
103
104
binho.writeBridgeUART(chr(payload))
105
prevTimestamp = datetime.now()
106
prevRowTime = currRowTime
107
108
print(str(rowCount) + '\t' + str(prevTimestamp) + '\t\t' + str(payload))
109
110
rowCount += 1
111
112
binho.stopBridgeUART(uartEscapeString)
113
binho.ping()
114
print('Finished Replaying...')
115
print()
116
binho.setLEDColor('BLUE')
117
binho.close()
118
print('Goodbye!')
Copied!
Last modified 7mo ago
Copy link