#include "lptgpib.h" #include #include #include #include #include #include #include static const int zdroj_adresa=20; // 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 */ #define NRFD 0x02 /* LPT pin 14 */ extern int lpt_base; int main(int argc,char **argv) { setbuf(stdout,NULL); lptgpib_init(0x378); int init=1; for (;;) { // GPIB -> obrazovka if (init) { lptgpib_command(UNL); lptgpib_command(MLA+0); lptgpib_command(MTA+zdroj_adresa); init=0; } put_control(TRI | NDAC); /* clear NRFD */ usleep(1000000/10); if (get_control()&DAV) { /* wait for DAV */ char flags,val=lptgpib_read_byte(&flags); if (!(flags&ATN)) putchar(val); } put_control(TRI | NDAC | NRFD ); /* back to default state */ usleep(1000000/10); /* chvili pockat, asi zbytecne, jen aby to bylo videt na portu */ // klavesnice -> GPIB 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 str[LINE_MAX],*s=fgets(str,sizeof(str),stdin); assert(s==str); s=strchr(str,'\n'); assert(s); assert(s[1]==0); *s=0; lptgpib_write(zdroj_adresa,str); init=1; } } }