Hi,
What's the difference between printing an array of characters in one go and printing the same set of characters one-by-one?
Have a look at this bit of working code....
char myBuffer[100];
int z=0;
// Read entire set of bytes in and copy them into character array
while(PduEnc.available() > 0)
{
byte y = PduEnc.readPduChar();
myBuffer[z+1]=0;
myBuffer[z]=(char)y;
z++;
}
// Display character array on screen
Serial.print("myBuffer<");Serial.print(myBuffer);Serial.println(">");
// Output full character array to SMS module on port 3
Serial3.print(myBuffer);
It's part of a project that uses an arduino mega to send SMSs. This snippet reads in a set of characters from my PDU encoder class into a large buffer, (myBuffer) and then outputs the contents of this buffer to the SMS module on serial port 3.
As I said, this code works fine, the SMS get's sent without problems but it requires the use of a temporary staging area myBuffer which takes up a lot of space that I can't afford. (my example uses 100 characters, but it ought to be over 300 for full functionality).
My solution is this snippet, it reads each byte in from the encoder (one by one), and then outputs it straight away to the SMS module on Serial3......
// Read each PDU encoded byte from the encoder and write it straight to the SMS module
while(PduEnc.available() > 0)
{
byte y = PduEnc.readPduChar(); // Read in a single byte
Serial.print((char)y); // Display single byte to screen
Serial3.print((char)y); // Output single byte to SMS module on port 3
}
This doesn't work, I get an error from the SMS module (The error is "Invalid PDU mode parameter" - which basically seems to mean there's something wrong with your data!). I've experimented with reading and writing the data as both bytes and characters and casting between the two but with no progress, the data is also echoed to the display and appears identical in both cases, my best guesses so far are either that the 'print' command handles arrays of characters differently to individual characters, OR that by printing each character one by one I'm some how screwing up the baud rate that the SMS module expects to receive the data at.
Help please!