05-10-2018 06:49 PM
Hello all,
I'm working with a system with currently consists of a python gui that controls a piece of hardware through serial usb communication with an arduino and need to convert the GUI to LabVIEW. In essence, the python script is generating 128 points of a sine wave and writing them to the arduino, which parses the data and sends it to a DAC IC via SPI. When the arduino is ready to receive data, it sends FF over the serial port. So far, I have a code that initializes the VISA device, generates a waveform 128 points at a time, and writes them to the device. However, I'm getting an error when I try to write the data using NI VISA in LabVIEW.
If I write "\r\n" (hexadecimal D, A) to the COM port, I get no errors, but when I try to write 128 16-bit zeros (256 8-bit zeros), followed by "\r\n", I get the error:
VISA: (Hex 0xBFFF0000) Unknown System Error (miscellaneous error).
I realize this is all very vague, but there's a lot going on so I'm trying to keep it simple and seek guidance of where to begin in trouble shooting.
Here are snapshots of the code pertaining to the VISA communication. I don't have much experience with serial communication with labview, so I just want to make sure I'm not doing something obviously wrong.
05-10-2018 08:55 PM
Probably not hitting on the exact issue, but here are some things to note:
1. Your Data To U8 VI could be replaced with a Flatten To String followed by a Concatenate String to add the End Of Line Constant.
2. Since you are transmitting and receiving binary/hex data (not printable characters according to ASCII), you should not be using the termination character. Something else in your protocol should be stating how many bytes are in the message.
3. It is typically a bad practice to mess around with the VISA buffer sizes. The defaults are typically larger than you need anyways. This would be my first thing to really look at when it comes to the error you are seeing.
4. You have a bunch of byte array constants followed by Byte Array To String. Just use a string constant and set the view to be Hex. It will make things more obvious.
5. Whenever you use a display that is not the default for numerics and strings, you really should turn the "radix" or "display style" visibility to TRUE. Helps to avoid confusion.
05-10-2018 09:13 PM - edited 05-10-2018 09:37 PM
Thanks Crossrulz,
1. I had originally used number to string > Flatten String > Concatonate Strings - a colleague I spoke to recommended I stick with the U8 to Byte Array String. Are there advantages/disadvantages to either? After reading this again, I think you meant to wire the U8 array directly to Flatten to String. Is that right? I set the string indicator in the Data to U8 subVI to Hex View, but it seemes it is adding extra information in the beginning of the array. I tried to create an array of 128 FF U16 values (128 repetitions of 00FF). There is an extra 0000 0100 added at the beginning though for some reason (see screenshot)
2. Okay - I was using a Termination Character because I was getting a Timeout Error when I was not sending one. I have now set the T/F for "Termination Character" on the VISA Configure Serial Port VI to F. Should that resolve that timeout error?
.
3. I'll try not specifying buffer size - the only reason I did was because it was done in the python script I'm trying to replicate. I'm guessing that more of these low-level functions require definition in python. Should I still create one and just not specify a size? Should I remove the "Flush Buffer" vi after it?
4. Not exactly sure what you mean by using a string constant. In the snapshot I posted, I was trying to write 128 zeros to the buffer to initialize it with some data (may or may not be necessary. After initializing it (downstream of what you can see in the snapshot, I will be generating 128 points of a waveform, passing it to a queue for a producer/consumer loop, and writing those 128 points to the write buffer (or at least I hope to). I guess you're suggesting converting an array of n U16 values to 2*n U8 values to a string containing the concatonated hex values? Before I get there though, I need to resolve the issue with writing to the darn thing.
5. Not sure what you mean by the display style to TRUE.
**After making the changes mentioned here (eliminating termination character on VISA config, sending U8 array to Flatten String before VISA write, not specifying buffer size), I am still getting the same error. BLAST! Current configuration in screenshot VI_2.png
05-10-2018 09:44 PM
I also tried concatenating the strings after flatten string before writing, and still get the same error.
05-11-2018 06:35 AM
@dmhuffman2010 wrote:
1. After reading this again, I think you meant to wire the U8 array directly to Flatten to String. Is that right?
No, I am referring to the U16 array. If you already have a U8 array, then just use Byte Array To String, which actually compiles to a noop. But with the U16, you eliminate steps by just using the Flatten To String. Another benefit if the Flatten To String is that you can set the Endianness (big vs little).
@dmhuffman2010 wrote:
2. Okay - I was using a Termination Character because I was getting a Timeout Error when I was not sending one. I have now set the T/F for "Termination Character" on the VISA Configure Serial Port VI to F. Should that resolve that timeout error?
This is a problem in your protocol. Do you have it fully defined? Do note that if you are sending hex/binar data, you cannot use a termination character since your data could potentially have a byte that matches it. Typically when talking to an Arduino, ASCII formatted text is used and the the termination character works. You will need to use functions like Number To Decimal String to do this. But the Arduino also has functions to "printline and "readline".
@dmhuffman2010 wrote:
4. Not exactly sure what you mean by using a string constant.
I am referring to a bunch of U8 arrays immediately followed by Byte Array To String. It is much clearer if you just use a string constant.
@dmhuffman2010 wrote:
5. Not sure what you mean by the display style to TRUE.
Right-click on one of your constants. Go to Visible Items. For numerics, there is an option for "radix". For strings it id "Display Style".
05-11-2018 06:37 AM - edited 05-11-2018 06:48 AM
@dmhuffman2010 wrote: I tried to create an array of 128 FF U16 values (128 repetitions of 00FF). There is an extra 0000 0100 added at the beginning though for some reason
That is the array size. There is an input on the Flatten To String to disable that.
EDIT: Adding example