From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Almacenar datos después de realizar una operación viRead/ Storing data after make an viRead operation

 Hola, estoy realizando un programa en Visual Studio (lenguaje c) el cual, tras una operación de lectura, almacena en una estructura los datos del dispositivo con los que se conecta, es decir, su ID y el descriptor del instrumento. No obstante, tras realizar la operación viFindNext, y comunicarse con el siguiente dispositivo, el descriptor del anterior instrumento guardado en las estructura de datos, cambia automáticamente por este. Ocurre lo mismo para el ID en el buffer de lectura, es decir, tras recibir el ID de otro instrumento, cambia el anterior que tenia guardado. Finalmente, se almacena el ultimo instrumento, quedando repetido tanto el descriptor, como el ID dos veces(dos instrumentos leidos). Les dejo el código por aquí. Muchas gracias!!!

 

Hi, i`m making an Visual Studio program(C language), whom, after make an read operation, storing the data of the device what is conected in a structure, that is, descriptor and ID. However,  after making an viFindNext operation, and conected with following device, the descriptor of the before instrument, store in the data structure, autamatically change for this new. Occur the same for the ID in the read buffer, that is, after receive the new ID of the device, chage the ID of the first device store. Finally, store the descriptor and the ID of the last device, remain this repeated in two places. I put the code here. Thank you very much!!!!

 

 

Nota: son dos dispositivos conectados por 2 cables de pares. El equipo detecta cuatro dispositivos en total.

Note: there are two device pair wired conected, so the computer detected four devices 

 

#include<visa.h>
#include<string.h>
#include<stdio.h>

 

#define TAMA 200

 

typedef struct
{
   char caracter; 
   ViBuf ID;
   ViBuf Descrtiptor;

}IV;

 

typedef IV Equipo[2];


void inicializa(ViBuf* buffer);
void almacena(Equipo* equipo, char caracter, ViBuf descriptor, ViBuf ID);
void InicioComunicaciones(ViBuf buffer);

 


int main()
{

  ViBuf buffer[TAMA];

   

   inicializa(&buffer);
   InicioComunicaciones(buffer);

 

   return 0;
}

 

void inicializa(ViBuf* buffer)
{
     for (unsigned i = 0; i < TAMA; i++)
     {
      buffer[i] = ' ';
     }


}

 

void almacena(Equipo* equipo, char caracter, ViBuf descriptor, ViBuf ID)
{
    if (caracter == 'B')
    {
       equipo[0]->caracter = caracter;
       equipo[0]->Descrtiptor = descriptor;
       equipo[0]->ID = ID;

    }
   else
    {
       equipo[1]->caracter = caracter;
       equipo[1]->Descrtiptor = descriptor;
       equipo[1]->ID = ID;

    }

 

 }

 

 void InicioComunicaciones(ViBuf buffer)
 {

    ViSession manejador_sesion, manejador_recursos;
    ViFindList lista;
    ViInt32 num, retcnt;
    ViChar Descriptor[TAMA];
    int contador = 0;

    Equipo equipo;

 

    if (viOpenDefaultRM(&manejador_sesion) != VI_SUCCESS)
    {

        printf("ERROR DE INICIO DE SESION \n");
    }


   if (viFindRsrc(manejador_sesion, "?*INSTR", &lista, &num, Descriptor) != VI_SUCCESS)
   {
       printf("No se han encontrado dispositivos\n");

   }
   else
  {

 

    while (contador !=num)
    {

 

      if (viOpen(manejador_sesion, Descriptor, VI_NULL, VI_NULL, &manejador_recursos) != VI_SUCCESS)
       {

       printf("ERROR DE APERTURA \n");

       }
       else
      {

 

          viWrite(manejador_recursos, "*IDN?\n", 6, &retcnt);


          viRead(manejador_recursos, buffer, TAMA, &retcnt);

 
          char *p=strstr(buffer,"\n");
          *p = '\0';

           char caracter = (char)(contador + 65);

           

        printf("%c.%s [%s]\n",caracter,(ViBuf)Descriptor,buffer);

        almacena(equipo, caracter, (ViBuf) Descriptor, buffer);

               if (contador == 3)
               {


                  printf("caracter[0] %c \n", equipo[0].caracter);
                  printf("descriptor[0] %s \n", equipo[0].Descrtiptor);
                  printf("ID[0] %s \n", equipo[0].ID);

                  printf("caracter[1] %c \n", equipo[1].caracter);
                  printf("descriptor[1] %s \n", equipo[1].Descrtiptor);
                  printf("ID[1] %s \n", equipo[1].ID);
                }

        }

 

 contador++;

 

    if (viFindNext(lista, Descriptor) != VI_SUCCESS)
    {

    printf("ERROR \n");

   }
}

 

    viClose(manejador_recursos);

  }

 

viClose(manejador_sesion);

}

 

 

 

0 Kudos
Message 1 of 2
(790 Views)

Hello,

 

Is this anyhow related to NI?

__________________________________________
The best way to thank, is to give KUDOS
0 Kudos
Message 2 of 2
(653 Views)