11-14-2008 01:11 AM
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
Solved! Go to Solution.
11-14-2008 01:16 AM
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
11-14-2008 02:43 AM
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
11-14-2008 05:38 AM
11-14-2008 05:55 AM - edited 11-14-2008 06:03 AM
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
11-14-2008 05:55 AM
Hi nick7,
in your case the attached code should also work.
Mike
11-14-2008 06:04 AM
11-14-2008 08:49 AM
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)
11-14-2008 10:59 AM
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