Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
learn:tutorials:libraries:linx:misc:custom_command_example [2015/06/29 18:53]
Sudharsan Sukumar
learn:tutorials:libraries:linx:misc:custom_command_example [2015/07/06 17:13] (current)
Sudharsan Sukumar
Line 1: Line 1:
 ====== Custom Command Example ====== ====== Custom Command Example ======
  
-This is an example on how to use a custom command to control an LCD display. ​ The LCD display used is the PmodCLP by Digilent.+This is an example on how to use a custom command to control an LCD display. ​ The LCD display used is the [[http://​www.digilentinc.com/​Products/​Detail.cfm?​Prod=PMOD-CLP | PmodCLP]] by Digilent. ​ 
 + 
 +{{:​learn:​tutorials:​libraries:​linx:​misc:​20150629_121254.jpg?​300|}}
  
 ==== Prerequisites ==== ==== Prerequisites ====
Line 10: Line 12:
 ==== Hardware ====      ==== Hardware ====     
 ----  ---- 
-Any [[learn:​libraries:​linx:​devices | LINX Device]].+Any [[learn:​libraries:​linx:​devices | LINX Device]].  In this case, a chipKIT WF32 is used.
  
 === Software ==== === Software ====
Line 17: Line 19:
  
  
-^  Firmware IDE  ^^+^  Firmware IDE Used  ^^
 ^Device Family^IDE^ ^Device Family^IDE^
-|Arduino|[[http://​arduino.cc/​en/​Main/​Software | Arduino IDE]]| 
 |chipKIT|[[http://​chipkit.net/​started/​install-chipkit-software/​ | MPIDE]]| |chipKIT|[[http://​chipkit.net/​started/​install-chipkit-software/​ | MPIDE]]|
 +// 
 +//
 === Procedure ==== === Procedure ====
 ---- ----
-The idea for this example was to write a string constant, convert into a U8 array, and display ​what you wrote in the string constant on the LCD display using MPIDE and the chipKIT WF32.+The idea for this example was to write a string constant, convert ​that into a U8 array, and display the string constant on the LCD display using MPIDE and the chipKIT WF32.
  
-  ​- Make sure you're using LINX 1.2 or later. +  - Generate Firmware
-  ​Generate the LINX firmware libraries in the appropriate location for your device'​s IDE by opening LabVIEW and under the Tools tab go to MakerHub --> ​ LINX -->  ​Generate Firmware ​Libraries. +
-  - Generally for MPIDE you want to generate the firmware library in C:​\users\*your name*\My Documents\mpide\libraries) +
-  - Restart the device IDE+
   - In the device IDE open the LINX example for the device and interface you're using. (In this case, **File>>​Examples>>​LINX>>​ChipKIT_WF32_Serial**)   - In the device IDE open the LINX example for the device and interface you're using. (In this case, **File>>​Examples>>​LINX>>​ChipKIT_WF32_Serial**)
-  - The examples are read only so save a copy somewhere.  This will be your custom firmware+  - The examples are read only so save a copy somewhere. 
-  - At the bottom of the firmware, after the void loop, add your custom function. ​ The function must return an **int** and must have 4 parameters: **unsigned char**, **unsigned char***, **unsigned char***, **unsigned char***. ​ Below is the function used. \\ +  - At the bottom of the firmware, after the void loop, the custom function ​is added.  The function must return an **int** and must have 4 parameters: **unsigned char**, **unsigned char***, **unsigned char***, **unsigned char***. ​ Below is the function used. \\ 
  
 <sxh c++; title: Custom Command PmodCLP >  <sxh c++; title: Custom Command PmodCLP > 
Line 47: Line 46:
   - **response** is a U8 array. ​ Fill this with the data bytes you want to send back to LabVIEW.   - **response** is a U8 array. ​ Fill this with the data bytes you want to send back to LabVIEW.
   - The function should return 0 (or use the L_OK constant) if everything went well, or an error number otherwise.   - The function should return 0 (or use the L_OK constant) if everything went well, or an error number otherwise.
-  - The following is the code required to initialize the display for 8-bit interface mode and then write the input decimal values ​onto the LCD display. ​ This includes function set, turning the display on, clearing the display, and setting the entry mode.  After this initialization process, the cursor will point to the first entry on the LCD display and will be ready to write. ​ Since the function must return at least 1 value, the response variable has one entry (0) and the number of response bytes is 1.+  - The following is the code required to initialize the display for 8-bit interface mode and then write the input from LabVIEW ​onto the LCD display. ​ This includes function set, turning the display on, clearing the display, and setting the entry mode.  After this initialization process, the cursor will point to the first entry on the LCD display and will be ready to write. ​ Since the function must return at least 1 value, the response variable has one entry (0) and the number of response bytes is 1.
  
  
Line 80: Line 79:
 int Channels[8] = {34, 35, 36, 37, 30, 31, 32, 33}; //This array contains the data bus pins from DB0 to DB7. int Channels[8] = {34, 35, 36, 37, 30, 31, 32, 33}; //This array contains the data bus pins from DB0 to DB7.
  
-int variable[8];​ //use for dummy array in order to bit shift the incoming integer value+int variable[8];​ //use for dummy array in order to bit shift each input byte
  
 // FUNCTION SET // FUNCTION SET
Line 150: Line 149:
   }   }
   ​   ​
-//Read each bit from the input array and write each channel high or low for each bit position in the data bus.+//Read each byte from the input array and write each channel high or low for each bit position in the data bus.
 for (int j=0; j < (numInputBytes);​ j++) for (int j=0; j < (numInputBytes);​ j++)
   {   {
Line 183: Line 182:
  
   - Now the custom command function needs a forward declaration. ​ Above void setup(), add **int clp();**   - Now the custom command function needs a forward declaration. ​ Above void setup(), add **int clp();**
-  - Next, custom ​commands need to be attached to a **LINX Listener** so they can be called from LabVIEW. ​ This is accomplished using the **AttachCustomCommand()** function of the LINX Listener.+  - Next, the custom ​command is attached to a **LINX Listener** so it can be called from LabVIEW. ​ This is accomplished using the **AttachCustomCommand()** function of the LINX Listener.
   - The **AttachCustomCommand()** takes two arguments:   - The **AttachCustomCommand()** takes two arguments:
-    - The first is the custom command number (0-63). ​ This is the number you'll use in LabVIEW to call this command.+    - The first is the custom command number (0-63). ​ This is the number you'll use in LabVIEW to call this command. In this case, 0 is used.
     - The second is the custom function.     - The second is the custom function.
   - Add the following code to the **setup()** function to attach the custom command to the LINX Listener (in this case called **LinxSerialConnection**) ​   - Add the following code to the **setup()** function to attach the custom command to the LINX Listener (in this case called **LinxSerialConnection**) ​
Line 193: Line 192:
 </​sxh>​ </​sxh>​
  
- +  ​Next, firmware ​is uploaded ​to the device. 
-  ​Build and deploy/​upload the firmware to the device. +  - The Custom Command VI (**Functions Palette>>​MakerHub>>​LINX>>​Utilities>>​Custom Command**) ​is used to call the custom function.
-  - Use the Custom Command VI (**Functions Palette>>​MakerHub>>​LINX>>​Utilities>>​Custom Command**) to call the custom function.+
   - Below are the resulting block diagram and front panel for the given code above as well as the LCD display.   - Below are the resulting block diagram and front panel for the given code above as well as the LCD display.
   - There are only 16 spaces that can be filled on the LCD display, so the code only allows for a size less than or equal to 16.   - There are only 16 spaces that can be filled on the LCD display, so the code only allows for a size less than or equal to 16.
  
 {{ :​learn:​tutorials:​libraries:​linx:​misc:​customfrontclp.png |}} {{ :​learn:​tutorials:​libraries:​linx:​misc:​customfrontclp.png |}}
 +True Case:
 {{ :​learn:​tutorials:​libraries:​linx:​misc:​customblockclp.png |}} {{ :​learn:​tutorials:​libraries:​linx:​misc:​customblockclp.png |}}
 +False Case:
 {{ :​learn:​tutorials:​libraries:​linx:​misc:​false_case.png |}} {{ :​learn:​tutorials:​libraries:​linx:​misc:​false_case.png |}}