Re: [EXTERNAL] Re: GPIB as a pure slave

dave penkler <[email protected]> Mon, 16 Jan 2023 14:01:54 +0100
Newsgroups gmane.linux.hardware.gpib.general
Message-ID <CAL=kjP19ojha6r9u_jSCqwm0FxK-fJvwOh5WTOiNN3JcHiONXg@mail.gmail.com>
Hi Stefan,
It looks like in your case the slave board was already addressed as a
listener before you started slave_test which is why you got the timeout.
Here is a new version that deals with this case. It loops until it reads a
string when addressed as a listener and then writes back that string when
addressed as talker. If the read times out it prints "read timeout" and
goes back to the loop.
On the master side once a string has been written the response must be read
before writing another. Are you using ibterm on the master or something
else ?

$ ./slave_test2
read timeout
read timeout
Got hello
Got bye
Got quit
slave done
$

cheers,
-Dave

On Sun, 15 Jan 2023 at 09:46, Stefan Olejnik <[email protected]>
wrote:

>  Hi, Dave
>
> Thanks a lot for Your effort.
>
> I have tested Your program, but it is almost the same as I have used. The
> result are as follows:
>
> root@imx8mm-var-dart:/home/stefan/bin#
> root@imx8mm-var-dart:/home/stefan/bin# ./slave_test
> [  124.896503] tnt4882: minor 0 read timed out
> [  124.900712] tnt4882: read timed out
> Got hello
> [  127.968496] tnt4882: write timed out
> error: ibwrt fail
>  - EABO 6: Operation aborted
> root@imx8mm-var-dart:/home/stefan/bin# ./slave_test
> [  187.105354] tnt4882: minor 0 read timed out
> [  187.109563] tnt4882: read timed out
> Got *IDN?
>
> [  190.177371] tnt4882: write timed out
> error: ibwrt fail
>  - EABO 6: Operation aborted
> root@imx8mm-var-dart:/home/stefan/bin#
>
> READING:
>
> Interesting is that during "ibrd" even read timeout is coming from
> TNT4882, the data are read OK. I am using reading per char,  till END or
> END-OF-STRING => "\n"  and I am getting no time-out during reading.
>
> WRITTING:
>
> First "ibwrt" is always time-outed, the second also, but data are
> delivered, as I am already described. Therefore I am using short TIMO (
> e.g. 10ms ) for ibwrt, and on the receiver device is TIMO set to 3s, and I
> am getting the data. Of course from second "ibwrt".
>
> Stefan.
>
>
>

_______________________________________________
Linux-gpib-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-gpib-general
slave_test2.c (text/x-csrc, 1.4 KB)
/* Slave aka device mode programme
 * Reads a string when addressed to listen
 * and writes it back when addressed to talk
 * until it reads a string="quit"
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef unsigned char uint8_t;
#include <gpib/gpib_user.h>
#include <gpib/ib.h>

int cb=0;   /* minor of slave board */

static void myError(char * mess) {
  int erc = ThreadIberr();
  fprintf(stderr,"error: %s\n", mess);
  fprintf(stderr," - %s\n", gpib_error_string(erc));
  if (erc == 0) fprintf(stderr," system error: %s\n",strerror(ThreadIbcnt()));
  exit(1);
}

int main() {
  uint8_t buf[256],mbuf[512];
  int len=0,n,run=1;
  int status;
  int ev_mask=TIMO | LACS;
  if (ibconfig(cb,IbcTMO,T3s) & ERR) myError("ibconf fail TMO");
  if (ibeot(cb,1) & ERR) myError("ibeot fail");
  while (run) {
    status = ibwait(cb,ev_mask);
    if (status & ev_mask  & LACS) {
      status = ibrd(cb,buf,256);
      if (status & ERR) {
	if (status & TIMO) {
	  fprintf(stderr,"read timeout\n");
	  continue;
	} else myError("ibrd fail");
      }
      len = ThreadIbcnt();
      buf[len] = 0;
      printf("Got %s\n",buf);
      if (strcmp(buf,"quit")==0) run = 0;
      ev_mask = TIMO | TACS;
    } else  if (status & ev_mask & TACS) {
      n = sprintf(mbuf,"Reply: %s",buf);
      if (ibwrt(cb,mbuf,n) & ERR) myError("ibwrt fail");
      ev_mask = TIMO | LACS;
    }
  }
  fprintf(stderr,"slave done\n");
  exit(0);
}