Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting USB to Serial with MCU and LabVIEW

Solved!
Go to solution

Hello,

 

I have a USB to Serial connection with my microcontroller (MCU) and I'm trying to communicate with it using LabVIEW. I have gone as far as seeing my COM port in MAX  (it appears as COM 5) as well as in LabVIEW. 

 

Problem:

 

1. Using the example Basic Serial Write and Read.vi, I dont get any ny response from the mcu (Motorolla M68HC12). Im only transmitting 4 bytes to test a connection between LV and the mcu. The example runs for a few seconds and stops with no error message, and the front panel shows 0 bytes read.

 

2. Using the VISA Test Panels in MAX: I get Error BFFF0015 on viRead. I researched this error and the following knowledgebase stated that; For VISA Read operations, this error may be induced by attempting to read more bits than are available at the serial port. Since LV displays zero bytes read, I'm assuming thats the reason behind this error.

 

Question: Am I doing something wrong? e.g. commands in LV need to be written a certain way or am I missing a step in communicating with the mcu? Any ideas/assistance will be appreciated.

0 Kudos
Message 1 of 16
(5,609 Views)

This is a common error and more often than not, is a problem with your VISA Write, the serial port configuration, or the type of cable used.

 

Of course you need to write the command correctly for LabVIEW, just like you need to write it correctly for every programming language. You don't mention exactly what you are sending and what you expect to read. I would also recomend you try a standard terminal emulation program such as Hyperterminal, ProComm, TerraTerm, etc.

0 Kudos
Message 2 of 16
(5,609 Views)

Thanks for the information. I figured out a significant part of the problem. The characters i'm sending are in Hex, but MAX Test Panels interprates them as ASCII. I verified this in my MCU program. The following Knowledgebase showed me how to send Hexadecimal characters in the VISA Test Panels. And matching the return count in the viRead tab also helped in MAX. I believe I can now send and receive data in MAX.

 

Problem: 


The LabVIEW example is still a dud. Highlight execution shows all is OK. Im sending the following characters: Hex: 03 FD B5 B5 or as the knowledgebase describes: \x03\xFD\xB5\xB5 (which works in MAX). 

 

Any ideas will be appreciated.

 

Thanks.

0 Kudos
Message 3 of 16
(5,534 Views)
Solution
Accepted by topic author PSerial

How are you actually sending the characters? I hope you are not entering that \x string? There is nothing in LabVIEW that is going to interpret \x correctly. There have been countless posts on sending hex in LabVIEW. The easiest way is to simply right click on the string control/constant and select 'Hex Display' and simply type 03 FD B5 B5.

0 Kudos
Message 4 of 16
(5,528 Views)

That worked. Thanks 🙂

0 Kudos
Message 5 of 16
(5,524 Views)

(Hex display)

0 Kudos
Message 6 of 16
(5,523 Views)

Hello there, I'm now working with a project that is using USB serial. kinda similar to the topic discussed here. Yet i don't get the solution and still getting this error of: 

 

BFFF0015:

 

VI_ERROR_TMO

Timeout expired before operation completed.

 

I'm sending ASCII data. Any help would be much appreciated! Thanks in advance.

0 Kudos
Message 7 of 16
(5,441 Views)

Hey kawthar,

 

Have you tried verifying communication in Measurement and Automation Explorer or going through the troubleshooting steps listed in the first knowledge based article mentioned in this thread? The time out error can occur for a couple different reasons. Increasing the time out or adding a wait after your VISA write might work to get your communication line functioning properly. These processes are detailed in the above mentioned article. 

 

Were you able to communicate with your device previously or is this your first communication line to it?

 

Luke W

0 Kudos
Message 8 of 16
(5,430 Views)
Thanks for the reply Luke!
Basically, the problem I'm facing now is:
I'm using a transceiver module which I have installed in NI-VISA and it is recognized by MAX as follows:
USB0::0x10C4::0xEA60::0001::RAW
Manufacturer: Silicon Labs (0x10C4)
Model: CP2102 USB to UART Bridge
But I have some questions regarding the confusion:
1. I'm a bit confuse here whether it should be recognized as USB device or Serial COM Port because once it is USB recognized, I can't select COM port for examples and my project in front panel/block diagram. 
2. Is LabVIEW really compatible with SiLabs hardware devices because;
3. When I want to find NI Instrument Drivers in LabVIEW as for Plug & Play, although it is connected when scan for instrument, there is no SILab in manufacturer. 
4. In Open VISA Test Panel, for Basic I/O, vi read fails as return status shows error of BFFF0015. 
5. Even in LabVIEW, example of Basic Serial Write & Read, there is no response in read string.
It works fine with X-CTU. I have no idea in which field is the problem. Thanks again for helping!

 

0 Kudos
Message 9 of 16
(5,426 Views)

You are correct, there is not currently a driver for this manufacturer. Do you have the driver installed from the Silicon Labs website for your device?

I think this might be it: http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

It sounds like this may be necessary to have it recognized as a com port. If you recently installed a toolkit or newer version of LabVIEW (after the initial installation of this driver), you should try re-installing this driver

 

If you have this driver already, have you verified the commands and that they are in proper format/syntax?

 

Luke W

0 Kudos
Message 10 of 16
(5,422 Views)