LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Block by Block Binary Data Transfer

Hi..!!
 
 I have a file(dummy.dld) Which contains 275 kb of binary data. The following code transfers a file at a time..Let us assume that a block referes 1024 bytes..How can seprate the file as several block of data and send them one by one to the device...?..pls help me??
 
Thanx and Regards,
Venki.
 
 
#include <rs232.h>
#include <formatio.h>
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>
int main (int argc, char *argv[])
{
 int  fH = 0;
 int  i, br;
 unsigned char msg[256];
 //FILE *fH = NULL;
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1;    /* out of memory */
 
 
 OpenComConfig (4, "COM4", 38400, 0, 8, 1, 512, 512);
 fH = OpenFile ("dummy.dld", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
 
    printf("%d",fH);
 ComFromFile (4, fH, 0, -1);

 Delay (0.2);

 br = GetInQLen (4);
 DebugPrintf ("Bytes at port 4: %d\n", br);
 ComRd (4, msg, br);
 
 
 CloseCom (4);
 
 if (fH > -1) CloseFile(fH);
 return 0;
 
}
0 Kudos
Message 1 of 2
(2,864 Views)

You simply can read from the file in a buffer and send the buffer to the com port:

while ((br = ReadFile (fH, buffer, 1024)) > 0) {
    ComWrt (4, buffer, 1024);
}

This is the simplest way. Alternatively you can try iterating directly with ComFromFile in the hope that this function moves the file pointer as long as it reads the file content and sends it to the com port: I have never attempted to do this way so I cannot assure that it will work. In this option, you could also try moving the file pointer with SetFilePtr in case ComFromFile does not.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,860 Views)