06-23-2016 03:15 PM
HI
I am trying to send about 2 to 3 Mb data to comport using comwrt(); function . By using this some data abound 1 mb its sends data and after that its stops looks likes hang. pleas look into my code.
please give solution for this .
/****************************************************************************/
int CVICALLBACK LoadData (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
ssize_t size;
int f_Handle = 0;
char *iamgeData = NULL;
char file[MAX_PATHNAME_LEN];
int flag=0;
if (event != EVENT_COMMIT) return 0;
GetProjectDir (file);
if (FileSelectPopup (file, "*.bin", "", "Data file to load", VAL_LOAD_BUTTON, 0, 0, 1, 0, file) == VAL_NO_FILE_SELECTED)
return 0;
GetFileSize (file, &size);
iamgeData = malloc (size);
f_Handle = OpenFile (file, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
ReadFile (f_Handle, iamgeData, size);
flag = ComWrt(comport, iamgeData, size);
}
// ComWrtByte
if(flag)
{
outqlen = GetOutQLen (comport);
if (outqlen < 0)
{
if (f_Handle > 0)
CloseFile (f_Handle);
if (iamgeData) free (iamgeData);
}
}
return 0;
}
06-23-2016 05:33 PM - edited 06-23-2016 05:40 PM
There are a couple of hints on this subject that can help you in developing your code.
First of all, how do you open the com port? Read the help on OpenComConfig and see how to configure outputQueueSize parameter to exclude the output buffer. If you do not exclude the buffer you may terminate the write before it is actually finished.
Second:you are not discriminating errors in write; at least issue a message in case of errors!
Next: writing 3 mb in a single pass is risky; I suggest you to read and transmit the file in chunks.
GetOutqLen returns a negative value only in case of errors: is that the condition you are trying to trap at the end of your function? If so, you should do something more than simply closing the file: at least issue a warning to the user! On the other hand: if there are characters to transmit you leave the file open: is this correct? When are you supposed to close it?
Finally : have you considered using ComFromFile function?
07-01-2016 07:53 AM
HI
Thanks for you reply .
Actually my appilction is : i have an bin file of more than 2 MB and i need sending to my system using com . so i tried as above but its sending some anount means 70% of data and stucks . but i tried to check COm wrt return value its showing 0 . can you elabirote more fro me .
I am opning poert priv only i am doing some comamd rx and tx to test and then i am sending this .bin file.
Config : BaudRate :115200 , Parity :0, Databits :8, Stopbits :1, Inputq :2048, Outputq :8,
and i tried with to in increase Outputq but its more worst result .
Thank you ,
07-04-2016 01:44 AM
Hi patil,
you appear to have missed what I wanted you to notice on OpenComConfig command. Quoting from the command help (highlight is mine):
outputQueueSize | int | The size of the output queue for the selected port. If you specify 0, OpenComConfig uses 512. If you specify a value greater than 0 but less than 30,OpenComConfig uses 30. If you specify a negative value for outputQueueSize, the output queue is not used and the data is written to the port directly. There is no maximum limitation on the queue size. However, some serial drivers have a maximum of 32,767 and give undefined behavior when you use a larger queue size. NI recommends that you use a queue size no greater than 32,767. |
Setting this value to -1 ensures you are sending data directly to the prot instead of using an intermediate buffer for transmit. Try this way and see if it works better. If it still does not work perfectly you will need to split the transmission in a few blocks and check GetOutQLen to return 0 before sending additional data to the port.
07-07-2016 10:37 AM
HI,
Thnak you for your suggestion . i tried with -1 value but its showing error -1 after completion of trasfer data,
error is : NON-FATAL RUN-TIME ERROR: "cviCallbacks.c", line 738, col 12, thread id 0x0000192C: Function ComWrt: (return value == -1 [0xffffffffffffffff]). The operation completed successfully.
please guide me . sliptiing the data is very critical in my appliction case . i will try that too.
thank you :;)
07-08-2016 01:31 AM - edited 07-08-2016 01:31 AM
According to the help, in this case
For error code -1 (UnknownSystemError), call the GetRS232ErrorString function to obtain a specific Windows message string.
Let's see if there's some additional info that may help in understanding what's happening.
BTW, are you using an actual serial port or some virtual COM port out of an USB-to-RS232 or Ethernet-to-RS232 converter? In this case, can you test it with a machine with an onboard serial port?
07-08-2016 02:16 PM
HI
I am using USB to RS232 ( Vertual COM port)
07-08-2016 05:08 PM - edited 07-08-2016 05:08 PM
Have you tried calling GetRS232ErrorString? What does it report?
07-11-2016 08:52 AM
hi
GetRS232ErrorString showimg "This operaton completed sucessfully ".
Actully i called GetRS232ErrorString funtion after "flag = ComWrt (comport, Data, size); " funtion is that right way to call ? please conform .
07-11-2016 09:20 AM
I don't know what is happening and what that -1 may imply; it is to be said, though, that I never try to transfer such a big amount of data in a single pass, I normally am on the opposite side: a lot of short messages very frequent.
Can you try sending the message in smaller blocks, say 10 blocks 2-300 kb each?
In any case, since this is a non fatal error, if the destination device recevies all data you can ignore it either unchecking Run >> Break on >> Library Errors menu item or by enclosing ComWrt command in a pair of SetBreakOnLibraryErrors () instructions if you want to keep the general option alive.