I’m currently playing with a max232 on the extender.
The serial port works fine and i’m able to communicate with other equipements, but… as soon as I open the com port in a gadgeteer application, I get the following message in VS : [italic]Updating display configuration. DEVICE WILL NOW REBOOT. Visual Studio might lose connection, and debugging might need to be manually restarted[/italic], and the screen is disabled. I had to deploy an empty gadgeteer app to restore it.
When I do the same in an app based on the NetMF console application, the screen keeps working.
Here is the code I used in the gadgeteer app :
using System;
using System.IO.Ports;
using System.Text;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT;
namespace TestSerialPort
{
public partial class Program
{
// Fez Spider sockets :
// Com1 : 11
// Com2 : 4
// Com3 : 8
// Com4 : 9
private SerialPort comPort;
void ProgramStarted()
{
comPort = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
comPort.Handshake = Handshake.RequestToSend;
comPort.DataReceived += ComPortDataReceived;
comPort.ErrorReceived += ComPortErrorReceived;
comPort.ReadTimeout = 200;
try
{
Debug.Print("Opening " + comPort.PortName);
comPort.Open();
Debug.Print("open");
}
catch (Exception ex)
{
Debug.Print("Unable to open com port\n" + ex.ToString());
}
button.ButtonPressed += ButtonPressed;
}
void ButtonPressed(Button sender, Button.ButtonState state)
{
if (comPort.IsOpen)
{
button.TurnLEDOn();
try
{
var buf = Encoding.UTF8.GetBytes(DateTime.Now + "\r\n");
comPort.Write(buf, 0, buf.Length);
}
catch (Exception ex)
{
Debug.Print(ex.ToString());
}
button.TurnLEDOff();
}
else
Debug.Print("Com port not open");
}
void ComPortErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
string eventTypeName;
switch (e.EventType)
{
case SerialError.Frame: eventTypeName = "frame"; break;
case SerialError.Overrun: eventTypeName = "overrun"; break;
case SerialError.RXOver: eventTypeName = "RX overflow"; break;
case SerialError.RXParity: eventTypeName = "RX parity error"; break;
case SerialError.TXFull: eventTypeName = "TX buffer full"; break;
default: eventTypeName = e.ToString(); break;
}
Debug.Print("Error received : " + eventTypeName);
}
void ComPortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
string eventTypeName;
switch (e.EventType)
{
case SerialData.Chars: eventTypeName = "characters"; break;
case SerialData.Eof: eventTypeName = "EOF"; break;
default: eventTypeName = e.ToString(); break;
}
int available = comPort.BytesToRead;
Debug.Print("Data received : " + eventTypeName + ", " + available + " bytes");
var buf = new byte[available];
comPort.Read(buf, 0, available);
Debug.Print(new string(Encoding.UTF8.GetChars(buf)));
}
}
}
Some incompatibilities between standard assemblies and gadgeteer ?