/*private void AddToCanTrace(string line) * { * if (m_EnableCanLog) * { * DateTime dtnow = DateTime.Now; * using (StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\CanTraceCANUSBDevice.txt", true)) * { * sw.WriteLine(dtnow.ToString("dd/MM/yyyy HH:mm:ss") + " - " + line); * } * } * }*/ /// <summary> /// sendMessage send a CANMessage. /// </summary> /// <param name="a_message">A CANMessage.</param> /// <returns>true on success, othewise false.</returns> override public bool sendMessage(CANMessage a_message) { LAWICEL.CANMsg msg = new LAWICEL.CANMsg(); msg.id = a_message.getID(); msg.len = a_message.getLength(); msg.flags = a_message.getFlags(); msg.flags = LAWICEL.CANMSG_EXTENDED; // Test for now msg.data = a_message.getData(); int writeResult; //AddToCanTrace("Sending message"); AddToCanTrace("TX: " + msg.id.ToString("X6") + " " + msg.data.ToString("X16")); writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg); if (writeResult == LAWICEL.ERROR_CANUSB_OK) { //AddToCanTrace("Message sent successfully"); txCount++; bitsPerSecond += 109; return(true); } else { errCount++; switch (writeResult) { case LAWICEL.ERROR_CANUSB_COMMAND_SUBSYSTEM: AddToCanTrace("Message failed to send: ERROR_CANUSB_COMMAND_SUBSYSTEM"); break; case LAWICEL.ERROR_CANUSB_INVALID_PARAM: AddToCanTrace("Message failed to send: ERROR_CANUSB_INVALID_PARAM"); break; case LAWICEL.ERROR_CANUSB_NO_MESSAGE: AddToCanTrace("Message failed to send: ERROR_CANUSB_NO_MESSAGE"); break; case LAWICEL.ERROR_CANUSB_NOT_OPEN: AddToCanTrace("Message failed to send: ERROR_CANUSB_NOT_OPEN"); break; case LAWICEL.ERROR_CANUSB_OPEN_SUBSYSTEM: AddToCanTrace("Message failed to send: ERROR_CANUSB_OPEN_SUBSYSTEM"); break; case LAWICEL.ERROR_CANUSB_TX_FIFO_FULL: AddToCanTrace("Message failed to send: ERROR_CANUSB_TX_FIFO_FULL"); break; default: AddToCanTrace("Message failed to send: " + writeResult.ToString()); break; } return(false); } }
/// <summary> /// sendMessage send a CANMessage. /// </summary> /// <param name="a_message">A CANMessage.</param> /// <returns>true on success, othewise false.</returns> override public bool sendMessage(CANMessage a_message) { LAWICEL.CANMsg msg = new LAWICEL.CANMsg(); msg.id = a_message.getID(); msg.len = a_message.getLength(); msg.flags = a_message.getFlags(); msg.data = a_message.getData(); if (m_DoLogging) { DumpCanMsg(msg, true); } int writeResult; writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg); if (writeResult == LAWICEL.ERROR_CANUSB_OK) { return(true); } else { return(false); } }