Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length



Pages: [1]
  Print  
Author Topic: Serial Port "Data Received" Delegate function not triggering  (Read 689 times)
sreekar
Newbie
*
Posts: 3


View Profile
« on: February 16, 2010, 08:09:41 PM »

I am working with COM2 (RX1, TX1) and COM4 (RX3, TX3) of the USBizi board and I am facing a peculiar problem with the data received delegate function of the serial port class.

COM2 is connected to a Bluetooth Serial adapter board and COM4 is connected to a FTDI USB-Serial board. They both have the same data received delegate function as shown below.

The Serial Port initialization code
Code:
try
            {
                // The Bluetooth module is connected to RX1 and TX1 pins of USBizi.
                // COM1 string refers to RX0 TX0, Accordingly RX1 TX1 refers to COM2
                BTSerialPort = new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One);
                BTSerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(BTSerialPort_ErrorReceived);
                BTSerialPort.DataReceived += new SerialDataReceivedEventHandler(BTSerialPort_DataReceived);
                BTSerialPort.Open();

               
                // FTDI Serial Port
                FTDISerialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
                FTDISerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(BTSerialPort_ErrorReceived);
                FTDISerialPort.DataReceived += new SerialDataReceivedEventHandler(BTSerialPort_DataReceived);
                FTDISerialPort.Open();
               
            }
            catch (Exception EXP)
            {
                Debug.Print("Error Initializing and Opening Serial Port: " + EXP.Message);
            }

Here is the Data Received Event Handler (Green refers to a LED connected to a PWM port)
Code:
static void BTSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
                Green.Set(100, 50);

                // Read data from the IN buffer
                int NoOfBytesReceived = BTSerialPort.BytesToRead;
                NoOfBytesReceived = FTDISerialPort.BytesToRead;
                byte[] ReceivedData = new byte[NoOfBytesReceived];

                // Read only the first character as it indicates whether we want Command or Data mode
                int NoOfBytesRead = BTSerialPort.Read(ReceivedData, 0, NoOfBytesReceived);
                NoOfBytesRead = FTDISerialPort.Read(ReceivedData, 0, NoOfBytesReceived);
             

                //Echo what you received
                BTSerialPort.Write(ReceivedData, 0, NoOfBytesRead);
                FTDISerialPort.Write(ReceivedData, 0, NoOfBytesRead);
}
               



When the board is connected to my computer through the USB slave cable and I deploy the program from within VS 2008, I am able to catch the data received event. All of these things happen as expected
1. I can place a breakpoint inside the event handler and catch the event when I send a character through the serial port.
2. The green LED starts to glow when I send a character
3. The character is echoed back to my terminal program

But, when I remove the board out of my computer and power it up with a battery and send serial data from either of the COM ports, the event is not triggered. None of the above three happens.

In the Beginner's Guide book, there is no example showing the use of Data Received Event function.

I am curious why my board is acting the way it is.

Thanks
Sreekar
Logged
SupportAdmin
Administrator
Hero Member
*****
Posts: 5394



View Profile WWW
« Reply #1 on: February 16, 2010, 08:21:46 PM »

We have recently found similar symptoms which we are already investigating. Once 4.0 is out this week, please give it a shot and let us know how it goes
Logged
sreekar
Newbie
*
Posts: 3


View Profile
« Reply #2 on: February 16, 2010, 08:33:54 PM »

Thanks for the immediate response. I will sense the serial port within my Main While loop for now.

Will repost when I have tried the 4.0.

Thanks
Sreekar
Logged
GHI_Support
Administrator
Hero Member
*****
Posts: 1252


View Profile
« Reply #3 on: February 17, 2010, 09:27:09 AM »

I think this is a known issue. You just have to switch the order of Open serial port and subscribing to DataReceived event and it work fine.
Logged
Pages: [1]
  Print  
 
Jump to: