Author Topic: Interpreting the data from RS232?  (Read 1469 times)

0 Members and 1 Guest are viewing this topic.

Offline SpannersToSparksTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: gb
Interpreting the data from RS232?
« on: August 21, 2019, 12:23:34 pm »
Hi

I 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 using ModBus RTU ascii protocol, so I guess as long as my monitor can translate that, I am good right?

Cheers
« Last Edit: August 21, 2019, 01:04:13 pm by SpannersToSparks »
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: Interpreting the data from RS232?
« Reply #1 on: August 21, 2019, 01:58:55 pm »
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

Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline MosherIV

  • Super Contributor
  • ***
  • Posts: 1530
  • Country: gb
Re: Interpreting the data from RS232?
« Reply #2 on: August 21, 2019, 06:36:16 pm »
Quote
Ah ok, its using ascii protocol, so I guess as long as my monitor can translate that, I am good right?
Yes, 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.
 

Offline SpannersToSparksTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: gb
Re: Interpreting the data from RS232?
« Reply #3 on: August 22, 2019, 08:12:02 am »
Hi guys

Thanks 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 instances https://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 has analog outputs which 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!
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: Interpreting the data from RS232?
« Reply #4 on: August 22, 2019, 08:33:17 am »
Hi guys

Thanks 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 instances https://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 has analog outputs which 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!

Analog 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.
« Last Edit: August 22, 2019, 08:38:32 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline SpannersToSparksTopic starter

  • Regular Contributor
  • *
  • Posts: 85
  • Country: gb
Re: Interpreting the data from RS232?
« Reply #5 on: August 22, 2019, 08:50:29 am »
Thanks Psi

Would that need some additional electronics and code at the PC end to make sense of the voltages?
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: Interpreting the data from RS232?
« Reply #6 on: August 22, 2019, 08:53:07 am »
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.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2309
  • Country: ca
Re: Interpreting the data from RS232?
« Reply #7 on: August 23, 2019, 07:05:29 pm »
Hi

I 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 using ModBus RTU ascii protocol, so I guess as long as my monitor can translate that, I am good right?

Cheers
Software 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf