Problem reading serial data

Hi all,

I have a similar project and my issue is when I m trying the write the send_meters to serial. The hex data {0x80, 0x01, 0x1C} is arriving to machine in a different format.

If I m sending 80 01 1C from Hercules using HEX it works on the machine.

byte send_meters[] = {0x80, 0x01, 0x1C};

void sendMeters() {
Serial.write(send_meters, sizeof(send_meters));
}

I also tried with {128, 01, 31} in decimal format but still a different answer on the machine.

Any ideas what I m doing wrong?

Regards
Radu

Split form an old topic

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.

Posting tips.

  • Your OS and version can be valuable information, please include it along with extra security you are using.
  • Always list the version of the IDE you are using and the board version if applicable.
  • How to insert an image into your post. ( Thanks Robin2 )
  • Add your sketch where applicable but please use CODE TAGS ( </> )
  • Add a SCHEMATIC were needed even if it is hand drawn
  • Add working links to any specific hardware as needed (NOT links to similar items)
  • Remember that the people trying to help cannot see your problem so give as much information as you can

Show your receiver codes. Is receiver another Arduino or a stand-alone machine? Does receiver expect ASCII codes instead of 'natural binary' being sent by Serial.Write(?

ArduProim:
I have a similar project and my issue is when I m trying the write the send_meters to serial. The hex data {0x80, 0x01, 0x1C} is arriving to machine in a different format.

It would help if you tell us how it is arriving.

...R

I'm using ESP8266 D1 MINI with RS232 serial port.

esp8266 code:

byte send_meters[] = {0x80, 0x01, 0x1C};

void setup() {
  Serial.begin(19200, SERIAL_8E1);
  while (!Serial) {
    ;
  }

  establishContact();
}

void loop() {
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.write(send_meters, sizeof(send_meters));    
    delay(200);
  }
}

Machine answer:

IN > 00
IN > 8E
IN > F4

Expected answer from machine must be:

OUT > 01 1E 00 00 00 00 00........etc
IN > 01 1C
IN > 80

According to the machine documentation the data must be sent in binary format. 19200 bits per second, parity even.

I don't understand why If I'm sending from Hercules Monitor the same command in HEX 80 01 1C it works.

I attached a screenshot with working Hercules config.

Many thanks.

Image from Reply #5 so we don't have to download it. See this Simple Image Posting Guide

...R

ArduProim:
According to the machine documentation the data must be sent in binary format. 19200 bits per second, parity even.

Can you post a link to the documentation, and if it is long, tell us what pages are relevant.

Have you tried this with a regular Arduino Uno or Mega?

...R

Connect your device with a Software Serial Port of ESP having a RS232<--->TTL converter i between and then try these codes: (Keep RX/TX Port being connected only with Serial Monitor).

#include<SoftwareSerial.h>
SoftwareSerial mySerial(SRX, STX);  //choose suitable GPIO Pins of ESP

byte send_meters[] = {0x80, 0x01, 0x1C};

void setup() 
{
  Serial.begin(9600);
  mySerial.begin(19200, SERIAL_8E1);
 // while (!Serial) {
//    ;
  }

  establishContact();
}

void loop() {
}

void establishContact() 
{
  //while (Serial.available() <= 0) {
    mySerial.write(send_meters, sizeof(send_meters));   
    delay(10);
  //}

  while(mySerial.available()>0)
  {
      char x = mySerial.read();
      Serial.print(x);
  }
}

Note: We don't see (except a foreign character) in your following Hercules Receiver what you are receiving from the machine. Are you sending space character in between the bytes of 80 01 1C? Why are they not like 80011C?

Somebody recently posted the below SoftwareSerial function which apparently inverts for TTL/RS232 communication, assuming the RS232 device uses a 5v line voltage.

SoftwareSerial modem(10, 11, 1);

There is the following constructor with three arguments -- what is the actual meaning and implementation of the 3rd argument? Normally, we declare/define the first two arguments; in that case, what is the default value of the 3rd argument -- is it 0?
sscons.png

sscons.png

what is the default value of the 3rd argument -- is it 0?

No, it is false, as can be seen in the function prototype that you posted

UKHeliBob:
No, it is false, as can be seen in the function prototype that you posted

false is the symbolic name which must have some kind of numeric value to get stored in memory. Or the string "false" gets stored?

You do not need to know what gets stored for false, just use false

What does it matter if the value is 0, 123 or even -99 ? You should not rely on false being a particular value and don't need to as long as you compare it with true or false.

It most certainly is not stored as "false"

If you really are interested in the value of false then you could take the radical step of printing it

post #7 reply

Can you post a link to the documentation, and if it is long, tell us what pages are relevant.

Have you tried this with a regular Arduino Uno or Mega?

No. I will buy a regular Arduino and I will come back.

post #8 reply

I tried with SoftwareSerial but I'm not able to set the parity even SERIAL_8E1.

From Hercules, I'm able to send command without space in hex like: 80011C

thanks.

Thanks for the documentation.

When I now look back to Reply #5 I realise I don't know how to interpret the pieces under the headings "Machine answer" and "Expected answer from machine must be:" Perhaps you can explain them in more detail.

I have never used anything other than "no parity" so I wonder if the SoftwareSerial even parity is being misunderstood. It would be nice to be able to compare a logic analyzer trace from your Hercules program and from the Arduino. What would happen if you set it for ODD parity ?

...R

If there is anyone interested to help me with some paid consultation via skype I m open. I spent over one week and I didn't manage to communicate properly.
Thanks.

ArduProim:
If there is anyone interested to help me with some paid consultation via skype I m open. I spent over one week and I didn't manage to communicate properly.
Thanks.

You need to ask that in the Gigs and Collaborations section. Perhaps click Report to Moderator and ask to have the entire Thread moved there. I don't do paid work myself.

...R

Hello, I'm looking to find someone to offer me paid consultation via skype in order to help me to fix this communication issue. Is someone interested?
Thanks.