hal s

hal s

  • NA
  • 3
  • 3.3k

Simultaneous Reading from Serial Port Problem

Aug 23 2010 12:19 AM
Hi,

I am new to serial port programming. I have RFID reader & sensor transmitting data through serial port. When RFID reader reads RFID hanger & sensor reads an object simultaneously then sensor fails to transmit data. Below is the code:

  private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            StationDATA szCANData;
            
            //String szData ="";
            int nBytesToRead = serialPort1.BytesToRead;
            byte[] szBuff = new byte[nBytesToRead];
            //string szCOM= serialPort1.ReadExisting();
            //szData += serialPort1.ReadExisting();
            //ProcessBuffer(szData);
            serialPort1.Read(szBuff, 0, nBytesToRead);
            
            szCANData.StationID = szBuff[0];
            szCANData.StationCMD = szBuff[1];
            szCANData.StationMSG0 = szBuff[2];
            szCANData.StationMSG1 = szBuff[3];
            szCANData.StationMSG2 = szBuff[4];
            szCANData.StationMSG3 = szBuff[5];
            szCANData.StationMSG4 = szBuff[6];
            szCANData.StationMSG5 = szBuff[7];
            szCANData.StationMSG6 = szBuff[8];
            szCANData.StationMSG7 = szBuff[9];
            szCANData.EOD = szBuff[10];
}

Please help. Many thanks

Answers (2)