LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to display unsigned and signed numbers in single chart

Solved!
Go to solution

Hello all,

 

I am trying to find a solution to switching a single chart between displaying a signed integer and an unsigned integer.

 

Essentially I have a U16 source that comes from an array.  Some of the array is signed, some is unsigned.  I break up the array into separate "channels" and then display them graphically in a chart (one "channel" at a time).  For testing purposes the array is simply several counters going from 0 to 65535 over and over again for the unsigned, and simply putting the source through an I16 converter gives me -32,768 to 32,768 for the signed.

 

My problem is that I want to be able to see the unsigned and signed data on the same chart; if I know a "channel" is unsigned then a switch is one way, and if the "channel" is signed then I flip the switch.  I am wondering how, if it's possible, to "switch" between the unsigned source and the converted data from the I16 converter.  I've tried a Case Structure with a switch, but the data sticks as U16.  I've tried the Select function but the inputs have to be the same type, so that doesn't work either.  

 

The easy solution would be to have two charts, but that seems to be a hack workaround rather than a solution to the problem.  If anyone could help, please let me know if there is a solution on how to do this elegantly with Labview!  Any questions, let me know.  I've put a screenshot up to describe what I'm trying.

Download All
0 Kudos
Message 1 of 10
(3,667 Views)

That is not a "red error indicated here" on your one image.  It is a coercion dot which means the data is being coerced from one type to another.

 

You can't have a 16-bit datatype be both signed and unsigned.  You are actually trying to force the chart to be a 17-bit integer to handle both U16 and I16.

 

What you should do is make your chart an I32.  Then both I16 and U16 will be coerced to that, but nothing will be truncated since the range of I32 can handle the ranges of both I16 and U16.

Message 2 of 10
(3,654 Views)
Solution
Accepted by rocket_author

This is how...

 

Untitled.png

--------------------------------------------------------

New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI


Message 3 of 10
(3,628 Views)

Many thanks to BTC_Admin and RavensFan for helping me work through this.  With the proper use of the converters and going to I32 to make the data types similar for switching, it works like a charm.  For those interested, see attached screenshot for how I ended up wiring this up.  Not particular complex or difficult, but it was getting the data types to work that was the challenge here.

0 Kudos
Message 4 of 10
(3,588 Views)

I don't see why you need the select function or the I16 to I32 conversion.  Just do an I32 conversion on whatever value comes in.

0 Kudos
Message 5 of 10
(3,563 Views)

@RavensFan wrote:

I don't see why you need the select function or the I16 to I32 conversion.  Just do an I32 conversion on whatever value comes in.


I can't quite explain it as I'm just responding to what the other engineers that I'm working with want, but apparently the array from which we pull sub-arrays and elements is only unsigned from the source, and based upon what array it is, they want to be able to interpret it as a signed number or unsigned number.  I'm not saying it's the most logical or efficient way to go about things, but this is legacy software that is already in place that they originally needed updated to Windows 7, and now a year later I'm still tweaking it for whatever changes get piped down from our customer so you know how that goes.  Just when I think I'm getting done, they come back without small request.  The upside is that I've learned a heap about Labview and feel much more comfortable in it because I've had to problem solve.  

0 Kudos
Message 6 of 10
(3,538 Views)

Maybe you need to do a typecast on it.  Typecast it as I16 then use the bullet conversion to I32.  For the other path, just use the I32 bullet conversion, then select which one you want to pass on.

 

How do the other engineers determine whether a particular value is supposed to be signed or unsigned?

0 Kudos
Message 7 of 10
(3,528 Views)

Typecast was something I looked into, but simply couldn't find good documentation on its proper usage.  I would love to find some useful info and sample code; the detailed help of Labview just didn't give me the info I needed.  That being said, I'm an electrical engineer learning Labview largely by trial and error with no real training or reference materials, so perhaps my slope is steeper than it needs to be and software engineers would have a better background for this stuff.

 

As far as how the other engineers know if what they're looking at should be signed or unsigned, we have a "data dictionary" that breaks up every section of the array that is being read.  It changes often as things are moved around, as we're still in deep development.

0 Kudos
Message 8 of 10
(3,526 Views)

Please tell us where you think the detailed help for typecast is lacking?

 

Everything in a PC is stored in memory as one or more bytes.  The typecast function tells how to intepret those bytes.  Let's say you have 8 bytes in a row containing some bit pattern.  You could interpret that as a series of ASCII characters as a string.  Or as a double precision floating point number.  As a Signed 32-bit integer, or an unsigned 32 bit-integer.  It could even be looked as as an array of 8-bit, or 16-bit integers.

 

Typecast lets you redefined a piece of data to be interpreted as another type of data.

0 Kudos
Message 9 of 10
(3,521 Views)

I'm in the middle of work so let me get back to you on this, hopefully this evening or tomorrow if I have some free time.

 

Thanks again for all the help.

0 Kudos
Message 10 of 10
(3,519 Views)