LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2010, 05:14 PM   #1
ergit
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
Question script for serial comunnication: ok with cutecom but no answer from command line


Hi all,
I have been trying to communicate with a device (vaisala hmt330) by rs232. Every thing goes fine if I use cutecom. However, I am using the unit along with other instruments, and I wanted a single program that could read the data from the separate instruments and write it all to a single data file.

I tried to write a script to accomplish the job but I'm unable to send data to the device. I can read from it but I can't make it stop sending data in order to ear commands.

This script works fine for reading the data:
#/bin/bash
stty -F /dev/ttyUSB0 19200 -cstopb cs8 -parenb -crtscts -ixon -ixoff
while true
do
cat /dev/ttyUSB0
done

But I can't find the way to make the HMT330 listen to the serial port. If I do this:
echo ANYCOMMAND\r >/dev/ttyUSB0
the HMT330 just ignores the command and remains sending data.

From vaisala the info for user is:
Bauds 19200
Parity No
Data bits 8
Stop bits 1
Flow control None

Any suggestions?
Is there any way in which I can "see" what commands cutecom is sending?
Maybe I just missing some very simple issue but I can't figure out what it can be :-(

Thank you very much for your time. I will be very grateful for any help ;-)
Ergit
 
Old 03-21-2010, 11:28 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Not sure if this helps but I found the Device::Modem module works well if you use perl...

cheers
 
Old 03-22-2010, 02:53 AM   #3
ergit
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Humm... Yes! Perl should have been my solution but I don't know Perl and I was trying to avoid learn it, as this serial communication should be a simple thing to do. Ironically this idea was to save me time.
 
Old 03-22-2010, 03:11 AM   #4
ergit
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Good morning all,
actually I had a development today! If I connect serial cable, then run the script and only then power-up
the instrument, in this situation I get a prompt from the device.

HMT330 / 4.05
>

New problem: in this prompt I was supposed to type commands and hit ENTER.
But when I do this, the cursor just goes to the next line and the command is
not executed.
I assume this is a problem with recognition of the "end of line" or "carriage
return"... so I tried the usual shell non printing characters:
R\n
R\r
But still don't works :-(
Any suggestions would be appreciated.Thanks,
 
Old 03-22-2010, 08:54 AM   #5
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
If you don't have any luck, there's a script here called mpi (functional but alpha), even without knowing perl you should be able to hack it about and make it do what you want

cheers
 
Old 03-22-2010, 04:26 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
What commands are you using to send data to the device? Using the echo command with the -e option will enable the standard sequences. See echo man pages for more info.
echo -e "r\n" > /dev/ttyS0

I prefer using some higher level language for serial communications then a shell script.
 
1 members found this post helpful.
Old 03-24-2010, 11:22 AM   #7
ergit
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up problem solved

Thank you very very much michaelk ;-)
echo -e solved my problem!

In case this could be useful to someone I'm posting the script that I'm using with a VAISALA HMT330 humidity and temperature meter.

#/bin/bash
stty -F /dev/ttyUSB0 19200 -cstopb cs8 -parenb -crtscts -ixon -ixoff onlcr
echo "Power-up the Vaisala HMT330 [ENTER]:"
read
echo -e "S\r\n" > /dev/ttyUSB0
echo -e "DATE\r\n" > /dev/ttyUSB0
echo "Enter new date [yyyy-mm-dd]:"
read "data"
echo -e "$data\r\n" > /dev/ttyUSB0
echo -e "TIME\r\n" > /dev/ttyUSB0
echo "Enter time [hh:mm:ss]:"
read "time"
echo -e "$time\r\n" > /dev/ttyUSB0
echo "Enter file name [*.txt]:"
read "nome"
echo -e "R\r\n" > /dev/ttyUSB0
while true
do
cat /dev/ttyUSB0 > $nome
done

I'm using the "Service Port Connection" and it is in RUN-mode.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to go to the command line in OpenBSD intermentals *BSD 1 01-28-2010 10:58 AM
please help with command line or script thtr2k Linux - Software 2 03-04-2007 01:03 PM
change serial port IO addresses by command line powah Linux - Hardware 1 08-01-2006 07:55 AM
Help with cutecom serial/USB converter required alex.pujols Linux - Newbie 0 09-13-2005 11:32 PM
Installing a serial modem from command line harperonline Solaris / OpenSolaris 2 06-27-2005 07:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration