Титла: Kak da otvorq Comm Port
Публикувано от: sgeorgiev в Jan 31, 2009, 17:31
Zdraveite.
Vyprosa mi e kak se otvarqt Comm portove pod Linux. Ima li programa v linux podobna na Hiperterminala pod Windows.
Ima li fail v /dev s koito moga da rabotq.
Molq ako razpolagate s nqkoq statiq ili drugi materiali svyrzani s nachina na upotreba na Comm pod Linux daite link.
Blagodarq vi predvaritelno,
Титла: Re: Kak da otvorq Comm Port
Публикувано от: tarator в Jan 31, 2009, 18:29
COM1 е /dev/ttyS0. Ако използваш някакъв USB конвертор /dev/ttyUSB0.
Аз използвам minicom, може би има по-добри програми, но с тази съм свикнал.
Титла: Re: Kak da otvorq Comm Port
Публикувано от: Slevin_ в Jan 31, 2009, 22:34
tarator ти е отогворил. Аз също ползвам minicom. Ако държиш на GUI, то потърси cutecom.
Титла: Re: Kak da otvorq Comm Port
Публикувано от: sgeorgiev в Feb 05, 2009, 11:42
Blagodarq vi za informaciqta.
Opitah da napisha sobstvena programka koqto da otvarq comm kato file, no ne uspah da namerq nachin da setna BITS PER SEC i stop bita.
Molq ako razpolagate s nqkoi tutorial ili drugi materiali kak stava pishte.
Титла: Re: Kak da otvorq Comm Port
Публикувано от: BULFON в Feb 05, 2009, 12:11
http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html GeSHi (C): /* * example.c: very simple example of port I/O * * This code does nothing useful, just a port write, a pause, * and a port read. Compile with `gcc -O2 -o example example.c', * and run as root with `./example'. */ #include <stdio.h> #include <unistd.h> #include <asm/io.h> #define BASEPORT 0x378 /* lp1 */ int main() { /* Get access to the ports */ if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);} /* Set the data signals (D0-7) of the port to all low (0) */ outb(0, BASEPORT); /* Sleep for a while (100 ms) */ usleep(100000); /* Read from the status port (BASE+1) and display the result */ printf("status: %d\n", inb (BASEPORT + 1)); /* We don't need the ports anymore */ if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);} exit(0); } /* end of example.c */
Последно, но не на последно място: http://www.google.bg/search?q=linux+com+port+c+program&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Титла: Re: Kak da otvorq Comm Port
Публикувано от: sgeorgiev в Feb 06, 2009, 08:25
Blagodarq vi za linkovete. Programata se poluchi mnogo oprostena. #include <stdio.h> #include <sys/types.h> #include <fcntl.h> #include <termios.h> #include <string.h>
void sendCommand(int fd, char *command, char *result, int size) { int i = 0; memset(result, 0, size); write(fd, command, strlen(command)); char p; char c; do { p = c; c = '\0'; int res = read(fd, &c, 1); if(res > 0) { result[i] = c; i++; } }while(p != 'K'); }
int main() { long BAUD = B4800; // derived baud rate from command line long DATABITS = CS8; long STOPBITS = 0; long PARITYON = 00; long PARITY = 00;
struct termios newtio; int fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK); if(fd < 0)printf("Error!!!\n");
fcntl(fd, F_SETOWN, getpid());
newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; newtio.c_lflag = 0; //ICANON; newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=1; tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio);
char result[128]; int i; for(i=0; i<20; i++) { sendCommand(fd, "AON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "BON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "CON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "DON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "EON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "FON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "GON\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "STATE\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "AOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "BOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "COFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "DOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "EOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "FOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "GOFF\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "STATE\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "AIN\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "DIN\r", result, sizeof(result)); printf("RESULT: %s\n", result); sendCommand(fd, "ERROR\r", result, sizeof(result)); printf("RESULT: %s\n", result); } return 0; }
Publicuvam coda ako nqkoi drug se sblyska s takyv problem nadqvam se da mu pomogne.
|