(SOLVED) Arduino + Mono + Reading from serial (the operation has timed out)

My Development Environment:

  • Hardware: Arduino MEGA 2560/UNO (firmwares: arduino-usbserial-mega.hex/arduino-usbserial-uno.hex)
  • Hardware: MACBOOK PRO 13i 2011
  • Software: MAC OSX 10.6.7
  • Software: Arduino 0022
  • Software: Monodevelop 2.4.2

[u]**Problem sample code: Arduino Playground - HomePage

// SerialTest.cs
//
// The MIT License
//
// Copyright (c) 2008 Matias Korhonen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.IO.Ports;

class MainClass
{
public static void Main(string[] args)
{
SerialPort sport = new SerialPort("/dev/tty.usbmodemfa131", 9600);

if (sport != null)
{
if (sport.IsOpen)
{
sport.Close();
}
}

Console.WriteLine("Arduino Serial Test");

sport.Open();

while(true)
{
Console.WriteLine(sport.ReadLine());
}
}

}

Results in this output:

Unhandled Exception: System.TimeoutException: The operation has timed-out.
at System.IO.Ports.SerialPortStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00086] in /private/tmp/monobuild/build/BUILD/mono-2.6.7/mcs/class/System/System.IO.Ports/SerialPortStream.cs:151
at System.IO.Ports.SerialPort.read_byte () [0x00007] in /private/tmp/monobuild/build/BUILD/mono-2.6.7/mcs/class/System/System.IO.Ports/SerialPort.cs:608
at System.IO.Ports.SerialPort.ReadTo (System.String value) [0x00042] in /private/tmp/monobuild/build/BUILD/mono-2.6.7/mcs/class/System/System.IO.Ports/SerialPort.cs:670
at System.IO.Ports.SerialPort.ReadLine () [0x00000] in /private/tmp/monobuild/build/BUILD/mono-2.6.7/mcs/class/System/System.IO.Ports/SerialPort.cs:653
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:ReadLine ()
at ArduinoSerial001.MainClass.iThread_Daemon_Start () [0x00020] in /Users/bartjanssen/Projects/Monodevelop/Arduino-Serial-001/Arduino-Serial-001/Main.cs:68
The application was terminated by a signal: SIGHUP

Question:

What could be wrong and be the reason for the time out ?

What could be wrong and be the reason for the time out ?

Could it be you're trying to upload Processing code to an Arduino?

No, the above code doesn't get send to the arduino device, it's code (C#) is used in the monodevelop IDE to produce a binary that can read output from the usbserial port attached to the arduino device ...

Topic: Interfacing Arduino with other Software ...

Sorry, I missed the Macbook reference.

Topic: Programming questions

Have you tried an Apple forum?

its not per se Apple related, monodevelop is cross platfrom ...

Have you tried the cross-platform (non-Arduino-specific) forums (fora?)
Still: Topic: Programming questions

Which forum is that ?

All I can find on this forum is : Arduino Forum
Interfacing w other software on the computer.

SOLUTION FOUND:

Apparantly when you connect an Arduino UNO/MEGA to a MAC system you get two devices loaded, in my case /dev/tty.usbmodemfd121 and /dev/cu.usbmodemfd121 ...

All the time and effort I put in above was tested with /dev/tty.usbmodemfd121 and with no luck ...
(I use /dev/tty.usbmodemfd121 as a reference in the Arduino IDE 0022 to upload and read from the serial)

Changing to /dev/cu.usbmodemfd121 in the code DOES WORK and makes reading from the serial possible !!!

I couldn't find anything about this in the manuals , it might be worth adding imo.

Woot!