Can several C # forms use the same serial port to send and receive data?

0

I am working on a project with Arduino and C # and I hope that my C # solution is composed of several forms and that they use the same serial port (since that has been my problem so far) and I was thinking that an easy way it would be a class but I do not know how the data of the forms would be received

    
asked by Ronald Chén 16.10.2018 в 05:57
source

1 answer

0

So that all your forms, when trying to send data to the Arduino, use the same port, you just have to create a class that takes care of it. For example:

using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Threading.Tasks;

namespace *nombre_de_tu_proyecto*
{
public static class SerialPortClass
    {
    public static SerialPort serialPort1 { get; set; } = new SerialPort();
    }
}

Being a static class you can call it from any of your forms to write through that port. In addition, from any form you can instantiate or modify any of the properties of the serialPort created.

    
answered by 30.12.2018 в 22:25