Go Down

Topic: Byte reading and bit interpretation (Read 710 times) previous topic - next topic

nborsato

Mar 26, 2018, 04:23 am Last Edit: Mar 26, 2018, 08:13 am by robtillaart
Folks,

I need to read bytes from a measurement device, I have already visited several topics and I was able to implement some classes and read data through the serial port using the Javacomm and RXTXcomm API, but I am having difficulty interpreting the bits, I believe it is due to the way of reading .

The device emits a block of 8 bytes every second, the data is binary, reading as below I get to numbers equal or less than 255, what should I do to have readable data?

Code: [Select]
int Octeto1 = 0;

int LedRX = 13;

void setup () {
  Serial1.begin(110); //Comunica com o medidor
  Serial.begin(115200); //Comunica com o monitor serial PC
{
  pinMode(LedRX, OUTPUT);
}
}

void loop () {
  if (Serial1.available() > 0){
    Serial.println("Recebendo Informacoes");
    digitalWrite(LedRX, HIGH);
    delay(100);
  }
  else { 
    digitalWrite(LedRX, LOW);
  }

    Octeto1 = Serial1.read();
   
   Serial.println(Octeto1);
}



robtillaart

your code also reads data when none is available

Code: [Select]
int Octeto1 = 0;

int LedRX = 13;

void setup ()
{
  Serial1.begin(110);
  Serial.begin(115200);
  Serial.println(__FILE__);

  pinMode(LedRX, OUTPUT);
  digitalWrite(LedRX, LOW);
}

void loop ()
{
  if (Serial1.available() > 0)
  {
    Serial.println("Recebendo Informacoes");
    digitalWrite(LedRX, HIGH);
    delay(100);

    while (Serial1.available() > 0)  // process all data that is available
    {
      Octeto1 = Serial1.read();
      Serial.print(Octeto1);
      Serial.print(", ");
    }
    Serial.println();
  }

  digitalWrite(LedRX, LOW);

}

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

UKHeliBob

Quote
what should I do to have readable data?
What are you expecting to read ?
Numbers ?
Text ?
Both ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Robin2

Image from Original Post so we don't have to download it. See this  Simple Image Guide



...R
Two or three hours spent thinking and reading documentation solves most programming problems.

wildbill

What is the device sending these bytes?

oqibidipo

Also, which device is reading these bytes?
Code: [Select]
 Serial1.begin(110); //Comunica com o medidor
110 bps is too slow for HardwareSerial on a typical AVR-based Arduino running at 16 MHz (or even at 8 MHz).
SoftwareSerial should be able to do it.

Go Up