Skip to content
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

Confusing serial.readUntil behaviour #3355

Closed
Parakleta opened this issue Aug 29, 2020 · 13 comments
Closed

Confusing serial.readUntil behaviour #3355

Parakleta opened this issue Aug 29, 2020 · 13 comments
Assignees

Comments

@Parakleta
Copy link

Describe the bug

When using serial.readUntil to read delimited data, the returned string doesn't line up with the delimiters. I cannot figure out how it chooses what data to return. I have tried several different delimiters and the result is always the same.

To Reproduce
Steps to reproduce the behavior:

Load the following program:

serial.setWriteLinePadding(0)
basic.forever(function () {
    serial.writeLine("||" + serial.readUntil(serial.delimiters(Delimiters.Colon)) + "##")
})

Then using a terminal program, send the following text ab:cd:ef:

Expected behavior

I should get back the following strings ||ab##, ||cd##, and ||ef##.

Screenshots

I get the following output in Termite:

61 62 3a 63 64 3a 65 66 3a                       ab:cd:ef:       
7c 7c 61 62 3a 63 23 23 0d 0a 7c 7c 23 23 0d 0a  ||ab:c##..||##..
7c 7c 65 66 23 23 0d 0a                          ||ef##..        
@abchatra
Copy link
Collaborator

@pelikhan can you answer this question?

@pelikhan
Copy link
Member

It only works with the first character of the string.

@abchatra
Copy link
Collaborator

Questions answered

@Parakleta
Copy link
Author

Sorry, but what does that mean?

@pelikhan
Copy link
Member

Only the first character of the delimiter string is used, the rest is ignored.

@Parakleta
Copy link
Author

How does that apply to the example I’ve given? I’m only using the colon character as a delimiter and it’s clearly not breaking at any consistent point

@pelikhan
Copy link
Member

Sorry i read the sample wrong.

@pelikhan pelikhan reopened this Mar 25, 2021
@abchatra
Copy link
Collaborator

@pelikhan is this is a bug?

@Parakleta
Copy link
Author

Also curious to know what your basis for saying only the first delimiter character is used. It's not clear from the documentation about the readUntil method but the onDataReceived method clearly states "delimiters is a string containing any of the character to match" which suggests that it delimits on any matching character, and I would have assumed readUntil would operate the same way. Could you also please clarify this point since we're here?

@Parakleta
Copy link
Author

I would assume anything with inconsistent behaviour is a bug, which is why I reported it. :)

@pelikhan
Copy link
Member

pelikhan commented Mar 25, 2021 via email

@martinwork
Copy link
Contributor

It's OK with V2 but not V1. I've created lancaster-university/microbit-dal#480

@abchatra
Copy link
Collaborator

this is a dal external issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants