Test and Measurement Forum

PSD binary file format

Forum for discussing PicoScope (version 5)

PSD binary file format

Postby gg20000 » Fri May 14, 2004 5:43 am

I used a ADC216 with the Picoscope s/w to record a signal @ max sampling freq - ie 333kS.s-1. I need to import ALL samples o fth etime history in a third party software in binary form. To do so, I ll need the exact format of the binary file .PSD created: number of bytes, format, structure, resolution, precision.
The help file is more than vague on that matter.
Pico Team early reply would be greatly appreciated !
\Jerome.
gg20000
 

Postby markspencer » Fri May 14, 2004 9:32 am

Hi,

Thank you for your post.

I have checked the help file and we believe that this may have gone out of date. I am going to have a look at this and will post my results. Unfortunately, this may take a few days to get a definitive answer.

Best regards,
Regards,

Mark Spencer
User avatar
markspencer
Site Admin
Site Admin
 
Posts: 598
Joined: Wed May 07, 2003 9:45 am

Postby markspencer » Tue May 25, 2004 3:20 pm

Hi,

This should help those who wish to get data out of a .psd file. It has been tested on a ADC212 range, but should work with out change with a ADC-216, and 200's.

The help manual states that the Times came first, where infact they are the last part.

Code: Select all
#include <windows.h>
#include <stdio.h>
#include <assert.h>

#define FILEPSD2 "test.psd" // name of file

// used to check that the .psd file has not been saved commpressed
#define COMPRESSED_FLAG 0x80000000UL

// PSD EOF marker
#define PS_EOF 10

// PSD header
typedef struct
{
   short owner;
    short section_type;
   short section_no;
   short no_of_parts;
} PSDHEADER;


void main(void)
{
   FILE *fp;
    PSDHEADER header;
   BOOL ok;
    HANDLE hFile;
   DWORD nb;
    DWORD length;
   short *channel1_adc, *channel2_adc;
   long *times;
   int part = 0;
   long no_of_samples, i;
   char single[200];
   int lth;
   short number_of_channels;

   no_of_samples = 0;

    hFile = CreateFile(FILEPSD2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);


   if (hFile == INVALID_HANDLE_VALUE)
      exit (0);

   number_of_channels = 1;

    ok = ReadFile(hFile, &header, sizeof(PSDHEADER), &nb, NULL);

   ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
    SetFilePointer (hFile, length, NULL, FILE_CURRENT);

    //enter a loop and keep going
   //until either PS_EOF is reached or some DATA is found.

    while (header.section_type != PS_EOF)
   {
    // read the header
      ok = ReadFile(hFile, &header, sizeof(PSDHEADER), &nb, NULL);

     // if the header is of type 1 or 2 get the data and times
     if(header.section_type == 1 || header.section_type == 2)
     {
        // Always Part1 read settings, and discard
         ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
          ReadFile(hFile, (BYTE *) &single, length, &nb, NULL);

        // Number of bytes making up part 2
        ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
       
        // check the file is not compressed.
          if(length & COMPRESSED_FLAG)
        {
           printf("The data is compressed");
           exit (0); 
        }
        else
        {
             channel1_adc = (short *) malloc (length);
             ok = ReadFile(hFile, channel1_adc, length, &nb, NULL);
        }

        // if you are using 2 channels on the ADC-2xx and ADC-100 units
        if(header.section_type == 2)
        {
         // number of channels used set to 2
         number_of_channels = 2;
         // read the number of bytes in part 3
            ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
          // check that the file is not compressed
            if(length & COMPRESSED_FLAG)
         {
           printf("The data is compressed");
           exit (0); 
         }
          else
         {
              channel2_adc = (short *) malloc (length);
              ok = ReadFile(hFile, channel2_adc, length, &nb, NULL);
         }
        }

         // if only one channels is used read the number of bytes in part 3
        // if 2 channels have been used then this will be part 4
        ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
         // check that the file is not compressed
          if(length & COMPRESSED_FLAG)
        {
           printf("The data is compressed");
           exit (0);
        }
        else
        {
            times = (long *) malloc (length);
         ok = ReadFile(hFile, times, length, &nb, NULL);
        no_of_samples = length / 4;
        }

     }
     else
     {
       // move the file pointer on the number of bytes, this is not needed.
         part = 0;
        if (times)
       {
          while (part < header.no_of_parts)
         {         
            ReadFile(hFile, &length, sizeof(DWORD), &nb, NULL);
             ok = SetFilePointer (hFile, length, NULL, FILE_CURRENT);
             part++;
         }
       }
     }
   }
   
   // write data in to the .txt file.
    if(no_of_samples > 0)
    {
      fp = fopen (FILETXT, "w");
      if (fp)
      {
         fprintf(fp, "Channel A\nTimes, ADC\n");
          for (i = 0; i < no_of_samples; i++)
         {
           fprintf(fp, "%ld, %d\n", times[i], channel1_adc[i]);
         }

         if(number_of_channels == 2)
         {
            fprintf(fp, "\nChannel B\nTimes, ADC\n");
             for (i = 0; i < no_of_samples; i++)
           {
              fprintf(fp, "%ld, %d\n", times[i], channel2_adc[i]);
           }
         }


         fclose(fp);
      }
    }

    free (times);

    free (channel1_adc);


   if (number_of_channels == 2)
   {
     free (channel2_adc);
   }

    CloseHandle(hFile);
}


Best regards,
Regards,

Mark Spencer
User avatar
markspencer
Site Admin
Site Admin
 
Posts: 598
Joined: Wed May 07, 2003 9:45 am


Return to PicoScope 5

Who is online

Users browsing this forum: No registered users and 0 guests