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