Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

reciving data from RS232

hellow sir

 

i make a project in which i take the data from serial im new to labview and dnt know how to segregate the incoming bytes from microcontroller and anyone tell me how to solve it , and i also attached my controller code.

 

thhanks in advance for replyng

 


#if defined(__PCM__)
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=300, xmit=PIN_C6, rcv=PIN_C7)
#endif

void main() {
long a1,a2,a3;
long c2,c3;
//int32 x,u;
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
a1=0;
a2=0;
a3=0;
do {
//temperature data
set_adc_channel(0);
delay_us(10);
a1 = Read_ADC();
delay_us(10);
delay_us(5);
printf("temp%03Lu",a1);
if(a1 <= 35)
{ output_high(PIN_B1);
output_low(PIN_B0);
}
else if(a1 > 35)
{ output_low(PIN_B1);
output_high(PIN_B0);
}
//Humidity data
set_adc_channel(1);
delay_us(10);
a2 = Read_ADC();
c2 = a2-42;
delay_us(5);
printf("humd%03Lu",c2);
if(c2 <= 40)
{ output_high(PIN_B3);
output_low(PIN_B2);
}
else if(c2 > 40)
{ output_low(PIN_B3);
output_high(PIN_B2);
}
//Level data
set_adc_channel(2);
delay_us(10);
a3 = Read_ADC();
c3 = a3-27;
delay_us(5);
printf("leve%03Lu",c3);
if(c3 <= 25)
{ output_high(PIN_B5);
output_low(PIN_B4);
}
else if(c3 > 25)
{ output_low(PIN_B5);
output_high(PIN_B4);
}



} while (TRUE); //end do
} // end main

 

 plz reply to me

 

0 Kudos
Message 1 of 26
(4,290 Views)

First, you posted to the wrong board. This is not a multifunction DAQ question. It should have been posted to the Instrument Control board.

 

Second, have you confirmed communication in a program such as Hyperterminal? If you have, then try one of the RS-232 examples (i.e. Basic Serial Write and Read). If you can get something there, try putting the VISA Read inside a loop. In order to really help, you should post a VI with some data in an indicator. You can do that with the example by running so that you see data and then going to the edit menu and selecting 'Make Current Values Default'. Save the VI with a new name. Post that.

0 Kudos
Message 2 of 26
(4,282 Views)

Hi adeelghani,

 

How are you getting on with this problem?

 

Did the examples Dennis suggested help?

 

Let us know if you need any further examples or explanation.

 

Thanks,

Owen.S
Applications Engineer
National Instruments
0 Kudos
Message 3 of 26
(4,270 Views)

thanks for replaying sir i get ur point but the problem is still that the microcontroller data out (which shows on hyper terminal ) is serail that is "temp 28 humidity 29 level 10"  and the serial data is 8 bit

 

1) how can i segregate the signal bit and than perform action ???  e.g graph level vary

2) or how i can collect the data and perform seprate action 

   

   if  temprature vary the coresponding graph vary according tothat value

   water level vary the corresponing level bar vary  and same 4 humidity

 

can i also change in my controller program ???

 

i hope u get my point and thanks for helping me replyng me i hope u solve that

 

take care   

 

 

0 Kudos
Message 4 of 26
(4,255 Views)

Did you even try the serial examples that come with LabVIEW? Since you did not post the modified VI with some actual data, I'm going to assume that you did not. Before you can get help with any code, you have to show the code you are using and explain where the problem is.

 

If you have the string terminated with a CR or LF, just set the number of bytes to read to some large number. You'll get the entire string and then you just have to parse it. There are numerous string functions that you can use. Look at the string palette and look through the examples that come with LabVIEW.

0 Kudos
Message 5 of 26
(4,251 Views)

Hi adeelghani,

 

I have written some code to help you segregate the data coming through your serial port. The code will get the data being transmitted, then providing it is in the format "temp 28 humidity 29 level 10" it will "cut out" the 28 at the start and then put that in a graph named "Temperature". Hopefully you can expand on this code to include the humidity and level. After the data has been seperated you can use this value and manipulate it however you want.

 

You just need to set up the port you are using and the other variables and it should work.

 

The VI is attached to the bottom of this post.

 

Let me know if you have any further questions.

 

Kind regards,

Owen.S
Applications Engineer
National Instruments
0 Kudos
Message 6 of 26
(4,248 Views)

thanks again 4 replyng

 

the file u send cant open in my system the error is

undefinedso what is the remdy

 

thanks 4 replyng.

0 Kudos
Message 7 of 26
(4,241 Views)

Well, here is a simpler version and it assumes that you are terminating the string. Please answer some of the questions I asked and run one of the examples. There are countless ways to do serial coms and if you don't provide some details, all we can do is guess and that's just wasting time.

 

 

0 Kudos
Message 8 of 26
(4,239 Views)

bundle of thanks to both members which help me lot

 

i apriciate ur post and ur quick reply superb

 

im not wastng ur time i have advantage to learn 4m u both members 

 

im new labview user and have little knowledge so that u have suffer frm me i hope if ur sharing continue im not new new in labview 

 

again thanks

 

i tell u whats the result.

0 Kudos
Message 9 of 26
(4,235 Views)

Hi adeelghani,

 

No problem at all.

 

Let us know if you have any further questions.

 

Kind regards,

Owen.S
Applications Engineer
National Instruments
0 Kudos
Message 10 of 26
(4,233 Views)