Question about sending serial data and data types (bytes vs string)

Hello, I have a newbie data types question -

We have an older RS232 scale we are trying to send / receive data from. The protocol says that it should receive a 'W' (57h) command.

If a scale accepts one of these would it necessarily accept all of them, or could these be interpreted differently by a serial device / machine?

Serial1.write('W');
Serial1.write(0x57);
Serial1.write('\x57);

Thank you.

this is the same thing. difference is between
Serial1.write(10); and Serial1.print(10);

1 Like

Does that compile?

Thank you both. Yes, Serial1.write('\x57); compiles for me.

So to round it out, if I am sending Serial1.write('W'); and it's not working, then sending Serial1.write(0x57); is identical and will actually not cause the serial device to respond differently - is that correct?

For what board? When I attempt to compile it for a Mega, I get:

sketch_jun27a:2:17: error: missing terminating ' character
   Serial1.write('\x57);
                 ^~~~~~~
C:\Users\GFV\AppData\Local\Temp\arduino_modified_sketch_801905\sketch_jun27a.ino: In function 'void setup()':
sketch_jun27a:4:1: error: expected primary-expression before '}' token
 }
 ^

Can you provide a link to the manual for the scale?

Does the 'W' need to be followed by a CR (carriage return) or NL (new line).

@gfvalvo sorry I should have clarified, I'm using a Particle Photon.

Thanks, it's an older CAS PD II scale. In this case TYPE 2 doesn't want CR or terminator character. I believe it's this one: https://www.cas-usa.com/media/software/interface-scales/OPOS%20scale%20Protocol%20sheet_v14%20-%2020160726.pdf

We've done MCU to scale communication for other scales with similar protocols (including the newer PD-2Z), but are stumped as to why this isn't working. The confounding thing is that when the scale is hooked up to an older Windows PC Point of Sale which seems to be sending the W character (with no extra characters or terminators), the scale responds.

At this point we've tried debugging using an Android Serial USB Terminal app (same UART settings, same Serial to USB cable as the POS) as well as our own board, and can't figure out what the Windows PC is doing differently. We've confirmed the Windows PC seems to just be sending the W command on repeat.

Something related to UTF encoding (I don't think so)?

Or is it somehow sending the raw Decimal value (in this case 87 which is 57h)?

Thanks for the help!

Does the Particle Photon handle 7 bit with even parity correctly? If not, have you tried 8 bit, no parity and sending 0xd7 instead of 0x57? If I'm looking at RS-232 correctly that would be the equivalent to 7 bit even parity.

Are you absolutely certain you do not have the RS-232 Rx and Tx lines connected incorrectly?

Thanks @david_2018. I'm sure it can do 7E1. We also tried both null modem and straight through just to be safe. I'll also try your suggestion with the client tomorrow.

The more I think about this, I think I must be overcomplicating this and the PC must be sending some Newline that I'm somehow missing. I'll try again with the client tomorrow.

Dos this board assert TTL logic or RS232 logic over the UART Port during communication with the Scale?

@GolamMostafa we connect the board with an RS232 TTL converter (DB9 end) which works with other scales, does that help?

If your Arduino Board asserts TTL logic and the Scale accepts RS232 logic, then you need to insert a TTL <----> RS232 Converter (Fig-1) between Arduino and Scale. Would appreciate to see your sketch.
TTLRS232ConverterModule
Figure-1:

Are you using the same RS-232 cable that you use for the other scales?

@GolamMostafa yes, we are using an RS232 TTL converter.

@david_2018 yes, we have been debugging on the Android device using the same Serial to USB cable that works between the scale and current Windows PC POS. And when testing with our board, we are using the same types of RS232 cables as we typically use, and testing both null modem and straight through.

Can you please, post a picture of your connection and the sketch?

Do you have a 8 Ch 24MHz logic analyser?
Such a logic analyser can be used to show each and every single logic level-change
and with the software pulseView you can translate the LOW/HIGHS into serial ASCII-coded bytes

Do you you have a digital storage oscilloscope?

Do you have an extra serial-to-USB-com-port-adapter which you could connect in parallel to the PC with which the scale is working?

And then when this serial-to-USB-COM-Port-adapter is connected you "listen" to the data-communication and display all the bytes with a terminal-software as hexadecimal.

Printing the bytes as hexadecimal will show each new line or carriage return character

Just to become a better picture of it all:
Does the scale have a standard RS232-interface which works not on TTL-voltage-level but on 12V?

Are you aware that serial interfaces can work with hardware-handshaking over additional wires in the serial cable?

Are you aware that serial interfaces can have software-handshaking (Xon/Xoff) ?

Did you do some cross-checking connecting your older PC which works with the scale not connecting to the scale but to a second PC to see what the older PC is really sending?

best regards Stefan

But does that cable work between the TTL-to-RS232 adapter you are using, on a Particle Photon (or other Arduino board) and the other scales? My concern is that the Rx and Tx pins on the DB9 connector on the TTL-to-RS232 adapter are swapped from the position they would be on the serial port of a PC.

Same type of cable is not testing with that special particular exact the same cable.

The chance that the cables are really different is rather low but you could fool yourself for months and years if there is a physical difference between two cables.

So to make really sure I would use that special particular EXACT the same cable. For both.

If you need different connectors put an adapter in series. Or solder a cable on your own to be 101% sure that the physical wiring is the same.

If using PC/USB and Scale, then you use the following cable (Fig-1, RS232/USB).
image
Figure-1:

If using Arduino and Scale, then you need to use the following cable (Fig-2) to connect your Scale with RS232 <----> TTL Converter.
image
Figure-2:

@StefanL38 thank you for the response. We don't have those two pieces of hardware.

We do have an extra serial to USB com port adapter and this is what we used to connect the Android device to the PC to "listen" and confirm it was sending the 'W' character on repeat (same UART settings). As far as I could tell, this was the only byte it was sending - but I think I must be missing something here. For attempting to debug and connect the Android device to the scale, we used the exact same working serial to USB cable.

I'm not familiar with 12v vs TTL voltage level - but if it's working with a standard USB to serial cable connected to a PC, is this a possibility / relevant?

I'm familiar with the concept of handshaking, but if the PC is only sending the W command (as far as I can tell), is there a handshake occurring (whether software or hardware)? Thank you.