Pages: [1]   Go Down
Author Topic: What happens if sketch tries to write to serial when no port is available?  (Read 459 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

For testing purposes i write data to the serial port. But what happens if the serial port is not connected and the sketch still tries to write to serial port?

and another question:

In my sketch i append data to a string which i write to an SD card. It seems that when the string becomes too large (8000 characters orso) there is just garbage in the file. Can't post it here cos the charater coding is not accepted...

This happens faster (i.e. the strings size is smaller (at 4000 characters)) when the baudrate is higher. I assume hereby that when you write a lot to the serial port, it eats more memory thus leaving less room for the datastring to become large.

is this true?
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
But what happens if the serial port is not connected and the sketch still tries to write to serial port?

Nothing happens. Unless the other end should write something back or some kind of handshake protocol is involved, your sketch can't tell if the port is connected or not.
« Last Edit: June 19, 2012, 11:19:15 am by pekkaa » Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
For testing purposes i write data to the serial port. But what happens if the serial port is not connected and the sketch still tries to write to serial port?
The data spills out of the port and runs all over the carpet.  Data stains are a pain to get out.

Quote
In my sketch i append data to a string which i write to an SD card. It seems that when the string becomes too large (8000 characters orso) there is just garbage in the file. Can't post it here cos the charater coding is not accepted...

This happens faster (i.e. the strings size is smaller (at 4000 characters)) when the baudrate is higher. I assume hereby that when you write a lot to the serial port, it eats more memory thus leaving less room for the datastring to become large.

is this true?
The faster you write to the serial port the more chance you have of overflowing the serial buffer.  As this is a cyclic buffer you will start losing characters.  It won't corrupt other memory, nor consume more space.

It is more likely that you are using the String class and you are fragmenting your memory and it's all getting in a mess.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Data stains are a pain to get out.
Only the 1s. The 0s are easy to clean up.
Logged

Pages: [1]   Go Up
Jump to: