Benutzer-Werkzeuge

Webseiten-Werkzeuge

A PCRE internal error occured. This might be caused by a faulty plugin

serieller_port

====== serieller Port ====== ===== in der Shell ===== * [[http://lifeeditor.blogspot.com/2009/05/linux-rs232-programming.html]] * [[http://forums.fedoraforum.org/showthread.php%3Ft%3D176658]] * [[http://www.linuxforums.org/forum/programming-scripting/54611-serial-communications-rs-232-command-line.html]] ein Beispiel: #!/bin/sh exec 3 <> /dev/ttyS0 echo "Command 1" >&3 Lesen Reaktion <&3 echo "$response" >> /tmp/response.log exec 3>&- ===== Pascal ===== => ISBN 3-928051-42-3 ==== rechteckgenerator.pas ==== Program Rechteckgenerator; uses CRT; const BA = $3F8; var Zeit : Word; Taste : Char; procedure Generator (Schleifenzeit: Word); var N: Word; begin Port [BA+4] := 1; for N := 0 to Schleifenzeit do; Port [BA+4] := 0; for N := 0 to Schleifenzeit do; end; begin repeat write ('Schleifenzahl 0...65535 '); readln (Zeit); repeat Generator (Zeit); until KeyPressed; Taste := ReadKey; until Taste = chr(27); end. ==== schalterabfrage.pas ==== Program Schalterabfrage; uses CRT; const BA = $3F8; var Puffer: Array[1..2000] of Byte; n: Word; funktion CTS: Byte; begin CTS := (Port [BA+6] AND 16) div 16; end. begin Port [BA+4] := 2; ClrScr; repeat for n := 1 to 2000 do Puffer[n] := CTS; for n := 1 to 2000 do write (Puffer[n]); delay (1000); until KeyPressed; delay (2000) end. ===== C/C++ ===== * [[http://www.easysw.com/~mike/serial/serial.html]] * [[http://www.ontrak.net/linux.htm]] * [[http://www.linuxquestions.org/questions/programming-9/serial-port-programming-285597/]] * [[http://www.linuxquestions.org/questions/programming-9/linux-serial-port-programming-clash-224769/]] * [[http://www.linuxquestions.org/questions/linux-networking-3/programming-the-serial-port-111713/]] [[http://www.easysw.com/%7emike/serial/serial.html#2_5]]: #include <stdio.h> /* Standard input/output definitions */ #include <string.h> /* String function definitions */ #include <unistd.h> /* UNIX standard function definitions */ #include <fcntl.h> /* File control definitions */ #include <errno.h> /* Error number definitions */ #include <termios.h> /* POSIX terminal control definitions */ /* * 'open_port()' - Open serial port 1. * * Returns the file descriptor on success or -1 on error. */ int open_port(void) { int fd; /* File descriptor for the port */ // seriellen USB-Port öffnen fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { /* * Could not open the port. */ perror("open_port: Unable to open /dev/ttyS0 - "); } else fcntl(fd, F_SETFL, 0); return (fd); } // Daten in den seriellen USB-Port schreiben n = write(fd, "ATZ\r", 4); if (n < 0) fputs("write() of 4 bytes failed!\n", stderr); // Daten aus dem seriellen USB-Port lesen fcntl(fd, F_SETFL, FNDELAY); // // The FNDELAY option causes the read function to return 0 // if no characters are available on the port. // To restore normal (blocking) behavior, // call fcntl() without the FNDELAY option: //fcntl(fd, F_SETFL, 0); // seriellen USB-Port schließen close(fd); Konfiguration des seriellen Ports -> //No parity (8N1)//: options.c_cflag &= ~PARENB options.c_cflag &= ~CSTOPB options.c_cflag &= ~CSIZE; options.c_cflag |= CS8;

serieller_port.txt · Zuletzt geändert: 2016/04/13 00:50 (Externe Bearbeitung)