LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i process the stream..?

How can i process the stream..?
 
   Hi..!
   I have stream of random numbers, I need to assign them for 4 different variables.
   In otherway,
   
           a1=(float)Random(-0.8,0.8);
        SetCtrlVal(panel4,PANEL_4_NUMERIC_2,a1);
        SetCtrlVal(panel4,PANEL_4_NUMERIC_3,a1);
          SetCtrlVal(panel4,PANEL_4_NUMERIC_4,a1);
          SetCtrlVal(panel4,PANEL_4_NUMERIC_5,a1);
   I have placed the above code in timer.
   I have to display the first generated random number in the NUMERIC_2 and second generated random number
   in NUMERIC_3 control and vice versa.
Please help me.
Thanx and regards,
Venki.
 
0 Kudos
Message 1 of 4
(3,041 Views)

Let me see if I have correctly understood your problem...

First generated number goes on control1, second on control2, third on control3, fourth on control5, fifth on control1 again and so on scannin controls one at a time.

In this hipothesis, a good approach can be:

1. Create an array of control handles:

int  ctl[] = { PANEL_4_NUMERIC_2, PANEL_4_NUMERIC_3, PANEL_4_NUMERIC_4, PANEL_4_NUMERIC_5 }

2. Use a static variables inside timer callback to hold index in the array. Write new value on the i-th element of the array and reset index as appropriate:

static idx = 0;

a1 = (float)Random (-0.8, 0.8);

SetCtrlVal (panel4, ctl[idx], a1);

if (++idx > 3) idx = 0;



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 4
(3,036 Views)
Hi .!
 
   Thanx it helps. I have got the data stream from a device by using the RS232 cable i have assigned the stream to different variables. Still, because of the white space i have problem.
How can i remove all the white spaces from a chracter buffer..?.
 
Thanx and Regards,
Venki.
  
  
0 Kudos
Message 3 of 4
(3,019 Views)
Both if you are processing the string while receiving it or after the message was received, basically you must scan the string one character at a a time and copy the characters to a new string if they are not whitespaces.
 
A sample source for processing the string and skipping whitespaces can be found in toolbox.c (located on your disk in <cvidir>\toolslib\toolbox): look at StrDupWithoutSurrWhiteSpace function which creates a copy of a string without leading and trailing spaces. This code must be extended since it removes only whitespaces at beginning and end of the string, but can be a good starting point to work on.


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 4
(3,014 Views)