private void Send_Message(Communication.Communication_Message message_to_Send) { List <byte> OutputBuffer = new List <byte>(); Sending_Data encoder = new Sending_Data(); SendBytes(serialPort, encoder.Send_Trame(message_to_Send)); }
private static async Task <bool> EnvoiAsync(System.IO.Ports.SerialPort serialPort1, Trame_Decoder decoder) { byte[] data_to_send; //Envoie le message Sending_Data comm = new Sending_Data(); Communication.Communication_Message trame = new Communication.Communication_Message(); trame.Trame.Instruction = Communication.Com_Instruction.BOOTLOADER; trame.Trame.Slave_Adresse = (Communication.Slave_Adresses)destination_board; trame.Trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE; int page_length = 0; //start listening for messages and copy the messages back to the client foreach (string _line in _lines) { byte _line_length = TwoChar_To_Byte(_line[1], _line[2]); page_length += _line_length; data_to_send = ReadHexLine_to_ByteArray(_line); trame.Trame.Length = (byte)data_to_send.Length; for (int i = 0; i < data_to_send.Length; i++) { trame.Trame.Data[i] = data_to_send[i]; } //Envoi du message decoder.Push_Message_Out(trame); //Cree une trame de communication line_number_position++; /*await Task.Delay(2); * if(page_length >= 4096) * { * await Task.Delay(200); * page_length = 0; * }*/ //await Task.Delay(1); while (decoder.Received_Messages.Count == 0) { ; } if (decoder.Received_Messages.Dequeue().Trame.Instruction == Communication.Com_Instruction.BOOTLOADER_ACK) { await Task.Delay(1); } else { return(false); } if (cancellationToken) { throw new TaskCanceledException(); } } return(true); }