Hi Guys,
I recently got HYDRA and I want to use two serial ports, one for XBEE socket, one for GSM module. I don’t want to use Gadgeteer, but pure NETMF. I found out that in my case only COM1 works well, but others throws ArgumentException when I try to create new instance of SerialPort.
public static void Main()
{
string[] ports = new string[] { "com1", "com2", "com3", "com4" };
foreach (var port in ports)
{
SerialPort serial = null;
try
{
serial = new SerialPort(port, 9600);
serial.Open();
if (serial.IsOpen)
{
Debug.Print("Port " + port + " is open!");
}
else
{
Debug.Print("Failed to open port " + port + "!");
}
}
catch (Exception ex)
{
Debug.Print("Failed to open port " + port + " due exception " + ex.GetType().Name);
continue;
}
finally
{
if (serial != null) serial.Dispose();
}
}
}
Here is an output of this code:
Port com1 is open!
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.NativeEventDispatcher::.ctor [IP: 0000] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0030] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0009] ####
#### UARTTest.Program::Main [IP: 0043] ####
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
Failed to open port com2 due exception ArgumentException
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.NativeEventDispatcher::.ctor [IP: 0000] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0030] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0009] ####
#### UARTTest.Program::Main [IP: 0043] ####
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
Failed to open port com3 due exception ArgumentException
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### Microsoft.SPOT.Hardware.NativeEventDispatcher::.ctor [IP: 0000] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0030] ####
#### System.IO.Ports.SerialPort::.ctor [IP: 0009] ####
#### UARTTest.Program::Main [IP: 0043] ####
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
Failed to open port com4 due exception ArgumentException
Device info from MFDEPLOY is:
DeviceInfo:
HAL build info: 4.1.2821.0, Microsoft Copyright (C) Microsoft Corporation. All rig
OEM Product codes (vendor, model, SKU): 255, 0, 65535
Serial Numbers (module, system):
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Solution Build Info: 4.1.2821.0, Microsoft Copyright (C) Microsoft Corporation. All rig
AppDomains:
default, id=1
Assemblies:
mscorlib,4.1.2821.0
Microsoft.SPOT.Native,4.1.2821.0
Microsoft.SPOT.Hardware,4.1.2821.0
Microsoft.SPOT.Graphics,4.1.2821.0
Microsoft.SPOT.TinyCore,4.1.2821.0
Microsoft.SPOT.IO,4.1.2821.0
System.IO,4.1.2821.0
Microsoft.SPOT.Hardware.Usb,4.1.2821.0
Microsoft.SPOT.Hardware.SerialPort,4.1.2821.0
Microsoft.SPOT.Net,4.1.2821.0
System,4.1.2821.0
Microsoft.SPOT.Touch,4.1.2821.0
Microsoft.SPOT.Ink,4.1.2821.0
UARTTest,1.0.0.0
Thanks for any help.
Jan