The LinuxCnc_PokeysLibComp project integrates PoKeys devices with LinuxCNC, providing real-time control and monitoring capabilities. This repository contains the necessary components, scripts, and documentation to set up and use PoKeys devices with LinuxCNC.
The repository is organized into the following directories:
pokeys_py/
: Contains Python scripts for interfacing with PoKeys devices.pokeys_rt/
: Contains real-time components for PoKeys devices.tests/
: Contains unit tests, integration tests, and other testing-related files.docs/
: Contains project-related documentation.scripts/
: Contains scripts for setup, configuration, and auxiliary tasks.To install the LinuxCnc_PokeysLibComp project, follow these steps:
git clone https://github.com/zarfld/LinuxCnc_PokeysLibComp.git
cd LinuxCnc_PokeysLibComp
sudo sh install.sh
The project has been tested with the following hardware:
The following features have been implemented and tested:
Count: 55
pokeys.[DevID].digin.[PinID].in
: State of the hardware inputpokeys.[DevID].digin.[PinID].in-not
: Inverted state of the inputpokeys.[DevID].PEv2.[PEv2Id].digin.Home.Pin
: Home switch pin (0 for external dedicated input)pokeys.[DevID].PEv2.[PEv2Id].digin.Home.Filter
: Digital filter for Home switchpokeys.[DevID].PEv2.[PEv2Id].digin.Home.invert
: Invert Home (PoKeys functionality)pokeys.[DevID].PEv2.[PEv2Id].digin.LimitN.Pin
: Limit- switch pin (0 for external dedicated input)pokeys.[DevID].PEv2.[PEv2Id].digin.LimitN.Filter
: Digital filter for limit- switchpokeys.[DevID].PEv2.[PEv2Id].digin.LimitN.invert
: Invert limit- (PoKeys functionality)pokeys.[DevID].PEv2.[PEv2Id].digin.LimitP.Pin
: Limit+ switch pin (0 for external dedicated input)pokeys.[DevID].PEv2.[PEv2Id].digin.LimitP.Filter
: Digital filter for limit+ switchpokeys.[DevID].PEv2.[PEv2Id].digin.LimitP.invert
: Invert limit+ (PoKeys functionality)pokeys.[DevID].PEv2.digin.Emergency.Pin
pokeys.[DevID].PEv2.digin.Emergency.invert
pokeys.[DevID].PEv2.digin.Probe.Pin
pokeys.[DevID].PEv2.digin.Probe.invert
Count: 55
pokeys.[DevID].digout.[PinID].out
: Value to be written (possibly inverted) to the hardware outputpokeys.[DevID].digout.[PinID].invert
: If TRUE, out is inverted before writing to the hardwareCount: 7
pokeys.[DevID].adcin.[AdcId].value-raw
: The hardware readingpokeys.[DevID].adcin.[AdcId].value
: The hardware reading, scaled according to the scale and offset parameterspokeys.[DevID].adcin.[AdcId].scale
: The input voltage (or current) will be multiplied by scale before being output to valuepokeys.[DevID].adcin.[AdcId].offset
: This will be subtracted from the hardware input voltage (or current) after the scale multiplier has been appliedCount: 6
pokeys.[DevID].adcout.[AdcId].value
: The value to be written. The actual value output to the hardware will depend on the scale and offset parameterspokeys.[DevID].adcout.[AdcId].enable
: If false, then output 0 to the hardware, regardless of the value pinpokeys.[DevID].adcout.[AdcId].offset
: This will be added to the value before the hardware is updatedpokeys.[DevID].adcout.[AdcId].scale
: This should be set so that an input of 1 on the value pin will cause 1Vpokeys.[DevID].adcout.[AdcId].high_limit
: When calculating the value to output to the hardware, if value + offset is greater than high_limit, then high_limit will be used insteadpokeys.[DevID].adcout.[AdcId].low_limit
: When calculating the value to output to the hardware, if value + offset is less than low_limit, then low_limit will be used insteadpokeys.[DevID].adcout.[AdcId].max_v
: Max output voltagepokeys.[DevID].adcout.pwm.period
: PWM period, shared among all channelsCount: 29
pokeys.[DevID].encoder.[EncId].count
: Encoder value in countspokeys.[DevID].encoder.[EncId].position
: Encoder value in position units (see parameter “scale”)pokeys.[DevID].encoder.[EncId].reset
: When True, force counter to zeropokeys.[DevID].encoder.[EncId].scale
: The scale factor used to convert counts to position units. It is in “counts per position unit”pokeys.[DevID].rtc.sec
: Secondpokeys.[DevID].rtc.min
: Minutepokeys.[DevID].rtc.hour
: Hourpokeys.[DevID].rtc.dow
: Day of weekpokeys.[DevID].rtc.dom
: Day of monthpokeys.[DevID].rtc.doy
: Day of yearpokeys.[DevID].rtc.month
: Monthpokeys.[DevID].rtc.year
: Yearpokeys.[DevID].rtc.loop_frequ
: Actual loop frequency of pokeys.comp updated after rtc.sec changedpokeys.[DevID].rtc.loop_frequ_demand
: Demand value for loop frequency (if 0, default of 10Hz will be used)To ensure the reliability and correctness of the pokeys_py
component, a comprehensive test suite has been developed. The tests cover various functionalities, including digital I/O, analog I/O, PEv2, counters, PWM outputs, and peripheral devices. The tests are categorized into unit tests, integration tests, functional tests, and performance tests.
Before running the tests, make sure you have the following prerequisites installed:
pytest
testing frameworkunittest.mock
for mocking PoKeys device responsesYou can install pytest
using pip:
pip install pytest
Unit tests are designed to test individual functions and methods within the pokeys_py
component. To run the unit tests, navigate to the tests
directory and execute the following command:
pytest test_analog_io.py
pytest test_counter.py
pytest test_digital_io.py
pytest test_pev2_motion_control.py
pytest test_ponet.py
pytest test_pwm.py
Integration tests verify the interaction between the pokeys_py
component and the PoKeys hardware and LinuxCNC. To run the integration tests, execute the following command:
pytest test_integration.py
Functional tests simulate real-world usage scenarios for the pokeys_py
component. To run the functional tests, execute the following command:
pytest test_functional.py
Performance tests ensure that the pokeys_py
component meets real-time operation requirements. To run the performance tests, execute the following command:
pytest test_performance.py
After running the tests, pytest
will display the test results in the terminal. The results will indicate the number of tests passed, failed, or skipped. Additionally, you can generate a coverage report to identify untested code.
To generate a coverage report, use the following command:
pytest --cov=pokeys_py --cov-report=html
The coverage report will be generated in the htmlcov
directory. Open the index.html
file in a web browser to view the detailed coverage report.
Some tests may require physical hardware to run. For hardware-dependent tests, make sure the PoKeys device is connected and properly configured. Follow the setup steps provided in the documentation to ensure the hardware is ready for testing.
To integrate the tests into an automated testing pipeline, set up continuous integration (CI) to run the tests on every commit or pull request. This ensures that the code is continuously tested and any issues are detected early in the development process.
To run tests with mocks or simulators, follow these steps:
CI
to true
to enable the use of mocks in the CI environment.pytest
.For example:
export CI=true
pytest test_analog_io.py
pytest test_counter.py
pytest test_digital_io.py
pytest test_pev2_motion_control.py
pytest test_ponet.py
pytest test_pwm.py
pytest test_integration.py
pytest test_functional.py
pytest test_performance.py
To toggle between real and mock devices, set the CI
environment variable accordingly:
CI
environment variable or set it to false
:unset CI
# or
export CI=false
CI
environment variable to true
:export CI=true
The documentation provides clear instructions on running tests, setup steps for hardware-dependent tests, and interpreting test results and coverage reports. It is essential to keep the documentation up to date as new features are implemented and tests are added.
By following these instructions, you can ensure the reliability, correctness, and performance of the pokeys_py
component, making it easier to maintain and develop in the future.
To ensure that the CI workflow runs smoothly, it is important to configure GitHub Actions runners properly. This section provides instructions for setting up self-hosted runners and verifying the required permissions and access for runners.
Create a Runner: Follow the instructions in the GitHub documentation to create a self-hosted runner. You can find the documentation here.
Install the Runner: Download and install the runner on your machine. Make sure to follow the installation steps provided in the documentation.
Configure the Runner: Configure the runner by running the config.sh
script. Provide the necessary details such as the repository URL, runner name, and labels.
Start the Runner: Start the runner by running the run.sh
script. The runner should now be online and ready to pick up jobs.
Repository Access: Ensure that the runner has access to the repository. This can be done by adding the runner to the repository settings under the "Actions" tab.
Permissions: Verify that the runner has the necessary permissions to access the repository. This includes read and write permissions for the repository.
Runner Logs: Check the runner logs for any errors or issues that might be preventing the job from being picked up. The logs can be found in the runner/logs
directory.
Self-Hosted Runners: If using self-hosted runners, ensure they are online and properly configured. This includes verifying the network connectivity and ensuring that the runner is not blocked by any firewall or security settings.
GitHub-Hosted Runners: If using GitHub-hosted runners, verify that there are no restrictions or limitations on the number of concurrent jobs. This can be done by checking the GitHub Actions settings in the repository.
By following these steps, you can ensure that the GitHub Actions runners are properly configured and have the necessary permissions and access to run the CI workflow successfully.
Code reviews are an essential part of our development process. They help ensure code quality, maintainability, and foster collaboration within the team. The following guidelines outline the expectations for code reviews:
For detailed guidelines, please refer to the Code Review Guidelines.
We welcome contributions from the community to help improve the project. Please take a moment to review the CONTRIBUTING.md file for guidelines on how to contribute.
This project is licensed under the MIT License. See the LICENSE file for more details.
To keep the repository organized, please follow these branch naming conventions:
feature/{feature-name}
bugfix/{bug-name}
improvement/{improvement-name}
hotfix/{hotfix-name}
Each new feature or bug fix should have its own branch created from the latest version of the main branch. The branch should focus on one feature or issue to ensure isolated development.
This repository aligns with LinuxCNC’s development practices and canonical interfaces. The components have been reviewed and updated to follow LinuxCNC coding guidelines, ensuring that HAL and INI files conform to LinuxCNC’s structure and formatting. Real-time components comply with LinuxCNC’s real-time constraints, and all components follow the canonical interface definitions. The code adheres to LinuxCNC's code style and formatting guidelines, and test cases have been created and run to validate conformity.
To simplify the testing process and ensure consistency across different environments, we have integrated Docker into our testing workflow. This allows you to run tests inside a Docker container, providing an isolated and reproducible environment.
To build the Docker image for testing, follow these steps:
Ensure you have Docker installed on your machine. You can download and install Docker from here.
Clone the repository and navigate to the project directory:
git clone https://github.com/zarfld/LinuxCnc_PokeysLibComp.git
cd LinuxCnc_PokeysLibComp
Dockerfile
:docker build -t linuxcnc-pokeyslibcomp .
Once the Docker image is built, you can run tests inside the Docker container. This ensures that tests are executed in a consistent environment, regardless of the host system.
To run tests inside the Docker container, use the following command:
docker run --rm linuxcnc-pokeyslibcomp
This command will start a Docker container from the linuxcnc-pokeyslibcomp
image and execute the tests inside the container. The --rm
flag ensures that the container is removed after the tests are completed.
By using Docker for testing, you can ensure that tests are executed in a consistent and isolated environment, reducing the chances of environment-related issues and making it easier to reproduce and debug test failures.
create_images.sh
ScriptThe create_images.sh
script automates the build and image creation process for Raspberry Pi 4 Bullseye, Bookworm, and amd64 hybrid. Follow these steps to use the script:
Ensure you have the necessary dependencies installed for cross-compiling for ARM and natively compiling for amd64.
Run the create_images.sh
script:
chmod +x create_images.sh
./create_images.sh
The script will build and create images for Raspberry Pi 4 Bullseye, Bookworm, and amd64 hybrid, following the structure and format of existing LinuxCNC releases. It will also test and validate the generated images.
The generated images are stored in the repository's releases or a suitable cloud storage platform. You can download the images from the following links:
In the GitHub Actions workflow file, ensure that the runs-on
key is correctly specified. The correct syntax for the runs-on
key should be runs-on: ${{ matrix.os }}
instead of runs-on: [self-hosted, ${{ matrix.os }}]
.
The following platforms and LinuxCNC versions are supported:
To replicate the CI environments locally, follow these steps:
Clone the Repository:
git clone https://github.com/zarfld/LinuxCnc_PokeysLibComp.git
cd LinuxCnc_PokeysLibComp
Set Up the Environment:
sudo apt-get update
sudo apt-get install -y qemu qemu-user-static debootstrap
Run the CI Pipeline Locally:
./create_images.sh
Test and Validate the Generated Images:
sudo qemu-system-aarch64 -M raspi3 -kernel rpi4_bullseye/boot/vmlinuz-*-arm64 -initrd rpi4_bullseye/boot/initrd.img-*-arm64 -append "root=/dev/sda2" -hda rpi4_bullseye.img -nographic
By following these steps, you can replicate the CI environments locally and ensure that the generated images are functioning correctly.
To make it easier for new contributors to get started, we use specific labels to identify issues and pull requests that are suitable for beginners. These labels help contributors find tasks that match their experience level and ensure a smooth onboarding process.
good first issue
: For issues that are simple, well-documented, and require minimal background knowledge.beginner friendly
: For issues that require basic knowledge of the project but are ideal for newcomers.help wanted
: For issues where assistance is needed, often broader in scope but still accessible.documentation
: For tasks that involve contributing to documentation (which can be a good entry point for new contributors).low-hanging fruit
: For smaller, isolated issues that are quick to solve.When creating or reviewing issues and pull requests, apply the appropriate labels to help new contributors find suitable tasks. Here are some guidelines:
We encourage new contributors to look for issues with these labels. If you are a first-time contributor, start by exploring the issues labeled good first issue
, beginner friendly
, or documentation
. These tasks are designed to help you get started with the project and build your confidence as a contributor.
A new CI job has been added to automatically review issues in the repository that are not yet labeled and assign the correct label based on the issue content. This helps maintainers and contributors identify tasks efficiently.
The CI job is configured using GitHub Actions. The workflow file is named label_issues.yml
and is located in the .github/workflows/
directory.
The CI job is triggered automatically in the following scenarios:
The CI job uses a Python script named label_issues.py
to analyze the issue content and assign labels based on keywords or an NLP model. The script uses the requests
library to interact with the GitHub API.
The CI job implements a confidence threshold to avoid incorrect labeling. If the confidence level is high (e.g., over 80%), the label is applied automatically. If the confidence level is low, the issue is flagged for manual review by maintainers with a comment like:
"This issue could not be confidently labeled. Please review manually."
Maintainers can manually override the label if the CI job incorrectly assigns one. The CI job also applies a needs-review
label for issues where it is unsure about the appropriate label.
The CI job excludes issues that already have one or more labels. It does not remove or change existing labels unless flagged by a maintainer.
The CI job logs its actions, such as which issues were labeled and which issues it flagged for manual review. Optionally, it can send a daily or weekly report summarizing its actions to maintainers.
In case the CI job fails or cannot process an issue (e.g., due to parsing errors), it flags the issue with a needs-review
label and provides a log or error report.
The following are examples of labels that can be automatically assigned by the CI job based on issue content:
good first issue
: For issues that include terms like "beginner", "easy", "first-time", "simple", or "docs".documentation
: For issues that include terms related to documentation, like "README", "docs", "documentation".help wanted
: For issues that contain requests for help.bug
: For issues that include terms like "bug", "error", "issue".enhancement
: For issues that include terms like "feature", "enhancement", "improvement".By implementing this CI job, the repository ensures that issues are well-organized and labeled appropriately, improving issue management and making it easier for contributors to navigate the repository.
pokeyslib
To facilitate testing and development, you can easily swap between the real pokeyslib
and the mocked pokeyslib
. This allows you to run tests without the need for physical PoKeys devices.
pokeyslib
CI
environment variable to true
to enable the use of the mocked pokeyslib
.export CI=true
pytest
.pytest test_analog_io.py
pytest test_counter.py
pytest test_digital_io.py
pytest test_pev2_motion_control.py
pytest test_ponet.py
pytest test_pwm.py
pytest test_integration.py
pytest test_functional.py
pytest test_performance.py
pokeyslib
CI
environment variable or set it to false
to use the real pokeyslib
.unset CI
# or
export CI=false
pytest
.pytest test_analog_io.py
pytest test_counter.py
pytest test_digital_io.py
pytest test_pev2_motion_control.py
pytest test_ponet.py
pytest test_pwm.py
pytest test_integration.py
pytest test_functional.py
pytest test_performance.py
Here is an example of how to configure and run tests with the mocked pokeyslib
:
export CI=true
pytest test_counter.py
This will run the test_counter.py
tests using the mocked pokeyslib
, allowing you to validate the behavior of the pokeys_py
component without the need for physical hardware.
By following these instructions, you can easily swap between the real and mocked pokeyslib
, enabling comprehensive testing and development of the pokeys_py
component.
pokeyslib
DesignEach function provided by the real pokeyslib
will have a mocked version with the exact same signature. The mocked function will simulate the expected hardware behavior.
Real pokeyslib.h
:
POKEYSDECL int32_t PK_DigitalIOGet(sPoKeysDevice* device, uint8_t pinID, uint8_t* pinValue);
Mocked Version:
int32_t PK_DigitalIOGet(sPoKeysDevice* device, uint8_t pinID, uint8_t* pinValue) {
*pinValue = 1; // Simulate the pin being high
return PK_OK;
}
All other functions in the library, such as PK_DigitalIOSet
, PK_AnalogIOGet
, PK_PEv2_PulseEngineMove
, etc., will follow the same approach, mimicking the real behavior of the functions.
All the structures and enums defined in the original pokeyslib.h
need to be replicated exactly in the mock to ensure binary compatibility when linking against components.
Real pokeyslib.h
:
typedef struct sPoKeysDevice_Info {
char deviceName[32];
uint32_t serialNumber;
uint88 firmwareVersionMajor;
uint8_t firmwareVersionMinor;
uint8_t numberOfPins;
} sPoKeysDevice_Info;
Mocked pokeyslib.h
(identical to the real header):
typedef struct sPoKeysDevice_Info {
char deviceName[32];
uint32_t serialNumber;
uint88 firmwareVersionMajor;
uint8_t firmwareVersionMinor;
uint8_t numberOfPins;
} sPoKeysDevice_Info;
The mocked library will maintain internal state to simulate real device behavior across function calls. This is particularly important for functions like PK_DigitalIOSet
and PK_DigitalIOGet
, where setting an output pin should affect subsequent input reads.
The mock library must allow for custom configuration of the device state prior to tests. This includes setting up the initial state of pins, analog values, and other peripheral settings.
void setup_mock_device() {
device_state.pins[0] = 1; // Simulate pin 0 being high
device_state.pins[1] = 0; // Simulate pin 1 being low
}
Linking the Mock Library:
pokeyslib
will be linked into the test environment.pokeyslib
will be linked.CMake Example:
if(BUILD_TESTS)
target_link_libraries(my_tests PRIVATE mocked_pokeyslib)
else()
target_link_libraries(my_project PRIVATE real_pokeyslib)
endif()
Replacing the Real Library:
pokeyslib
.pokeyslib
should work seamlessly with existing unit tests and integration tests.TEST(MockPoKeysTest, TestDigitalIO) {
sPoKeysDevice* device = CreateMockDevice();
uint8_t pinValue = 0;
PK_DigitalIOGet(device, 0, &pinValue);
ASSERT_EQ(pinValue, 1); // Check that the mock returns the expected value
}
Identify all Functions and Structures:
pokeyslib.h
to identify all the functions, structures, and enums that need to be mocked.Implement Mocked Functions:
State Management:
Testing:
Documentation:
pokeyslib
for testing and production.This mocked pokeyslib
will allow for full unit testing and CI pipeline testing without the need for physical devices. By maintaining the same interface as the real library, no changes to existing components will be necessary, ensuring seamless integration.
We have a comprehensive Wiki to help you get started with the project and find detailed documentation. The Wiki is structured and organized according to best practices, making it easy to navigate and find the information you need.
We encourage contributions to the Wiki to keep it up to date and comprehensive. If you would like to contribute to the Wiki, please follow these guidelines:
git clone https://github.com/your-username/LinuxCnc_PokeysLibComp.git
cd LinuxCnc_PokeysLibComp
git checkout -b wiki/your-wiki-contribution
git add .
git commit -m "Update Wiki: your contribution description"
git push origin wiki/your-wiki-contribution
By following these steps, you can contribute to the Wiki and help improve the documentation for the project.
PoKeys Device | Supported Versions | Notes |
---|---|---|
PoKeys57E | 4.0, 4.1, 4.2 | Limited support |
PoKeys57CNC | 3.5, 3.6, 3.7 | Limited support |
PoKeys57U | 2.8, 2.9 | Limited support |
PoKeys56U | 1.5, 1.6 | Limited support |
The following table outlines the compatibility between different versions of LinuxCNC and the LinuxCnc_PokeysLibComp project:
LinuxCNC Version | Supported | Notes | |
---|---|---|---|
2.8.x | Yes | Limited support | |
2.9.x | Yes | Limited support | |
2.7.x | No | Not supported | nothing of them is Fully supported yet. this sis still in development no approval of support done! |
We encourage the use of GitHub Discussions for questions, feature requests, and ideas before creating issues or pull requests. This helps keep the issue tracker focused on actionable items and fosters community engagement.
We have created the following categories in GitHub Discussions to help organize conversations:
When starting a discussion, please follow these guidelines:
Use GitHub Discussions for:
By using GitHub Discussions effectively, we can build a stronger community around the project and make the repository more welcoming to both new and experienced users.
You can access the GitHub Discussions for this repository here.
We appreciate your interest in supporting the LinuxCnc_PokeysLibComp project! Your sponsorship helps us continue to develop and maintain this project. Here are some ways you can sponsor us:
For more detailed information on sponsorship tiers and benefits, as well as instructions on how to sponsor through GitHub Sponsors and PayPal, please refer to our Sponsorship Page.
Thank you for your support!
To set up two-factor authentication (2FA) for GitHub repositories, follow these steps:
By following these steps, you can enhance the security of your GitHub repository by requiring two-factor authentication for all collaborators. For more detailed instructions, refer to the GitHub documentation on setting up 2FA.
To enable Dependabot security alerts and automatic updates for your GitHub repository, follow these steps:
Dependabot will now monitor your repository for security vulnerabilities and automatically create pull requests to update dependencies when vulnerabilities are found.
To set up CodeQL for code scanning in your GitHub repository, follow these steps:
CodeQL will now analyze your code for security vulnerabilities and provide detailed reports on potential issues.
To enable secret scanning for your GitHub repository, follow these steps:
Secret scanning will now monitor your repository for exposed secrets, such as API keys and passwords, and alert you if any are found.
To limit access control and enforce the principle of least privilege for your GitHub repository, follow these steps:
By limiting access control and enforcing least privilege, you can reduce the risk of unauthorized access and protect your repository from potential security threats.
The Canonical Device Interface (CDI) is a standardized interface for interacting with PoKeys devices in the LinuxCnc_PokeysLibComp project. It provides a consistent and unified way to access and control various features of PoKeys devices, ensuring compatibility and ease of use.
The CDI supports the following features:
To read the state of a digital input pin and write a value to a digital output pin using the CDI, follow these examples:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Read the state of digital input pin 0
pin_value = device.digital_read(0)
print(f"Digital input pin 0 state: {pin_value}")
# Set the state of digital output pin 0 to high
device.digital_write(0, 1)
print("Digital output pin 0 set to high")
To read the value of an analog input pin and write a value to an analog output pin using the CDI, follow these examples:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Read the value of analog input pin 0
analog_value = device.analog_read(0)
print(f"Analog input pin 0 value: {analog_value}")
# Set the value of analog output pin 0 to 2.5V
device.analog_write(0, 2.5)
print("Analog output pin 0 set to 2.5V")
To configure the Pulse Engine (PEv2) for motion control and move an axis using the CDI, follow these examples:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Configure the Pulse Engine for axis 0
device.pev2_configure_axis(0, steps_per_unit=200, max_velocity=1000, acceleration=500)
print("Pulse Engine axis 0 configured")
# Move axis 0 to position 10.0
device.pev2_move_axis(0, 10.0)
print("Axis 0 moved to position 10.0")
To read the state of a matrix keyboard using the CDI, follow this example:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Read the state of the matrix keyboard
key_state = device.matrix_keyboard_read()
print(f"Matrix keyboard state: {key_state}")
To set the state of an LED and read the state of a button on the CNC keyboard using the CDI, follow these examples:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Set the state of LED 0 to on
device.kbd48CNC_set_led(0, 1)
print("LED 0 on the CNC keyboard set to on")
# Read the state of button 0 on the CNC keyboard
button_state = device.kbd48CNC_get_button(0)
print(f"Button 0 on the CNC keyboard state: {button_state}")
To read the value of an encoder using the CDI, follow this example:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Read the value of encoder 0
encoder_value = device.encoder_read(0)
print(f"Encoder 0 value: {encoder_value}")
To read the real-time clock values using the CDI, follow this example:
import pokeys_py
# Initialize the PoKeys device
device = pokeys_py.PoKeysDevice()
# Read the real-time clock values
rtc_values = device.rtc_read()
print(f"RTC values: {rtc_values}")
To configure the CDI for use with PoKeys devices in LinuxCNC, follow these steps:
Connect the Hardware: Ensure that the PoKeys devices are properly connected to your system according to the hardware requirements.
Update LinuxCNC Configuration Files: Update the LinuxCNC configuration files to include the PoKeys components. Refer to the following example configuration:
[HAL]
# Load PoKeys HAL component
loadrt pokeys
# Add PoKeys device
addf pokeys.0 servo-thread
# Configure digital inputs and outputs
net input-0 <= pokeys.0.digin.0.in
net output-1 => pokeys.0.digout.1.out
# Configure analog inputs and outputs
net analog-input-0 <= pokeys.0.adcin.0.value
net analog-output-1 => pokeys.0.adcout.1.value
halcmd
command to monitor the state of the inputs and outputs.By following these steps and examples, you can effectively use the Canonical Device Interface to interact with PoKeys devices in the LinuxCnc_PokeysLibComp project.
For detailed instructions on converting existing LinuxCNC HAL and INI files for use with pokeys.comp
, pokeys_homecomp.comp
, and kbd48cnc.comp
, refer to the Converting HAL and INI Files documentation.