From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can you split a byte in 8 bits?

Hello all,
 
I am a student in my training period working with Labview.
I made a tcp/ip connection in labview with socket workbench,
For testing i am sending 1 byte at the time to labview. Labview recieves that byte and i can see it.
Now i want to split that byte in labview in 8 bits.
(For example to read the outputs of a PLC)
 
Does someone know how to do this? or is there a standard example in labview to do this?
 
 
greets, mukkel

Message Edited by mukkel on 09-09-2005 02:27 AM

0 Kudos
Message 1 of 19
(25,761 Views)
Perhaps the attachment below will help

0 Kudos
Message 2 of 19
(25,733 Views)

In TCP, LV uses a bytestream represented as a string. To see the actual bits, you need to convert the string to an array of numbers (String to Byte Array VI), then extract the number you want (Index Array. If there is only one byte, it will be the first element in the array) and change it into a boolean array (Number to Boolean Array). These VIs can be found in the String>>Additional..., Array and Boolean palettes. Pretty simple, huh?

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).

Message Edited by tst on 09-09-2005 10:44 AM


___________________
Try to take over the world!
Message 3 of 19
(25,733 Views)
Hello Mukkel,

I think the attached VI does what you need, the function, of course comes bilt-in with LabVIEW.



We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 4 of 19
(25,730 Views)
Thanks for all that quik help.
 
I've made a VI (see atchment)
 
It can read and write bytes. Continu recieving files is no problem.
 
But it keeps sending bytes. (the delay is just for testing so i can read the data)
Now i want to make a kind of switch/button that must be pressed before a byte will be send.
Then i can set a value first and then send it.
Does someone know how?
 
0 Kudos
Message 5 of 19
(25,699 Views)
The send loop is set to only terminate on an error condition, is this what you intended ?

There is a button to cause it to start sending data, but you will have to decide what condition will stop the send loop.

Perhaps you don't need the while loop for the transmit portion of your code?

0 Kudos
Message 6 of 19
(25,686 Views)
Have a look at the 4.x mode of typecast. It allows you to go directly from string to boolean array and back, eliminating the U8 middleman. 🙂
 
(I also don't understand why you need to go via a boolean cluster, go to an array directly. See attached image of a code draft)
 

Message Edited by altenbach on 09-09-2005 09:14 AM

Message 7 of 19
(25,682 Views)

Thanks, altenbach that's the one I was trying to remember for an example. I had forgotten to go for the 4.X variant.

As an aside - how does one post a picture in the forum direclty ?

0 Kudos
Message 8 of 19
(25,665 Views)


@Conseils wrote:
As an aside - how does one post a picture in the forum direclty ?
  1. Attach your image, then go back and edit the post.
  2. Right-click on the attachment link and "copy shortcut".
  3. Go to the desired text location.
  4. Click on the "insert an Image" icon and paste the shortcut (just hit ctrl+v).
  5. Submit. 😄


Message 9 of 19
(25,659 Views)
HI all.
 
Thanks for all the help.  I got the right VI now made out of your examples.
The type cast 4X doesnt work how i wanted. If i placed that one it sends 2 bytes thats 1 to much 😉
But it is fixed now.
 
greets mukkel
 
0 Kudos
Message 10 of 19
(25,601 Views)