redirecting serial inputs to a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redirecting serial inputs to a file?
# 1  
Old 02-26-2006
redirecting serial inputs to a file?

i have an external device sending serial messages i want to connect this device to a serial port in my sun blade box and record those messages to a file, how can i read the serial port and write it to file?
Thanks
# 2  
Old 02-27-2006
I dont know if the following code will work, but since all devices are essentially files, maybe you could do this:
Code:
while read message; do
echo $message > /path/to/file_you_want
done < /dev/path_to_serial_device

# 3  
Old 02-27-2006
Not a whole lot of info here. Bear in mind that fibre channel and ethernet are serial too. We are moving towards a all-serial world. I guess we are talking about tty devices which are often labeled something like "Serial A" and "Serial B". If so, there could be some problems. Both the port and the device need to be configured to the same settings. To get started you will need to stuff like baud rate, character width, number of stop bits, and type of parity. You can depend on 1 stop bit being enough but everything else can vary. This is often expressed as something like "9600 8-1-none". You also need to know what kind of flow control the device supports and how fast it might send messages. And you need to know what format the messages are in. Are they binary data? Or are they 80 character lines of ascii data that could be typed at a keyboard?
# 4  
Old 02-27-2006
thanks all for your answer, i'll try it tomorrow.\
You're right Perderabo, i was talking about an RS232 connection. All the parameters you mention are configurables on the external device and i have all the infor to change it, right now it is (i think) "32000-8-n-1" and messages are 80 characters by line, but i don't know how to configure the serial port on the box. wich command should i use?
# 5  
Old 02-27-2006
You use the stty program to configure a port. The stty program operates on whatever tty is attached to fd 0. This enables stuff like:
stty -a < /dev/ttya > /some/data/file 2>&1
However, at close() time, the tty driver checks to see if any process still has the device file open. If not, the driver resets the port characteristics back to default. So the sequence:
stty -a < /dev/ttya
stty 38400 < /dev/ttya
stty -a < /dev/ttya
will show the port at 9600 before and after the stty command in the middle. This leads a lot of people to conclude that the middle stty command did not work. To fix this, open the tty and connect it to an unused fd early in the script. Like this:
exec 4</dev/ttya
this will keep the driver's close() routine from reseting the port.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting/Capturing inputs supplied in interactive script

Hello Is it possible to redirect standard input into a file in an interactive script like we do for standard out and input using &2 and &1. Enter source : hi Enter destination : bye In the log i can see like this when I am using script.sh 2>&1 | tee file Enter source : Enter... (3 Replies)
Discussion started by: ningy
3 Replies

2. Shell Programming and Scripting

Storing user inputs into a file

Hi, Am trying to store the user inputs into a file, but the below code will store only the first line of the values. I need to store all the user input values which may contain one or more lines. Thanks in advance. echo "please enter file names"; read name; echo $name>/tmp/test (11 Replies)
Discussion started by: rogerben
11 Replies

3. Shell Programming and Scripting

Take 10 user inputs and output to file?

I want a script that will prompt a user to enter 10 numbers and out put them into a file. This what I have so far, but isn't working. I'm guessing it's something easy I'm not seeing. Thanks for any help. #!/usr/bin/ksh echo "Enter 10 numbers" for i in 1 2 3 4 5 6 7 8 9 10 do read .... ... (8 Replies)
Discussion started by: AxlVanDamme
8 Replies

4. Shell Programming and Scripting

Scripting A Source File With User Inputs

I need to write what I thought would be a fairly simple 2-line UNIX script. It can be written PERL, csh, ksh...or whatever is easiest. The entire script will be: Begin Scipt source MySourceFile execute MyExecutable.exe End Script The problem is that MySourceFile can not be... (1 Reply)
Discussion started by: MMorrison
1 Replies

5. Shell Programming and Scripting

How to read inputs from a file

Hello; Please I need to read inputs from a file change 1 or 2 things the output to another file. (1 Reply)
Discussion started by: jimoney
1 Replies

6. UNIX for Dummies Questions & Answers

How to set the File Paths for Inputs and Outputs

I have couple of shell scripts. Each shell script accepts command line argument as inputfilename. Each shell script creates a summary file, status file. All these files are stored in a particular directory...Eg InputFile is to be picked from /home/ProjectName/ftp_inputfiles/ Outputs are to... (1 Reply)
Discussion started by: Amruta Pitkar
1 Replies

7. Shell Programming and Scripting

Checking the format of inputs in a file

Hi, I have a script that takes the contents of another file as inputs. Its assumed that there are 3 values in the input file that are seperated by '|'. I have to check in my script, whether the filed seperator used in the input file is '|' or not. If its not a '|' I have to print a error... (13 Replies)
Discussion started by: sendhilmani123
13 Replies

8. Shell Programming and Scripting

Validating inputs from a file

Hi, I have a file called inputs. Now that file has the values like this: 1 2 3 Now In my script called 'get.sh' I do this : exec < inputs read a b c d Now I know that there will not be any value in d. How can I check it. I need the exact condition for checking whether the variable has... (1 Reply)
Discussion started by: sendhilmani123
1 Replies

9. Shell Programming and Scripting

Inputs from a file

Hi, I have a shell script that has to taken inputs from a file say "Inputs". Now I take 2 inputs at a time. Suppose the Inputs file contains numbers like 2 3 4 5 Now I have a written a script for adding 2 numbers. When I run the script for first time 2 and 3 must be the inputs. When i run the... (4 Replies)
Discussion started by: sendhil
4 Replies

10. Shell Programming and Scripting

Reading in two inputs from a file

Hi all, I've been assigned the task of modifying a script which reads in names of tables from a list file, exports a 30 days worth of data from these tables, then deletes the table. The list file will now contain a table name and a number next to it indicating how many days to archive. I need... (1 Reply)
Discussion started by: MadHatter
1 Replies
Login or Register to Ask a Question