read the packet data from the Serial port...

asked 2015-06-01 07:22:26 -0600

rebel gravatar image

I'm trying to read the data packet from Serialport.Actually i have a Serial program code that read all data packets contionusly, But i tried to read some datas which means,I comparing the receiving packet header to reference headerpacket in the program ,if the packet header is matched, take read operation, otherwise reject that data. so how to change the read function in the program ............

#using <System.dll>
using namespace System;
using namespace System::IO::Ports;

ref class PortDataReceived
{
public:
static void Main()
{
    SerialPort^ mySerialPort = gcnew SerialPort("COM1");

    mySerialPort->BaudRate = 9600;
    mySerialPort->Parity = Parity::None;
    mySerialPort->StopBits = StopBits::One;
    mySerialPort->DataBits = 8;
    mySerialPort->Handshake = Handshake::None;
    mySerialPort->RtsEnable = true;

    mySerialPort->DataReceived += gcnew SerialDataReceivedEventHandler(DataReceivedHandler);

    mySerialPort->Open();
    Console::ReadKey();
    mySerialPort->Close();
}

   private:
    void DataReceivedHandler(
                    Object^ sender,
                    SerialDataReceivedEventArgs^ e)
  {
      SerialPort^ sp = (SerialPort^)sender;
      String^ indata = sp->ReadExisting();
      Console::WriteLine("Data Received:");
      Console::Write(indata);
   }
  };

 int main()
{
     PortDataReceived::Main();
}
edit retag flag offensive close merge delete

Comments

1

I'm not sure, but this looks like C#, not C++?

gvdhoorn gravatar image gvdhoorn  ( 2015-06-01 08:11:57 -0600 )edit

Also it doesn't have anything to do with ROS.

dornhege gravatar image dornhege  ( 2015-06-01 08:18:59 -0600 )edit