7dps Type with CAN Comms
I am trying to send GPS longitude and latitude over CAN bus, but am running into issues with the fixed point 7dps type using the DBC import method. In my DBC file, I am using a signed integer type with a factor of 1e-07. The code is throwing errors because a 7dps type cannot be automatically converted to an integer with a factor. I can try using the Convert.ToInteger() function, but I am assuming this will truncate the decimal points.
I tried this too, but it throws errors trying to convert a constant integer to a 7dps.
I would appreciate any suggestions. Thank you!
- Code: Select all
if (This.CAN Bus neq This.CAN Bus.Not in Use)
{
local ok = true;
// Messsage 1
local h = DBC.Main Bus.ECU GPS1.TxOpen();
local lat = Convert.ToInteger(GPS.Latitude) * 10000000;
local long = Convert.ToInteger(GPS.Longitude) * 10000000;
DBC.Main Bus.ECU GPS1.TxInitialise(h);
DBC.Main Bus.ECU GPS1.GPS Latitude.SetInteger(h, lat);
DBC.Main Bus.ECU GPS1.GPS Longitude.SetInteger(h, long);
ok = DBC.Main Bus.ECU GPS1.Tx(h);
ok = ok;
}
I tried this too, but it throws errors trying to convert a constant integer to a 7dps.
- Code: Select all
local lat = Convert.ToInteger(GPS.Latitude * Convert.ToFixed7DP(10000000));
I would appreciate any suggestions. Thank you!