LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with inserting 0 when value of boolean array is 0

Hello everybody,
 
I have a serious problem with a measurement-data file (txt-file) in HEX-code of mine.
 
the arrangement: I got 12 sensors of which only the active ones send data.
The measurement data file consists of a header with the information which sensors are active. For example 101000000000 means, that sensors 1 and 3 were active and sending data.
After a CR LF (End of Line; HEX:  0D0A) there are the actual measurement data and after another CR LF there is a footline.
 
The measurement data itsself is build up like this:
the first byte is a counter, then there comes a time in seconds (4byte) and after that the sensor data of the active sensors: 2 byte voltage, 2 byte current, another 2 byte voltage and 2 byte current and afterwards a 1byte long information about the measurement range. then there comes the same in information for the next active sensor (again 2byte voltage, 2byte current, 2byte voltage, 2 byte current, 1byte range = 9byte for every sensor).
After the data for 1 counter reading is completed there comes a seperator LF (HEX: 0A) and afterwards the next next data line.
 
For example for 2 active sensors 1 sensor data line could look like this:
counter | time          | voltage1a | current1a | voltage1b | current1b | range1 | voltage2a | current2a | voltage2b | current2b| range2 | seperator
01          0000 0000   00FF          01FA          007F          007A          01          024B          122E          004A          00AB         01         0A
result in (decimal)
1             0                 255             506            127            122             1            587             4654          74              171            1
 
Now my problem is, that i shall produce an array where the data of all 12 sensors is shown. Thats why i have to insert the value 0 in the array-elements where no data is received. for the example above with the header 101000000000 this would effect in the following:
 
counter|time|volt1a|curr1a|volt1b|curr1b|range1|volt2a|curr2a|volt2b|curr2b|range2|volt3a|curr3a|volt3b|curr3b|range3|volt4a|curr4a|volt4b|curr4b|range4|...
1           0      255   506   127   122      1         0         0         0        0          0      587   4654     74     171     1       0       0      0       0       0       ... many 0.
 
I already tried several things. But somehow my VI doesnt, at least not the way I want it to :=). It doesnt insert the 0's when the boolean array resulting from the header value 0 but only 5 times the value 0.
 
Could someone please tell me what i did wrong ?
An example measuremnt data file is inserted as default in the attached VI.
 
Thx Karl-Heinz


Message Edited by suppi on 11-18-2007 10:37 AM

Message Edited by suppi on 11-18-2007 10:37 AM
Download All
0 Kudos
Message 1 of 13
(3,166 Views)


suppi wrote:
Could someone please tell me what i did wrong ?

Your main problem is that your inner FOR loop never uses the data from the shift register, but just outputs the last array. You need to (1) initialize the shift register with an empty array and (2) use built array to either append real or zeroed data.
  • There are many things that could be improved, for example the loops that run only once can be deleted.
  • To take an array subset you should use "array subset" instead of "split array".
  • It is more natural to concatenate arrays using built array "(concatenate mode)" instead of "insert into array".
  • Why do you output DBL data if all are actually integers?
  • ...

You do the unflattening of the data way too complicated! let me find a better way.

0 Kudos
Message 2 of 13
(3,157 Views)

Hello altenbach,

thx for your fast answer. unfortunately and like you may have seen from my programming-stile I am not very experienced in using LV.

Could you please tell me how to realize (1) and (2) ? Is there maybe a LV example I could use ?

Thx Karl-Heinz

0 Kudos
Message 3 of 13
(3,149 Views)
Karl-Heinz
 
Try the following quick modification (LabVIEW 8.0). See if it works. Modify as needed. 🙂
 
A lot of your code was very inefficient, for example you reverse the big array several times, just to split it into parts. I show you an alternative. You don't need to scan the binary formatted text, just see which characters are not zero (x48) to make the boolean array.
 
It is probably easiest to convert the string to a byte array and reshape it for one record/row. Now you can just autoindex and cast each row as required. For each row, it is better to initialize a fixed size array with zeroes and then fill with data at the right locations. The rest is already zero. This is much more efficient than building the array from small parts.
 
See if this brings you closer to a solution. Let me know if you have any questions. There are probably small bugs and oversights, so please verify correct operations.
 
 
0 Kudos
Message 4 of 13
(3,130 Views)

wow, thx altenbach, this is just great. I am really very thankful, I would have never got this.

I will now take some time to understand the VI. This really brings me forward.



Message Edited by suppi on 11-18-2007 02:34 PM
0 Kudos
Message 5 of 13
(3,126 Views)
Hi,
 
I think I got the functionality of this VI.
 
But unfortunately I got another problem. How I found out now, I have to convert the data of the several columns. The 1st voltage-column of each sensor has to be divided by (HEX) 0800. The 1st current-column has also to be divided by (HEX) 0800 and then multiplied by the value of range. But thats not simply it. Range is a placeholder. If range is 0 then current has to be multiplied by 1, if range is 1 current has to be multiplied by 10 and if range is 2 current has to be multiplied by 100.
 
And if this would not be enough, the 2nd voltage-column of each sensor has to divided by (HEX) 0148 and the 2nd current by (HEX) 0100.
 
I would know how to implement that when I have the several columns as arrays, but I really have no idea how to handle that in the FOR-Loop.
 
Can someone please help me ?
 
Karl-Heinz


Message Edited by suppi on 11-20-2007 01:20 PM
0 Kudos
Message 6 of 13
(3,092 Views)


suppi wrote:
And if this would not be enough, the 2nd voltage-column of each sensor has to divided by (HEX) 0148 and the 2nd current by (HEX) 0100.

OK. now it gets a bit more complicated, because you are no longer dealing with integers, but need an orange array. Do you want SGL or DBL?
 
In any case, an easy way would be to just divide by an array of four desired values as follows (assuming SGL). Modify as needed.
 
 


Message Edited by altenbach on 11-20-2007 12:27 PM
0 Kudos
Message 7 of 13
(3,082 Views)
thx altenbach,
 
I have never really worked with single precision values, so I think I need double. But is there a difference using these 2 in my case ?
 
I will try to convert your VI with the hints given in your picture.
 
Karl-Heinz
0 Kudos
Message 8 of 13
(3,073 Views)
The code for DBL should be nearly the same.
  1. Change the representation of the element where you initialize the array (right-click...representation)
  2. Change the coversion bullets to DBL
  3. Change the final array indicator to DBL.

See how far you get. 🙂



Message Edited by altenbach on 11-20-2007 12:54 PM
0 Kudos
Message 9 of 13
(3,069 Views)
Thx, I will try to.
 
Do you any way how to realize the selection of the range, is it even possible ? Because I would need that to show thr right value of the 1st current.
 
Karl-Heinz


Message Edited by suppi on 11-20-2007 03:05 PM

Message Edited by suppi on 11-20-2007 03:06 PM
0 Kudos
Message 10 of 13
(3,064 Views)