delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2014/05/07/10:50:21

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
Date: Wed, 7 May 2014 10:34:04 -0400 (EDT)
From: Jude DaShiell <jdashiel AT shellworld DOT net>
To: djgpp AT delorie DOT com
Subject: Re: djgpp_terminal
In-Reply-To: <lkd82j$1g2q$1@adenine.netfront.net>
Message-ID: <alpine.BSF.2.01.1405071031340.80857@freire1.furyyjbeyq.arg>
References: <lkd82j$1g2q$1 AT adenine DOT netfront DOT net>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Please check and be sure you have all of djgpp installed then see if 
usleep is defined.  You may not have a full djgpp installation on your 
machine and that can cause these kind of errors.

On Wed, 7 May 2014, david wrote:

> I would ask about GPIB terminal in DJGPP ....
> 
> usleep is not defined, so poll function is Linux tooo
> 
> #include "lptgpib.h"
> #include <stdio.h>
> #include <string.h>
> #include <X11/Xpoll.h>
> #include <X11/Xos_r.h>
> #include <X11/Xlibint.h>
> #include <unistd.h>
> #include <assert.h>
> #include <sys/io.h>
> #include <limits.h>
> #include <pthread.h>
> #include <pc.h>
> 
> static const int zdroj_adresa=10;
> 
> // lptgpib.c
> #define get_control() (inportb(lpt_base+2) ^ 0x04)
> #define put_control(x) outportb(lpt_base+2, (x) ^ 0x04)
> #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) {
>   lptgpib_init(0x378);
>   int init=1;
>   for (;;) {
> 
>     // GPIB -> obrazovka
>     if (init) {
>       fprintf(stderr,"Inicializuji port... ");
>       lptgpib_command(UNL);
>       lptgpib_command(MLA+0);
>       lptgpib_command(MTA+zdroj_adresa);
>       fprintf(stderr,"hotovo.\n");
>       init=0;
>     }
>     put_control(TRI | NDAC);    /* clear NRFD */
>     usleep(1000000/10);
>     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);
>     }
>     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;
>       fprintf(stderr,"zapisuji radek: %s\n",str);
>       lptgpib_write(zdroj_adresa,str);
>       fprintf(stderr,"zapsan radek.\n");
>       init=1;
>     }
> 
>   }
> }
> 
> I tried with timeout >>
> 
> #include "lptgpib.h"
> #include <stdio.h>
> #include <time.h>
> #include <string.h>
> #include <unistd.h>
> #include <assert.h>
> #include <sys/io.h>
> #include <sys/types.h>
> #include <x11/Xpoll.h>
> #include <limits.h>
> #include <pc.h>
> 
> static const int zdroj_adresa=1;
> 
> // lptgpib.c
> #define get_control() (inportb(lpt_base+2) ^ 0x04)
> #define put_control(x) outportb(lpt_base+2, (x) ^ 0x04)
> #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) {
>   lptgpib_init(0x378);
>   int init=1;
>   for (;;) {
> 
>     // GPIB -> obrazovka
>     if (init)
>       fprintf(stderr,"Inicializuji port... ");
>     lptgpib_command(UNL);
>     lptgpib_command(MLA+0);
>     lptgpib_command(MTA+zdroj_adresa);
>     if (init)
>       fprintf(stderr,"hotovo.\n");
>     init=0;
>     put_control(TRI | NDAC);    /* clear NRFD */
>     usleep(1000000/10);
>     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);
>     }
>     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 timeval *timeout;
>     memset(&read_fds,0,sizeof read_fds);
>     FD_ZERO(&read_fds);
>     FD_SET(0, &read_fds);
> 
>     timeout.tv_sec = 0;
>     timeout.tv_usec = 0;
>     int i=select(1,&read_fds,NULL,NULL,&timeout);
>     assert(i==0||i==1);
>     if (i==1) {
>       char str[1000],*s=fgets(str,sizeof(str),stdin);
>       assert(s==str);
>       s=strchr(str,'\n');
>       assert(s);
>       assert(s[1]==0);
>       *s=0;
>       fprintf(stderr,"zapisuji radek: %s\n",str);
>       lptgpib_write(zdroj_adresa,str);
>       fprintf(stderr,"zapsan radek.\n");
>     }
> 
>   }
> }
> 
> is There some way to write correct terminal, read,write function in DJGPP??
> Thanks for any idea
> 
> David
> 
> 
> 
> --- news://freenews.netfront.net/ - complaints: news AT netfront DOT net ---
> 
> 

jude <jdashiel AT shellworld DOT net>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019