Ok,
This is an odd one, at least to me.
A very quick test application has the following code:
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using System.IO.Ports;
using System.Threading;
namespace Arendee.XBeeToRS232
{
public class MainWindow : Window
{
private const int READ_DELAY = 200;
private SerialPort xbeePort;
private SerialPort rs232Port;
private Text countText;
private ulong counter;
public MainWindow()
{
Initialize();
Thread worker = new Thread(new ThreadStart(() => Run()));
worker.Start();
}
private void Initialize()
{
Width = SystemMetrics.ScreenWidth;
Height = SystemMetrics.ScreenHeight;
var panel = new StackPanel(Orientation.Vertical);
Font smallFont = Resources.GetFont(Resources.FontResources.small);
Font largeFont = Resources.GetFont(Resources.FontResources.large);
var titleText = new Text(smallFont, "XBEE TO RS232 GATEWAY v1.0.0.1")
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
countText = new Text(largeFont, "0")
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
panel.Children.Add(titleText);
panel.Children.Add(countText);
Child = panel;
Visibility = Visibility.Visible;
}
private void Run()
{
xbeePort = new SerialPort("COM2",9600);
xbeePort.DataReceived += xbeePort_DataReceived;
rs232Port = new SerialPort("COM3", 115200);
rs232Port.DataReceived += rs232Port_DataReceived;
xbeePort.Open();
rs232Port.Open();
Thread.Sleep(Timeout.Infinite);
}
void xbeePort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ProcessData(xbeePort, rs232Port);
}
void rs232Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ProcessData(rs232Port, xbeePort);
}
private void ProcessData(SerialPort source, SerialPort destination)
{
Thread.Sleep(READ_DELAY);
var buffer = new byte[source.BytesToRead];
var read = source.Read(buffer, 0, buffer.Length);
destination.Write(buffer, 0, read);
UpdateCounter();
}
private void UpdateCounter()
{
counter++;
Debug.Print(counter.ToString());
Dispatcher.Invoke(new TimeSpan(0,0,0,5,0), new DispatcherOperationCallback((o) =>
{
countText.TextContent = counter.ToString();
return null;
}), null);
}
}
}
(Quick & dirty, I know, but not the point here)
When I run this on a ChipWorkX by debugging in VS.NET,
the serial ports will receive and send data and update the display.
As soon as I do not run this with a debugger attached,
the screen will still be displayed, but neither ports ever receive
any data and the display is never updated.
What gives?
UPDATE:
[ulist]
If you start by debugging in VS2010 and then press STOP
the debugger is disconnected and the application keeps running and it works.
As soon as you press the reset button, the application starts again but it doesn’t work anymore
[/ulist]