FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 08-30-2011, 01:08 PM
Martin McCormick
 
Default String Manipulation and a Need for RS-232

I have used GCC C for years to write a number of
programs for work and play and it is great but I think I am
needing to branch out a bit as my latest project is causing me
fits.

I have a scanner radio receiver that uses RS-232 to
communicate with the computer and I got that part of things to
work well. Here's the problem. The radio receives commands via
CSV strings as in sin,abc,def,1,7,8,etc,etc
and its output is
also CSV as in sin,err
or sin,lot,of,variables,to,read

I also got that working such that it could read the
response and break out all the CSV variables in to separate
strings. In other words, it does work and with gdb, one can
trouble-shoot it fairly easily.

I have this nagging feeling, though, that there may be a
better way to write this program since C is not as good at
string manipulation as some other languages. In my program, you
have to do a lot of grunt work just to be sure that the 15TH
field really is the 15TH field in the string one is sending out.

In the standard set of tools that are free and found on
most Unix systems, which language such as perl, python, etc can
handle rS-232 gracefully and do strings without having to
reen vent the wheel?

I had this epiphany after spending most of last weekend
and early this morning digging through this program I had
written only to find that the reason things weren't working was
that it appears that I sent out a CSV string with some of the
variables shifted by a couple of spaces. I can easily fix that,
but it got me to thinking.

If I can do all of this within one language, including
the RS-232 coms, that will be great.

Thanks for any suggestions.

Martin McCormick WB5AGZ Stillwater, OK


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201108301308.p7UD8pTl087328@x.it.okstate.edu">http ://lists.debian.org/201108301308.p7UD8pTl087328@x.it.okstate.edu
 
Old 08-30-2011, 01:27 PM
Axel Freyn
 
Default String Manipulation and a Need for RS-232

Hi Martin,
On Tue, Aug 30, 2011 at 08:08:51AM -0500, Martin McCormick wrote:
> [...]
> In the standard set of tools that are free and found on
> most Unix systems, which language such as perl, python, etc can
> handle rS-232 gracefully and do strings without having to
> reen vent the wheel?
> [...]

I would give python a try, maybe together with the pySerial-module from
http://pyserial.sourceforge.net/
While pyserial simplifies the access to rs232 and cares about all platform
dependence, it's not really standard I think.

If your program shall work on all Unix systems and installing pySerial (or
distributing it together with your code) is not an option, you can open the port
directly in python too -- but then of course you have to care more about error
debugging e.g.

HTH,

Axel


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20110830132725.GL2125@axel">http://lists.debian.org/20110830132725.GL2125@axel
 
Old 08-30-2011, 01:58 PM
Martin McCormick
 
Default String Manipulation and a Need for RS-232

Axel Freyn writes:
> I would give python a try, maybe together with the pySerial-module from
> http://pyserial.sourceforge.net/
> While pyserial simplifies the access to rs232 and cares about all platform
> dependence, it's not really standard I think.
>
> If your program shall work on all Unix systems and installing pySerial (or
> distributing it together with your code) is not an option, you can open
> the port
> directly in python too -- but then of course you have to care more about
> error
> debugging e.g.

Thank you. I looked briefly at python some time ago for
something else and liked what I saw so I will give it another
try for this project. The serial communications are not terribly
complex, but they are at 57600 baud or more so all the low-level
timing has to work or one gets absolutely nothing but garbage
and flaky performance.

Again, thanks for your response.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201108301358.p7UDwe2k087834@x.it.okstate.edu">http ://lists.debian.org/201108301358.p7UDwe2k087834@x.it.okstate.edu
 
Old 08-30-2011, 02:25 PM
Hugo Vanwoerkom
 
Default String Manipulation and a Need for RS-232

Martin McCormick wrote:

I have used GCC C for years to write a number of
programs for work and play and it is great but I think I am
needing to branch out a bit as my latest project is causing me
fits.

I have a scanner radio receiver that uses RS-232 to
communicate with the computer and I got that part of things to
work well. Here's the problem. The radio receives commands via
CSV strings as in sin,abc,def,1,7,8,etc,etc
and its output is
also CSV as in sin,err
or sin,lot,of,variables,to,read

I also got that working such that it could read the
response and break out all the CSV variables in to separate
strings. In other words, it does work and with gdb, one can
trouble-shoot it fairly easily.

I have this nagging feeling, though, that there may be a
better way to write this program since C is not as good at
string manipulation as some other languages. In my program, you
have to do a lot of grunt work just to be sure that the 15TH
field really is the 15TH field in the string one is sending out.

In the standard set of tools that are free and found on
most Unix systems, which language such as perl, python, etc can
handle rS-232 gracefully and do strings without having to
reen vent the wheel?

I had this epiphany after spending most of last weekend
and early this morning digging through this program I had
written only to find that the reason things weren't working was
that it appears that I sent out a CSV string with some of the
variables shifted by a couple of spaces. I can easily fix that,
but it got me to thinking.

If I can do all of this within one language, including
the RS-232 coms, that will be great.



If I were in your situation, I would convert your C programs to C++
(changing <prog>.c to <prog>.cpp) and use Qt. I use it many places just
for its string manipulation and Qt has great documentation.


Just install libqt4-dev, qt4-dev-tools, qt4-qmake and qt4-doc.

Create a <prog>.pro file for your <prog>.cpp and run 'qmake -o Makefile
<prog>.pro' and then 'make' and away you go.


Hugo

















--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: j3irt1$37d$1@dough.gmane.org">http://lists.debian.org/j3irt1$37d$1@dough.gmane.org
 
Old 08-30-2011, 02:47 PM
Martin McCormick
 
Default String Manipulation and a Need for RS-232

Hugo Vanwoerkom writes:
> If I were in your situation, I would convert your C programs to C++
> (changing <prog>.c to <prog>.cpp) and use Qt. I use it many places just
> for
> its string manipulation and Qt has great documentation.
>
>
> Just install libqt4-dev, qt4-dev-tools, qt4-qmake and qt4-doc.
>
>
> Create a <prog>.pro file for your <prog>.cpp and run 'qmake -o Makefile
> <prog>.pro' and then 'make' and away you go.

I can see the good thing about that is that the parts
that work can stay which is a good thing. I did get the serial
communications working the way they need to for this application
and the parser that indexes data received from the radio also
works correctly so this is sort of a glass 3/4 full.

Thank you.

Martin


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201108301447.p7UEliN4088281@x.it.okstate.edu">http ://lists.debian.org/201108301447.p7UEliN4088281@x.it.okstate.edu
 
Old 08-30-2011, 04:40 PM
Hartwig Atrops
 
Default String Manipulation and a Need for RS-232

Hi.

> I have this nagging feeling, though, that there may be a
> better way to write this program since C is not as good at
> string manipulation as some other languages. In my program, you
> have to do a lot of grunt work just to be sure that the 15TH
> field really is the 15TH field in the string one is sending out.

Why not use regular expressions? It's included in the GNU C lib. Not as nice
as in Perl, but it works:

#include <regex.h>

Regards,

Hartwig



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201108301840.18535.Hartwig.Atrops@arcor.de">http://lists.debian.org/201108301840.18535.Hartwig.Atrops@arcor.de
 
Old 08-30-2011, 05:18 PM
Ivan Shmakov
 
Default String Manipulation and a Need for RS-232

>>>>> Martin McCormick <martin@x.it.okstate.edu> writes:

[…]

> I also got that working such that it could read the response and
> break out all the CSV variables in to separate strings. In other
> words, it does work and with gdb, one can trouble-shoot it fairly
> easily.

[…]

> In the standard set of tools that are free and found on most Unix
> systems, which language such as perl, python, etc can handle rS-232
> gracefully and do strings without having to reen vent the wheel?

[…]

> If I can do all of this within one language, including the RS-232
> coms, that will be great.

In Unix-like systems, including GNU/Linux, there isn't really
any difference between using a regular file, pipe, virtual
terminal, or a serial port. Most of the time, one just does it,
and it works.

E. g., if I'd have to read a line from COM1, I could do it
easily in, say, Bash:

$ read x < /dev/ttyS0
$ printf %s
"$x"
Hello, world!
$

(Assuming there's some device attached that sends “Hello,
world!” just at the right moment.)

There're a few things that may require explicit attention.
First of all, I'm almost certain that it will be necessary to
set the serial port to a particular mode (like: bit rate,
bitness, parity.) I guess that many languages have support for
it (including a wrapper for the ioctl(2) system call, which, I
guess, you're familiar with.)

However, it's not /necessary/ to set the serial port's mode in
your own program. Instead, you may set it with stty(1), once,
and then just run the program. It's almost exactly what happens
if you'll use a “classic” serial terminal, or a modem and a
machine running a terminal emulator.

Second, the device may be using a newline sequence different to
that of the system, and it may be a bit tricky to set up the
language chosen to interpret it properly.

Also, it will really be nice to implement serial device locking
(I'm familiar with the UUCP locking scheme, but I vaguely recall
that it was to be deprecated; hopefully no misunderstanding on
my part.) That way, only one of the programs trying to
simultaneously use the port will succeed, while the others will
fail with a nice error message.

That being said, my personal preference for that kind of task
would be Perl. I guess that the points above could be resolved
by searching the CPAN archives [1].

[1] http://search.cpan.org/

PS. I'm still interested in serial ports, partly due to having a live
UUCP link, and partly due to having some interest in embedded
systems' development, so I guess I'd be able to answer a few
more questions on them in this list (though it's a bit OT.)

--
FSF associate member #7257 Coming soon: Software Freedom Day
http://mail.sf-day.org/lists/listinfo/ planning-ru (ru), sfd-discuss (en)


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 86fwkies34.fsf@gray.siamics.net">http://lists.debian.org/86fwkies34.fsf@gray.siamics.net
 
Old 08-31-2011, 12:51 AM
David Christensen
 
Default String Manipulation and a Need for RS-232

On 08/30/2011 06:08 AM, Martin McCormick wrote:

In the standard set of tools that are free and found on
most Unix systems, which language such as perl, python, etc can
handle rS-232 gracefully and do strings without having to
reen vent the wheel?


I've used Perl and Win32::SerialPort to do instrumentation and control
on Windows via RS-232 and RS-485. For Linux, try Device::SerialPort:


http://search.cpan.org/~cook/Device-SerialPort-1.04/SerialPort.pm


HTH,

David


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: 4E5D8583.3000507@holgerdanske.com">http://lists.debian.org/4E5D8583.3000507@holgerdanske.com
 

Thread Tools




All times are GMT. The time now is 10:03 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org