I2c input char count unknown

Not that familiar with serial communication. I need to read a string of characters from an i2c device, but I don’t know how many characters I need to read. It could be anything between 4 and 9. How do I set this up in xod?

Forgot to mention, every string is terminated with 3 bytes containing hex FF. Including the four byte ones. i.e. there is one byte of data, then three terminator bytes with hex FF.

Try to make a loop and process the input bytes one by one.
For example If the range is from 4 to 9 :

Request and read 4 bytes;
Process last 3 bytes (byte2, byte3 and byte4). If they are 0xFF then the terminal sequence is found and the byte1 is the data;
If they are not 0xFF then request and read one more byte (byte5);
Again process last 3 bytes (byte3, byte4 and byte5). If they are 0xFF then the terminal sequence is found and the data is byte1 and byte2;
And so repeat until you get a terminal sequence or nothing to read or other boundary conditions.

I hope I clearly described the idea =)

Looks like the easiest way to determine when you have a “complete” string is to collect the string in accumulate-string while sending a copy of each character received to pulse-on-sequence so you know when you have the 3-byte end sequence. At that point, accumulate-string should have a copy of the full string, including the 3-byte end sequence.

Thank you very much for the rapid responses, much appreciated.
@gabbapeople, do you mean that the loop has to contain a request for a single character AND a single character read? There is no way of just reading characters until a condition is met?
@gweimer thanks for the tip! I’d found accumulate-string, but was wondering how I was going to detect the end condition. Pulse-on-string is the answer.

I mean pulse-on-sequence, not pulse-on-string. Whoops. :flushed:

Hi @gweimer, I have run into a brick wall. I can get neither accumulate-string nor pulse-on-sequence to work as I expected.

This is what I ended up with. The output from the accumulate-string is unknown characters. The first two I sent it were 00h and 01h, and the last five were FFh. I figured that the pulse-on-sequence would trigger when it got three FFh characters and the count would be incremented, but that didn’t happen.

While mucking around with it I also noticed that the count (for the characters being added to the string) wasn’t reset when I hit the reset tweak, hardly surprising as there was nothing connected to the reset pin on the count. So I added a connection from the reset tweak (connected to RST on the accumulate-string node) to the RST button on the count. Tried it again, and NOTHING HAPPENED. No amount of clicking the tweak-pulse connected to the PUSH pin on the accumulate-string node caused anything to appear in the watch node connected to the output string of the accumulate-string node. I took the connection out again, and tried again, but again nothing. The structure is now back to exactly identical to the one in this screen shot, but nothing ever appears in the watch node connected to the accumulate-string node.

So in desperation I closed XOD without saving and reopened the project. Put everything back like it was in the screenshot above, and it all worked again. No idea what happened, but it seems to be back. Now my tweak-reset also resets the counter. Although I have noticed the old string stays on the output pin until another character is pushed to the node. I assume that’s intentional.

However, the behaviour has changed again. When I first started playing with this, characters like 00h and 01h were displayed as an empty box. FFh was displayed as a white diamond with a question mark in it. Now, however, any character that is not in the standard character set is just not displayed. In this shot you can see 3 "h"s in the string, but a count of 14 characters added to the string. The other 11 are all FFh.
Screenshot from 2019-12-31 16-52-57-shrunk

For what it’s worth I closed and reopened XOD again (having saved where everything was working before), and now FFh is displayed as the white diamond with question mark again, but 00h and 01h are not displayed.

And I can’t figure out how to set a string constant to a hex value.

Can you advise what I’ve done wrong?
I’m giving up now, I have to go out. I’ll get back to this next decade.

Happy new year!

Your images are too small to read most of it. I suspect your SEQ string is actually 'FFhFFhFFh" (9 characters) instead of just 3 special characters. Yeah…It looks like concat converts FFh into a string of “FFh”. I tried using accumulate-string to build the SEQ to use, but it still doesn’t work with FFh. It does work with 24h ("$"). I suspect pulse-on-sequence is doing an implicit conversion of FFh that breaks things.

Current implementation of pulse-on-sequence is not very robust. Searching for SEQ “XY” will fail to spot “XXY” since it matches 1st X, then determines second X is not next character in sequence, but does not see that it can be the 1st character in SEQ. It is not a simple fix since building a map of all possible character repeats for longer strings is not trivial; the simpler (but more compute & memory intensive) solution would be to compare the last length(SEQ) of input characters with SEQ. Storing input characters in char buffer like accumulate-string might resolve the FFh issue as well (but may not work well with input-string…). I don’t have much experience with strings in C++, so I don’t know what issues a rewrite would be running into… I’ll create a separate thread for these bugs & maybe XOD developers can come up with a cleaner fix than I would.