Problem Serial Port bytes missing with write method

tomrod 96 Reputation points
2021-01-24T08:36:12.19+00:00

Hi everyone, I am using Visual Studio 2013 (C#) in order to test serial port. I have an array of bytes and I am trying to send it via Serial Port using two USBSerialConverter. The data that I receive is between 14 to 18 bytes of lenght (it change everytime i execute the code), not 30 as the size of array.

            byte[] tx_Data = new byte[30];
            ...
            string bitString = BitConverter.ToString(tx_Data);
            Console.WriteLine(bitString);
            serialPort1.Open();
            Console.WriteLine(tx_Data.Length);
            serialPort1.Write(tx_Data, 0, tx_Data.Length);
            serialPort1.Close();

The Console.WriteLine from this code is:
4F-42-2D-30-35-30-34-2D-32-34-33-36-2C-0C-01-13-17-33-09-0F-0F-0A-1E-58-00-00-00-00-C8-26
30

but I receive something like.
4F 42 2D 30 35 30 34 2D 32 34 33 36 2C 0C 01 13

What I could be doing wrong?
thanks for your help.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,096 questions
{count} votes

Accepted answer
  1. tomrod 96 Reputation points
    2021-01-30T04:18:12.53+00:00

    Finally, the problem was the USB-Serial Converter which I was using (CH340). I changed it to FT232RL and I has able to send all the data. Thanks for your hints.

    Best Regards

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. tomrod 96 Reputation points
    2021-01-26T18:08:31.603+00:00

    Thanks for your advice,
    by default the baud rate was 9600, then I changed it to 19200 and it works very well. What could be wrong when I use 9600 baud?


  2. tomrod 96 Reputation points
    2021-01-29T21:24:07.113+00:00

    Now the same code works well sending all the data with 9600 baud, but it works with virtual COM ports. Before I was testing with two ch340 USB-Serial Coverter. Maybe these modules are the problem, I will try with FT232RL.

    Best Regards

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.