This is the mail archive of the cygwin mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi guys I'm working on a little c program to receive and save strings from the serial-port into a local file on a Windows XP/2003 Server machine. The program is working very well on a linux machine but if I try to run it under windows I just get stupid characters like: 0x11 â 0x6 â 0x7 0x1f â 0x7f â what I really wanted to get is this: 0x2 â 0x4a J 0x55 U 0x53 S 0x54 T 0x49 I 0x4e N 0x20 0x54 T 0x49 I 0x4d M 0x42 B 0x45 E 0x52 R 0x4c L 0x41 A 0x4b K 0x45 E 0x20 0x2f / 0x20 0x52 R 0x6f o 0x63 c 0x6b k 0x20 0x79 y 0x6f o 0x75 u 0x72 r 0x20 0x62 b 0x6f o 0x64 d 0x79 y 0x3 â but I only get the right chars when I open a windows Hyperterminal and close it before I start my program. After a week of searching around the internet you are my last hope. the rs232.c file Is my program-code: and cygcheck.out is the output of "cygcheck -s -v -r" thank you for help moe
Attachment:
cygcheck.out
Description: Text document
// transportation of the playing Title of the "digitalen Campusradio bit eXpress" to the Internet #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> #include <unistd.h> #include <time.h> // modem #define MODEMDEVICE "com2" //#define MODEMDEVICE "/dev/ttyS0" // output-files #define PLAY "aktuell.txt" #define HISTORY "older.txt" int main() { // global variables int fd, result, start, pos; FILE *fd2, *fd3; char str[2], title[200]; struct termios termios_p; time_t t; struct tm tm; // Modem fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) {printf("could not open serialport"); return -1;}; fcntl(fd, F_SETFL, 0); //get the current options tcgetattr(fd, &termios_p); cfsetispeed(&termios_p, B9600); cfsetospeed(&termios_p, B9600); termios_p.c_cflag |= (CLOCAL | CREAD); termios_p.c_cflag &= ~PARENB; // parity no termios_p.c_cflag &= ~CSTOPB; // stop bit 1 termios_p.c_cflag &= ~CSIZE; // Mask the character size bits termios_p.c_cflag |= CS8; // Select 8 data bits termios_p.c_cflag &= ~CRTSCTS; // disable hardware flow control termios_p.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // RAW Input termios_p.c_oflag &= ~OPOST; // RAW output //set the options tcsetattr(fd, TCSANOW, &termios_p); tcflush(fd,TCIOFLUSH); start = 0; pos = 0; while(1) { result = read(fd, str, 1); if(result != -1) { printf("0x%x %c\n", str[0], str[0]); if(str[0] == 0x02) {start = 1; pos = 0;} else if (str[0] == 0x03) {start = 0; title[pos] = '\0'; // write to file fd2 (now playing title) fd2 = fopen(PLAY, "w"); if (fd2 < 0) {printf("error open file %d\n"), PLAY; return -1;} fprintf(fd2, "%s", &title[2]); fclose(fd2); // write to file fd3 (history file) fd3 = fopen(HISTORY, "a"); if (fd3 < 0) {printf("error open file %d\n"), HISTORY; return -1;} time(&t); localtime_r(&t, &tm); fprintf(fd3, "%d-%02d-%02d %02d:%02d:%02d %s\n", 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, &title[2]); fclose(fd3); } else {if (start = 1) {title[pos++] = str[0];}} } } }
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |