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 )