Replies: 2 comments 3 replies
-
| Do you have a non-python example you can post/link that does what you're looking for? ... but I think these tests do what you're looking for? https://github.com/robotpy/mostrobotpy/blob/main/subprojects/pyntcore/tests/test_struct_topic.py | 
Beta Was this translation helpful? Give feedback.
-
| I poked at this a bit more and found a way to do it: What we've done in Java for a long time relies on  NetworkTableInstance inst = NetworkTableInstance.getDefault();
m_poller = new NetworkTableListenerPoller(inst);
m_poller.addListener(
     new MultiSubscriber(inst, new String[] { "foo" }, PubSubOption.keepDuplicates(true)),
     EnumSet.of(NetworkTableEvent.Kind.kValueAll));
...
for (NetworkTableEvent e : m_poller.readQueue()) {
    ValueEventData ve = e.valueData;
    NetworkTableValue v = ve.value;
    byte[] b = v.getRaw();
    Rotation3d[] sights = m_buf.readArray(b);
}                       Here's an example of using a StructArray subscriber in python, which does the unpacking (but can't subscribe to a prefix): inst = ntcore.NetworkTableInstance.getDefault()
sub = inst.getStructArrayTopic("foo/1", Datum).subscribe([])
...
queue = sub.readQueue()
item = queue.pop()
value0: Datum = item.value[0]
value1: Datum = item.value[1]Here's an example that works in python, stepping through the raw array: inst = ntcore.NetworkTableInstance.getDefault()
poller = ntcore.NetworkTableListenerPoller(inst)
poller.addListener(["foo"], ntcore.EventFlags.kValueAll)
...
queue = poller.readQueue()
event = queue.pop()
item_size = wpistruct.getSize(Datum)
raw_array  =  event.data.value.getRaw()
raw_item_array = [raw_array[i : i + item_size] for i in range(0, len(raw_array), item_size)]
value0: Datum = wpistruct.unpack(Datum, raw_item_array[0])
value1: Datum = wpistruct.unpack(Datum, raw_item_array[1])So this works fine, it's just that the "listener poller" unpacking is so much clumsier than in the nice clean "subscriber" case. | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
So I have a set of StructArrayTopics identified by a key prefix, and I want to subscribe to updates for all of them, and I'm having trouble figuring out how to do it.
I tried using a NetworkTableListenerPoller with readQueue(), from which I can get ValueEventData and eventually Value.getRaw(), but I can't find a way to unpack the bytes into the correct array.
Is there a wpistruct array unpacker? or some other way to combine "subscribe to prefix" with "StructArray"?
thanks!
Beta Was this translation helpful? Give feedback.
All reactions