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

    Bluetooth.setConsole(1);
    Serial1.setup(9600,{rx:D14});
    Serial1.on('data', function(d) {
      console.log("SERIAL:"+JSON.stringify(d))­;
    });
    
  • 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;
        }
        else
        {
            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';
    
        if(debugPort!=NULL){
            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;
        }
        else
        {
            return false;
        }
    }
    
About

Avatar for Gustav @Gustav started