LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid the reading back of the data which ever i have written through RS-232 library from a cvi?

Hi,
I am trying to implement a hyper terminal in to my CVI application.
where i am using InstallComCallback for collecting the data and printing in my text box.
As shown below:-
main()
{
 RS232Error = OpenComConfig (comport, devicename, baudrate, parity,
                                        databits, stopbits, inputq, outputq);
...........
 FlushInQ (1);
 FlushOutQ (1);
.........
 InstallComCallback (1, LWRS_RXCHAR, 0, 13 , Event_Char_Detect_Func, 0);
............
...........
}
 
where my callback function is:-
 
void CVICALLBACK Event_Char_Detect_Func (int portNo,int eventMask,void *callbackData)
{
 char OutMessage[256];
 char readcomdata[2000] = {0};
 int read_byte;
 int count  ;
 
 if(eventMask & LWRS_RXCHAR)
 {
  read_byte = ComRd(comport,readcomdata,count = GetInQLen (comport));
  SetCtrlVal(5,TABPANEL_3_TEXTBOX,readcomdata); 
 
 }
 return;
}
 
Till this point it is fine and i am able to read everything from the device and get printed on my text box.
The problem which i am facing is while writing, whenever i tried to write through another UI call back i am reading back the same thing which i am writing plus results of the command which i have given.
like as follows i have give a read command like r 0x30000000 on my terminal and i am getting prints like:-
 
BOOT> r 0x30000000r 0x30000000
30000000 : 0042fa05
 
"r 0x30000000" this is extra.

Please let me know how to avoid reading back while writing, is there any status checks for doing this.

And please let me know whether the above functions are appropriate for reading.

Thanks in advance.

Regards

Siva

 

 

 


 
 
 
 
0 Kudos
Message 1 of 4
(3,018 Views)
Siva -

Is your device echoing the characters it receives back to you?  This is sometimes called "echo" or "autoecho", and is often available with terminals. 

NI recommends using LWRS_RECEIVE or LWRS_RXFLAG instead of LWRS_RXCHAR.

If your incoming data is always delimited with a linefeed or a carriage return, you can set the callback to not be called until the delimiter is received.  This is a more effective approach, unless you have some reason for inspecting each character the moment it is received.

InstallComCallback (1, LWRS_RXFLAG, 0, 13 , Event_Flag_Detect_Func, 0);

if (eventMask & LWRS_RXFLAG)  {
   read_byte = ComRd (comport, readcomdata, count = GetInQLen (comport));
   SetCtrlVal (5,TABPANEL_3_TEXTBOX,readcomdata);   
}


0 Kudos
Message 2 of 4
(3,006 Views)

Hi Menchar,

Thanks for your reply.

My device is not echoing the charecters that it has received.

The question is when i am trynig to send some thing through the device, it is recieving what ever i have sent along with the reply from the device which i need.

It is becoming difficult to seperate them and print only the reply which i need.

I cant use LWRS_RXFLAG because "the destination or target device is controlled by us now and we are not sure that definetly we will include a carriage return at the end of what ever we have sent to host " so i need to capture everything.

Thanks and Regards

Siva

 

0 Kudos
Message 3 of 4
(2,978 Views)

Siva -

Are you making sure the chars you're writing to the Text Control are in the form of a string?  Text controls are like string controls, you must use a string with SetCtrlVal.

The rs-232 library calls read bytes, not strings.  You have to turn the bytes read into a string by adding a null char '\0' at the end of the bytes read.  You can do this with

readcomdata[read_byte] = '\0';

Otherwise, when you write to the text control it'll keep writing until it finds a null (0) byte.  Maybe this accounts for the "extra" stuff you're seeing.

Menchar

Message Edited by menchar on 04-09-2007 09:59 AM

0 Kudos
Message 4 of 4
(2,952 Views)