You have NO checking that will prevent you from writing beyond the end of the array, whatever size you ended up making it. Do NOT expect your program to behave properly without array bounds checking.
When the device is started the setup() searches for any received SMS and sends them trought the port. It loops as long as there are messages in the buffer.(I used the example code for receiving SMS and added some needed functionality)
After no more SMS are available it gives an "ok" trought the port letting the frontend know that it is ready to send SMS. those are sent in loop(), which works fine.
readSerial() is also from code example and wasn't modified at all.
EDIT:
After some more testing I found out that when Arduino is not responding due to too many SMS at once it doesn't even go past the gsm ready. I tested this with the example SMS receive; where I should get the "Not connected" or "GSM initialized" message, I get nothing.
When you call readSerial(), you pass it three different arrays. NONE of them are 200 elements long. Why does readSerial() assume a 200 element array?
Why does readSerial() block until all outgoing serial data has been sent? Specifically, why does it do that when it outputs no data? That is what flush() does. Seems completely useless.
Which Arduino are you using? I'm beginning to suspect that you are running out of memory.
I made readSerial() 200 elements long because the application can send up to 200 characters per SMS message. More did cause it to send slower and less could cause shortage of text content.
I don't understand what you mean by blocking data. readSerial() was used in the Arduino example for sending SMS messages, so I used it for my own.
I am using Arduino Uno(from China) and a Arduino GSM Shield 2.
I am starting to think that the SIM card became corrupt, because if I am trying it out in my phone, I cannot send a SMS message to myself. Which is odd, since the card is 2 days old.
I made readSerial() 200 elements long because the application can send up to 200 characters per SMS message.
You need to declare readSerial() to take a pointer to a char (array) and a length. You need to make sure that readSerial() does not write beyond the end of the array.
When you pass a 20 element array to the function, the function can only write 20 characters to the array. It does NOT matter that the function thinks it has a 200 element array to deal with.
Where are you located? Text messages are usually limited to 160 characters (at least in the US).
Yes SMS messages are 160 here aswell, but it is possible to send more than 160 characters, it just makes 2 messages instead.
I tested it with 200 chars and more and it worked fine.
I am not quiet understanding what you are telling. Am I correct taht pointers work the same as references to variables?
readSerial() cannot go beyond 200 characters because there is char[] in code that is longer than 200(yes msg is 320 but the application doesn't send beyond 200 characters).
But how can I manage the array size if I get it from the desktop application?
You can't get the array from the PC. You create the array on the Arduino. You might populate the array with data from the serial port. If that is the case, you have two choices. You can make the array as large as reasonable, and throw away data that won't fit, or you can use dynamic memory allocation to handle any amount of data.
Given the limited amount of memory on the Arduino, the first option is a better choice, most of the time.