Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

how to manage data after getting from serial com port?

Solved!
Go to solution

hi all,

i am new to labview and serial communication. i tried to receive data on labview from external device (pic18f452). it is done but the data i receive is in form of strings. if microcontroller gives "11.25"  ,in labview each letter comes at different string as ("1" "1" "." "2" "5").. how can i manage data.. to make it single constant as 11.25, a number.

 

if possible also attach some examples with ur replies ... thanx in advance.

0 Kudos
Message 1 of 9
(4,316 Views)
Solution
Accepted by M.Mohsin

It seems you are reading too fast, read until an endcharacter is probably putting the characters in one string that can be translated with the string to number conversion routines in the string palette.

greetings from the Netherlands
0 Kudos
Message 2 of 9
(4,307 Views)

M.Mohsin,

 

Can you show us a screenshot of your code?  

 

Also, I recommend looking at the Serial Communication examples available in Example finder in LabVIEW.  You can find these in Help > Find Examples > Hardware Input and Output > Serial. 

 

Regards

0 Kudos
Message 3 of 9
(4,302 Views)

thnx both of u. both helped. i used model of serial communication from examples .. and used string to number block and i got correct value .

another problem came now. that is, when i use the frequency for 1Hz of my source(whos data i am transferreing and monitoring) i get most of the value and plot is fine. but when i raise frequency upto 50Hz of my source. it reads just 5 values out of 200 in 1 cycle. i tried to increase baud rate upto 115200. it increased upto 7 value.. what things can i change to make to get more values on plot. i am using 10-bit adc from pic18f452 at 20MHz. and Focs/32 as charging time of capacitor. and serial sommuncation from same block.

 

0 Kudos
Message 4 of 9
(4,295 Views)

First it's important that the serial communication parameters match the spec for your external device (PIC). You will want to check it's manuals for those values. If those are matching, I would try using the I/O buffer at a large size.  You can see this utilized in the Advanced Serial Read and Write.vi example.

 

Again, a screenshot would really help to make sure we are on the same page and save time if this doesn't help.

 

 

0 Kudos
Message 5 of 9
(4,285 Views)

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

signed long Vin,Vin1, mV,Vdec,Vfrac;
unsigned char op[12];
unsigned char i,j,m,lcd[5],ch1,ch2,abc[5];

signed long Iin,Iin1,Iin2,Idec,Ifrac;
unsigned char ap[12],tp[12];
unsigned char k,lcd1[5],ch11,ch22;
char uart_rd;

void main() {
int c;
int q=65;

Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);


TRISA=0xFF;
TRISD = 0x00;
UART1_Init(115200); 
Delay_ms(100);

UART1_Write(10);
UART1_Write(13);

ADCON1= 0x88;
ADCON0=  0x80;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
TRISD = 0x00;
PORTD = 0x00;

 for(;;){
   ADON_bit = 1;
   delay_ms(1);
   GO_DONE_bit=1;


   while(GO_DONE_bit){

      Vin = Adc_Read(0);
      Lcd_Out(2,1,"V = ");
      Lcd_Out(1,1,"I = ");
      Vin = (((976*Vin)/1000)-500)*40;

      Vdec = Vin / 100;
      Iin = (Vin/80);
      Idec = Iin/100;
      if(Vin<=0){
         Vin = Vin * (-1);
         Iin = Iin * (-1);
         Vdec = Vdec * (-1);
         Idec = Idec * (-1);
         }
      Ifrac = Iin % 100;
      Vfrac = (Vin) % 100;
      LongToStr(Vdec,op);
      LongToStr(Idec,ap);
      LongToStr(Vdec,tp);
      k=0;
      for(m=0;m<=11;m++)
      {
         if(ap[m] != ' ')
         {
            lcd1[k]=ap[m];
            k++;
         }
      }
      k=0; m=0;
      for(m=0;m<=11;m++)
      {
         if(tp[m] != ' ')
         {
            abc[k]=tp[m];
            k++;
         }
      }

      Lcd_Out(1,6,lcd1);
      i=0;
      for(i=0;i<3;i++){
         UART1_Write(abc[i]);
      }


Lcd_Out_Cp(".");
ch11 = Ifrac / 10;
ch22 = Ifrac % 10;
Lcd_Chr_Cp(48+ch11);
Lcd_Chr_Cp(48+ch22);



UART1_Write_Text(" ");

//Delay_ms(100);



j=0;
for(i=0;i<=11;i++)
{
if(op[i] != ' ')
{
lcd[j]=op[i];
j++;
}
}
Lcd_Out(2,6,lcd); // Output to LCD
Lcd_Out_Cp("."); // Display "."
ch1 = Vfrac / 10; // Calculate fractional part
ch2 = Vfrac % 10; // Calculate fractional part
Lcd_Chr_Cp(48+ch1); // Display fractional part
Lcd_Chr_Cp(48+ch2);
Delay_ms(1);

}

}


}

 

 

The above is my code. made on mikroC

 

check the problem.  the first graph is for AC frequency 0.1 Hz and other is 50Hz . and i took the labview module from some one's post on these fourms.

Download All
0 Kudos
Message 6 of 9
(4,274 Views)

Hi

I saw the continuous run button active on the frontpanel !

Why is that one active ?

It means that you are starting and stopping your vi and inbetween clearing some data.

Can you post your vi?

greetings from the Netherlands
0 Kudos
Message 7 of 9
(4,255 Views)
0 Kudos
Message 8 of 9
(4,254 Views)

No problem with the continuous run button but don't use it anymore....

The while inside handles the IO nicely but a few other questions:

 

1) why not use VISA instead of the old serial lib, this is done anyway one level deeper, so youre only adding subvi overhead, not much but evrything counts.

2) You are reading characters with 1ms delay and then if you have 1 or more characters immediately translate them into a float and also add them to a graph.

    If you have an endcharacter ( a space, or a comma or anything not a decimal point or digit) then you could use the visa read with endcharacter enabled and always get complet values.

 

I hope this solves your problem

good luck

greetings from the Netherlands
0 Kudos
Message 9 of 9
(4,243 Views)