Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit096861a

Browse files
committed
update unused USBKit and SerialPort
1 parentb82abfe commit096861a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

‎bindings/device/SerialPort.cpp‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,25 @@ py::class_<BSerialPort>(m, "BSerialPort")
5656
.def(py::init(),"")
5757
.def("Open", &BSerialPort::Open,"",py::arg("portName"))
5858
.def("Close", &BSerialPort::Close,"")
59-
.def("Read", &BSerialPort::Read,"",py::arg("buf"),py::arg("count"))
60-
.def("Write", &BSerialPort::Write,"",py::arg("buf"),py::arg("count"))
59+
//.def("Read", &BSerialPort::Read, "", py::arg("buf"), py::arg("count"))
60+
.def("Read", [](BSerialPort& self,size_t count) {
61+
std::vector<uint8_t>buffer(count);
62+
ssize_t result = self.Read(buffer.data(), count);
63+
if (result >0) {
64+
returnpy::bytes(reinterpret_cast<constchar*>(buffer.data()), result);
65+
}
66+
returnpy::bytes();
67+
},"",py::arg("count"))
68+
//.def("Write", &BSerialPort::Write, "", py::arg("buf"), py::arg("count"))
69+
.def("Write", [](BSerialPort& self, py::buffer data){
70+
/*std::string buffer = data;
71+
const void* buf =buffer.data();
72+
size_t count = buffer.size();*/
73+
py::buffer_info info = data.request();
74+
size_t count = info.size;
75+
constvoid* buffer = info.ptr;
76+
return self.Write(buffer,count);
77+
},"",py::arg("data"))
6178
.def("SetBlocking", &BSerialPort::SetBlocking,"",py::arg("blocking"))
6279
.def("SetTimeout", &BSerialPort::SetTimeout,"",py::arg("microSeconds"))
6380
.def("SetDataRate", &BSerialPort::SetDataRate,"",py::arg("bitsPerSecond"))

‎bindings/device/USBKit.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ py::class_<BUSBEndpoint, std::unique_ptr<BUSBEndpoint,py::nodelete>>(m, "BUSBEnd
111111
std::vector<uint8_t>buffer(dataLength);
112112
ssize_t result = self.ControlTransfer(requestType, request, value, index, length, buffer.data());
113113
returnpy::bytes(reinterpret_cast<constchar*>(buffer.data()), result);
114-
},"", py::arg("requestType"), py::arg("request"), py::arg("value"), py::arg("index"), py::arg("length"), py::arg("data")) .def("InterruptTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); ssize_t result = self.InterruptTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data")) .def("BulkTransfer", [](const MyDevice& self, py::bytes data) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); ssize_t result = self.BulkTransfer(buffer.data(), dataLength); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data")) .def("IsochronousTransfer", [](const MyDevice& self, py::bytes data, py::list packetDescriptors) { size_t dataLength = py::len(data); std::vector<uint8_t> buffer(dataLength); // Converti packetDescriptors da lista Python a un array C++ std::vector<usb_iso_packet_descriptor> descriptors; for (auto item : packetDescriptors) { descriptors.push_back(item.cast<usb_iso_packet_descriptor>()); } ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength, descriptors.data(), descriptors.size()); return py::bytes(reinterpret_cast<const char*>(buffer.data()), result); }, py::arg("data"), py::arg("packetDescriptors"))
114+
},"",py::arg("requestType"),py::arg("request"),py::arg("value"),py::arg("index"),py::arg("length"),py::arg("data"))
115115
//.def("InterruptTransfer", &BUSBEndpoint::InterruptTransfer, "", py::arg("data"), py::arg("length"))
116116
.def("InterruptTransfer", [](const BUSBEndpoint& self, py::bytes data) {
117117
size_t dataLength =py::len(data);
@@ -132,7 +132,7 @@ py::class_<BUSBEndpoint, std::unique_ptr<BUSBEndpoint,py::nodelete>>(m, "BUSBEnd
132132
std::vector<uint8_t>buffer(dataLength);
133133
ssize_t result = self.IsochronousTransfer(buffer.data(), dataLength,packetDescriptors,packetCount);
134134
returnpy::bytes(reinterpret_cast<constchar*>(buffer.data()), result);
135-
},"",py::arg("data"))
135+
},"",py::arg("data"),py::arg("packetDescriptors"),py::arg("packetCount"))
136136
.def("IsStalled", &BUSBEndpoint::IsStalled,"")
137137
.def("ClearStall", &BUSBEndpoint::ClearStall,"")
138138
;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp