LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

send file to serial port using comfromfile

Hi,

 

I am current working on a project with requires to transfer a bin file to the controller, if the file is valid i will get the correct respose.

if we send a file in hyperterminal using send text file option i am getting response from the controlller as file valid.

I want to send a file through the code i used comfromfile function i am getting invalid file reponse from the controller even i tried byte by byte with comwrtbyte also i received the same invalid response..

I cross checked the rs232 configuraiton of both hyperterimal and my code..both are same..even i checked with port sniffer tool to capture the port data..both are same.

I am not able to find what is the issues with my code. what is the differece in the Hypertemail and CVI functions..

 

Regards
Vikram Kumar P

0 Kudos
Message 1 of 24
(5,873 Views)

Hi,

 

Can you send your code so that we can take a look at it ?

 

0 Kudos
Message 2 of 24
(5,863 Views)

Please find the part of code i have given only the transfter bin file part below 

 

int QuickLoadBinFIle(char *binFilePath)
{
 
 char *tempData = NULL;
 
 int i = 0;
 ssize_t binFileSize;
 ssize_t binDataRead = 0;
 FILE *binFileHandle;
 
 
 binFileHandle = fopen (binFilePath, "rb");
 if(binFileHandle != NULL)
 {
  GetFileSize (binFilePath, &binFileSize);
  serialData = calloc(binFileSize+10, 1);
  binDataRead = fread (serialData, 1, binFileSize, binFileHandle);
  fclose(binFileHandle);
 }
 else
 {
  return -1;
 }
 return 0;
}

 

 

strcpy(qlBuffer, serialData);

 

 

 

if(command_num == 6)
    { 

    

if(0 == QuickLoadBinFIle("c:\testcode.bin"))

{     
     for(i = 0; i < gWriteDataSize; i++)
     {
      RS232Error= ComWrt(comport, qlBuffer, 1);
         qlBuffer++;
      Delay(0.1);
     }
     LogStatusGUI("Loding bin file Completed...") ;
     Delay(1);
    }

}

0 Kudos
Message 3 of 24
(5,863 Views)

Hi, there are a couple of hints that come to my mind looking at your code:

 

First of all I don't understand where exactly that strcpy lies in the code: in this respect strcpy can be a possible cause of problems since it will stop copying data on the first NULL byte, and since your data is bynary data a NULL byte could be present everywhere in the source file. But it seems to be not used in the last function you posted? On the other hand you are using qIBuffer, so... ?

 

Second hint, why don't you simply use ComWrt (comPort, serialData, binFileSize); ? Do you really need to send a byte at a time? Why not using ComWrtByte in that case?

 

Third suggestion: in QuickLoadBinFIle I would move GetFileSize and test for return code before opening the file (or use FileExists for the same reason), so to skip all the function in case the file does not exist. I know you are testing errors on fopen, but I would personally prefer to avoid disk access if I'm not sure the file exists.



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 4 of 24
(5,857 Views)

I don't understand which problems you are facing when using ComFromFile: can you post the relevant code and tell us if you receive an error in CVI or in the external device and which one?

 

You can additionally look at this discussion that covers sending bynary data to external devices via serial communications.



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?
Message 5 of 24
(5,851 Views)

Thank you for your support....

As per policy i cant share my complete code..

whatever eariler shared code is a part of my application code where the binary data is transfered..there is no issues with formating reading coping.

I checked the serial data variable before sending the data is correct what expected to send.

 

I tried all the serial functions comwrtbyte, comfromfile, comwrt & visa functions..the same behavior is received

 

please find the attachment of catured data from portman tool.

 

attached 3 files

hyperterminal captured data - I am getting valid response from controller

cvi exe captured data - I am getting failed response from controller.

 

binary data - downloadable binary file to a flash memory using the RS 232 communication system

 

0 Kudos
Message 6 of 24
(5,837 Views)

I'm not sure I can understand what is happening there, but it seems to me that you have saved the same log with different names: attached files are identical (fc found no differences: they are byte-by-byte the same) so we can't be sure of what CVI is sending.

At present I can only observe that hyperterminal is relatively faster than your CVI code: it writes 80 bytes/sec while you have a 100 msec delay between characters; could it be that the controller does not accept incoming message because it's too slow?



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 7 of 24
(5,825 Views)

As a last note: hyperterminal log and binary data file are different in that the log have some characters at start of transmission that do not appear in binary file (see rows #2 to 47 in the log). May these be added by hyperterminal to sync the transmission?



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 8 of 24
(5,823 Views)

Thanks for your support..

 

The first few characters are commands that is Q0 0x00000000 000000F0 <bin file data>/r/n this is the complete message and the formating is done in the code..I checked with probe the format is correct...and regarding the delay i tried all the ways of delay's like without delay and adding 0.001, 0.01,...etc

   

Please find the attachment for hyperterminal screen shot..

 

0 Kudos
Message 9 of 24
(5,817 Views)

Well, I'm out of ideas at this point.

If communications settings are ok and you receive no errors both in tx and rx the only issue I can see is some timing or synchronizazion setting missing between CVI program and the external board, but I'm really only guessing at this...



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 10 of 24
(5,797 Views)