-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Update usbtmc read to handle transfer_size
and discard alignment bytes
#465
Update usbtmc read to handle transfer_size
and discard alignment bytes
#465
Conversation
… wMaxPacketSize discrepancies in some drivers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. The logic seems sound except for the collection of the received valid data in the received_message bytearray (see comment).
Can you also add an entry to the changelog ?
@hcoffin-vecatom @arr-ee would you mind having a look ?
Co-authored-by: Matthieu Dartiailh <[email protected]>
I will wait to see if @arr-ee or @hcoffin-vecatom want to comment before merging. They have contributed to usbtmc support and have more test capabilities than I do, to check the changes. |
This does seem to mess things up a little with my Siglent SDG 1062X, but I think @Jimmyvandenbergh 's changes follows the USBTMC protocol better so I think its probably for the best. It is still significantly better than before #449 where I would get different responses each time I ran the code because a full message wasn't being read. For other's reference I'll put what happens on my device: I run
and expect the response With the changes in this PR, I instead get The reason this happens is, in the first transfer, the device sets the transfer size to 52 when it should be 56. So, the device sends the two transactions (I'm including the header just for completeness) Then, a second transfer occurs with the following response |
One more note: Examples: For my 1062X, Siglent seems to be relying on the termination character to determine which bytes might be alignment bytes. The transfer size reported by the device in the header seems to max out at 52 (i.e., the max that can be sent in one transaction), even if a transfer is multiple transactions, and is therefore pretty much meaningless. For @arr-ee 's SDG2122X (#449 (comment)) it seems like the device never reports an EOM and instead relies on the termination character to specify that a message is complete (each transfer is still finished after a short transaction). In issue #463 , the Rigol DS1102Z-E doesn't seem to be sending short transactions to end a transfer, but the device does put a termination character at the end of the last transaction, presumably to indicate that no more data will be sent. Screenshot from USBTMC spec that I am using to define the terms "message", "transfer", and "transaction": |
@hcoffin-vecatom according to table 4 or 9 of the USBTMC specification.
so this seems that if the bmTransferAttributes is not set this field must be ignored else one needs to stop reading data when for example `\n is set as termination char.
As this is part of the header and should be > 0x000000.
Looking at both message you receive then one is wxMaxPacketsize (52+12 start package = 64) and the other is the short package size (4). Which fulfills the USBTMC spec when termination char is met. So has the Siglent device has termination char enabled? for reference for everyone: the official test measurement class specification |
Bytes 4-7 are actually 0x34 0x00 0x00 0x00 for that transaction, not 0x00 0x00 0x00 0x00, it's just printed funny because 0x34 (52 decimal) is the ascii code for the character '4' (so it prints 4\x00\x00\x00). I probably should have printed the header as pure hex values to make it more clear. |
Got it, then everything makes sense in your comment. With this information and following the USBTMC protocol, either one of following should happen
|
Agreed it is a bug on the Siglent device side. Your PR matches the protocol as far as I understand it. I don't think a workaround needs to be included, but I figured I would share my buggy device experience (along with the others mentioned) in case someone is trying to figure out what is going on with their own buggy device. |
Between this and #463 I wonder if we should at least include a WARN when used with known “quirky” devices pointing to relevant issues since these behaviours are quite subtle and confusing, and are likely to be hit by quite a few people since both Rigol and Siglent devices in question target the lower end of the market. I hope to find some time to look into #463 and quirks support soon; meanwhile, enormous thanks to @Jimmyvandenbergh and @hcoffin-vecatom for your time and a very educational dive into the standard! |
Thanks for the very nice discussion indeed. |
Got some time to dive a bit further in the Rigol communication, since we have a Rigol DG1022Z at work.
Therefore this is a bug in their software, when the requested bytes (including USBTMCHEADER) are equal to the I have setup a test with our USBTMC device, and can see these USBTMC devices send a USBTMC 2.0 specification:
I think some adjustments need to be made to the code as also the header should be filled with the requested bytes and not the chucks. |
Could this be linked to the discussion in #468 ? Would you have the bandwidth to test this patch ? |
@MatthieuDartiailh i will have a look, and also #468 where you looped me in. just updated this code to a working variant for Rigol DG1022Z and our own instruments in PR #470 |
This PR resolves an issue where the
wMaxPacketSize
is incorrectly reported by certain drivers.As referenced in PR #417,
wMaxPacketSize
from the USB endpoints should be used. However, on Windows with thelibusb1
driver,wMaxPacketSize
is always reported as1024
, even for USB 2.0 devices, where it should be512
(wMaxPacketSize = 0x200
). This can be listed with theUSB Device Viewer
of Windows.To address this, the current PR enhances the changes made in PR #449 by leveraging the known
transfer_size
value from the USBTMC header, ensuring correct data handling despite incorrectwMaxPacketSize
reporting by the driver.Additionally, this PR fixes an issue from PR #449 where alignment bytes were not being discarded. The message should only contain the number of bytes indicated by
transfer_size
, so the USBTMC header and any alignment bytes are now properly discarded.black . && isort -c . && flake8
with no errors