Array de Bytes Cshapr - Dúvida
12/04/2015
0
Alguém sabe como eu poderia pegar o primeiro e o último byte deste array de bytes ? Estarei no aguardo, obrigado!
Fábio Carvalho
Posts
13/04/2015
Lucas Ramos
Thiago ele colocou na descrição C#.
Fábio,
Essa função pode te auxiliar para o intervalo de Tempo
Thread.Sleep
Primeiro byte
buffer[0]?
Último byte
buffer[buffer.Length - 1]
13/04/2015
Fábio Carvalho
c#
Fábio,
Essa função pode te auxiliar para o intervalo de Tempo
Thread.Sleep
Primeiro byte
buffer[0]?
Último byte
buffer[buffer.Length - 1]
Lucas, valeu!Irei tentar, caso dê certo irei postar aqui mais tarde.
13/04/2015
Thiago Santana
Mas a ideia é essa mesmo primeiro elemento posição 0.
Ultimo elemento posição = tamanho do array - 1
16/04/2015
Fábio Carvalho
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; try { //retrieve number of bytes in the buffer int bytes = 1, bytesLast = 0; while (bytesLast != bytes) { Stopwatch sw = new Stopwatch(); bytesLast = bytes; // delay em microsegundos ------------------------------------------------------------ sw.Start(); while ((sw.ElapsedTicks / (Stopwatch.Frequency / (1000L * 1000L))) < interchar_delay_us) ; sw.Stop(); //------------------------------------------------------------------------------------ bytes = sp.BytesToRead; } //create a byte array to hold the awaiting data comBuffer = new byte[bytes]; //read the data and store it sp.Read(comBuffer, 0, bytes); if (bytes > 4 && bytes < 13) { if(clsProtocolo.ChecarCRC(comBuffer)) EventDataRecived(comBuffer); Console.WriteLine(); foreach (var b in comBuffer) { Console.Write(String.Format("{0:X} ", b)); }; } } catch { // MessageBox.Show("Erro"); Console.WriteLine("ERROR"); } // Console.ReadKey(); }
Clique aqui para fazer login e interagir na Comunidade :)