Main Site Documentation

Comm1 Error message / question - thanks (PROBLEM SOLVED)


#1

Hello Tiny CLR
I get a System.InvalidOperationException when trying to open COM1.
I suspect there is some initialization of COM1 that I am missing.
I can not find anything in the Tiny CLR examples or documentation.
I would be very appreciative if you can take a quick look and let me know what you think.
Thanks !

THE CODE … crashes at UART.Open():

using System;
using System.IO;
using System.Threading;
using System.IO.Ports;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.System;

namespace MFConsoleApplication1

{

    public class Program

    {

        const byte MIDI_Channel = 1;    // Midi Channel 2

        const int MIDI_BAUD_RATE=31250;

        const int SERIAL_PORT_RATE = MIDI_BAUD_RATE;



        public static void Main()

        {

            byte[] b = new byte[] { 0xC1, 0x05 };  // 0xC1=prog chg ch 2, 0x05=patch 6

            int i = b.Length;

         // b[0]=0xB0 | (MIDI_Channel & 0x0F);  // Program Change

         // b[1]=0x00;



         // System.IO.Ports.SerialPort UART = new System.IO.Ports.SerialPort("COM1", MIDI_BAUD_RATE, Parity.None, 8, StopBits.One);

            SerialPort UART = new SerialPort("COM1", MIDI_BAUD_RATE, Parity.None, 8, StopBits.One);



            UART.Open();

            UART.Write(b, 0, b.Length);

            UART.Flush();

            UART.Close();



        while (true)

          {

          LED.Write(!LED.Read())
          Thread.Sleep(2000);

          }

        }

    }

}

THE ERROR MESSAGE BEING THROWN

Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\mscorlib.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Native.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Hardware.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.Hardware.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.IO.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Hardware.SerialPort.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Users\Maestro\Documents\Visual Studio 2008\Projects\MFConsoleApplication1\MFConsoleApplication1\bin\Debug\MFConsoleApplication1.exe’, Symbols loaded.

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.Hardware.USBizi.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Hardware.Usb.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.System.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.IO.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Graphics.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.TinyCore.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\Microsoft .NET Micro Framework\v4.0\Assemblies\Microsoft.SPOT.Net.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.Net.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\FEZDomino_GHIElectronics.NETMF.FEZ.dll’

‘Microsoft.SPOT.Debugger.CorDebug.dll’ (Managed): Loaded ‘C:\Program Files\GHI Electronics\GHI NETMF v4.0 SDK\Assemblies\GHIElectronics.NETMF.USBHost.dll’

The thread 0x2 has exited with code 0 (0x0).

#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####

#### Microsoft.SPOT.Hardware.Port::ReservePin [IP: 0000] ####

#### System.IO.Ports.SerialPort::HandlePinReservations [IP: 002e] ####

#### System.IO.Ports.SerialPort::Open [IP: 001d] ####

#### MFConsoleApplication1.Program::Main [IP: 003e] ####

#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####

#### System.IO.Ports.SerialPort::HandlePinReservations [IP: 0063] ####

#### System.IO.Ports.SerialPort::Open [IP: 001d] ####

#### MFConsoleApplication1.Program::Main [IP: 003e] ####

A first chance exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.SerialPort.dll

An unhandled exception of type ‘System.InvalidOperationException’ occurred in Microsoft.SPOT.Hardware.SerialPort.dll


#2

My guess is you have the a wrong GHI assembly in your references. Make sure you have the right one for your board. The exception seems to be a mismatch of pin and board.


#3

Does the code works with standard baudrate like 9600?
Clean your code to only the 2 lines of code you need and remove any other files in your project. Try now again!


#4

Thanks GUS, I must have had a bad assembly. I created a new project and re-added my assemblies. The code then started to work (at both 31250 and 9600) baud. I appreciate the quick response ! I always seem to find a solution minutes after the posting. I apologize for any inconvenience… I love this product !