Example

Top  Previous  Next

#define CHANNEL    5 // using channel 5

#define OpenFile  11 // handler-specific

#define CloseFile 12 // handler-specific

 

int ReadFile(SC6xSmtI *I, char *name) {

   int i, n, Max;

   struct {

      int Code;

      int Arg;

      char Name[256];

   } P;

   P->Code = 0;                    // unused

   P->Arg  = 0;                    // unused

   strcpy(P->Name, "HscFile.dll"); // handler name

   HscPutArgs(I, CHANNEL, sizeof(P), &P);

   n = Smt_HscControl(I, CHANNEL, OpenHandler, 0);

   if (n < 0return n;           // no handler

 

   P->Code = 1;                   // Open for input

   P->Arg  = 0;                   // unused

   strcpy(P->Name, name);         // Filename

   HscPutArgs(I, CHANNEL, sizeof(P), &P);

   n = Smt_HscControl(I, CHANNEL, OpenFile, 4096); // 4KB buffer

   if (n > 0) {

      for (i=0; i<4; i++) {       // try to read 4 x 128 bytes

         n = HscRead(I, CHANNEL, 128, Buffer);

         if (n==0break;

         YourProcess(n, Buffer);  // do something with the data

      }

      Smt_HscControl(I, CHANNEL, CloseFile, 0); // Close

   }

   Smt_HscControl(I, CHANNEL, CloseHandler, 0);

   return n;

}

 

This would result in the following transactions on channel 5, assuming the file, test.dat, contains 70 words:

 


Host


DSP


 

OpenHandler


OK

 


 

OpenFile,  "test.dat", Data=4096


OK, Data=4096

 


 

HscRead, Data=128


OK, Data=128

 


 

HscRead, Data=128


OK, Data=128

 


 

HscRead, Data=128


OK, Data=24

 


 

HscRead, Data=128


OK, Data=0

 


 

CloseFile


OK

 


 

CloseHandler


OK