I am wanting to compile text buffers for each UART port.
With all other IDE and compilers that I have used in the past, this method worked fine.
But apparently Arduino handles strings differently.
I want to be able to create a string from characters received on a port and terminate the string when I receive a 0x0D (cr)
I also want to test and parse the string based on character positions.
Please advise.
With all other IDE and compilers that I have used in the past, this method worked fine.
But apparently Arduino handles strings differently.
I want to be able to create a string from characters received on a port and terminate the string when I receive a 0x0D (cr)
I also want to test and parse the string based on character positions.
Please advise.
Code:
void USBrx()
{
char USBrxData[20],BLErxData[20],DSPrxData[20];
char receivedChar;
int index;
if (Serial.available() > 0) // USB UART RX = 0
{
receivedChar = Serial.read();
if (receivedChar == 0x0D)
{
USBrxData[USBrxptr+1] = 0;
DecodeCmd();
}
else
USBrxData[USBrxptr++] = receivedChar;
}
for (index=0;index<20;index++)
USBrxData[index] = 0; // clear buffer
// *********************************************************************
void DecodeCmd()
{
int ptr;
unsigned short DACvolts;
for (ptr=0;ptr<20;ptr++)
Serial.print(USBrxData[ptr]);
if (USBrxData[0] == '<') // BLE serial
{
SendToBLE();
Serial.print("toBLE");
}
else
if (USBrxData[0] == '>') // DSP serial
{
Serial.print(">");
SendToDSP();
}
else
if (USBrxData[0] == 'R')
{
int sensorValue = analogRead(A17);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
}
else
if (USBrxData[0] == 'V')
{
DACvolts = 100*(USBrxData[1]-48) + 10*(USBrxData[2]-48) + USBrxData[3]-48;
WriteToDAC(DACvolts);
Serial.print(DACvolts);
}
for (ptr=0;ptr<20;ptr++) // clear rx buffer
USBrxData[ptr] = 0;
USBrxptr = 0;
}
}