LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

complex to byte array

I need to convert a complex single to a byte array for transmission via ethernet packet (with the inclusion of a checksum.

 

In Matlab:  you can use the following to get a byte array from a complex single:

 

cSingle = single(.1234+i*.3456);

bytes = [swapbytes(typecast(real(cSingle),

         swapbytes(typecast(imag(cSingle),'uint8'))];

 

Mathscript does not support the typecast or swapbytes functions.

 

So how can I convert the complex single to a byte array?

 

Thanks:

ARGOLD

'uint8')) ...

0 Kudos
Message 1 of 9
(6,901 Views)

 

cut/paste issue on the original:

 

bytes = [swapbytes(typecast(real(cSingle),'uint8')) ...

             swapbytes(typecast(imag(cSingle),'uint8'))];

 

0 Kudos
Message 2 of 9
(6,898 Views)

Do you really need to do this in MathScript? Seems much easier in plain LabVIEW. 😉

0 Kudos
Message 3 of 9
(6,882 Views)

Yes I need to do this in mathscript.  It is a small part of a bigger function and needs to be done in several places.  It would be silly to break the function up into multiple v.i.'s.

 

It is also easy to do in MatLab (as shown above) so why should it not be just as easy to do in mathscrtipt?

 

When you come right down to it, are we not just reading the hex bytes out of the memory?  The only real issue is to swap bytes or not to swap bytes.  That should be easy in any event.

 

Cordially,

ARGold

0 Kudos
Message 4 of 9
(6,877 Views)

Hey ARGold,

Please take a look at this list of functions if you have not already: LabVIEW MathScript Function List. This is the list of all functions we can perform in mathscript.

National Instruments
Applications Engineer
0 Kudos
Message 5 of 9
(6,838 Views)

I have searched through the function list and do not see how to solve this particular problem.

 

I need more specific help.

 

Cordailly,

ARGold

0 Kudos
Message 6 of 9
(6,835 Views)

You could possibly try and write the function yourself if the function isn't supported.  This might be more difficult, but if you absolutely cannot step outside of your mathscript to do the conversion, then this might be necessary.

 

http://zone.ni.com/reference/en-XX/help/371361B-01/lvhowto/defining_mathscript_functions/

 

Jon S

Applications Engineer
National Instruments
0 Kudos
Message 7 of 9
(6,807 Views)

Thanks Again Jon:

 

Your replies so far have been "mathscript 101".   The last reply is too general and high level to do anything with and common knowledge to all but the most novice of mathscript/matlab coders.

 

What I do need is more information about what is happening under the hood in the bits and bytes world of mathscript "classes"  (the term used by matlab to define all the data types).  This should be a relatively simple operation of extracting, byte by byte, the raw data from a given type (double, complex, single, etc.) and creating a byte array.  I need to know the specific instruction(s) to extract the bytes from the data type. Once done, the swapping operation should be easy.

 

Having written the above, here is a question you might be able to answer:  Can mathscript "call" a VI?  If so, I could write the function in labview and call it (repeatly) from mathscript...

 

Cordially,

ARGold

0 Kudos
Message 8 of 9
(6,803 Views)

Sorry Jon:

 

It wasn't you replying earlier...

0 Kudos
Message 9 of 9
(6,800 Views)