Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

All the Windows python enumerations

Expand / Collapse
 

All the Windows python enumerations


Getting started programming in any language can be challenging.
Learning how to write properly coded lines can be hard enough, but adding in a 3rd party library and knowing what you need to add in can seem down right impossible.

My biggest challenge was knowing to add an enumeration (enum), when to add it, and then using it.
To help you get past this, here is an example python file having all the mcculw enumerations in one place.

you could copy and paste all or some of lines from attached file, lines 25 through 35.
or you could add a subset of them.

You can add them all and use only the ones you need.  If you do add them all but only use a few, depending on your programming environment such as PyCharm, the ones used will be in a BOLD font while the unused ones will not be.  At the end of development you can delete any that are not in Bold font or not used.

Some of the enums you will use, some you may never use.  But here they all are.
This is just a complete list with simple examples showing how to use them as a variable. Note there was no particular reasoning as to which enumerated valued I used.  It was not based on most used, nor first in the list.  It's just an example of syntax.

For example. if you were to write a app featuring analog input of a USB-1808 which is input channel configurable.  Taking a voltage measurement, you might want to configure an input channel to single ended.  You would need to add the enumeration for AnalogInputMode:

from mcculw.enums import AnalogInputMode

The line of code to set a channel to single ended would look like this:

ul.a_chan_input_mode(board_num, channel, AnalogInputMode.SINGLE_ENDED)

or

a_input_mode = AnalogInputMode.SINGLE_ENDED
ul.a_chan_input_mode(0, 0, a_input_mode)

As stated, this line of code could be used for a USB-1808 series where you can individually set each channel to single ended or differential input mode programatically.  In the above example, board_num and channel are not important to this KB article, to set the channel to single ended you would use "AnalogInputMode.SINGLE_ENDED".  But to get it to accept this syntax, you would first need to include:

from mcculw.enums import AnalogInputMode

To return an analog input measurement to a variable named value_volts from a USB-1808 using the bipolar 10 Volt range, you would include this line:

value_volts = ul.v_in_32(0, 0, ULRange.BIP10VOLTS, 0)

or

ai_range = ULRange.BIP10VOLTS
value_volts = ul.v_in_32(0, 0, ai_range , 0)

To get the function call ul.v_in_32 to accept the selected range, your import statement would be:

from mcculw.enums import ULRange

These enums can be included in one import like this:

from mcculw.enums import AnalogInputMode, ULRange.

NOTEs:  
1.  This KB article does not go into the definitions of what each enumeration does nor when and how they are used.  It is solely to demonstrate implementation.

2.  "from mcculw import ul" is not only required to gain access to the enumerations, it is also required to access the UL library calls.




Rate this Article:

Attachments


mcculw_ul_all_enums_included.py mcculw_ul_all_enums_included.py (4.09 KB, 95 views)

Add Your Comments


For comments email TechSupport@mccdaq.com.

Details
Article ID: 50824

Last Modified:1/26/2021 3:44:01 PM

Article has been viewed 225 times.

Options