Skip to content

Commit 3866d10

Browse files
committed
qtvcp -docs: update libraries/code snippets with core.py changes
function names changes, add an example of pin reading writing
1 parent a6456f0 commit 3866d10

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

docs/src/gui/qtvcp-code-snippets.adoc

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ from qtvcp.core import Qhal
264264
----
265265

266266
This is to allow access to *QtVCP's HAL component*.
267+
<<cha:qtvcp:Qhal,For more info: Qhal>> +
268+
Qhal's newPin function returns a QPin object.
269+
<<cha:qtvcp:QPin,For more info: QPin>>
267270

268271
.Instantiate `Qhal` in the `INSTANTIATE LIBRARY SECTION`
269272
[source,python]
@@ -272,7 +275,7 @@ QHAL = Qhal()
272275
----
273276

274277
.Add a function that gets called when the pin state changes
275-
Under the `initialised__` function, make sure there is an entry similar to this:
278+
Under the `initialized__` function, make sure there is an entry similar to this:
276279

277280
[source,python]
278281
----
@@ -284,8 +287,8 @@ Under the `initialised__` function, make sure there is an entry similar to this:
284287
# the widgets are instantiated.
285288
# the HAL pins are built but HAL is not set ready
286289
def initialized__(self):
287-
self.pin_cycle_start_in = QHAL.newpin('cycle-start-in',QHAL.HAL_BIT, QHAL.HAL_IN)
288-
self.pin_cycle_start_in.value_changed.connect(lambda s: self.cycleStart(s))
290+
self.pin_cycle_start_in = QHAL.newPin('cycle-start-in',QHAL.HAL_BIT, QHAL.HAL_IN)
291+
self.pin_cycle_start_in.pinValueChanged.connect(lambda o,s: self.cycleStart(s))
289292
----
290293

291294
.Define the function called by pin state change in the `GENERAL FUNCTIONS SECTION`
@@ -313,6 +316,35 @@ In this way the cycle start button works differently depending on what tab is sh
313316

314317
This is simplified - _checking state and error trapping might be helpful_.
315318

319+
== Read/Write System HAL Pins Directly
320+
Sometimes you need to read a system pin and creating a HAL pin and connecting to it,
321+
is more work then required. You can read it directly without connecting to it.
322+
323+
Here is how to read a pin, parameter, or signal:
324+
325+
[source,python]
326+
----
327+
self.h.hal.get_value('spindle.0.at-speed')
328+
329+
# or use the Qhal library like this:
330+
QHAL.getValue('spindle.0.at-speed')
331+
----
332+
333+
Here is how to write to an unconnected pin or a non driven signal:
334+
335+
[source,python]
336+
----
337+
self.h.hal.set_p('componentName.pinName','10')
338+
self.h.hal.set_s('componentName.signalName','10')
339+
340+
# or use the Qhal library like this:
341+
QHAL.setPin('componentName.pinName', '10')
342+
QHAL.setSignal('componentName.signalName', '10')
343+
----
344+
345+
Using 'self.h.hal' or 'QHAL.hal' allows access to the HAL python module functions:
346+
<<cha:python-hal-interface, Python HAL Interface>>
347+
316348
== Add A Special Max Velocity Slider Based On Percent
317349

318350
Some times you want to *build a widget to do something not built in*.

docs/src/gui/qtvcp-libraries.adoc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,23 @@ ACTION.TOUCHPLATE_TOUCHOFF(search_vel, probe_vel, max_probe,
383383
z_offset, retract_distance, z_safe_travel, rtn_method=None, error_rtn = None)
384384
----
385385

386+
[[cha:qtvcp:Qhal]]
387+
386388
== Qhal
387389

388-
A library for HAL component interactions.
390+
A library for HAL component/system interactions.
389391

390392
=== Attributes
391393

392394
These are the functions that can be called on the Qhal object:
393395

394-
*`newpin(name, pin type constant, pin direction constant)`*:: returns a new QPin object
395-
*`getpin(name)`*:: returns an existing named QPin object
396-
*`getvalue(name)`*:: returns the named pin's value, use the full component/pin name.
397-
*`setp(name,value)`*:: sets the named pin's value, use the full component/pin name.
398-
*`makeUniqueName(name)`*:: returns an unique HAL pin name string by adding '-x' (a number) to the base name
396+
*`setUpdateRate(cyclerate)`*:: Set cycle rate in ms
397+
*`newPin(name, pin type constant, pin direction constant)`*:: returns a new QPin object
398+
*`getPinObject(name)`*:: returns an existing named QPin object
399+
*`getValue(name)`*:: returns the named pin, signal, or parameter's value, use the full component.pin name.
400+
*`setPin(name,value)`*:: sets the named pin's value, use the full component.pin name.
401+
*`setSignal(name,value)`*:: sets the named signal's value, use the full component.pin name.
402+
*`makeUniqueName(name)`*:: returns an unique HAL pin name string by adding '-x' (a number) to the given pin name string
399403
*`exit()`*:: kills the component
400404

401405
=== Constants
@@ -418,13 +422,14 @@ Available object references:
418422
* *comp* the component object
419423
* *hal* the hal library object
420424

425+
[[cha:qtvcp:QPin]]
421426
== QPin
422427
A wrapper class around HAL pins
423428

424429
=== Signals
425430
There are 3 Qt signals that the QPin pin can be connect to:
426431

427-
* *value_changed* will call a named function with an argument of the current value
432+
* *value_changed* will call a named function with an argument of the current value (depreciated)
428433
* *pinValueChanged* will call a named function with arguments of the pin object and the current value
429434
* *isDrivenChanged* will call a named function with arguments of the pin object and current state when
430435
the pin is (un)connected to a driving pin

0 commit comments

Comments
 (0)