📄 pyvcp.lyx
字号:
#LyX 1.3 created this file. For more info see http://www.lyx.org/\lyxformat 221\textclass book\begin_preamble\usepackage[plainpages=false,pdfpagelabels,colorlinks=true,linkcolor=blue]{hyperref}\end_preamble\language english\inputencoding default\fontscheme bookman\graphics default\float_placement !htbp\paperfontsize default\spacing single \papersize letterpaper\paperpackage a4\use_geometry 1\use_amsmath 1\use_natbib 0\use_numerical_citations 0\paperorientation portrait\leftmargin 1in\topmargin 1in\rightmargin 0.8in\bottommargin 0.8in\secnumdepth 1\tocdepth 5\paragraph_separation skip\defskip smallskip\quotes_language english\quotes_times 2\papercolumns 1\papersides 1\paperpagestyle default\layout ChapterVirtual Control Panels\begin_inset LatexCommand \label{cha:Virtual-Control-Panels}\end_inset \layout SectionIntroduction\layout StandardTraditional machine control panels are large sheets of steel with push buttons, knobs, lights and sometimes meters mounted on them. They have many advantages - the buttons are far more rugged than a computer keyboard, and large enough that you can usually operate the correct one by feel while looking elsewhere, for example at the tool. However, they also have disadvantages. The occupy a lot of panel space, they are expensive, and wiring them into the PC can use up a lot of I/O pins. That is where Virtual Control Panels come in.\layout StandardA Virtual Control Panel (VCP) is a window on the computer screen with buttons, meters, switches, etc. When you click on a VCP button, it changes the state of a HAL pin, exactly as if you had pressed a physical button wired to an input pin on an I/O card. Likewise, a VCP LED lights up when a HAL pin goes true, just like a physical indicator lamp wired to an output pin on an I/O card. Virtual control panels are not intended to replace physical panels - sometimes there is just no substitute for a big rugged oil-tight push button. But virtual panels can be used for testing or monitoring things that don't require physical buttons and lights, to temporarily replace real I/O devices while debugging ladder logic, or perhaps to simulate a physical panel before you build it and wire it to an I/O board.\layout SectionpyVCP\layout StandardThe layout of a pyVCP panel is specified with an XML file that contains widget tags between <pyvcp> and </pyvcp>. For example:\layout LyX-Code<pyvcp>\newline <label text="This is a LED indicator"/>\newline <led/>\newline </pyvcp>\layout Standard\align center \begin_inset Graphics filename pyvcp_mypanel.png\end_inset \layout StandardIf you place this text in a file called tiny.xml, and run \layout LyX-Codehalrun -I loadusr pyvcp -c mypanel tiny.xml\layout StandardpyVCP will create the panel for you, which includes two widgets, a Label with the text \begin_inset Quotes eld\end_inset This is a LED indicator\begin_inset Quotes erd\end_inset , and a LED, used for displaying the state of a HAL BIT signal. It will also create a HAL component named \begin_inset Quotes eld\end_inset mypanel\begin_inset Quotes erd\end_inset (all widgets in this panel are connected to pins that start with \begin_inset Quotes eld\end_inset mypanel.\begin_inset Quotes erd\end_inset ). Since no <halpin> tag was present inside the <led> tag, pyVCP will automatically name the HAL pin for the LED widget mypanel.led.0\layout StandardFor a list of widgets and their tags and options, see the widget reference below.\layout StandardOnce you have created your panel, connecting HAL signals to and from the pyVCP pins is done with:\layout LyX-Codehalcmd linksp \layout StandardIf you are new to HAL, the HAL Tutorial\begin_inset LatexCommand \ref{cha:HAL-Tutorial}\end_inset is recommended.\layout SectionSecurity of pyVCP\layout StandardParts of pyVCP files are evaluated as Python code, and can take any action available to Python programs. Only use pyVCP .xml files from a source that you trust.\layout SectionUsing pyVCP with AXIS\begin_inset LatexCommand \label{sec:pyvcp-with-axis}\end_inset \layout StandardSince AXIS uses the same GUI toolkit (Tkinter) as pyVCP, it is possible to include a pyVCP panel on the right side of the normal AXIS user interface. A typical example is explained below.\layout StandardPlace your pyVCP XML file describing the panel in the same directory where your .ini file is. Say we we want to display the current spindle speed using a Bar widget. Place the following in a file called spindle.xml:\layout LyX-Code<pyvcp>\newline <label>\newline <text>"Spindle speed:"</text>\newline </label>\newline <bar>\newline <halpin>"spindle-speed"</halpin>\newline <max_>5000</max_>\newline </bar>\newline </pyvcp>\layout StandardHere we've made a panel with a Label and a Bar widget, specified that the HAL pin connected to the Bar should be named \begin_inset Quotes eld\end_inset spindle-speed\begin_inset Quotes erd\end_inset , and set the maximum value of the bar to 5000 (see widget reference below for all options). To make AXIS aware of this file, and call it at start up, we need to specify the following in the [DISPLAY] section of the .ini file:\layout LyX-CodePYVCP = spindle.xml\layout StandardTo make our widget actually display the spindle-speed it needs to be hooked up to the appropriate HAL signal. A .hal file that will be run once AXIS and pyVCP have started can be specified in the [HAL] section of the .ini file:\layout LyX-CodePOSTGUI_HALFILE = spindle_to_pyvcp.hal\layout StandardThis change will run the HAL commands specified in \begin_inset Quotes eld\end_inset spindle_to_pyvcp.hal\begin_inset Quotes erd\end_inset . In our example the contents could look like this:\layout LyX-Codelinksp spindle-rpm-filtered pyvcp.spindle-speed\layout Standardassuming that a signal called \begin_inset Quotes eld\end_inset spindle-rpm-filtered\begin_inset Quotes erd\end_inset already exists. Note that when running together with AXIS, all pyVCP widget HAL pins have names that start with \begin_inset Quotes eld\end_inset pyvcp.\begin_inset Quotes erd\end_inset .\layout Standard\align center \begin_inset Graphics filename pyvcp_AXIS.png lyxscale 50 scale 50\end_inset \layout StandardThis is what the newly created pyVCP panel should look like in AXIS. The \family typewriter sim/lathe\family default configuration is already configured this way.\layout SectionpyVCP Widget reference\layout StandardHAL signals come in two variants, BIT and FLOAT. pyVCP can either display the value of the signal with an indicator widget, or modify the signal value with a control widget. Thus there are four classes of pyVCP widgets that you can connect to a HAL signal. A fifth class of helper widgets allow you to organize and label your panel.\layout List\labelwidthstring 00.00.00001. Widgets for indicating BIT signals: LED\layout List\labelwidthstring 00.00.00002. Widgets for controlling BIT signals: Button, Checkbutton, Radiobutton\layout List\labelwidthstring 00.00.00003. Widgets for indicating FLOAT signals: Number, Bar, Meter\layout List\labelwidthstring 00.00.00004. Widgets for controlling FLOAT signals: Spinbox, Scale, Jogwheel\layout List\labelwidthstring 00.00.00005. Helper widgets: Hbox, Vbox, Tabel, Label, Labelframe\layout SubsubsectionSyntax\layout StandardEach widget is described briefly, followed by the markup used, and a screen shot. All tags inside the main widget tag are optional.\layout SubsubsectionGeneral Notes\layout StandardAt the present time, both a tag-based and an attribute-based syntax are supported. For instance, the following XML fragments are treated identically:\layout LyX-Code<led halpin="my-led"/>\layout Standardand\layout LyX-Code<led><halpin>"my-led"</halpin></led>\layout StandardWhen the attribute-based syntax is used, the following rules are used to turn the attributes value into a Python value:\layout EnumerateIf the first character of the attribute is one of the following, it is evaluated as a Python expression: \family typewriter {(["'\layout EnumerateIf the string is accepted by int(), the value is treated as an integer\layout EnumerateIf the string is accepted by float(), the value is treated as floating-point\layout EnumerateOtherwise, the string is accepted as a string.\layout StandardWhen the tag-based syntax is used, the text within the tag is always evaluated as a Python expression.\layout StandardThe examples below show a mix of formats.\layout SubsectionLED\layout StandardA LED is used to indicate the status of a BIT signal. The LED color will be on_color when the BIT signal is true, and off_color otherwise.\layout LyX-Code<led>\newline <halpin>"my-led"</halpin> \newline <size>50</size> \newline <on_color>"blue"</on_color>\newline <off_color>"black"</off_color>\newline </led>\layout Standard\align center \begin_inset Graphics filename pyvcp_led.png\end_inset \layout Standard<halpin> sets the name of the pin, default is \begin_inset Quotes eld\end_inset led.n\begin_inset Quotes erd\end_inset , where n is an integer\newline <size> sets the size of the led, default is 20\newline <on_color> sets the color of the LED when the pin is true. default is \begin_inset Quotes eld\end_inset green\begin_inset Quotes erd\end_inset \newline <off_color> sets the color of the LED when the pin is false. default is \begin_inset Quotes eld\end_inset ref\begin_inset Quotes erd\end_inset \layout SubsectionButton\layout StandardA button is used to control a BIT pin. The pin will be set True when the button is pressed and held down, and will be set False when the button is released.\layout LyX-Code<button>\newline <halpin>"my-button"</halpin>\newline <text>"ON"</text> \newline </button>\layout Standard\align center \begin_inset Graphics filename pyvcp_button.png\end_inset \layout SubsectionCheckbutton\layout StandardA checkbutton controls a BIT pin. The pin will be set True when the button is checked, and false when the button is unchecked.\layout LyX-Code<checkbutton>\newline <halpin>"my-checkbutton"</halpin>\newline </checkbutton>\layout StandardAn unchecked checkbutton: \begin_inset Graphics filename pyvcp_checkbutton1.png\end_inset , and a checked one: \begin_inset Graphics
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -