Ejemplo n.º 1
0
    public void Connect(string name)
    {
        if (serialPort == null)
        {
            serialPort = new System.IO.Ports.SerialPort();
        }

        if (name == "")
        {
            return;
        }

        if (serialPort.IsOpen)
        {
            serialPort.Close();
        }

        serialPort.BaudRate       = portSpeed;
        serialPort.PortName       = name;
        serialPort.ReadBufferSize = 65000;
        this.portName             = name;

        try
        {
            serialPort.Open();
            Logger_New_Line.Log("Serial Port:" + serialPort.PortName + " Opened!", 6, Color.black);
        }
        catch
        {
            Logger_New_Line.Log("Error while oppening Serial Port:" + serialPort.PortName + "!", 6, Color.red);
        }
    }
Ejemplo n.º 2
0
    IEnumerator test_logger_quantity()
    {
        for (int i = 0; i < 1000; i++)
        {
            Logger_New_Line.Log("Test Internal Logger", 6, Color.black);
            yield return(new WaitForSeconds(0.1F));
        }

        yield return(null);
    }
Ejemplo n.º 3
0
 public void DisConnect()
 {
     try
     {
         serialPort.Close();
         Logger_New_Line.Log("Serial Port:" + serialPort.PortName + " Closed!", 6, Color.black);
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
    public void Start()
    {
        //utilisé pour le logger, accessible en static
        Logger_Viewer = this.gameObject.GetComponent <Logger_New_Line>();


        Logger_Channel[] channels = Channel_Toggle.GetComponentsInChildren <Logger_Channel>();
        foreach (Logger_Channel chan in channels)
        {
            Logger_Channel_Dictionnary.Add(chan.Channel_id, chan.GetComponentInParent <Toggle>());
        }
    }
Ejemplo n.º 5
0
    private void Start_Sending_Task()
    {
        //start asynchronous data sending
        tasks.Add(Task.Factory.StartNew(async() =>
        {
            while (this.serialPort.IsOpen == false)
            {
                await Task.Delay(100);
            }



            Logger_New_Line.Log("Serial Port:" + serialPort.PortName + " Opened! Starting sending!", 6, Color.black);
            while (true)
            {
                if (serialPort != null && serialPort.IsOpen)
                {
                    port_opened = true;

                    if (this.isAllowedToSend || !wait_for_Sending_Clearance)
                    {
                        byte boucle = 0;
                        while (OutputMessages.Count > 0)
                        {
                            Send_Message(OutputMessages.Dequeue());
                            boucle++;
                            if (boucle > 5)
                            {
                                break;
                            }
                        }
                        this.isAllowedToSend = false;
                    }
                }
                else
                {
                    port_opened = false;
                    await Task.Delay(1);
                }

                if (Comport_cancellationToken)
                {
                    throw new TaskCanceledException();
                }
            }
        }));
    }
Ejemplo n.º 6
0
    public bool ReadRemoveInputByte(int count, out byte[] datas)
    {
        if (serialPort == null || serialPort.IsOpen == false)
        {
            datas = new byte[0];
            return(false);
        }

        if (serialPort.BytesToRead < count)
        {
            Logger_New_Line.Log($"Not enought data {count} in RX buffer {serialPort.BytesToRead}", 6, Color.black);
            count = serialPort.BytesToRead;
        }

        //Receptions des datas
        datas = new byte[count];
        serialPort.Read(datas, 0, count);

        return(true);
    }
Ejemplo n.º 7
0
    private void Reading_Task(string file)
    {
        //vérifie qu'il y a bien des données à lire
        if (deserialized_data.messages.Count == 0)
        {
            return;
        }

        Interprete_Message Interpreter = this.GetComponent <Interprete_Message>();

        //start asynchronous data sending
        tasks.Add(Task.Factory.StartNew(async() =>
        {
            Logger_New_Line.Log($"Start Reading logged data: {System.IO.Path.GetFileName(file)}", 6, Color.black);
            Communication.Communication_Message message_output = new Communication.Communication_Message();

            DateTime heure_premier_enregistrement = deserialized_data.messages[0].Heure;

            TimeSpan delay     = new TimeSpan();
            DateTime last_hour = heure_premier_enregistrement;

            //Si une pause dans la lecture est demandee
            while (Pause_Reading_Token)
            {
                await Task.Delay(100);
            }

            //Pour chaque message dans la Liste
            foreach (Communication.Communication_Message message in deserialized_data.messages)
            {
                //Attend que l'heure de traiter ce message soit venue
                delay = message.Heure.Subtract(last_hour);

                await Task.Delay(Math.Abs((int)(delay.TotalMilliseconds / Reading_Speed)));

                //interprete ce message
                try
                {
                    Interpreter.Add_Message_To_Queue(message);
                }
                catch
                {
                    Logger_New_Line.Log("Exception while reading", 6, Color.red);
                }

                Nb_Lines_Read++;

                last_hour = message.Heure;

                //si on demande l'arret de la lecture
                if (Stop_Reading_Token)
                {
                    throw new TaskCanceledException();
                }

                //Si une pause dans la lecture est demandee
                while (Pause_Reading_Token)
                {
                    await Task.Delay(100);
                }
            }
        }));
    }