LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to implement this C code line: for ( int i = 0; i < G_ReadLen; i = i + 2 )

Solved!
Go to solution

I want to implement the following C++ code in labview but i cannot make or loop to increase by two

 

int j = 0; for ( int i = 0; i < G_ReadLen; i = i + 2 )

{

BYTE AD_H = ByteArray.GetAt(i);

BYTE AD_L = ByteArray.GetAt(i + 1);

ValueArray[j] = AD_H << 8;

ValueArray[j] = ValueArray[j] + AD_L;

unsigned long Temp = ValueArray[j] >> 12;

Volts[j] = ((float)ValueArray[j]) * 0.0048875;Message.Format(

"%X , %X - %X, -- %d, +%.3f Volts", AD_H, AD_L, ValueArray[j], ValueArray[j], Volts[j]);

m_output_ep1i.InsertString(0,Message);

j = j + 1;

}

 

Thanks

0 Kudos
Message 1 of 9
(4,012 Views)

Hi nick7,

you can use a for loop and connect the duration number to n, calcualte the i value you need inside the loop.

 

Mike

0 Kudos
Message 2 of 9
(4,009 Views)

Hi nick7,

 

You could also use a while loop with the loop termination condition as i < G_Readlen and within the loop increment i by 2 and j by 1. You would need to pass the values of i and j to shift registers.

 

Hope this helps!

 

Cheers!

 

Sanka

 

0 Kudos
Message 3 of 9
(3,988 Views)
Solution
Accepted by topic author nick7
Thanks a lot sanka problem solved I atached the solution
0 Kudos
Message 4 of 9
(3,966 Views)

Your code will not work.

 

You are replacing elements of an empty array. A no-op in LabVIEW.

 

Besides there is a lot easier way to do this:

 

I just hope this is not a homework assignment.

And for completeness sake here is Mikes solution (seen below):

 

 

Ton

 

 

Message Edited by TonP on 11-14-2008 12:55 PM
Message Edited by TonP on 11-14-2008 01:03 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 5 of 9
(3,955 Views)

Hi nick7,

in your case the attached code should also work. 

 

Mike

Message 6 of 9
(3,954 Views)
I love the way LabVIEW has tidied up all that C code (which took me a couple of minutes to get my head round). I then opened Mikes post (Which took up about 20% of the real estate) and recognised what was happening in about 0.5 secs! gotta love it! 🙂
LabVIEW 2012
0 Kudos
Message 7 of 9
(3,940 Views)

Top my code is workig fine.

Here a few words on what I am doing:

PIC18F4550 micro board --> USB bulk in enpoind read delivers an array of 704 bytes (every two bytes contain a 10 bit voltage value)-->procces data to end up with 352 word (16bits) data.

HI byte XXXX XXDD  DDDD DDDD low byte (X :dont care bit)

0 Kudos
Message 8 of 9
(3,894 Views)

Most likely you do a 'String to U8' node conversion.

 

If you replace that with the Typecast I used you can directly convert from string to U16 array.

 

The fact that your code works is propably becuase you have a hidden constant to the Array shift register.

 

Good luck,

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 9
(3,849 Views)