Main Site Documentation

Using multiple COM port


#1

Hi,
I try to use multiple COM port together, but I dont have lucky, and it doesnt work well.
I use FezDomino with XPort (COM1) and DS2480 (COM2).
When I use only Xport on (COM1), it works.
When I use only DS2480 on (COM2), it work.
But when I use both Xport and DS2480 together, FezDomino received data only from one of them. Sometime dont receiving Xport and sometime dont receiving DS2480.
I spend couple of hour for finding problem in correct working of XPort and DS2480, but they work well.
Have you any idea where I may look for problem or how to test it for better debug information?

Thanks Dalibor


           comPortIbutton = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            comPortIbutton.Handshake = Handshake.None;
            comPortIbutton.DataReceived += new SerialDataReceivedEventHandler(comPortIbutton_DataReceived);
            comPortIbutton.Open();

            comPortXPort = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
            comPortXPort.Handshake = Handshake.None;
            comPortXPort.DataReceived += new SerialDataReceivedEventHandler(comPortXPort_DataReceived);
            comPortXPort.Open();
...
        static void comPortXPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            while (comPortXPort.Read(array1bajt, 0, 1) == 1)
                queue.Enqueue(array1bajt[0]);
        }
        static void comPortIbutton_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            while (comPortIbutton.Read(array2bajt, 0, 1) == 1)
                comPortXPort.Write(array2bajt, 0, 1);
        }


#2

You need to open the port and then add the recieve event.


#3

Hi,
It doesnt help. The same situation, but I realized, that comport.Read is implemented as blocked read, and this is the problem how I using this functiont.

Thanks anyway Dalibor.

PS: In Broch_FEZ_Domino.pdf and v Broch_FEZ_Mini.pdf you have bad description in remapping COM port 4 (// COM4 is now connected to An3 and An4) it may be connected to AN2 and AN3.


#4

Take a look at SeriaPort class documentation. there are many useful methods and properties.
Like ReadTime out to increase or decrease the time out of reading. the default timeout I believe 500mSec? you can set it to 0 if you don’t want the read function to block at all.

Another thing. very important!!!
As long as you are stuck in an even handler. no other even can be fired!
for example:
you have a while loop in COM1 event receive. this is wrong. you ave to exit this function ASAP to let a chance to other events to run such as COM2’s.

Why don’t you check “bytestoread” before reading? this way you ensure you read only the bytes available in the receiver’s FIFO?


#5

Hi,

as I write, maybe not as clear as I want (my English is not so good).
I find the problem (using blocked read in event) and I solve it.

The problem was that I used comPort.Read in event, and this is what you said too. This is the problem, because comPort.Read is blocked read and stop the event thread and other events don’t start.
I rewrite it using other comPort function and it works fine.

Thanks


#6

i can’t find the serialport object to use with starter kit it show up in the object browser but not in the code.


#7

Did you follow the book examples?


#8

@ jks_access

I guess you forgot to add the reference Microsoft.SPOT.Hardware.SerialPort.
Read the text p75 of the beginner book :wink:

As Im still waiting for the board :frowning: I’m reading some documentation and the Serial port related stuff, namely the System.IO.Ports.SerialPort class, was moved into new separate Microsoft.SPOT.Hardware.SerialPort.dll assembly. That is why you need to add this assembly but in the code you need only

using System.IO.Ports;

good luck

Just to add (I don’t think it’s in the book ;)) : You also need to add a reference to Microsoft.SPOT.Hardware in order to be able to setup parity, stopbits (e.g System.IO.Ports.Parity.None) I