Sponsored Content
Top Forums Programming Problem with read data from serial device Post 302398760 by Corona688 on Thursday 25th of February 2010 01:20:30 PM
Old 02-25-2010
Why are you null-terminating the buffer after you print it? You're closing the barn, but the horse's already left.

Never call printf from a signal handler. fprintf(stderr, "stuff"); might work since that's unbuffered but even that is not guaranteed. Use write(), along with sprintf if necessary.

Are you sure the device uses hardware flow control?

wait_flag should be volatile.

If your goal is to just wait for I/O, you don't need to use SIGIO, you can just configure your terminal to make you wait when you do a read(). This would be better IMHO, since under some circumstances signals can be missed. You could also use select().

code tags for code please. [ code ] my fancy program [ /code ] but without the spaces in the tags. This will show your code with proper indenting.

Last edited by Corona688; 02-25-2010 at 02:27 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

serial port device path

hi. Im trying to install a switch. And the manual says i should type a command including a SerialPortDevicePath. which is the filepath to serial port used for connection. However.. nothing about how to find this info. Could anyone help me where to find this path? thx mr.T (6 Replies)
Discussion started by: tyskertøs
6 Replies

2. Programming

Accessing device with Prolific USB-serial controller.

I am trying to access DG-100 gps logger on Mac OS X with POSIX API. The device uses a Prolific usb-serial controller, and connect to the usb port on my mac. After I install the Prolific driver, it shows up as /dev/tty.usbserial and /dev/cu.usbserial. The vendor has published the data format. So... (1 Reply)
Discussion started by: monkeybiz
1 Replies

3. Linux

Device serial number

Hey! I'm trying to figure out a sollution for a problem I have at my company with an Iomega MiniMax 500 GB USB disk. If i run cat /proc/bus/usb/devices I get this information: T: Bus=01 Lev=02 Prnt=04 Port=00 Cnt=01 Dev#= 5 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00... (2 Replies)
Discussion started by: noratx
2 Replies

4. Ubuntu

Ubuntu 9.04 Serial application to telnet to serial device

Hello! I am working on an application which reads environmental instruments which have serial ports. The application requires a serial port to be present to talk to the device (i.e. /dev/ttyS0 ). In some instances the environmental devices will be 100's of yards away from the computer, so a... (5 Replies)
Discussion started by: mvona
5 Replies

5. Shell Programming and Scripting

problem to read data in array

My input is a long list of data start with "#": #read_1 123456898787987 #read_2 54645646540646406 #read_3 4654564654316 . . I got a bit confusing about how to set all in an array first. And then when I run a program name "statistic_program", it will read the array in scalar and do... (24 Replies)
Discussion started by: patrick87
24 Replies

6. AIX

Tape drive problem - no process to read data written to a pipe

Hi Everyone, The machine I'm working on is an AIX 5.3 LPAR running on a P650. oslevel -r shows 5300-08. I'm trying to take a backup to a SCSI tape drive, which has been working up until this point. I know of nothing that has changed recently to cause this problem. But when I try to take a... (0 Replies)
Discussion started by: need2bageek
0 Replies

7. SCO

Modifying serial printers device

I am trying to change one of my serial printers from /dev/ttyr002 to /dev/ttyr014: lpstat -s device for check3: /dev/ttyr002 device for check4: /dev/ttyr002 I changed the tty setting for check3 in: /etc/printcap /var/spool/lp/admins/lp/printers/check3 to /dev/ttyr014 Then I get:... (4 Replies)
Discussion started by: herot
4 Replies

8. Programming

Wrong data with Read from a serial port.

hi, I've a problem on my C/C++ program with Posix Library. I have to read data from the serial but I have incorrect data, in fact I get a bunch of zeros: "2953.3174, 2785.2126, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0 , 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ,... (24 Replies)
Discussion started by: enaud
24 Replies

9. Programming

Read from serial port

Hi I try to communicate with a GSM modem, from C, for sending SMS. I use standart AT-commands. Working well with terminal. There is no problem writing ti the port. But when I try to read I only get a echo, I write "ATI" and get "ATI" back, I should get somthing like "SIEMENS 35... (4 Replies)
Discussion started by: dmiller
4 Replies

10. Shell Programming and Scripting

Read line from serial device with BASH

I'm new to Linux (Ubuntu 16.04), and very new to BASH scripting. I have a Numato 8-channel USB GPIO device, which is a DAQ that appears in the system as a serial port. In Linux it appears as ttyACM0. I can easily manipulate a GPO with, for example: echo "gpio set 7" > /dev/ttyACM0 ...followed... (12 Replies)
Discussion started by: Chalk-X
12 Replies
signal(3UCB)					     SunOS/BSD Compatibility Library Functions					      signal(3UCB)

NAME
signal - simplified software signal facilities SYNOPSIS
/usr/ucb/cc [ flag ... ] file ... #include <signal.h> void (*signal(sig, func))() int sig; void (*func)(); DESCRIPTION
signal() is a simplified interface to the more general sigvec(3UCB) facility. Programs that use signal() in preference to sigvec() are more likely to be portable to all systems. A signal is generated by some abnormal event, initiated by a user at a terminal (quit, interrupt, stop), by a program error (bus error, etc.), by request of another program (kill), or when a process is stopped because it wishes to access its control terminal while in the background (see termio(7I)). Signals are optionally generated when a process resumes after being stopped, when the status of child pro- cesses changes, or when input is ready at the control terminal. Most signals cause termination of the receiving process if no action is taken; some signals instead cause the process receiving them to be stopped, or are simply discarded if the process has not requested other- wise. Except for the SIGKILL and SIGSTOP signals, the signal() call allows signals either to be ignored or to interrupt to a specified location. See sigvec(3UCB) for a complete list of the signals. If func is SIG_DFL, the default action for signal sig is reinstated; this default is termination (with a core image for starred signals) except for signals marked with o or a dagger.. Signals marked with o are discarded if the action is SIG_DFL; signals marked with a dagger cause the process to stop. If func is SIG_IGN the signal is subsequently ignored and pending instances of the signal are discarded. Other- wise, when the signal occurs further occurrences of the signal are automatically blocked and func is called. A return from the function unblocks the handled signal and continues the process at the point it was interrupted. If a caught signal occurs during certain functions, terminating the call prematurely, the call is automatically restarted. In particular this can occur during a read(2) or write(2) on a slow device (such as a terminal; but not a file) and during a wait(3C). The value of signal() is the previous (or initial) value of func for the particular signal. After a fork(2) or vfork(2) the child inherits all signals. An exec(2) resets all caught signals to the default action; ignored signals remain ignored. RETURN VALUES
The previous action is returned on a successful call. Otherwise,-1 is returned and errno is set to indicate the error. ERRORS
signal() will fail and no action will take place if the following occurs: EINVAL sig is not a valid signal number, or is SIGKILL or SIGSTOP. SEE ALSO
cc(1B), kill(1), exec(2), fcntl(2), fork(2), getitimer(2), getrlimit(2), kill(2), read(2), sigaction(2), write(2), abort(3C), ptrace(3C), setjmp(3C), setjmp(3UCB), sigblock(3UCB), signal(3C), signal.h(3HEAD), sigstack(3UCB), sigvec(3UCB), wait(3C), wait(3UCB), termio(7I) NOTES
Use of these interfaces should be restricted to only applications written on BSD platforms. Use of these interfaces with any of the system libraries or in multi-threaded applications is unsupported. The handler routine func can be declared: void handler(signum) int signum; Here signum is the signal number. See sigvec(3UCB) for more information. SunOS 5.11 30 Oct 2007 signal(3UCB)
All times are GMT -4. The time now is 10:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy