Interpreting the data from RS232? - Page 1
Forum section: electronics / beginners

author: SpannersToSparks
author_rank: Regular Contributor
timestamp: August 21, 2019, 12:23:34 pm
content: HiI have an application where data is being sent over RS-232 to another computer, and I understand that you can get serial monitors and packet sniffers that will display the raw data being sent. However I am quite new to RS-232 and am not clear on a few things.How do I actually translate that data into something human understandable? In my application the data will be coming from a weigh scale and I want to just extract e.g. 85.3kg. Do I need some kind of translation software to locate the start bit, data field and stop bit, then translate the data field?EDIT: Ah ok, its usingModBus RTUascii protocol, so I guess as long as my monitor can translate that, I am good right?Cheers

author: Psi
author_rank: Super Contributor
timestamp: August 21, 2019, 01:58:55 pm
content: You can tap into each of the 2 lines quite easy. Connect one of them to an RX pin on a RS232 serial port of your spying PC.Then run any of the many free terminal software programs to see the data. (Putty will work but there are better ones for this application)You will have to either measure the band rate or just take a few guesses until you find it.If you want to monitor both directions at once you will need two serial ports on the spying PC.If you want the data in each direction to be synced up in time you may need to find some serial port monitoring software which can monitor two ports at once.However usually the data on something like this is very simply so monitoring them one at a time is enough.Make sure your spying PC serial port matches the target. eg +/-12v RS232 vs 5V UART

author: MosherIV
author_rank: Super Contributor
timestamp: August 21, 2019, 06:36:16 pm
content: QuoteYes, that is correct, sort of.Now you have to understand the formating of the ascii message, we call this a message protocol.If you do not have any published information about the protocol, you can try to work out what it is.Start with a known condition, eg no weight on the scale.See if the same message is being sent.Now add say 100g and see what the message changes to.Keep doing this until you figure out what the format is.

author: SpannersToSparks
author_rank: Regular Contributor
timestamp: August 22, 2019, 08:12:02 am
content: Hi guysThanks for the responses. It appears the unit actually has a choice of outputs, so RS-485 with Modbus RTU is available. I see there is a C library available that can create RTU instanceshttps://libmodbus.org/docs/v3.1.6/as well as a lot of free and paid software.I should be able to find out the exact "flavour" of protocol if needed from the manufacturer. If using the free offerings or the library, would I still need to determine which version of the RTU protocol is being used and inform the software accordingly?I can also buy a version that hasanalog outputswhich are apparently popular in industry, but I want to avoid having to implement any further electronics to interpret it at the PC end, hence sticking with the serial. What are the benefits to using the analog over serial, if any? The application is hopper weighing.Thanks for your help, its really appreciated!

author: Psi
author_rank: Super Contributor
timestamp: August 22, 2019, 08:33:17 am
content: Quote from: SpannersToSparks on August 22, 2019, 08:12:02 amAnalog will be 4-20mA current output which is a standard for industrial signalling.Very common for inputs on PLC's.Because the signal is current it's more immune to voltage spikes that you might get in an industrial environment.Zero is 4mA so you can detect a fault compared to a signal that is just zero.It's good for long distance wire runs because current doesn't degrade over distance like voltage does.

author: SpannersToSparks
author_rank: Regular Contributor
timestamp: August 22, 2019, 08:50:29 am
content: Thanks PsiWould that need some additional electronics and code at the PC end to make sense of the voltages?

author: Psi
author_rank: Super Contributor
timestamp: August 22, 2019, 08:53:07 am
content: The RS232 is easier for you.RS485 would need a differential serial port or converter.4-20mA current loop will need an analog input of some sort.Im sure you can get USB -> 4-20mA current inputs modules.If you can do RS232, do that.

author: macboy
author_rank: Super Contributor
timestamp: August 23, 2019, 07:05:29 pm
content: Quote from: SpannersToSparks on August 21, 2019, 12:23:34 pmSoftware never sees the start and stop bits. They are used by UART hardware to provide framing for individual bytes.Software will see a byte stream. In most cases this is not continuous, but a burst of a few bytes each time that a device wants to send something (a weight reading in your case). You can find various serial port monitor programs that can watch the serial port for data, and display it in a semi-readable way. These programs often can split the output into separate lines when there is a gap in the data (gaps between packets/bursts). Most can display the data as ASCII text and/or as raw binary data. You will not know the format of the data your scale is sending until you look at it. It might just be ASCII data, or it could be a 16 (or more) bit integer number sent as a sequence of bytes, which could be MSB or LSB first.A packet may have a header to delimit it, or nothing. It may terminate with a specific character(s) such as CR/LF (hex 0x0D 0x0A), or nothing. There may be a checksum, which is an extra byte calculated from the other bytes to help ensure data integrity. Or not. Hopefully once you look at the data stream with a good serial port monitor you will be able to pick out the pattern easily enough.