none
How to write to multiple serial ports at the same time RRS feed

  • Question

  • Hi,

    I am creating an application that sends out data to multiple serial ports(Arduino nano's). Speed plays a pretty big role in this project, so it isn't an option to write to all the serial ports one after the other.

    I am using "Write (Byte[], Int32, Int32)" to send the data to the serial ports and it is quick enough when it only has to send the data to a single serial port, but when it has to write the data to multiple serial ports it takes way longer, because it writes the data to the serial ports one after the other.

    So is there a way that I could write to multiple serial ports at the same time?

    Wednesday, February 20, 2019 7:09 PM

Answers

  • Try something like this (for three ports):

     

    using System.Threading;

    . . .

     

        var t1 = new Thread( () =>

        {

            // write to port 1

            // . . .

        } );

     

        var t2 = new Thread( () =>

        {

            // write to port 2

            // . . .

        } );

     

        t1.Start();

        t2.Start();

     

        // write to port 3

        // . . .

     

        t1.Join();

        t2.Join();

     

    It is also possible to use BackgroundWorker and events.

    • Edited by Viorel_MVP Wednesday, February 20, 2019 7:47 PM
    • Marked as answer by Mr.Nobody, Wednesday, February 20, 2019 9:04 PM
    Wednesday, February 20, 2019 7:46 PM

All replies

  • Try something like this (for three ports):

     

    using System.Threading;

    . . .

     

        var t1 = new Thread( () =>

        {

            // write to port 1

            // . . .

        } );

     

        var t2 = new Thread( () =>

        {

            // write to port 2

            // . . .

        } );

     

        t1.Start();

        t2.Start();

     

        // write to port 3

        // . . .

     

        t1.Join();

        t2.Join();

     

    It is also possible to use BackgroundWorker and events.

    • Edited by Viorel_MVP Wednesday, February 20, 2019 7:47 PM
    • Marked as answer by Mr.Nobody, Wednesday, February 20, 2019 9:04 PM
    Wednesday, February 20, 2019 7:46 PM
  • Thanks a lot

    Wednesday, February 20, 2019 9:06 PM