You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • what happens if you just do:

    Serial1.on('data', function(d) {
  • First it complains that i have to define both tx and rx pin, then it just prints undefined once and no data is arriving.

  • Found some useful information

    Reading data is done with getter functions and callback function pointers. For example, to get realtime data from the VESC, first set a callback to your function for handling the data using bldc_interface_set_rx_value_func and then request the data with bldc_interface_get_values.

    // Every time you want to read the realtime data you call the corresponding getter.
    // This will send the get command to the VESC and return. When the data is received
    // the callback will be called from the UART interface.
  • Here is some C code that i think does what im trying to do.

    int VescUart::packSendPayload(uint8_t * payload, int lenPay) {
    	uint16_t crcPayload = crc16(payload, lenPay);
    	int count = 0;
    	uint8_t messageSend[256];
    	if (lenPay <= 256)
    		messageSend[count++] = 2;
    		messageSend[count++] = lenPay;
    		messageSend[count++] = 3;
    		messageSend[count++] = (uint8_t)(lenPay >> 8);
    		messageSend[count++] = (uint8_t)(lenPay & 0xFF);
    	memcpy(&messageSend[count], payload, lenPay);
    	count += lenPay;
    	messageSend[count++] = (uint8_t)(crcPayload >> 8);
    	messageSend[count++] = (uint8_t)(crcPayload & 0xFF);
    	messageSend[count++] = 3;
    	messageSend[count] = '\0';
    		debugPort->print("UART package send: "); serialPrint(messageSend, count);
    	// Sending package
    	serialPort->write(messageSend, count);
    	// Returns number of send bytes
    	return count;
    bool VescUart::getVescValues(uint8_t comm) {
    	uint8_t command[1] = { comm }; // COMM_GET_VALUES or COMM_GET_UNITY_VALUE
    	uint8_t payload[256];
    	packSendPayload(command, 1);
    	// delay(1); //needed, otherwise data is not read
    	int lenPayload = receiveUartMessage(payload);
    	if (lenPayload > 55) {
    		bool read = processReadPacket(payload); //returns true if sucessful
    		return read;
    		return false;

Avatar for Gordon @Gordon started