Serial Port Write Echo

1.2k Views Asked by At

I know posts are there related to this point but it did not help me.I have a Wandboard running Android and it is connected to PC via USB port.I am using SerialPort .Net class to read and write data.It is designed as Request response manner.PC will request for data once in 5 seconds so it will write to port and wait for Wandboard to respond back within 1 second.If it responds then through SerialPort read method it will read data and so on the process will go on.The problem I am facing is the data that I wrote to the port is echoed back along with the desired response from the wandboard.the data that I wrote to the port is first in the order.No matter what I do it always echoes back my written data.To come up with a temporary solution,I am writing the data and appending new line at the end,so when I read post that as I am getting echo I skip the data till the first newline I get .

I know this is not a good approach but I have tried enough and could not stop port from echoing back what I had written.any help is highly appreciated.

Here is the code for writing and reading .

    /// <summary>
    /// Writes and receives data from AP board
    /// </summary>
    private void RequestAndResponse()
    {

        while (true)
        {

            try
            {
                if (myserialPort2 != null)
                {
                    int iwriteSize = 5;

                    if ( !myserialPort2.IsOpen)
                    {
                        myserialPort2.Open();
                    }

                    byte[] bytearrayOfSendCommand = new byte[iwriteSize];

                    bytearrayOfSendCommand[0] = 0x48;
                    bytearrayOfSendCommand[1] = 0x41;
                    bytearrayOfSendCommand[2] = 0x41;
                    bytearrayOfSendCommand[3] = 0x42;
                    bytearrayOfSendCommand[4] = 0x0A;

                    myserialPort2.Write(bytearrayOfSendCommand, 0, iwriteSize);

                    int size = myserialPort2.BytesToRead;
                    char[] bContent = new char[size];

                    var buffsize = myserialPort2.ReadBufferSize;
                    myserialPort2.Read(bContent, 0, size);

                    lock (objLocker)
                    {
                        char[] bContentTemp = bContent;

                       // ConsumePacketData(bContentTemp);
                    }

                    Thread.Sleep(2 * 1000);

                }

            }
            catch(Exception)
            {
               //to be implemented later
            }
        }
    }
1

There are 1 best solutions below

8
On

Please check your USB to Serial driver settings for the Echo option.