Hello ,
I'm using Henry's Bench code for reading canbus
and it's working great - and I see all the information on the serial monitor .
now I want to be able to save it into string \ array
how can I do this?
what do I need to setup ?
so in the end iwill have a string with this data inside : rcv - rxID - CanBusData
I was able to save it into a SD card , but I don't know how to save it into a string...
if (CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
// Serial.print("got data ");
rcvTime = millis();
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
rxId = CAN.getCanId();
// if (rxId == (0xC6 , HEX))
// {
// rxId = "david";
// }
Serial.print(rcvTime);
Serial.print("\t\t");
Serial.print("0x");
Serial.print(rxId , HEX);
Serial.print("\t");
myFile = SD.open("data.txt" , FILE_WRITE);
myFile.println(rcvTime);
myFile.print("-");
myFile.print("0x");
myFile.print(rxId, HEX);
myFile.print("-");
for (int i = 0; i < len; i++) // print the data
{
if (buf[i] > 15)
{
Serial.print("0x");
Serial.print(buf[i], HEX);
myFile.print("0x");
myFile.print(buf[i], HEX);
}
else
{
Serial.print("0x0");
Serial.print(buf[i], HEX);
myFile.print("0x0");
myFile.print(buf[i], HEX);
}
//Serial.print("0x");
//Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();
myFile.close();
You didn't seem to have any trouble writing it to the SD card. So, I can't see why you'd have any trouble "see"ing it. For whatever definition of "see" you have in mind.
this is my problem , how to save it into a array ot string
in the file it was easy - becasue I know how to write into a file .
but I don't know how to "save" into my own string so I can compare it after it.
Why would you want to store 16 in the i+2 position of the array?
You you want to store the data in an array, or a string representation of the data?
if you want to store a string representation of the data, you'd use a char array that was long enough, and sprintf() with the appropriate format string, to populate (and NULL terminate) the array, resulting in a string.
sorry - but I didn't understand you .
I will explain what I did :
myFileprint(buf , HEX); - give me the correct value of the data from buf array - for example "38" I thought that if i will do the same things in my new array called "FinalInfo" - I will get the same number -"38" this is OK correct right? now I want to take all there is in FinalInfo , which wiil be something like {test,22.11,1,2,3,4,5,6,7,38} and change it to string : test-22.11-1-2-3-4-5-6-7-38 I don't think I can explain this easier what I want to do.... please tell me you unserstand where I'm going with this Thanks ,