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

problem talking with sigrok #131

Closed
folkertvanheusden opened this issue Nov 18, 2021 · 5 comments
Closed

problem talking with sigrok #131

folkertvanheusden opened this issue Nov 18, 2021 · 5 comments

Comments

@folkertvanheusden
Copy link
Contributor

Hi,

The example in scpi-parser/examples/test-tcp is not compatible with sigrok:

sr: [00:00.005751] hwdriver: sr_config_list(): key 2147418112 (NULL) sdi (nil) cg NULL -> [uint32 20000]
sr: [00:00.005794] serial: Parsed serial device: tcp-raw/localhost/5025.
sr: [00:00.005813] scpi: Opening RAW TCP device tcp-raw/localhost/5025.
sr: [00:00.006057] scpi_tcp: Successfully sent SCPI command: '*IDN?'.
sr: [00:00.006116] scpi: Got response: 'MANUFACTURE', length 11.
sr: [00:00.006131] scpi: IDN response not according to spec: 'MANUFACTURE'

I believe this seems to be caused by the '*IDN?' response to be send in multiple write-calls causing multiple tcp/ip packets which are received as multiple read()-calls.

recvfrom(4, "*IDN?\n", 10, 0, NULL, NULL) = 6
write(4, "MANUFACTURE", 11)             = 11
write(4, ",", 1)                        = 1
write(4, "INSTR2013", 9)                = -1 EPIPE (Broken pipe)

sigrok-test.pcap.zip

@WyoOutlaw
Copy link

WyoOutlaw commented Nov 18, 2021 via email

@folkertvanheusden
Copy link
Contributor Author

@WyoOutlaw yes; at https://github.com/j123b567/scpi-parser/blob/master/libscpi/src/ieee488.c#L271 there's the code that emits it as 4 seperate mnemonics.
Eventually https://github.com/j123b567/scpi-parser/blob/master/libscpi/src/parser.c#L361 is called which calls writeData and that ends with a call to a write() call.
So that's not easy to fix.

@folkertvanheusden
Copy link
Contributor Author

folkertvanheusden commented Nov 18, 2021

Well, you can disable(!) the 'TCP_NODELAY' socket option while processing *IDN?
That way one can reasonably sure that the 4 packets are concatenated.
See 2a1fbbd in the pull request.

@j123b567
Copy link
Owner

The problem is on the sigrok site so the only correct solution is https://sigrok.org/bugzilla/show_bug.cgi?id=1750

TCP is stream protocol and underlaying packets are just unimportant technological detail. You should always depend on your message boundary (which is \n in SCPI). Unfortunately, many developers thing, that packets are important and they are doing the message boundaries, which is in case of TCP completely wrong assumption.

SCPI parser has API for this, so developer is free to implement output buffering. It is the reason, why there is separate write and flush callbacks. With write, you can write to your memory buffer and with flush, you can send the buffer over the wire.

You can also persuade the TCP stack not to send so often so it can buffer output messages for you.

Thank you @folkertvanheusden for both creating the sigrok issue and providing the TCP_NODELAY example.

j123b567 added a commit that referenced this issue Jan 16, 2023
see issue #131 (problem talking to sigrok over tcp)
@j123b567
Copy link
Owner

Should be solved by #133 on our side.

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

No branches or pull requests

3 participants