Re: GPIB as a pure slave

dave penkler <[email protected]> Fri, 13 Jan 2023 13:50:54 +0100
Newsgroups gmane.linux.hardware.gpib.general
Message-ID <CAL=kjP3GPFa8z_wNWhF5v3S+Te_Yem4c65WRxLh3e6C9SEqT5g@mail.gmail.com>
Hi Stefan,
Attached is a little programme slave_test to demonstrate pure slave aka
device mode.
It uses minor 0 in board mode.
On the slave side run slave_test and on the master ibterm.

On the slave side:







*$ cc -o slave_test slave_test.c -lgpib$ ./slave_test Got helloGot byeGot
quitslave done$ *

On the master side:












*$ ibterm -d 1Attempting to open /dev/gpib0pad = 1, sad = 0, timeout = 10,
send_eoi = 1, eos_mode = 0x0000ibterm>helloReply: helloibterm>byeReply:
byeibterm>quitibterm><CTRL-D>ibterm: Done.$ *

On Tue, 10 Jan 2023 at 17:11, Olejnik, Stefan <[email protected]>
wrote:

> I have the troubles with GPIB interface - National Instruments PCIe-GPIB.
> Kernel driver TNT4882. Configuration is as a pure slave - just listen and
> answer:
> interface {
>         minor = 0       /* board index, minor = 0 uses /dev/gpib0, minor =
> 1 uses /dev/gpib1, etc. */
>         board_type = "ni_pci"
>         name = "violet" /* optional name, allows you to get a board
> descriptor using ibfind() */
>         pad = 1 /* primary address of interface             */
>         sad = 0 /* secondary address of interface           */
>         timeout = T10s  /* timeout for commands */
>
>         eos = 0x0a      /* EOS Byte, 0xa is newline and 0xd is carriage
> return */
>         set-reos = no   /* Terminate read if EOS */
>         set-bin = no    /* Compare EOS 8-bit */
>         set-xeos = no   /* Assert EOI whenever EOS byte is sent */
>         set-eot = yes   /* Assert EOI with last byte on writes */
>
>         master = no     /* interface board is system controller */
> }
>
> When I am using "ibtest" then write command returns TIMO:
> : w
> enter a string to send to your device: testString
> sending string: testString
>
> [  200.928468] tnt4882: write timed out
> gpib status is:
> ibsta = 0xc100  < ERR TIMO CMPL >
> iberr= 6
> EABO 6: Operation aborted
>
> I have created test SW and find out, that if I am using "ibwrta/ibwait"
> command twice, second try is always successful. First returns TIMO.
> Reading is OK.
>
> On the other side is NI PC as a CIC.
>
> Thanks for any help....
>
> ------------------------------
>
> Please be advised that this email may contain confidential information. If
> you are not the intended recipient, please notify us by email by replying
> to the sender and delete this message.
> _______________________________________________
> Linux-gpib-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/linux-gpib-general
>

_______________________________________________
Linux-gpib-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-gpib-general
slave_test.c (text/x-csrc, 1.3 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 & LACS) {
      if (ibrd(cb,buf,256) & ERR) 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);
}