Discussion:
Bit-wise decoding/encoding of Strings for VISA serial UART
(too old to reply)
jeremyhannon
2007-06-13 22:10:12 UTC
Permalink
I have written a VHDL program to reside on a CPLD on a board that we are designing.  In product it should be talked to serially so I'm trying to use Labview to communicate to this board byte-by-byte over the serial port (COM1) of my computer. 
 
As a new Labview user I'm currently stuck on how to convert the in/out strings used with the VISA Serial controler into a form that I can use.  I'm specifically trying to send sets of 2 or 3 8-bit packets and then do bit-wise operations on each packet.
 
1)  I've found the "String to array of bytes" function, but also have seen references to a 512-character lookup to convert ASCII text into bytes.  Will both of these approaches work?  I'm concerned because I've seen that there are regular strings, hexadecimal strings, decimal strings, etc.
 
2)  What is the Labview function to convert a U8 byte into an array of booleans?  What about the other way, array of booleans to byte?
 
Does anyone have any example code where they've tried something similar?
 
I am using Labview 8.2
 
Stephanie J
2007-06-15 03:10:07 UTC
Permalink
Hi Jeremy,
1) You can use either. From the LabVIEW Help on the String to Byte Array: Converts a string into an array of unsigned bytes. Each byte in the array has the ASCII value of the corresponding character in the string. So you can use any type of string and basically does what you also mentioned.
2) You can use the Number to Boolean Array (and vice versa) for this.
Stephanie
jeremyhannon
2007-06-19 19:40:13 UTC
Permalink
Thanks, that solved my issue.  I can now create a boolean array -> Array to Num -> convert to U8 -> build array -> byte array to string -> VISA transmit, which seems to do the trick.
 
However, a few more questions.
1)  Is there a way to send a full eight-bit binary value through the VISA Transmit and Receive functions?  I've discovered that since they require string inputs, they are limited to ASCII, which is a 7-bit format.  If I convert an eight-bit number with MSB = '1' into a string I think it comes out as a space or some wierd character.  Are there any other serial functions that I can use to operate a full Serial UART interface?  (I'm trying to run a 115.2 Kb/s, 8-bit, Odd-Parity, 2-stop bit, no flow control interface)
 
2)  Can you use the same VISA name for two ports?  I'm trying to use the VISA to control both the Tx and Rx of the serial port on my computer.  Therefore in "Measurement & Automation" I have COM1 set to my serial port.  Inside my Labview program, I configure the port, then pass the Resource Name onto my VISA transmit and to the Property Node and VISA Receive for my Rx.  However, the property node always indicates 0 Bytes available, even when in hardware I have the Tx looped back into the Rx.  Could this be due to VISA naming?  And just to check, if my desired functionality is to read in a byte from the serial port (with the VISA receive function) every time data is available, is the best way to use the Property Node to indicate when bytes are available?
 
3)  How can you prevent a while loop from running the first time, before it evaluates logic for it's STOP?  I have a control panel Start button wired to the STOP button, and I desire for the whole loop to only run when that Start button is pressed.  However, it appears that the loop continuously evaluates the loop, runs once, evaluates the STOP, decides to stop, then since the loop is finished, begin to pull in inputs and run the loop again before realizing that the STOP condidition is true?  This is causing my serial transmitter to always be on.  I have also been repeatedly crashing the Labview software today, so perhaps there is a bug in the software.  Along with this issue, is there any way to conditionally prevent a function from running?  Like if I only wanted to add a value to an array if it was non-zero?
 
Jeremy
Dennis Knutson
2007-06-19 20:10:13 UTC
Permalink
When you send anything between x00 and xFF to the VISA Write, that is exactly what is being sent - all 8 bits. If you create an indicator on the Write Buffer input, go to the block diagram, right click and select Hex Display, you will see the correct information. Normal Display (such as a default probe uses), will not show unprintable characters.
I'm not sure what you mean by two ports. If you are looping back tx of Com1 to rx of Com1, then you have a single port and it soounds like you've done the correct thing with your LabVIEW code. If you are using Com1 and Com2, then the VISA Write and the VISA Read would require different resource names. If you go into Hyperterminal with the loop back on, does it work there?
I'm a little confused about your description of the while loop. When you click the run button on the tool bar, the while loop will Start and you would normally Stop the while loop with a front panel control. Are you nesting a while loop inside a case statement and is the case statement nested inside an outer while loop? Posting an image or (even better), the code iteslf will help make things clearer.
Yes, you can optionally add an element to an array. One of the basic techniques to do this is to use a shift register and inside one of the cases, use the Build Array function to add the element. The other case just wires the shift register straight through. I would suggest you look at the shipping examples. One that has been around foresever is Fundamentals>Arrays and Clusters>Separate Array Values.
jeremyhannon
2007-06-19 23:40:11 UTC
Permalink
Problems solved, thanks for your help.  Using Case statements with shift registers was effective at only incrementing my arrays when desired.  Regarding the VISA Write/Read, I chained them together so that the Read only executes after the Write and then passes the resource name back through a shift register.  I think a key was that I needed to alternate write, read, write, read ... in order to catch all of the bytes I was sending.  Originally I had only caught the last one as the Tx loop exited.  Regarding the While Loop, I was expecting the while loop to never begin until I had triggered it, rather than only stopping it on a condition.  However, I created a state '0' that does nothing and then the real operations begin in state 1, 2, etc, so that constantly running state '0' and stopping, running state '0' and stopping is ok.
 
Jeremy

Loading...