help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Octave, C++, mkoctfile// matrix handling


From: muellerp11811
Subject: Octave, C++, mkoctfile// matrix handling
Date: Wed, 16 May 2007 01:47:46 -0700 (PDT)

Hi All,

I' m using a C++ file -> compiled into an *.oct file to download trace data
from a spectrum analyzer in binary (Real32) format.  I can store the data
into one buffer at my C++ file  but I can not transfer the buffer content
into octave.

Can anybody help me about this please?

The attached C++ file gives only on value (point10) out to octave. But I
need all 501 trace points:

Octave listing (usage):

defaultRM=VISAsesnopen;
instr=VISAopen(defaultRM,'GPIB0::20::INSTR');
...

[data, length, status]=VISAreadB(instr);
....


C++ File listing (VISAreadB.cc):

#include <octave/oct.h>

#include <stdio.h>
#include <stdlib.h>
#include "visa.h"

#define MAX_CNT 131072


DEFUN_DLD (VISAreadB, args, ,
  "vi = VISAreadB()\n\
\n\
Reads binary data from a device.")
{
        /*program variable*/
        ViSession               instr;
        ViStatus                status                   =0;
        ViUInt32               retCount               =0;
        int                        nargin                    = args.length ();
        int                             i                        =0;

        ViChar                  sBuffer[80]             ={0};
        
    int lNumberPoints   = 0;
    int lNumberBytes    = 0;
   ViReal32 adTraceArray[MAX_CNT]  ={0};        //max of 2x8192 trace points
times 4 bytes per bucket for PSA
                                                                          //max 
of 2002trace points for FSP30
  

    // get arguments 
        instr   = args(0).scalar_value(); //Octave

        
        /* get number of bytes in length of postceeding trace data
           and put this in sBuffer*/
        viRead (instr,(ViPBuf)sBuffer,2,&retCount); 

        
        /* Put the trace data into sBuffer */
        viRead (instr,(ViBuf)sBuffer,sBuffer[1] - '0',&retCount);
        
        /* append a null to sBuffer */
        sBuffer[retCount] = 0;          

        /* convert sBuffer from ASCII to integer */
        lNumberBytes = atoi(sBuffer);   

        /* calculate the number of points given the number of byte in the trace
           REAL 32 binary format means each number is represented by 4 bytes*/
        lNumberPoints = lNumberBytes/sizeof(ViReal32);


        /*get and save trace in data array */
        if (MAX_CNT>lNumberBytes)
        {
                status=viRead 
(instr,(ViPBuf)adTraceArray,lNumberBytes,&retCount);
                if(status != VI_SUCCESS_MAX_CNT)
                {
                        printf("Warning:viRead failed.\n");
                }
                else
                {
                        status=0;
                }
        }
        else
        {
                printf("Warning:Allocated Output buffer to small.\n");
                adTraceArray[0]=0;
        }
        
        
        /* read the terminator character and discard */
        viRead (instr,(ViPBuf)sBuffer,1, &retCount);  

        // The list of values to return.
        octave_value_list retval;

        retval(0)       = octave_value(adTraceArray[10]);
        retval(1)       = octave_value(lNumberPoints);
        retval(2)       = octave_value(retCount);

        return retval;
}
-- 
View this message in context: 
http://www.nabble.com/Octave%2C-C%2B%2B%2C-mkoctfile---matrix-handling-tf3763356.html#a10638026
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]