Pages: [1]   Go Down
Author Topic: Arduino crashes with Serial bug?!  (Read 894 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 134
panta rei resist the resistors!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,
after several months of self mutilation for not coming back to the arduino forums...I'm back
with bugs  ;D

coulnd't solve this one.

I get a weird serial behaviour.

at the beginning, when starting the serial monitor, I kept getting this warning in the middle of nonsensical chars

Error inside Serial.serialEvent()
java.io.IOException: No error in readByte
      at gnu.io.RXTXPort.readByte(Native Method)
      at gnu.io.RXTXPort$SerialInputStream.read(RXTXPort.java:1250)
      at processing.app.Serial.serialEvent(Serial.java:214)
      at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
      at gnu.io.RXTXPort.eventLoop(Native Method)
      at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
      

after that I couldn't even upload the sketch. and got this warning...
BUT the port wasn't in use....no one was using it.

Error inside Serial.<init>()
gnu.io.PortInUseException: Unknown Application
      at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
      at processing.app.Serial.<init>(Serial.java:127)
      at processing.app.Serial.<init>(Serial.java:63)
      at processing.app.Editor.handleSerial(Editor.java:1421)
      at processing.app.EditorButtons.mousePressed(EditorButtons.java:373)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)


I checked everything:
- Serial.begin(19200) was set to the corresponding speed in the serial monitor - not the problem
- I checked for other programs using the comport but non that i knew where doing so.
- i tryed starting and stopping the serial monitor
- I tryed closing and restarting arduino
- I tryed closing and restarting windows (xp)
- I tryed uploading another simple sketch (led blink) and once i succeded, tryed the second time and got the same error...

did I brake arduino???
any idea?

cheers
oh ... and merry jingle bells to all the forum and a happy new year smiley
b.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey, welcome back!

Have you tried the Arduino board with a different computer?  Or a different board with the same computer?

If you can manage to upload a program to the Arduino that sends serial data to the computer (e.g. examples > serial_comm > serial_write_basic), can you see that data ("HIGH" or "LOW") properly in another program (like HyperTerm)?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 134
panta rei resist the resistors!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hey d.

unfortunately I don't have here another pc to try it with. but I have some new reports on the problem

after rebooting the pc this morning arduino seemed to work again, and could perfectly upload sketches on the board.
after a couple of trials I got the same error.
so I checked again if it was possible to connect with other terminal softwares.

terminal.exe (the standard terminal that is suggested with the arduino distro) can't strangely connect to COM9. it doesn't allow me to select it.

hyperterminal, after a couple of trials, managed to work, but is kind of difficult to use and I'm not totatlly sure if it did actually work fine...i got the serial feedback from my board.

right after hyperterminal worked I went to the arduino terminal software and it reported this NEW bug:

Error inside Serial.<init>()
gnu.io.UnsupportedCommOperationException: Invalid Parameter
      at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:171)
      at processing.app.Serial.<init>(Serial.java:130)
      at processing.app.Serial.<init>(Serial.java:63)
      at processing.app.Editor.handleSerial(Editor.java:1421)
      at processing.app.EditorButtons.mousePressed(EditorButtons.java:373)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at java.awt.Component.processEvent(Unknown Source)
      at java.awt.Container.processEvent(Unknown Source)
      at java.awt.Component.dispatchEventImpl(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
      at java.awt.Container.dispatchEventImpl(Unknown Source)
      at java.awt.Window.dispatchEventImpl(Unknown Source)
      at java.awt.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)

the new Serial library is kinda buggy!

I checked on myPc > properties > hardware manager > compPorts
for the right options of the arduino port.
- There is an option where you can change the number of the port, but oddly enough I couldn't put it lower than port 9 since it stated me that all other where in use...but looking at the hardware manager list I couldn't find it.
- there is another option in which you set the speed of the comport, i've set it to 19200 as it was the speed of my sketch.


I will try to uninstall and reinstall the FTDI drivers...to see if it's an issue with them.
does this new bug suggest you anything???
Error inside Serial.<init>()
gnu.io.UnsupportedCommOperationException: Invalid Parameter

thanks in advance
b.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Huh, what are the values of the following in your preferences.txt file (http://www.arduino.cc/en/Hacking/Preferences): serial.port, serial.debug_rate, serial.parity, serial.databits, serial.stopbits, serial.download_rate?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 134
panta rei resist the resistors!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

# set the serial port defaults
serial.databits=8
serial.stopbits=1
serial.parity=N
serial.port=COM1
serial.download_rate=19200

serial.debug_rate=9600
serial.burn_rate=115200

should I change the debu_rate???

in any case with or without changing this...Arduino decided to start working again!!!!?!?!?!
I can't explain why...I went to lunch and when I got back it all worked again.
- Terminal software could recognize comport9 and succesfully connect to it.
- Arduino could safely load and read with its serial monitor...
WEIRD WEIRD!  maybe its time for a format c: smiley

I've got another problem now... it concerns Serial handling...
it seems as I've got a data-type problem or the Serial lib is giving a data-type problem:
reading and storing a char from serial (Serial.read()) only becomes really a char (casts to) after being PRINTED BACK to SERIAL via Serial.print()

let me explain
this:
Code:
unsigned char My_string [5];
My_string[0] = Serial.read(); //should store a char '1' or '0' sent from any terminal

//if you try to check it - it won't work
//won't print - as it doesn't recognize it as a char ' '
//if (My_string[0] == '1') {  Serial.print( "I read Char: 1"); }

//wont work - as by using the double " " we are comparing to a string datatype and the compiler outputs:
//error: ISO C++ forbids comparison between pointer and integer
//if (My_string[0] == "1") {  Serial.print( "I read Char: 1"); }

//ONLY IF YOU FIRST PRINT IT BACK TO THE SERIAL BUFFER IT WILL BECOME READABLE AS A CHAR
Serial.print( My_string[0]);
if (My_string[0] == '1') {  
       Serial.print( "I read Char: 1"); //OK it prints out
}

I've tried all sorts of casting
byte my_char = My_string[0];
int my_char = My_string[0];
unsigned char my_char = My_string[0];
but none will work untill I printed back to Serial.

I've checked the new HardwareSerial lib and it seems only as a wrapper for old serial function.
everything leads back to wiring.c > void serialWrite(unsigned char c)
but it doesn't seem to be casting the datatype to anything...it should be a char but it doesn't print as a char...

any idea?
is it a pointers problem??? (tryed some * & combination but non really produced any good)

thanks in advance
b.
Logged

Florida, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 146
meow!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

One thing to watch out for is that Serial.read() returns -1 if there are no characters ready.  At 16 MHz, the processor can easily outrace the slow baud rate.  When you introduce a Serial.print, you are probably slowing things down to the point that another incoming character has time to arrive.  You can either check for -1, or you can wait for a character to arrive by using the following busy-loop:

Code:
while (Serial.available() == 0) {
    // do nothing... just wait for a character to arrive
}

If you do decide to check for -1, you should use an "int" to store the return value of Serial.read().  The -1 will be converted to 255 (0xff) if you store it in an "unsigned char", so there is no way to distinguish it from the byte 255 being received.
« Last Edit: January 06, 2007, 10:39:01 am by CosineKitty » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 134
panta rei resist the resistors!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks cosinekitty...
I was already using
while (Serial.available())
without even checking for a value

now that thing is misteriously working...as the bug before it magically solved without my intervention...

I had very weird behaviours on this board:
I tried one simple script-that worked in printing a simple serial feedback ("hello world",
 then only resetting the board...not changing or uploading the board, the script would bug!!!   :o
It was simple impredictable! some times it worked, some other it didn't

that got me nuts.. I tried every combination of actions...
it got to the cabalistical level that I thought it was my wool pool causing some electrostatic interference...so I took it out...
guess what...
it started working again!!!!!   :o  :o

can that be possible? or am I just placebo-ing it??

I'm not totally sure that this thing is solved, but for now it's working again, and hasn't bugged for a couple of hours so far...
I think this thing is testing my faith: if I believe, it will work. smiley

I'm down to timing issues now smiley
though I can't tell if tomorrow my code will autofix...
I'll give it a night of prayers and see what happens tomorrow.
else you will hear me again on the troubleshooting forum smiley

may the arduino be with you
b.
Logged

Pages: [1]   Go Up
Jump to: