Custom CAN message

Discussion and Support for MoTeC's M1 series ECUs

Re: Custom CAN message

Postby David Ferguson on Sat Aug 11, 2018 8:44 am

The particular CAN Bus speed is setup in M1 Tune under CAN. For each bus on the particular hardware, you can set the mode (basically the speed). So, you don't change this in M1 Build, you change it in M1 Tune with the package.

What I do for my CAN devices, is I provide two parameters that are set in M1 Tune. One is the "CAN Bus", which uses Data Type "CAN Bus Enumeration 2" to allow "Not in Use" as well as the valid CAN buses on that hardware. The other is "CAN Base ID", which is an Unsigned Integer with the Format set the Hexadecimal.

I advise reading the section "Using the CANComms Functions" found in the M1 Development Manual (in M1 Build use the menu Help->Manuals->M1 Development Manual).
David Ferguson
Veracity Racing Data
David Ferguson
Pro User
 
Posts: 1378
Joined: Fri Nov 07, 2008 2:45 am
Location: Paso Robles, California

Re: Custom CAN message

Postby gtihk on Sat Aug 11, 2018 1:42 pm

Thanks! It's Clear now.
I shall read up as suggested.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby gtihk on Mon Aug 13, 2018 2:13 pm

I have made a little progress. Need to verify with a SIM3 and CANcapture.
We are copying VCS transmit. Is it also possible to based on ADR transmit?Or will there be problems?
One other thing in the original meassages, the last Byte seems to be a counter or similar.How do we Replicate that?
It is a Honda, if it matters.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby rntechnologies on Mon Aug 13, 2018 6:51 pm

You can setup CAN Comms on any scheduled function at all, meaning that you can keep your own code separate if you wish.

An example of a custom can message would be as follows:

Code: Select all
local h = CanComms.TxOpen(false);

CanComms.TxInitialise(h, 8);
CanComms.SetUnsignedInteger(h, 0,  8, Convert.ToUnsignedInteger(Ambient Pressure);
CanComms.SetBit            (h, 8,     Engine State.AsInteger() < 2);
ok = ok and CanComms.TxStandard(h, bus, 0x999);

ok = ok;


This is transmitting on 0x999, and sending Ambient Pressure from bit 0-7, and an engine State flag if the engine state is < 2 in bit 8.

if you put this in its own scheduled function, you can then set the event to whatever transmit rate you require.

In relation to your counter question, what is the amount that is incremented? is it just + 1 each time? - there are a couple of ways you an implement a counter in the code.
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Custom CAN message

Postby gtihk on Tue Aug 14, 2018 4:56 pm

I copied your code to a schedule function.
It came back with an error on line 8.
It says: Expecting a '.'
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby David Ferguson on Wed Aug 15, 2018 2:38 am

So let's see if we can help you figure that out. On line 8, what possible identifier could need to have a "." added?

Perhaps it's an identifier not defined in that code. Perhaps it needs to be declared (ie, local xxx), or edited to reflect an identifier used in your project.

If you are not able to figure these types of problems out on your own, perhaps you should consider paying for the development to meet your needs.
David Ferguson
Veracity Racing Data
David Ferguson
Pro User
 
Posts: 1378
Joined: Fri Nov 07, 2008 2:45 am
Location: Paso Robles, California

Re: Custom CAN message

Postby rntechnologies on Wed Aug 15, 2018 10:24 am

As David mentioned, if you are unable to figure this one out and you are just copy/pasting code without fully understanding what is happening, i would really advise against working on the build platform without some more prior programming knowledge, or maybe paying for development would be a more advisable option.
Whilst we are referring to CAN messaging at the moment, i would hate to see something else within your project fail due to code that you may not fully understand.
Please don't think we are criticizing you, the build platform just assumes a level of prior programming knowledge that a lot of people aren't going to have.
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Custom CAN message

Postby gtihk on Wed Aug 15, 2018 4:57 pm

Thanks for the comments.
I am just trying to learn bit by bit when I have some spare time.
:oops:
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

Re: Custom CAN message

Postby rntechnologies on Wed Aug 15, 2018 9:47 pm

Here is my above CAN message broken down for you, and with the necessary declarations to explain what's happening:

Firstly, you need to open a CAN communications transmit handle, the false in this function is specifying that the message needs to be transmitted in little endian format with the handle being named 'h' for the purposes of re-use throughout further implementations of the code:
Code: Select all
local h = CanComms.TxOpen(false);


Next, i would normally specify a variable called 'bus' for the CANBus, again this is for the purpose of re-use throughout the code (remembering here, that i'm referencing an external input parameter called 'CAN Bus', this being a user selectable enumerator from within M1Tune):
Code: Select all
local bus = CAN Bus.AsInteger() - 1;


Following this, i usually also setup a variable called 'ok', this variable will contain the result of the CAN message transmission. What this means is that you can have an additional piece of code called if there is a problem with the message (the default state i set is 'True'):
Code: Select all
local ok = true;


After opening the transmit handle, you need to initialise a new CAN message, the parameters specified are the handle (which we created above), and the length of the CAN message:
Code: Select all
CanComms.TxInitialise(h, 8);


At this point, you now construct the message with the information you wish to send.
The information can be sent as individual bits, or integers etc, it's entirely dependant on the information you want to transmit.
In my example, the first part of the message contains the ambient pressure value, sent as an unsigned integer beginning at position 0 in the message, for 8 bits.
Code: Select all
CanComms.SetUnsignedInteger(h, 0,  8, Convert.ToUnsignedInteger(Ambient Pressure);


The second part of my message, is transmitting the engine state as an on/off flag (or bit) in position 8 of the message. Because it's a Bit, there is no need to specify a length.
Code: Select all
CanComms.SetBit            (h, 8,     Engine State.AsInteger() < 2);


Lastly, you tell the ECU to transmit the message that you have constructed above. This function requires the handle, the CANBus to transmit using, and the address to send the message on.
Code: Select all
ok = ok and CanComms.TxStandard(h, bus, 0x999);


At this point, the 'ok' variable will be 'True' if the message was successful, or 'False' if not.
This is the part where you would put your code to take action if the event was unsuccessful.

This part is required to avoid an issue when compiling in build, where you have not used the variable.
Code: Select all
ok = ok;


Hopefully this breaks down the message a bit more for you.
If you need more information on CAN messaging there are some webinars that the guys at MoTeC have put online, that should explain some stuff in more detail for you.
As I mentioned, build assumes a prior level of programming knowledge suited to an advanced user, there is some documentation within the help section of the build software that may point you in the right direction though.
Regards,
Ryan
Powertune Australia
rntechnologies
Pro User
 
Posts: 91
Joined: Tue Aug 07, 2018 9:45 am
Location: Sydney, Australia

Re: Custom CAN message

Postby gtihk on Thu Aug 16, 2018 6:48 pm

Thank you very much for taking the time to explain in such detail.
I will follow your example and do some simple things to test.
When I need professional help in a new project,I know where to go.
Thanks again for the patience.
M1 Build is new to me, So was PDM Manager which I can now do some simple things with.
Learning can be fun as well as frustrating at times.
gtihk
 
Posts: 76
Joined: Thu Jul 19, 2018 1:37 pm

PreviousNext

Return to M1 ECUs

Who is online

Users browsing this forum: No registered users and 14 guests

cron