/* * Constructs a message from the form and sends it * to the channel */ private bool SendMessage(int dlc, List <Signal> signals) { byte[] data = new byte[dlc]; Kvadblib.Status status = Kvadblib.Status.OK; Kvadblib.SignalHnd sh; bool error = false; foreach (Signal s in signals) { double min, max; status = Kvadblib.GetSignalByName(msgHandle, s.name, out sh); if (status != Kvadblib.Status.OK) { error = true; break; } Kvadblib.GetSignalValueLimits(sh, out min, out max); status = Kvadblib.StoreSignalValuePhys(sh, data, dlc, s.Value); //Check if the signal value was successfully stored and that it's in the correct interval if (status != Kvadblib.Status.OK || s.Value < min || s.Value > max) { error = true; break; } } if (!error) { Canlib.canWriteWait(chanHandle, msgId, data, dlc, msgFlags, 50); } return(error); }
//************************************ // CAN Transmit for a single transmission //************************************ public static void CanTransmitSingle(CanData can) { string hardwareString0 = can.hardware.Replace(" ", ""); string[] msgOutput = hardwareString0.Split(';'); can.handle = BusInterface.ReturnHandle(can.hardware); // Threading Part /*CanWrite writeCan = new CanWrite(); * * // Starts the Kvaser threading * Thread t2 = new Thread(delegate() * { * writeCan.KvaserWrite(can); * }); * t2.Start(); */ // Non-threading write option Canlib.canWriteWait(can.handle, can.id, can.msg, can.dlc, can.flags, 1000); CheckFlags(can); } // End GenericCanTransmitSingle