ultipos
Posts: 3
Joined: Fri Jun 17, 2016 2:59 pm

Stripping out RS232 ASCII Characters

Fri Jun 17, 2016 3:20 pm

Hi
We are look for some entrepreneurial expert who may already have done what I am looking for.
We want to strip unwanted characters from a RS-232 serial string.

We have a RS-232 device that outputs a serial stream containing 'standard, readable ASCI characters found on a keyboard and also formatting characters such as ↓- ♫☼ etc. We are wanting to strip out rranges of ASCII characters and output only 'readable' characters such as found on a standard keyboard.

We want to use a Raspberry Pi to do this job.

Has someone done this or does someone feel energetic enough to discuss taking this on as a project?

One step further, we may take this project to the next level by taking the RS-232 input, stripping out the unwanted ASCII characters and then presenting it on an ethernet port for transmission to a remote host.

Thanks in advance!

Clive

edge0f17
Posts: 17
Joined: Sun Oct 25, 2015 6:55 am

Re: Stripping out RS232 ASCII Characters

Fri Jun 17, 2016 4:58 pm

Linux already does this: http://linux.die.net/man/1/strings

strings -n 1 </dev/ttyama0

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Stripping out RS232 ASCII Characters

Fri Jun 17, 2016 5:15 pm

It's a trivial task. Any local club will be able to write something to do this in half an hour - all you need to do is specify which characters are to be passed and which are to be deleted. The Linux tr command (man tr) will do this from the command line.

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: Stripping out RS232 ASCII Characters

Fri Jun 17, 2016 7:56 pm

You don't specify what character encoding is being used - if it's UTF-8 (where bytes with the high bit clear map directly into ASCII characters, and all non-ASCII characters are composed of bytes with the high bit set - this makes decoding unambiguous), and if the data is coming in from a typical serial-to-USB converter cable, then the task could be as simple as this Python script:

Code: Select all

#!/usr/bin/env python3

import serial                                  # Pull in the serial library

ser = serial.Serial('/dev/ttyUSB0', 57600)     # Open port - adjust as needed
while True:                                    # Loop forever
    bytestring = ser.read()                    # Read one byte from port
    byte = bytestring[0]                       # Get value of first (only) byte
    if byte >= ord(' ') and byte <= ord('~'):  # Handle only printable ASCII
        character = chr(byte)                  # Convert to string for printing
        print(character)                       # Print ASCII character found

rotwang
Posts: 243
Joined: Sat Dec 07, 2013 1:12 pm

Re: Stripping out RS232 ASCII Characters

Sat Jun 18, 2016 11:30 am

ultipos wrote:Hi
We are look for some entrepreneurial expert who may already have done what I am looking for.
We want to strip unwanted characters from a RS-232 serial string.

We have a RS-232 device that outputs a serial stream containing 'standard, readable ASCI characters found on a keyboard and also formatting characters such as ↓- ♫☼ etc. We are wanting to strip out rranges of ASCII characters and output only 'readable' characters such as found on a standard keyboard.

We want to use a Raspberry Pi to do this job.

Has someone done this or does someone feel energetic enough to discuss taking this on as a project?

One step further, we may take this project to the next level by taking the RS-232 input, stripping out the unwanted ASCII characters and then presenting it on an ethernet port for transmission to a remote host.

Thanks in advance!

Clive
try the manual pages, "man tr" will start you off right. No python needed.

ultipos
Posts: 3
Joined: Fri Jun 17, 2016 2:59 pm

Re: Stripping out RS232 ASCII Characters

Sat Jun 18, 2016 12:46 pm

Thanks to you all for the responses.
From my side I wanted to establish whether the concept would be executable in real life.
From the sounds of it, it appears that we are not wanting to tackle the impossible.
However, with no personal experience in development with the Pi (we only use them as pre-purchased and configured devices), we are in unfamiliar territory.

Hence the reason for trying to find out if anyone has done something like this.

We'll probably look for a programmer that can give us an estimate on getting the job done.

But thanks very much for your input!

Clive

Slackware
Posts: 131
Joined: Mon Jan 18, 2016 3:45 pm

Re: Stripping out RS232 ASCII Characters

Sun Jun 26, 2016 1:29 pm

A simple piping script would take serial in, and output everything a-z or whatever you want to your program that wants it. That is what makes unix's so nice, you can filter before and after with a simple '|' pipe, and "<>"redirection.

ultipos
Posts: 3
Joined: Fri Jun 17, 2016 2:59 pm

Re: Stripping out RS232 ASCII Characters

Sun Jun 26, 2016 1:45 pm

Appreciate the replies.
Yippo - the console command in Unix is (was to me) really great.
Sometimes I hanker back to the days gone by when we used to work with SCO Unix.
(you probably have to be an old timer to remember it :D

Still clearly remember as a newbie having root privileges and managed to kill the kernel and brought a business' entire system down... Working through the night to fix it taught me never to do that again.

And IBMs AIX and UCSD Pascal...and then OOP took over.....

Anyway - as I said - we are subcontracting the project out as it is not as simple as I indicated and we will get someone to build three different systems to accomplish what we want.

Return to “General discussion”