LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle formfeed received on rs232?

Hi,

 

I am new to CVI, however have good knowledge of microcontroller based C programming. I am trying to figure out how to handle formfeeds sent by a device.

 

HARDWARE:

1) I am running LabWindows CVI 2013 on my PC

2) I have a electronic hardware which can serially communication using RS232

 

The Issue:

Basically the hardware responds to the commands sent through the serial port. previously i had been using HyperTerminal for the communication. Hence when the device responded with new data it sent form feed first and then the data.

 

Now I wanted to move on to a HMI development, I have setup the C code in CVI to send out serial commands and using 

 

InstallComCallback (COM_PORT, LWRS_RXCHAR, 0, 0, Event_Char_Detect_Func, 0); 

 

I am trying to read the data into a buffer and display it in a text box

 

void CVICALLBACK Event_Char_Detect_Func (int portNo,int eventMask,void *callbackData)
{
char readBuf[1000] = {0};
int strLen;
strLen = GetInQLen (COM_PORT);
ComRd (COM_PORT, readBuf, strLen);
SetCtrlVal (panelHandle, PANEL_OUTPUT_STRING, readBuf);

return;
}

 

However I am receiving small boxes instead of form feed. I used "LWRS_RXCHAR" so I could read each character individually and then maybe handle formfeeds but the compiler requires readBuf[] to be more then one character showing that it reads the complete RX data que before sending it to textbox (OUTPUT_STRING).

 

I can always make changes to the micro controller, but I want to know if there is a proper way of handling such a situation? or maybe I am doing someting wrong in the code above?? Help needed.

0 Kudos
Message 1 of 2
(4,018 Views)

Basically you could do what you are doing simply skipping the form feed, tat it: read in a soparate buffer and copy from this one to the effective char variable skipping the form feed.

 

But you have other alternatives:

 

  • Use ComRdTerm to read the string until the form feed is received:
    ComRdTerm (COM_PORT, readBuf, strLen, 14);
    In this case you should not have the form feed in the receive buffer
  • Setup the com callback to fire on the form feed (se the help for reference):
    InstallComCallback (COM_PORT, LWRS_RXFLAG, 0, 14, Event_Char_Detect_Func, NULL);
    In this case the com callback will be fired when a form feed is received anf you can read with ComRd but you must discard the form fedd (last character read)


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 2 of 2
(4,010 Views)