RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Access mapped CAN channels via Lua
Author Message
Reply with quote
Post Access mapped CAN channels via Lua 
I have some mapped CAN channels that I'd like to be able to try to transmit on another bus. However, these do not currently appear to be available as virtual channels.

What I am trying to do:

Code:

function onTick()
current_foo = getChannel("Foo") -- foo is a mapped CAN channel via the can mapping section of the app
print(current_rpm)
end


The error:

Code:
[lua] Script error: [string "setTickRate(1)..."]:63.0: Virtual channel not found!


Which makes sense. But how do I access these mapped CAN channels inside a script?

View user's profile Send private message Visit poster's website
Reply with quote
Post  
In the 2.13.0 beta firmware we introduced the ability to get a channel value by name in addition to the virtual channel ID created by addChannel().

https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#getChannel.28_Channel_ID_or_name_.29

However, in 2.13.0 this may fail with a fatal lua error if the sample rate falls on a boundary where the sample does not exist in the stream. e.g. requesting a channel value for a slowly sampled channel (1Hz) where you're requesting it at 50Hz. The work around is to set the source sample rate higher or the same as the polling rate (e.g. 50Hz for both)

In the next firmware release (2.13.2) we changed it so it's not a fatal error, but just returns nil if the channel value is not available. The lua script will need to check for a nil response before processing the value.

Hope this helps,


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
brentp wrote:
In the 2.13.0 beta firmware we introduced the ability to get a channel value by name in addition to the virtual channel ID created by addChannel().

https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#getChannel.28_Channel_ID_or_name_.29

However, in 2.13.0 this may fail with a fatal lua error if the sample rate falls on a boundary where the sample does not exist in the stream. e.g. requesting a channel value for a slowly sampled channel (1Hz) where you're requesting it at 50Hz. The work around is to set the source sample rate higher or the same as the polling rate (e.g. 50Hz for both)

In the next firmware release (2.13.2) we changed it so it's not a fatal error, but just returns nil if the channel value is not available. The lua script will need to check for a nil response before processing the value.

Hope this helps,


Happy to try the new firmware.

Is there a way to know what the channel ID is for mapped channels?

View user's profile Send private message Visit poster's website
Reply with quote
Post  
Hi - Yes, that is is documented in the wiki link I previously posted.


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
brentp wrote:
Hi - Yes, that is is documented in the wiki link I previously posted.


I think we're talking past eachother.

getChannel returns the numerical value of the channel referenced.

addChannel gives you a channel ID to use with getChannel.

I am asking:

Is there a way to know the channel ID for the channels in the mapped CAN area? Do the IDs start at 1 from the order of being listed?

I understand I can try the new firmware, but I am curious to know if there's a way to determine the mapped channel numerical ID.

I hope that makes more sense.

Thanks!

View user's profile Send private message Visit poster's website
Reply with quote
Post  
Thanks for the clarification.

When specifying a numeric ID in getChannel(), this is the ID that is provided by addChannel() in Lua. This part of the virtual channel system that exists only in Lua.

For channels defined outside of Lua (analog, CAN mapping, OBDII, etc) you need to specify the channel by name; there is no numeric ID mapping for those channels - you have to know the name of the channel in advance.

Hope that helps!


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum