Robotics StackExchange | Archived questions

read the packet data from the Serial port...

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();
}

Asked by rebel on 2015-06-01 07:22:26 UTC

Comments

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

Asked by gvdhoorn on 2015-06-01 08:11:57 UTC

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

Asked by dornhege on 2015-06-01 08:18:59 UTC

Answers