Page 1 of 1

How does the M1 handle CAN messages

PostPosted: Sun Feb 25, 2018 8:58 am
by IamTheStig
Hi all,

I'm adding some CAN sensors to the M1 via build. For this I have a "CAN-Signal-Template", which I just copy-and-paste and change the needed settings according to the type of singal. (I'm wondering why the M1 just does not have this option like it was also possible in the ADL3)
The internal code to get the value is:
Code: Select all
local hBig = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, true);
local hLittle = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, false);

local <Unsigned Integer> h = 0;
if (Message.Endianness eq Message.Endianness.Big Endian) {
   h = hBig;
} else {
   h = hLittle;
}
if (SensTemplate.CAN Bus neq SensTemplate.CAN Bus.Not in Use) {
   if (Message.ID > 0) {
      if (CanComms.RxMessage(h)) {
         if (Scale.Signed eq Scale.Signed.On) {
            Value = CanComms.GetInteger(h, Message.Offset,
               Message.Length) * Scale.Factor + Scale.Offset;
         } else {
            Value = CanComms.GetUnsignedInteger(h, Message.Offset,
               Message.Length) * Scale.Factor + Scale.Offset;
         }
         if (Timeout > 0) {
            Timer.Start(Timeout);
         }
      } else {
         if (Timeout > 0) {
            if (Timer.Remaining() <= 0) {
               Value = Calculate.NAN();
            }
         }
      }
   } else { Value = Calculate.NAN(); }
} else { Value = Calculate.NAN(); }

How does a M1 handle if multiple functions check for the same CAN-ID? Has the M1 an internal "distributer" that copies the message to every function. Or are the functions "stealing" messages from each other?
(If you have other comments on my code, feel free to comment ;) )

Re: How does the M1 handle CAN messages

PostPosted: Thu Aug 16, 2018 3:23 pm
by DarrenR
I would have to test it to know for certain, but I believe in the case a received message fits more than one RxOpenStandard() arguments (this case), the message will be copied to both receive buffers.

But why don't you just put the Message.Endianness parameter in the Open funciton, like this -
Code: Select all
local hBig = CanComms.RxOpenStandard(SensTemplate.CAN Bus.AsInteger() - 1,
   Message.ID, 0x0, Message.Endianness eq Message.Endianness.Big Endian);