Hi All, I'm having some trouble with Timo's library. I have created programs that can send N2K data and others that can receive N2K data, but so far I have been unable to create a program that can do both.
Here is the code in my setup() function:
// Reserve enough buffer for sending all messages.
NMEA2000.SetN2kCANSendFrameBufSize(250);
// Set Product information
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
100, // Manufacturer's product code
"MY-TEST", // Manufacturer's Model ID
"1.0.0.0 (2019-09-13)", // Manufacturer's Software version code
"1.0.0.0 (2019-09-13)" // Manufacturer's Model version
);
// Set device information
NMEA2000.SetDeviceInformation(12345, // Unique number. Use e.g. Serial number.
132,
25,
2046
);
NMEA2000.SetForwardStream(&Serial); // PC output on due programming port
// NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
// NMEA2000.SetForwardOwnMessages();
/* NOTE - I have tried all three of these modes, even though reading the comment and looking
at the library source indicates that ListenAndNode is the correct choice.
For two of them, I am unable to receive data and
I get a true return from NMEA2000.SendMsg(n2kMsg); and there is no indication that
any data from source 23 was published on the bus. I'm watching the bus with Can King.
With "ListenAndSend" I am able to receive data but still nothing is published on the bus.
If I leave all three commented out I can receive correctly.
*/
// If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
//NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode, 23);
//NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly, 23);
//NMEA2000.SetMode(tNMEA2000::N2km_ListenAndSend, 23);
// Uncomment this next line to dump bus traffic to serial
//NMEA2000.SetDebugMode(tNMEA2000::dm_ClearText); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
NMEA2000.SetDebugMode(tNMEA2000::dm_None); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
// Set false below, if you do not want to see messages parsed to HEX withing library
NMEA2000.EnableForward(false);
NMEA2000.SetMsgHandler(HandleNMEA2000Msg);
NMEA2000.Open();
Here is some code I am using to create the PGN and send it. Note that its a proprietary, destination global, fast-packet PGN. I have used this same code to send data in another application that is send only and it worked correctly:
bool sendN2kData(float d)
{
tN2kMsg n2kMsg;
n2kMsg.SetPGN(126720L); // Proprietary, destination global, fast-packet PGN
n2kMsg.Priority=7;
// definer tag
uint16_t definerTag = 0xE598;
n2kMsg.Add2ByteUInt(definerTag);
Serial.println("\r\n*** SENDING ***");
return NMEA2000.SendMsg(n2kMsg);
}
I'm out of ideas, so any help offered will be greatly appreciated. Thanks!