Page 1 of 1


Posted: Sat Aug 06, 2016 3:59 am
by lpettipa
Can anyone provide a simple example of how to use setCANfilter? Say to read only one particular CAN id only?

Posted: Sat Aug 06, 2016 8:27 am
by Adli
Ping - Also Interested.

Right now im achieving this using the logging script provided in the wiki - but im chasing a CAN stream of data that needs to be masked, and this seems like the only way?

I'd like to work this into a specific channel (Say ID 268) and mask 2 bytes (#2,3) with 0FFF...

Cant seem to use Hex, so can i use 1+0?

Code: Select all

setCANfilter(0, 268, 0, 00110000, 0111)

Posted: Sat Aug 06, 2016 8:29 am
by Adli
FYI, my code for logging a single CAD ID is below, shown with ID 999, adapted from ASL RCP2 Wiki
The key change is

Code: Select all

if id == 999 then
Full Lua Script

Code: Select all

--500K baud. set your baud rate here.
initCAN(0, 500000) 

setTickRate(30)  --onTick() will be called at 30Hz.

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN()
		id, ext, data = rxCAN(0, 100)
		if id == 999 then
			print(id ..', ')
			for i = 1,#data do
				print(data[i] ..', ')
	until id == nil
function onTick()

Posted: Sat Aug 06, 2016 7:43 pm
by lpettipa

I didn't know how to do hex either - but learned today - very easy. So if DEC=1280 (which is hex 500), were you would enter 1280, enter 0x500. Worked for me.

But if you print the can ID, it will still be in DEC. So I used this little function I found on google:

Code: Select all

function DEC_HEX(IN)
    local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
    while IN>0 do
    return OUT
just stick this function code in before your looping program.

so your print would look like this:

Code: Select all

ID will print in HEX

Posted: Sat Aug 06, 2016 7:50 pm
by lpettipa
so I'm trying to read values off a really busy CAN bus on a few specific ID's. Using the same method as Adli. Not sure it will help anyone else, but my tick rate was 100, and not much was coming thru - set tick rate to 1000, and now data is flowing.

This is not a solution - I think setCANfilter is the solution, awaiting firmware rev 2.10 to fix this......