Bindings: Python: Add DoIP Ethernet Activation

pull/73/head
Kyle Schwarz 2025-03-10 10:50:25 -04:00
parent f97fd75b8d
commit 89047447a6
5 changed files with 57 additions and 0 deletions

View File

@ -21,6 +21,7 @@ pybind11_add_module(icsneopy
icsneopy/api/version.cpp
icsneopy/device/devicetype.cpp
icsneopy/communication/network.cpp
icsneopy/communication/io.cpp
icsneopy/communication/message/message.cpp
icsneopy/communication/message/canmessage.cpp
icsneopy/communication/message/canerrormessage.cpp

View File

@ -0,0 +1,19 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include "icsneo/communication/io.h"
namespace icsneo {
void init_io(pybind11::module_& m) {
pybind11::enum_<IO>(m, "IO")
.value("EthernetActivation", IO::EthernetActivation)
.value("USBHostPower", IO::USBHostPower)
.value("BackupPowerEnabled", IO::BackupPowerEnabled)
.value("BackupPowerGood", IO::BackupPowerGood)
.value("Misc", IO::Misc)
.value("EMisc", IO::EMisc);
}
} // namespace icsneo

View File

@ -19,6 +19,7 @@ void init_device(pybind11::module_& m) {
.def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("enable_message_polling", &Device::enableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_current_message_count", &Device::getCurrentMessageCount)
.def("get_digital_io", &Device::getDigitalIO, pybind11::arg("type"), pybind11::arg("number"), pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_messages", [](Device& device) { return device.getMessages(); }, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("get_polling_message_limit", &Device::getPollingMessageLimit)
@ -42,6 +43,7 @@ void init_device(pybind11::module_& m) {
.def("remove_message_callback", &Device::removeMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("request_tc10_sleep", &Device::requestTC10Sleep, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("request_tc10_wake", &Device::requestTC10Wake, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_digital_io", pybind11::overload_cast<IO, size_t, bool>(&Device::setDigitalIO), pybind11::arg("type"), pybind11::arg("number"), pybind11::arg("value"), pybind11::call_guard<pybind11::gil_scoped_release>())
.def("set_polling_message_limit", &Device::setPollingMessageLimit)
.def("set_rtc", &Device::setRTC, pybind11::call_guard<pybind11::gil_scoped_release>())
.def("start_script", &Device::startScript, pybind11::call_guard<pybind11::gil_scoped_release>())

View File

@ -10,6 +10,7 @@ void init_event(pybind11::module_&);
void init_eventcallback(pybind11::module_&);
void init_eventmanager(pybind11::module_&);
void init_network(pybind11::module_&);
void init_io(pybind11::module_&);
void init_devicetype(pybind11::module_&);
void init_message(pybind11::module_&);
void init_canmessage(pybind11::module_&);
@ -39,6 +40,7 @@ PYBIND11_MODULE(icsneopy, m) {
init_version(m);
init_devicetype(m);
init_network(m);
init_io(m);
init_message(m);
init_canmessage(m);
init_canerrormessage(m);

View File

@ -128,3 +128,36 @@ TC10
print(f"post wake status: wake: {status.wakeStatus}, sleep: {status.sleepStatus}")
else:
print(f"{device} does not support TC10")
DoIP Ethernet Activation
========================
.. code-block:: python
import icsneopy
import time
devs = icsneopy.find_all_devices()
dev = devs[0]
dev.open()
# the device must be online for digital I/O
dev.go_online()
print(f"initial state: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, True)
print(f"after setting to true: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
# allow for observing the change
time.sleep(2)
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, False)
print(f"after setting to false: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
# allow for observing the change
time.sleep(2)