//This function is called everytime a message is received on an input port //"inPort" will hold the port the message was received by (1, 2, or 3) //"block" holds an object representing the current script block on the flowchart //"msg" holds an object representing the message received //type "block." or "msg." to see a list of available parameters and functions void OnReceiveMessage(uint8 inPort, ScriptBlock block, Message &msg) { if (!bFileOpen) { return; } //Here we pretend that we get some sort of ACK or response from the embedded device that indicates that //it is ready to receive the next packet of data containing the firmware image. Most reprogramming/flash //protocols has some sort of similar indicator meaing something to the effect of "read for data". //For testing, you can simply use a 29-bit transmitter that sends a packet with ID=1234 at a repeating //interval if (msg.GetID() == 1234) { //Prep our data payload packet that will be sent to the embedded device Message dataMsg; dataMsg.SetID(12345); dataMsg.Set11Bit(0); //I am assuming its 29-bit CAN messages block.PrintOutputText("Sending CAN packet ID=" + dataMsg.GetID() + " with data:", false, false, true, false); //Read up to 8 bytes of data from the firmware image to fill the next packet of CAN data int i = 0; for (i = 0; i < 8; ++i) { if (handle.isEOF()) { //Check for end of file block.PrintOutputText("\nEnd of file reached", false, false, false, true); //print a message indicating the data handle.close(); //Close file and release flag that indicates its open bFileOpen = false; break; } uint8 dataByte = handle.readUInt8(); //read a single byte of data from the file block.PrintOutputText(" " + dataByte, false, false, true, false); //print a message indicating the data dataMsg.SetData(i, dataByte); //and store the byte from the file directly into our CAN packet structure } block.PrintOutputText("\n", false, false, true, false); dataMsg.SetDataLength(i); //set the length to the number of bytes read from the file //And finally send the data packet block.SendMessage(1, dataMsg); } }