Writing 13 (0xd) actually writes 10 (0xa)

I have been having problems for many months now...over a year with communication between the Industruino and a host machine over USB using the `SerialUSB`. Today, perhaps I have come to the bottom of it. I wrote a script

for (uint8_t i{0}; i < 255; ++i)

    SerialUSB.write(&i, 1);

And I'm reading it similarly on the host. The output I get on the host is this:

[000769] t:main INFO real_machine:274 -- Good 0x0

[000821] t:main INFO real_machine:274 -- Good 0x1
[000872] t:main INFO real_machine:274 -- Good 0x2
[000873] t:main INFO real_machine:274 -- Good 0x3
[000924] t:main INFO real_machine:274 -- Good 0x4
[000975] t:main INFO real_machine:274 -- Good 0x5
[001027] t:main INFO real_machine:274 -- Good 0x6
[001078] t:main INFO real_machine:274 -- Good 0x7
[001130] t:main INFO real_machine:274 -- Good 0x8
[001181] t:main INFO real_machine:274 -- Good 0x9
[001232] t:main INFO real_machine:274 -- Good 0xa
[001284] t:main INFO real_machine:274 -- Good 0xb
[001336] t:main INFO real_machine:274 -- Good 0xc
[001387] t:main ERROR real_machine:272 -- Expected 0xd (13) got 0xa.
[001439] t:main INFO real_machine:274 -- Good 0xe
[001490] t:main INFO real_machine:274 -- Good 0xf
[001542] t:main INFO real_machine:274 -- Good 0x10
[001644] t:main ERROR real_machine:272 -- Expected 0x11 (17) got 0x12.
[001747] t:main ERROR real_machine:272 -- Expected 0x12 (18) got 0x14.
[001799] t:main ERROR real_machine:272 -- Expected 0x13 (19) got 0x15.
[001850] t:main ERROR real_machine:272 -- Expected 0x14 (20) got 0x16.
[001902] t:main ERROR real_machine:272 -- Expected 0x15 (21) got 0x17.
[001953] t:main ERROR real_machine:272 -- Expected 0x16 (22) got 0x18.
[002005] t:main ERROR real_machine:272 -- Expected 0x17 (23) got 0x19.
[002056] t:main ERROR real_machine:272 -- Expected 0x18 (24) got 0x1a.
[002108] t:main ERROR real_machine:272 -- Expected 0x19 (25) got 0x1b.
[002160] t:main ERROR real_machine:272 -- Expected 0x1a (26) got 0x1c.
[002211] t:main ERROR real_machine:272 -- Expected 0x1b (27) got 0x1d.
[002263] t:main ERROR real_machine:272 -- Expected 0x1c (28) got 0x1e.
[002314] t:main ERROR real_machine:272 -- Expected 0x1d (29) got 0x1f.
[002365] t:main ERROR real_machine:272 -- Expected 0x1e (30) got 0x20.
[002417] t:main ERROR real_machine:272 -- Expected 0x1f (31) got 0x21.

The `SerialUSB.write` overload taking a buffer (pointer) and a length should write binary data: https://www.arduino.cc/reference/en/language/functions/communication/serial/write/, however, it appears that byte 13 (0xd) is being translated to 10 (0xa). This might be natural for text-based transmissions (changing carriage return to line feed), but is very troublesome when attempting to submit binary data!! It looks like this also happens WITHIN submissions. Using something like `uint32_t num{0x100d00}; SerialUSB.write(&num, 4);`, I get:

[000670] t:main ERROR real_machine:282 -- Expected 0x10d00 (68864) got 0x10a00.
[000722] t:main ERROR real_machine:282 -- Expected 0x10d01 (68865) got 0x10a01.
[000773] t:main ERROR real_machine:282 -- Expected 0x10d02 (68866) got 0x10a02.
[000773] t:main ERROR real_machine:282 -- Expected 0x10d03 (68867) got 0x10a03.
[000825] t:main ERROR real_machine:282 -- Expected 0x10d04 (68868) got 0x10a04.

You can see that the INNER `0x0d`s are being converted to `0x0a`s.

I assume the other alignment issues are related. It looks like `0x11` and `0x13` simply aren't submitted?

Anyway, how do I get industruino to submit a byte 0x0d? How do I submit binary data using the SerialUSB interface?

Thank you for your time!

 

Aaron
Aaron
44
| 1 0 2
Asked on 3/23/22, 9:08 PM
0
vote
709 Views

I'm going to double-check the host settings to make sure there's no text processing there.

Aaron
on 3/24/22, 1:40 PM

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

68 follower(s)

Stats

Asked: 3/23/22, 9:08 PM
Seen: 709 times
Last updated: 3/24/22, 1:40 PM