Protocol fails
hello, need help. canbus codes works well, think needs little modify. when receiving messages want see codes 201:00;ff;03;00;32;09;00;ff see 201:0:ff:3:0:32:9:ff
i think must add codes too. codes below , me modify please
#include <can.h>
void setup()
{
serial.begin(9600);
serial.println("starting...");
can.begin(500);
}
void loop()
{
if (can.checknew())
{
if ( can.readfromdevice(&can_rxmsg) )
{
serial.print(can_rxmsg.id,hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[0],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[1],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[2],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[3],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[4],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[5],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[6],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[7],hex);
serial.print(";");
serial.println();
}
}
}
i think must add codes too. codes below , me modify please
#include <can.h>
void setup()
{
serial.begin(9600);
serial.println("starting...");
can.begin(500);
}
void loop()
{
if (can.checknew())
{
if ( can.readfromdevice(&can_rxmsg) )
{
serial.print(can_rxmsg.id,hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[0],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[1],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[2],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[3],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[4],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[5],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[6],hex);
serial.print(";");
serial.print("0x");
serial.print(can_rxmsg.data[7],hex);
serial.print(";");
serial.println();
}
}
}
why printing "0x" , ";" ?
anyway problem arduino print functions have no provision print leading zeros. have @ using sprintf() function, allow create formatted string in array , can print array.
do need display 0s? because if not it's still valid program use, move on real purpose of program.
______
rob
anyway problem arduino print functions have no provision print leading zeros. have @ using sprintf() function, allow create formatted string in array , can print array.
do need display 0s? because if not it's still valid program use, move on real purpose of program.
______
rob
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Protocol fails
arduino
Comments
Post a Comment