07-29-2012 05:04 PM
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
Solved! Go to Solution.
07-30-2012 01:49 AM
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
07-30-2012 09:40 AM
07-30-2012 09:49 AM
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.
07-30-2012 10:25 AM
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
07-30-2012 10:33 AM - edited 07-30-2012 10:34 AM
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.
07-30-2012 12:43 PM
@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
07-30-2012 12:47 PM
@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.
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
07-30-2012 12:51 PM
@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.
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
07-31-2012 08:37 PM - edited 07-31-2012 08:37 PM
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