Hi all,
And again, i’ve returned.
Not with a single question, and the hope that someone gives me an answer.
This time, i’ve managed to sort the problem out myself. The reason why i’m posting this, is because i think that there is a problem in the firmware of Fez Domino, or in NETMF. By posting this, i hope that someone will actually take the effort to try this out for themselves(when possible) and post some feedback.
The situation is as follows:
I’ve got a MOD-GPS from Olimex (MOD-GPS), which uses the UEXT connector to communicate with the Domino. It uses the +3.3v, gnd and COM2 RX/TX.
So far, so good. I’ve programmed some very basic code to read the GPS module. Everything works fine, as long as i start the program in Visual Studio, using the ‘start debugging’ button(or F5). The program let’s the LED flash when data which comes in over COM2, and it also writes that data to an USB drive.
Now the weird part starts:
When powering the Domino without a pc(using the power connector), or only using the usb-connector, nothing happend. No flashes, no usb-activity, no nothing. I tried (almost) everything! Putting it in release mode, testing led flash without data, writing bullshit data to the USB drive.
In many code examples, the SerialPort class is used by registering a ‘data received’ event handler. This didn’t work, unless i started the Domino using the ‘start debugging’ button in VS.
Solution:
I checked the SerialPort class for incoming data myself, and hey presto! There is actually data coming in! So, i’ve wrote a seperate thread in which the serialport’s ‘bytestoread’ field is constantly checked.
In code.
Doesn’t work:
{
SerialPort COM2 = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
COM2.DataReceived += new SerialDataReceivedEventHandler(COM2_DataReceived);
COM2.Open();
}
void COM2_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
... LED flash, Read data using COM2.Read(), ect. ...
}
Works:
{
SerialPort COM2 = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
COM2.Open();
}
/** Seperate thread */
void WorkerThread
{
while(true){
if(COM2.COM2.BytesToRead>0){
... LED flash, Read data using COM2.Read(), ect. ...
}
Thread.sleep(COM_CHECK_INTERVAL);
}
}
}
Solution for using Eventhandlers
When using the eventhandlers, they must be added to the serialport AFTER opening the serial port.
So this:
SerialPort COM2 = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
COM2.DataReceived += new SerialDataReceivedEventHandler(COM2_DataReceived);
COM2.Open();
is the wrong way. And this:
SerialPort COM2 = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
COM2.Open();
COM2.DataReceived += new SerialDataReceivedEventHandler(COM2_DataReceived);
Is the good way.
Case closed. Lesson learned. Time wasted.