Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

PIC USB connection using Visa4.3.0

Hi,

I am very new to the Labview and Visa. I have designed a hardware with PIC18F4550 microcontroller which supports USB module. The device consists of 4 LEDs which will be the indicator for the output. I am trying to make a simple input and output device using USB interface. I am using Labview 8.2 for the client software also NI-Visa 4.3.0 for the driver wizard.

I got the USB framework  (MCHPFSUSB) from the Microchip website (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1999&ty=&dty=&section=&NextRow=&ssUserText=mchpfsusb) and I used it to program the chip . I have created a driver using  NI-Visa and I have followed the procedure according to the tutorial from the NI website. Everything works fine until this point. When I open the "Measurement and Automation", I could find my device in the list. The resoruce name is shown as:  USB0::0x0401::0x00AA::NI-VISA-0::RAW. The attribute setting that i got from the "Measurement and Automation" is:

Timeout Value = 2000
Maximum Queue Length = 50
Termination Character = 0x0A
Termination Char Enable = VI_FALSE
IO Protocol = 1
Suppress End on Reads = VI_FALSE
USB Maximum Interrupt Size = 64
USB Control Pipe = 0x0000
USB Bulk-Out Pipe = 0x0001
USB Bulk-In Pipe = 0xFFFF
USB Interrupt-In Pipe = 0x0081
USB Alternate Setting = 0
USB Bulk-Out Pipe Status = 0
USB Bulk-In Pipe Status = -1
USB Interrupt-In Pipe Status = 0
USB End Mode for Reads = 5

For my first experiment, I just want to turn on and off the LEDs using a command from the Labview. I assume that the output will be controlled by the "Visa USB Control Out" (correct me if I am wrong), however it needs a set of input that I do not really understand. What do I have to fill in as the index, value, request type, and request for the  "Visa USB Control Out" ? Can someone help me? Thank you


Regards,
Hary
0 Kudos
Message 1 of 14
(5,091 Views)
After I looked through the C code, i figure out that I need to send an information in the form of "data packet". The C code for the data packet is like shown below:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef union DATA_PACKET
{
    byte _byte[USBGEN_EP_SIZE];  //For byte access
    word _word[USBGEN_EP_SIZE/2];//For word access(USBGEN_EP_SIZE msut be even)
    struct
    {
        enum
        {
            READ_VERSION    = 0x00,
            ID_BOARD        = 0x31,
            UPDATE_LED      = 0x32,
            DO_SUM        = 0xEE,
            RESET           = 0xFF
        }CMD;
        byte len;
    };
    struct
    {
        unsigned :8;
        byte ID;
    };
    struct
    {
        unsigned :8;
        byte led_num;
        byte led_status;
    };
    struct
    {
        unsigned :8;
        word word_data;
    };
} DATA_PACKET;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


When UPDATE_LED is active, this command will be executed:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case UPDATE_LED:
                // LED1 & LED2 are used as USB event indicators.
                if(dataPacket.led_num == 3)
                {
                    mLED_3 = dataPacket.led_status;
                    counter = 0x01;
                }//end if
                else if(dataPacket.led_num == 4)
                {
                    mLED_4 = dataPacket.led_status;
                    counter = 0x01;
                }//end if else
                break;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I am not really sure what data need to be sent from the labview. Is it has to be a byte?
I have tried using "Visa write" icon from labview to send a byte data but it seems of having no response. Do I need to specify the endpoint ? I tought endpoint0 is already configured when I attached the device to the computer.

0 Kudos
Message 2 of 14
(5,073 Views)
mura1ma,

There are a few things that I can suggest from what you sent me. First, I would try to communicate with your device using on of the LabVIEW shipping examples in the Example Finder. The example is called USB RAW - bulk.vi  and it utilized VISA reads and writes to accomplish communication with the device, you should not use the control VI unless you know your device needs to communicate in that specific form.

This however leads to my second concern, that is that I don't know what to send to your device or any of the other settings. The code you attach are just some structs that do not make any sense on their own. The way the VISA write works is that it sends an ASCII string of characters to the device, and on the low level it sending the representation of the ASCII. I would look for where in the documentation it shows what what parameters your device is expecting to receive.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 3 of 14
(5,053 Views)
Thank you for you reply MIX Master,
I am still a bit unclear about the data that VISA send. If I dont specify any endpoint (using Visa write icon) does it mean that I am sending the data to endpoint 0 ?
If I want to send data properly, should I specify the bmRequestType, bRequest, wValue, wIndex, and wLength?
0 Kudos
Message 4 of 14
(5,034 Views)
Hi,

Finally I realise that my input data has to be in byte. I am not really sure what happen after the ASCII data is passed through visa into the device. I have looked at how Labview stores strings and I am not really sure as to how it works. If I want to receive a byte representation of "00000001" what must I input in to the Visa buffer? (The buffer accept string only).

Thank you again
0 Kudos
Message 5 of 14
(5,004 Views)
A bit more detail of the previous question,

I have looked at how Labview stores strings and I am not really sure as to how it works. The help says that Labview stores a string as a series of bytes. The first 4 bytes stores the string length as a 32 bit sign integer and the following bytes each contains a character of the string. This complicates matter for me because I only want to send a byte as the input to my device. If I want to receive a byte representation of "00000001" what must I input in to the Visa buffer?

My question is: if I want to receive a byte representation of "00000001" what must I input in to the Visa buffer? (The Visa write buffer accept string only).

Thank you again
0 Kudos
Message 6 of 14
(5,002 Views)
ASCII is just a representation of HEX numbers, so when you send a "1" in ASCII it is represented by "0x01" in Hex or "0000 0001" in Binary. There are a number of different string conversion tools that will change the data type from numbers to strings for you and format them properly to be sent to your device. You can find them in the Programing»Strings»String/Number Conversions on the Functions Pallet.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 7 of 14
(4,983 Views)
Thank you. Finally I can send and receive data between the computer and the device. I just realised that I have not select the 'display style' of the write buffer in hex.
Is it possible to send a continuous data from the microphone to the computer using Visa?
0 Kudos
Message 8 of 14
(4,931 Views)
VISA uses buffered writes, so as long as you make sure there is data to send out in your buffer, it will continuously write to your device.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 9 of 14
(4,896 Views)
Hi mura1ma,

we are experiencing the same problems like you trying to communicate with a PIC18F4550 (with CVI).

Could you please post your VI (or an example) with which you finally could write to / read from the PIC?

Best regards

Philipp R.
0 Kudos
Message 10 of 14
(4,725 Views)