Skip to content

Commit e270a3c

Browse files
Improved documentation and testing of ASCWriter.
1 parent fd879fd commit e270a3c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

can/CAN.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class ASCWriter(Listener):
233233

234234
def __init__(self, filename):
235235
now = datetime.now().strftime("%a %b %m %I:%M:%S %p %Y")
236-
self.start = time.time()
236+
self.started = time.time()
237237
self.log_file = open(filename, "w")
238238
self.log_file.write("date %s\n" % now)
239239
self.log_file.write("base hex timestamps absolute\n")
@@ -254,8 +254,8 @@ def on_message_received(self, msg):
254254
if msg.id_type:
255255
arb_id = arb_id + "x"
256256
timestamp = msg.timestamp
257-
if timestamp >= self.start:
258-
timestamp -= self.start
257+
if timestamp >= self.started:
258+
timestamp -= self.started
259259

260260
line = self.LOG_STRING.format(time=timestamp,
261261
channel=1,

doc/listeners.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ These Listeners simply create csv and sql files with the messages received.
5757
ASCWriter
5858
---------
5959

60-
Logs CAN data to an ASCII log file.
60+
Logs CAN data to an ASCII log file compatible with other CAN tools such as
61+
Vector CANalyzer/CANoe and other.
62+
Since no official specification exists for the format, it has been reverse-
63+
engineered from existing log files. One description of the format can be found `here
64+
<http://zone.ni.com/reference/en-XX/help/370859J-01/dlgcanconverter/dlgcanconverter/canconverter_ascii_logfiles/>`_.
6165

6266
.. autoclass:: can.ASCWriter
6367
:members:

test/listener_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,16 @@ def testSQLWriterReceives(self):
6767

6868
def testAscListener(self):
6969
a_listener = can.ASCWriter("test.asc")
70-
notifier = can.Notifier(self.bus, [a_listener], 0.1)
7170
msg = can.Message(extended_id=True,
71+
timestamp=a_listener.started + 0.5,
7272
arbitration_id=0xabcdef,
7373
data=[1, 2, 3, 4, 5, 6, 7, 8])
74-
self.bus.send(msg)
75-
sleep(0.5)
74+
a_listener(msg)
7675
msg = can.Message(extended_id=False,
76+
timestamp=a_listener.started + 1,
7777
arbitration_id=0x123,
7878
data=[0xff, 0xff])
79-
self.bus.send(msg)
80-
notifier.stop()
79+
a_listener(msg)
8180
a_listener.stop()
8281
with open("test.asc") as f:
8382
print("Output from ASCWriter:")

0 commit comments

Comments
 (0)