-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bytearray index out of range #180
Comments
OK, this is mainly a documentation issue, i.e. my fault... The complete DAQ process -- setup, ODT allocation and recording is part of pyXCP; the example file run_daq.py is exactly what you are you looking for. There is some documentation in form of this discussion (will be reworked to offical documentation soon). |
Unfortunately, I had already tried that approach and this was the output:
Created a TRANSPORT = "ETH"
HOST = "HOSTNAME"
PORT = 1111
PROTOCOL = "UDP"
IPV6 = false
CREATE_DAQ_TIMESTAMPS = false And this is the script I ran: ap = ArgumentParser(description="DAQ test")
a2l = A2lParser(a2l_path)
signal = XcpUtils.get_attribute_dict_from_a2l_list(a2l.variable_list, signal_name)
event = XcpUtils.get_attribute_dict_from_a2l_list(a2l.event_list, event_name)
daq_lists = [
DaqList(
"part_1",
event.get("channel_number"),
False,
False,
[
(signal_name, signal.get("ecu_address"), 0, "U32"),
],
)
]
daq_parser = DaqRecorder(daq_lists, "run_daq", 1) # Record to ".xmraw" file.
with ap.run(policy=daq_parser) as x:
x.connect()
if x.slaveProperties.optionalCommMode:
x.getCommModeInfo()
x.cond_unlock("DAQ") # DAQ resource is locked in many cases.
print("setup DAQ lists.")
daq_parser.setup()
print("start DAQ lists.")
daq_parser.start()
time.sleep(10) # Run for 10 seconds.
print("Stop DAQ....")
daq_parser.stop()
print("finalize DAQ lists.\n")
x.disconnect() |
The timestamping code at this point is brand new; I didn't test the "no-timestamping" case; this is (hopefully) fixed now. |
Thanks! Seems to be running correctly, just a question about decoding, I used the Decoder example you have in this discussion, and ran into an issue, the measurement I'm reading is an array of size 784, but it only is giving me an array of size 1, is there a way to get the full array? Using this script ap = ArgumentParser(description="DAQ test")
a2l = A2lParser(a2l_path)
signal = XcpUtils.get_attribute_dict_from_a2l_list(a2l.variable_list, signal_name)
event = XcpUtils.get_attribute_dict_from_a2l_list(a2l.event_list, event_name)
daq_lists = [
DaqList(
"part_1",
event.get("channel_number"),
False,
False,
[
(signal_name, signal.get("ecu_address"), 0, "U32"),
],
)
]
# daq_parser = DaqToCsv(daq_lists) # Record to CSV file(s).
daq_parser = DaqRecorder(daq_lists, "run_daq", 1) # Record to ".xmraw" file.
with ap.run(policy=daq_parser) as x:
x.connect()
if x.slaveProperties.optionalCommMode:
x.getCommModeInfo()
x.cond_unlock("DAQ") # DAQ resource is locked in many cases.
print("setup DAQ lists.")
daq_parser.setup()
print("start DAQ lists.")
daq_parser.start()
time.sleep(1) # Run for 1 second.
print("Stop DAQ....")
daq_parser.stop()
print("finalize DAQ lists.\n")
x.disconnect()
# print(x.transport.policy.daqQueue)
class Decoder(XcpLogFileDecoder):
def __init__(self, recording_file_name: str) -> None:
"""
Regular Python constructor, gets the file name of the recording.
At this point you may set an output file name, e.g.
self.my_file_name = Path(recording_file_name).with_suffix(".txt")
"""
super().__init__(recording_file_name)
self.data = []
def initialize(self) -> None:
"""
Here you may create files, objects, ...
"""
def finalize(self) -> None:
"""
Close files, and the like at this stage.
"""
def on_daq_list(
self, daq_list_num: int, timestamp0: int, timestamp1: int, measurements: list
) -> None:
"""
As you may guess, this is called on every finished DAQ-list.
"""
print("measurements", measurements)
decoder = Decoder("run_daq.xmraw")
res = decoder.run() Got this output:
|
Hi, There's currently no built-in support for arrays, but this is a good point; I think, this feature could be easily added. For now you may try the following code: TYPE_SIZES = {
"U8": 1,
"I8": 1,
"U16": 2,
"I16": 2,
"U32": 4,
"I32": 4,
"U64": 8,
"I64": 8,
"F32": 4,
"F64": 8,
}
def create_array(name, tp: str, base_addr: int, addr_ext: 0, arr_size: int):
result = []
addr = base_addr
type_size = TYPE_SIZES[tp]
for idx in range(arr_size):
result.append((f"{name}[{idx}]", addr, addr_ext, tp))
addr += type_size
return result
DAQ_LISTS = [
DaqList(
"array_quantity",
1,
False,
True,
create_array("array", "I32", 0x4711, 0, 16) # just as example...
)
] But note:
Honestly, I don't understand why you want to bypass ArgumentParser, which is technically the interface to traitlets configuration handling. |
Also, is it possible to set the daq lists after the daq parser was set in AP.run(policy=daq_parser)? Recently came into an issue that my A2L file had set the wrong channel numbers and as a workaround I'm using the index from the channels list that are available using x.getDaqInfo |
I am also facing the same issue with the ArgumentParser, I think that it would be valuable to have the option to use the Master object directly rather than rely on the ArgumentParser completely. This is one of the reasons why I still use v0.21.11. |
Hi, I'm currently using pyxcp to read some signal's values using DAQ, but ran into a "bytearray index out of range" error that makes me unable to read the values.
As you can see in this image, response is an empty bytearray, but data is a bytearray of length 1799.
Here is the script I'm running that gets me this error
I'm running commands in the same order as Vector's CANape, and CANape does return some values with the same signal I'm reading in this script, any ideas what might I be doing wrong?
Python version, OS and pyxcp version:
The text was updated successfully, but these errors were encountered: