--- /dev/null
+#include "lptgpib.h"
+#include <stdio.h>
+#include <string.h>
+#include <poll.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/io.h>
+
+// lptgpib.c
+#define get_control() (inb(lpt_base+2) ^ 0x04)
+#define put_control(x) outb((x) ^ 0x04, lpt_base+2)
+#define TRI 0x20 /* tristate data lines */
+#define NDAC 0x04 /* LPT pin 16 */
+#define DAV 0x01 /* LPT pin 1 */
+
+extern int lpt_base;
+
+int main(int argc,char **argv) {
+ lptgpib_init(0x378);
+ for (;;) {
+ put_control(TRI | NDAC); /* clear NRFD */
+ if (get_control()&DAV) { /* wait for DAV */
+ fprintf(stderr,"ctu znak...\n");
+ char flags,val=lptgpib_read_byte(&flags);
+ if (flags&ATN)
+ lptgpib_print_command(val);
+ else
+ fprintf(stderr,"precten znak: %02x (%c)\n",val,val);
+ }
+ struct pollfd pollfd;
+ memset(&pollfd,0,sizeof pollfd);
+ pollfd.fd=0;
+ pollfd.events=POLLIN;
+ int i=poll(&pollfd,1,0);
+ assert(i==0||i==1);
+ if (i==1) {
+ char val;
+ i=read(0,&val,1);
+ assert(i==1);
+ fprintf(stderr,"zapisuji znak... %02x (%c)\n",val,val);
+ lptgpib_write_byte(val,0);
+ fprintf(stderr,"zapsan znak.\n");
+ }
+ }
+}