CAN Bus logger: Difference between revisions

No edit summary
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The following script will output all CAN bus messages received on CAN channel 1 to the RaceCapture/Pro log window.
The script shown below will output all CAN bus messages received on CAN channel 1 to the RaceCapture/Pro log window.


After writing the script, you can observe the output in the log monitor window in the RaceCapture app.
This is useful for seeing raw data from the CAN bus and can serve as a general diagnostic aid.


==Using a Terminal Program==
==Using the CAN Bus logger==
However, to gather large amounts of data, we recommend connecting directly to RaceCapture/Pro's serial console using a terminal program like Hyperterminal, RealTerm, minicom or similar.
* Copy (Ctrl-C) and paste (Ctrl-V) the script below into the script window of the app
** '''Note:''' Ensure any existing script is erased before copying in this logger script.
* Set the correct baud rate in RaceCapture's '''CAN Settings''' page
** Typical baud rates are: 250000, 500000 and 1000000
** It's a good idea to also set the same baud rate in the CAN Bus configuration view.
* Click the write configuration button (down arrow button on left) to write the script to RaceCapture/Pro.
* Check the check box to poll the log file. This will cause messages from the script to show up in the bottom window.
* Click the circular-arrow button to re-load the script.


* Close the RaceCapture app
[[Image:RaceCapture_CAN_bus_logger_scrip_view.png]]
* Connect to the RaceCapture device using HyperTermianl, RealTerm or Minicom using the COM port assigned by the operating system.
* Press <Enter> to see a list of commands
* View the log by issuing the command 'viewLog' at the serial console.
* You will see a dump of the CAN bus data to the screen.


==Script==
===Use the Preset===
We recommend using the provided preset for the CAN bus logger - just press '''Preset''' below the scripting window.
* '''Note''': You may need to update your presets by pressing the cloud update button.


===Copy / Paste script===
<pre>
<pre>
--500K baud. set your baud rate here.
-- Log messages from CAN bus
initCAN(0, 500000)
-- be sure to set the correct baud rate in the CAN settings


setTickRate(30)  --onTick() will be called at 30Hz.
--------------------------------------------------
-- change this to 0 for CAN bus 1, or 1 for CAN bus 2
canBus = 0
--------------------------------------------------


--this function drains all pending CAN messages
--this function drains all pending CAN messages
--and outputs messages to the log
--and outputs messages to the log
function outputCAN()
function outputCAN()
repeat  
repeat  
id, ext, data = rxCAN(0, 100)
  id, ext, data = rxCAN(canBus, 1000)
if id ~= nil then
  if id ~= nil then
print(id ..', ')
  print('[' ..id ..']: ')
for i = 1,#data do
  for i = 1,#data do
print(data[i] ..', ')
    print(data[i] ..', ')
end
  end
println('')
  println('')
end
  end
until id == nil
until id == nil
    println('Timeout: no CAN data')
end
end
   
   
function onTick()
function onTick()
outputCAN()
outputCAN()
end
end
setTickRate(30)
</pre>
</pre>
==Watching for messages==
If RaceCapture/Pro is receiving CAN bus messages, you will see them in the window below the script.
==I don't see data==
If you don't see the CAN bus messages you were expecting, there could be a number of issues:
* Baud rate is incorrect.  Determine the correct baud rate for the BUS and try agian.
* Bus termination is incorrect. RaceCapture/Pro has built in CAN bus termination. Ensure your CAN bus is balanced with terminators on each end.
* Interference / poor wire connection. Try shortening the wire or checking the connections.
* Incorrect Wiring for CAN bus connections. See the [[RaceCapturePro#Quick_Reference|Quick Reference]] for the pinout for the CAN bus connections. Ensure you're connected to the CAN bus used in the script (CAN 1 is the default for the script).
* Reversed CAN High and CAN Low wiring. Re-check the wiring.
==Advanced: Using a Terminal Program==
To gather large amounts of data, we recommend connecting directly to RaceCapture/Pro's serial console using a terminal program like Hyperterminal, RealTerm, minicom or similar.
* Close the RaceCapture app
* Connect to the RaceCapture device using HyperTerminal, RealTerm or Minicom using the COM port assigned by the operating system.
* Press <Enter> to see a list of commands
* View the log by issuing the command 'viewLog' at the serial console.
* You will see a dump of the CAN bus data to the screen.

Revision as of 15:00, 16 May 2019

The script shown below will output all CAN bus messages received on CAN channel 1 to the RaceCapture/Pro log window.

This is useful for seeing raw data from the CAN bus and can serve as a general diagnostic aid.

Using the CAN Bus logger

  • Copy (Ctrl-C) and paste (Ctrl-V) the script below into the script window of the app
    • Note: Ensure any existing script is erased before copying in this logger script.
  • Set the correct baud rate in RaceCapture's CAN Settings page
    • Typical baud rates are: 250000, 500000 and 1000000
    • It's a good idea to also set the same baud rate in the CAN Bus configuration view.
  • Click the write configuration button (down arrow button on left) to write the script to RaceCapture/Pro.
  • Check the check box to poll the log file. This will cause messages from the script to show up in the bottom window.
  • Click the circular-arrow button to re-load the script.

RaceCapture CAN bus logger scrip view.png

Script

Use the Preset

We recommend using the provided preset for the CAN bus logger - just press Preset below the scripting window.

  • Note: You may need to update your presets by pressing the cloud update button.

Copy / Paste script

-- Log messages from CAN bus
-- be sure to set the correct baud rate in the CAN settings

--------------------------------------------------
-- change this to 0 for CAN bus 1, or 1 for CAN bus 2
canBus = 0
--------------------------------------------------

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN()
 repeat 
  id, ext, data = rxCAN(canBus, 1000)
  if id ~= nil then
   print('[' ..id ..']: ')
   for i = 1,#data do
    print(data[i] ..', ')
   end
   println('')
  end
 until id == nil
    println('Timeout: no CAN data')
end
 
function onTick()
 outputCAN()
end

setTickRate(30)

Watching for messages

If RaceCapture/Pro is receiving CAN bus messages, you will see them in the window below the script.

I don't see data

If you don't see the CAN bus messages you were expecting, there could be a number of issues:

  • Baud rate is incorrect. Determine the correct baud rate for the BUS and try agian.
  • Bus termination is incorrect. RaceCapture/Pro has built in CAN bus termination. Ensure your CAN bus is balanced with terminators on each end.
  • Interference / poor wire connection. Try shortening the wire or checking the connections.
  • Incorrect Wiring for CAN bus connections. See the Quick Reference for the pinout for the CAN bus connections. Ensure you're connected to the CAN bus used in the script (CAN 1 is the default for the script).
  • Reversed CAN High and CAN Low wiring. Re-check the wiring.

Advanced: Using a Terminal Program

To gather large amounts of data, we recommend connecting directly to RaceCapture/Pro's serial console using a terminal program like Hyperterminal, RealTerm, minicom or similar.

  • Close the RaceCapture app
  • Connect to the RaceCapture device using HyperTerminal, RealTerm or Minicom using the COM port assigned by the operating system.
  • Press <Enter> to see a list of commands
  • View the log by issuing the command 'viewLog' at the serial console.
  • You will see a dump of the CAN bus data to the screen.