LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a string of bits to send out through VISA Serial questions, complete noob here...

Solved!
Go to solution

Hello all,

I'm trying now to scan through the values I have on my GUI clusters, and with those, construct a message to send through VISA.

 

I have the NI usb-> rs232 cable, and I've attached a connector to it, with pins 2 and 3 tied together so I can loopback and see the messages I'm sending.

 

I'm supposed to (from the instructions I'm reading on a design doc)  to send out a message 24 bits long.

And please bear with me, I've never worked on this low of a level before, nor with serial interfaces, so I may be completely off on how I"m trying to do it....and this is my

first stint really with LabView for this project.

 

I have a while loop executing every 20ms.

 

I have an event structure looking for user actions on my front panel.

 

I have also within that while loop, a flat sequence structure.....my assumption was, every 20ms, the flat sequence structure would execute, unless interrupted by an event....which would fire off, and then continue with the flat structure...

 

I saw the VISA write (and read) took a string.

 

So, I started the flat structure with constructing my outgoing bit/byte string....first section is hard coded, and then, through the next two sequences, it loop through,and based on the values of controls within each cluster, I concatenate to my outgoing string......at which case, I send it through the visa through the loopback, and display it on the message indicator.

 

It appears, that I can only send out 8 bits at a time through VISA...so, I'm trying to figure out (and I'm asking the people with the req about this part) why they said to send out such a long string....or, am I supposed to send out each 8 bit message, one at a time?

 

If the one 8 bit message at a time, I'm wondering how I let it know when I'm done?  I've heard and read things about start and stop bits, but I don't know where to put those.

 

Also, is the string what I'm supposed to be putting together to send for something expecting serial bit/byte data? I'd seen one reference to a byte string while researching, but I coulnd't find a byte string component on the palletes.

 

And when I run this (a simpler example of my real app, just showing here the parts I'm trying to figure out)....the message echoing back to me is:

 

111000010000\n

 

When if I have all tubes with a value in them....that I'd get something back like:

 

1110000111111110111111110\n

 

I'm also observing that the messages don't seem to be transmitting every 20ms....only seem to get a message back when when I trip an event, like the enable LEDs button.

 

Anyway, I'm confused I think, on some basic principals, and hope someone can maybe send me some links or give me some pointers on where I'm going so seriously wrong....

 

Is my string message construction the correct way to go?

Is something wrong with the program flow...the events + flat sequence structure?

 

I've gotten this far by searching forums and other NI papers, but I'm kind of stuck and confused I think on some concepts with VISA read/writes...and possible my flow control.

 

Any suggestion and/or links GREATLY appreciated.

 

Thank you,

 

cayenne

 

ps. some have asked to save for older versions, so I'm attaching a copy saved to v10 in addition to 2011

Download All
0 Kudos
Message 1 of 29
(5,329 Views)

You're misunderstanding some things. Event structures wait until events happens, thus your loop wont spin until an even happens ...

You can wire the 20 to the event timeout and place your communication in the timeout case, then it'll wait 20ms, perform the visa stuff, and if another thing happens while waiting it'll be performed.

 

//Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 29
(5,311 Views)
Ah, thank you. Ok, so I wire to the event 20ms....and move my looping to build the message section in there...I'll look into that. Thank you. Anyone else...with regard to the building of the bits into a string to send out over the usb to serial cable that I currently have in loopback mode? My questions on that with regard to am I building a binary message right (concatenating into one big string....and why I'm seeing what I am echo'ed back)? Thank you, cayenne
0 Kudos
Message 3 of 29
(5,287 Views)

You also don't understand the difference between bits and bytes. You state you have to send out 24 bits but your code does not reflect that. Your very first frame in that needless sequence structure builds a string with 8 characters. Each character is a single byte. so what you are sending there is 64 bits. The character '1' is not at all the same thing as a single '1' bit.

 

p.s. And please, learn a little about for loops and arrays. The indexing you are doing is all wrong. Simply wire in the array so that it autoindexes.

Message 4 of 29
(5,280 Views)

This post is basically a re-hash of another of his post on the same topic  http://forums.ni.com/t5/LabVIEW/Any-good-examples-of-constructing-and-parsing-byte-data/m-p/2051636

0 Kudos
Message 5 of 29
(5,267 Views)
Solution
Accepted by topic author cayenne

cayenne,

Your sequence structure is not needed.  You have a data dependency, so the sequence structure isn't really doing anything for you.  Seems to me that what you want to do is build the array from your clusters as you already have and send the array straight into a >0? function.  It will accept arrays and output a boolean array.  You can then use the Boolean Array to Number function to create a U8.  Do this for each of your clusters and build the results into an array of U8 along with your constant data.  Then use the Byte Array to String function to get a string to pass into the Write VISA.  No loops or structures needed.  Any additional manipulation you may need, I would recommend doing at the byte level.

Spoiler

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 29
(5,263 Views)

@Dennis_Knutson wrote:

You also don't understand the difference between bits and bytes. You state you have to send out 24 bits but your code does not reflect that. Your very first frame in that needless sequence structure builds a string with 8 characters. Each character is a single byte. so what you are sending there is 64 bits. The character '1' is not at all the same thing as a single '1' bit.

 

p.s. And please, learn a little about for loops and arrays. The indexing you are doing is all wrong. Simply wire in the array so that it autoindexes.


Thanks for the reply. No..I really have never worked with bits or bytes...i was just guessing that since the VESA write wanted a string, that is what I should send it.

 

Can you or someone give me an example of what constructing a proper string of 8 bits would look like vs the string I was putting together with 1's and 0's?

 

I've been looking at the string section...and haven't found a type of 'bit string'....?

 

TIA,

 

cayenne

0 Kudos
Message 7 of 29
(5,249 Views)

@crossrulz wrote:

cayenne,

Your sequence structure is not needed.  You have a data dependency, so the sequence structure isn't really doing anything for you.  Seems to me that what you want to do is build the array from your clusters as you already have and send the array straight into a >0? function.  It will accept arrays and output a boolean array.  You can then use the Boolean Array to Number function to create a U8.  Do this for each of your clusters and build the results into an array of U8 along with your constant data.  Then use the Byte Array to String function to get a string to pass into the Write VISA.  No loops or structures needed.  Any additional manipulation you may need, I would recommend doing at the byte level.

Spoiler

 


Thanks for the reply..!!

 

Ok...let me research on what U8 is....I've not worked with that data type before...

Interesting on treating this as boolean...hadn't thought of that either...makes sense, but I'd not thought that way before.

 

Ok, I'll give this a try tonight when I get back in front of LV!!!

 

Thank you,

 

C

0 Kudos
Message 8 of 29
(5,246 Views)

@cayenne wrote:

@crossrulz wrote:

cayenne,

Your sequence structure is not needed.  You have a data dependency, so the sequence structure isn't really doing anything for you.  Seems to me that what you want to do is build the array from your clusters as you already have and send the array straight into a >0? function.  It will accept arrays and output a boolean array.  You can then use the Boolean Array to Number function to create a U8.  Do this for each of your clusters and build the results into an array of U8 along with your constant data.  Then use the Byte Array to String function to get a string to pass into the Write VISA.  No loops or structures needed.  Any additional manipulation you may need, I would recommend doing at the byte level.

Spoiler

 


Thanks for the reply..!!

 

Ok...let me research on what U8 is....I've not worked with that data type before...

Interesting on treating this as boolean...hadn't thought of that either...makes sense, but I'd not thought that way before.

 

Ok, I'll give this a try tonight when I get back in front of LV!!!

 

Thank you,

 

C


Boolean Array answer

Message 9 of 29
(5,243 Views)

Thank you guys...

I'm getting closer, I've taken your examples...and trying to send it through the VISA, through the loopback and display the bits in on the front panel again...instead of the sets of 1's and 0's...I"m getting 127.

 

Can someone give me an idea where I'm going wrong with the translation of the byte data coming back to me...I'm reading the examples here and that other thread (thank you, I'd forgotten about that one)....I am closer to understand how to generate them, but when I receive them, I'm still hazy on how to convert from the string, and then go through it to test values or to print them to the screen on the front panel.

 

I think I'm close, but I'm just missing something...

 

Suggestions?

 

And again...thank you for your patience....I have never worked on this low of a level before, and please I know this example still has flow problems, etc...I'm only using this to try to get the concept of the construction, sending and receiving of the byte data....

 

cayenne

0 Kudos
Message 10 of 29
(5,205 Views)