Results 1 to 10 of 21
Hi All,
Does somebody has a simple program that read data from a serial port(ttys0). I use a small Suse server which is connected from a rs232 (ttys0) to a ...
- 02-09-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Read data from a serial port
Hi All,
Does somebody has a simple program that read data from a serial port(ttys0). I use a small Suse server which is connected from a rs232 (ttys0) to a alarm central. I need to store this data to a file. Many thanks for your help.
- 02-09-2008 #2
I've written a small program which reads and writes on the serial port. It does this over the modem, but you don't need that part. You will continue to need the parts that set the baud rate and such. Use your man pages to explain any function calls with which you're not familiar or which you might need to change (such as the baud rate).
You can download the C source for that program here. I will keep that program there for at least two weeks.
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 02-09-2008 #3
There is also a program called minicom which I've used in the past.
Linux since: 2001
Gentoo since: 2004
- - - - - - - -
Translation:
I fix things until they break.
- 02-09-2008 #4
Yes, minicom has great code examples. In the comments in the program I referenced earlier in this thread, I have a commentary on how minicom does its stuff, based in minicom's source code.
--
Bill
Old age and treachery will overcome youth and skill.
- 02-10-2008 #5Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Hi, many thanks for your help. I am not an expert in programming and I don't understand this error :
# cc modemsyntime.c
modemsyntime.c: In function ‘wb_string_produce’:
modemsyntime.c:1888: error: invalid lvalue in increment.
Thanks for your help !
- 02-10-2008 #6That's bizarre. I downloaded the source from the web page just now, compiled it with the same command you show, and got no error.modemsyntime.c: In function ‘wb_string_produce’:
modemsyntime.c:1888: error: invalid lvalue in increment.
What happens when you paste this script into the same directory that contains your copy of modemsynctime.c, and then run that script? What exact output do you get?
Code:#!/bin/sh cat > mst_short.c <<EOD #include <sys/ioctl.h> #include <sys/select.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h> #include <time.h> #include <unistd.h> typedef struct { size_t wb_length; size_t wb_occupied; size_t wb_next_produce_index; size_t wb_next_consume_index; unsigned char *wb_buffer; } write_buffer_t, *write_buffer_p; void wb_produce(write_buffer_p the_write_buffer, unsigned char the_data ); void wb_string_produce(write_buffer_p the_write_buffer, char *the_string ); /*--------------------------------------------------------------------------*/ void wb_produce(write_buffer_p the_write_buffer, unsigned char the_data ) { if(the_write_buffer->wb_occupied>=the_write_buffer->wb_length) { fprintf(stderr, "attempt to produce a byte to a full write buffer\r\n" ); exit(1); } the_write_buffer->wb_occupied++; the_write_buffer->wb_buffer[the_write_buffer->wb_next_produce_index]=the_data; the_write_buffer->wb_next_produce_index = (the_write_buffer->wb_next_produce_index+1)%the_write_buffer->wb_length; } /* wb_produce() */ /*--------------------------------------------------------------------------*/ void wb_string_produce(write_buffer_p the_write_buffer, char *the_string ) { while(*the_string) { wb_produce(the_write_buffer, *((unsigned char *)the_string)++ ); } } /* wb_string_produce() */ int main(void) { return 0; } /* main() */ EOD md5sum modemsynctime.c mst_short.c cc mst_short.c--
Bill
Old age and treachery will overcome youth and skill.
- 02-10-2008 #7Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Here is the output !
# ./test.sh
35365b06287ace06294e1a765312d96c modemsynctime.c
b90eaf8daf3d5fa8f8db05b7556568c1 mst_short.c
mst_short.c: In function ‘wb_string_produce’:
mst_short.c:72: error: invalid lvalue in increment
- 02-10-2008 #8Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Here is the new output after removing blank line at the end of modemsynctime.c.
# ./test.sh
6a259bb9dc305821af8e0789fe10ff8a modemsynctime.c
b90eaf8daf3d5fa8f8db05b7556568c1 mst_short.c
mst_short.c: In function ‘wb_string_produce’:
mst_short.c:72: error: invalid lvalue in increment
- 02-10-2008 #9
Someone else please help!
With that script, I was attempting to see whether you were compiling exactly what's on the web page, and also whether a short narrowing down of the problem produced the same error message.
The answer to the first question is "no", but we don't need to worry about that right now, because the problem is reproducible with the very short program this script compiled.
I took out the md5sum command and tried the script not only on my Linux system, but also on a BSD system (at shell.panix.com).
Would someone else out there please run the following shell script and see whether an error is produced? I can't get it to produce an error, try as I might.
Code:#!/bin/sh cat > mst_short.c <<EOD #include <sys/ioctl.h> #include <sys/select.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h> #include <time.h> #include <unistd.h> typedef struct { size_t wb_length; size_t wb_occupied; size_t wb_next_produce_index; size_t wb_next_consume_index; unsigned char *wb_buffer; } write_buffer_t, *write_buffer_p; void wb_produce(write_buffer_p the_write_buffer, unsigned char the_data ); void wb_string_produce(write_buffer_p the_write_buffer, char *the_string ); /*--------------------------------------------------------------------------*/ void wb_produce(write_buffer_p the_write_buffer, unsigned char the_data ) { if(the_write_buffer->wb_occupied>=the_write_buffer->wb_length) { fprintf(stderr, "attempt to produce a byte to a full write buffer\r\n" ); exit(1); } the_write_buffer->wb_occupied++; the_write_buffer->wb_buffer[the_write_buffer->wb_next_produce_index]=the_data; the_write_buffer->wb_next_produce_index = (the_write_buffer->wb_next_produce_index+1)%the_write_buffer->wb_length; } /* wb_produce() */ /*--------------------------------------------------------------------------*/ void wb_string_produce(write_buffer_p the_write_buffer, char *the_string ) { while(*the_string) { wb_produce(the_write_buffer, *((unsigned char *)the_string)++ ); } } /* wb_string_produce() */ int main(void) { return 0; } /* main() */ EOD cc mst_short.c--
Bill
Old age and treachery will overcome youth and skill.
- 02-10-2008 #10
I ran the script, and got the same error. I then removed the cast and re-compiled, and it worked.
So somehow, that cast is messing me up.
For what it's worth:
What I think may be happening is that you are telling it that the_string is of a different type, then trying to increment that. Which is to say, that line is equivalent to:Code:alex@danu ~ $ gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --disable-multilib --enable-libmudflap --disable-libssp --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu Thread model: posix gcc version 4.1.2 (Gentoo 4.1.2)
And perhaps it is saying that you cannot cast an lvalue?Code:(unsigned char *) the_string = ((unsigned char *) the_string) + 1
It's interesting that it does work for you, though.DISTRO=Arch
Registered Linux User #388732


Reply With Quote