12-31-2009 10:52 PM
Ok, i saw some forum discussions about how to make LabView talk with PIC18F4550, and did not find any solution up there, usually all the topics ended with nothing.
Ok, here is what i have done so far:
Microcontroller part: I have downloaded the Microchip Solutions example, compiled the example for PICDEM board, however i did not have PICDEM board, so i just assembled my own simple board with minimal elements. I runned that example on my PIC18F4550 and used the standard Human Interface Device driver, i runned also the example application and could toggle LEDs and read Potentiometer values. Then, once i saw that the device is working, i have uninstalled the driver and disconnected my device from USB.
Now: I have found the manual on the NI website, which says how to generate driver using NI-VISA tool, i have gone through that, and successfully generated driver for my device, then i installed this driver, plugged my USB with PIC, and could see its properties etc.
So far seems ok. Now, seems like a last step, i want to read data lets say from potentiometer through the PIC.
According to the previous manual, i am running now VISA Interactive Control tool, what im going to do now is to send some requests to my PIC and get answer/data from it.
take a look at some part of the firmware code on my PIC:
void ProcessIO(void) { //Blink the LEDs according to the USB device status if(blinkStatusValid) { BlinkUSBStatus(); } // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if(!HIDRxHandleBusy(USBOutHandle)) //Check if data was received from the host. { switch(ReceivedDataBuffer[0]) //Look at the data the host sent, to see what kind of application specific command it sent. { case 0x80: //Toggle LEDs command blinkStatusValid = FALSE; //Stop blinking the LEDs automatically, going to manually control them now. if(mGetLED_1() == mGetLED_2()) { mLED_1_Toggle(); mLED_2_Toggle(); } else { if(mGetLED_1()) { mLED_2_On(); } else { mLED_2_Off(); } } break; case 0x81: //Get push button state ToSendDataBuffer[0] = 0x81; //Echo back to the host PC the command we are fulfilling in the first byte. In this case, the Get Pushbutton State command. if(sw3 == 1) //pushbutton not pressed, pull up resistor on circuit board is pulling the PORT pin high { ToSendDataBuffer[1] = 0x01; } else //sw3 must be == 0, pushbutton is pressed and overpowering the pull up resistor { ToSendDataBuffer[1] = 0x00; } if(!HIDTxHandleBusy(USBInHandle)) { USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64); } break; case 0x37: //Read POT command. Uses ADC to measure an analog voltage on one of the ANxx I/O pins, and returns the result to the host { WORD_VAL w; if(!HIDTxHandleBusy(USBInHandle)) { mInitPOT(); w = ReadPOT(); //Use ADC to read the I/O pin voltage. See the relevant HardwareProfile - xxxxx.h file for the I/O pin that it will measure. //Some demo boards, like the PIC18F87J50 FS USB Plug-In Module board, do not have a potentiometer (when used stand alone). //This function call will still measure the analog voltage on the I/O pin however. To make the demo more interesting, it //is suggested that an external adjustable analog voltage should be applied to this pin. ToSendDataBuffer[0] = 0x37; //Echo back to the host the command we are fulfilling in the first byte. In this case, the Read POT (analog voltage) command. ToSendDataBuffer[1] = w.v[0]; //Measured analog voltage LSB ToSendDataBuffer[2] = w.v[1]; //Measured analog voltage MSB USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64); } } break; } //Re-arm the OUT endpoint for the next packet USBOutHandle = HIDRxPacket(HID_EP,(BYTE*)&ReceivedDataBuffer,64); } }//end ProcessIO
As you see it is ProcessIO function, with its main switch statement, for example case 0x37: means if it gets this value from host, then it must send value of the Potentiometer to USB host.
Now, what i tried to do is, in the VISA Interactive Control, i selected the Interface I/O tab, and then tried to send the request with the value 0x37 in the wValue field, the bmRequestType was 0x0, and what i get is weird values which i dont think are actual values of the Potentiometer reading.. (i tried change potentiometer, then do request again, and got same values)
also i tried to experiment with Basic I/O tab, and got same weird things...
so...at this stage, what am i doing wrong? what do i have to/supposed to do now?
or could u point me to valuable information source?
or the LabView Guru's on this website, say me please your opinion about this?
Solved! Go to Solution.
01-01-2010 01:50 PM
OK! i will make it more clear..
So, without LabView, my Host application for example sends 64 byte data packet to Device, the second byte has the value 0x37, once the Device received this, it replies with the same 64 byte message in which 3rd and 4th bytes have the data needed by Host.
Then, Host application just uses those 3rd and 4th bytes for its purpose.
So, again...my hardware works good with software. I uninstalled that driver, and successfully installed the VISAs driver, and now i want to realise the same schematic in LabView... so any ideas how can i do it? Or point me?
Thanks!
01-01-2010 02:55 PM
First, I would like to remind you that this is a holiday and you are not likely to get many response.
Second, there are a series of posts about USB communication that you should read. The first one is here.
Third, I don't understand at all why you would discard a working driver for the HID class and use VISA. Why don't you keep the working driver and interface to HID.dll with the call library function node?
01-01-2010 04:58 PM
First, I would like to remind you that this is a holiday and you are not likely to get many response.
>> Well, then thank You that for replying me during a holiday, and happy new year!
Second, there are a series of posts about USB communication that you should read. The first one is here.
>> I will study it now, it didnt hit my eye before.
Third, I don't understand at all why you would discard a working driver for the HID class and use VISA. Why don't you keep the working driver and interface to HID.dll with the call library function node?
>> Could you tell me more about this? So..in other words i can use some built in library functions of LabView to communicate with HID device with specific PID and VID by talking with HID.dll (in C:\windows\system32) right?
So as i see there are two ways to do this job:
1. Having VISA generate driver for you, and then write down a VI which would talk to that driver...right?
2. Call library functions talking with HID.dll
In the method 1, do i have to use NI-VISA programmers reference manual? Or something else?
In method 2, do i have to use this manual: http://www.ni.com/pdf/manuals/370109b.pdf - Using External Code in LabView ? Is that correct place to start with?
01-01-2010 11:50 PM
Ok, im surfing the web and NI website in order to find at least one example dealing with USB, which does something using call library function node... no luck..
so what i am doing now i created the vi, and in the block diagram placed call library function node, and lets say now i want at least read a string from my device, a product string. but im unsure exactly about what values does that element need as input...since im only reading...but LabView says its kinda error and does not execute...
again if there would be at least any example, or if someone knows about call library function node interfacing with HID.DLL could you please point me? that would help alot...
(do you really think choosing this method of USB communication would be faster/easier than using custom driver created by VISA?)
thanx