Closed tomboland closed 4 years ago
Oh, I didn't know about TCGETS2
!
This code looks interesting: https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L148-L162
It looks like there's a better way to do this: https://github.com/elixir-circuits/circuits_uart/blob/master/src/uart_comm_unix.c#L183-L194
Apologies, no one ever sends me straces
and they're so helpful that I skimmed over almost everything else you posted when I saw TCGETS2. When I get more time, I'll read this more carefully. Thanks for the report!!!
Hi, thanks for the amazingly quick response! You may see I've just submitted a PR which uses those newer ioctls. I added a simple test, and all of the other tests are still passing (on my machine, fingers crossed on Travis!). Please let me know what you think!
And actually, I can talk to my DSP now! It works! :)
Fixed in f17ca766c11ad3f1a4859b38067df6e9929c84c1.
Setup
circuits_uart 1.4.1 OS is Manjaro Linux, Kernel 5.6.6 I7 Laptop Communicating with a USB serial cable to a DSP amplifier (Mac Audio Reference 2.1 DSP) The software I'm writing is here: https://github.com/tomboland/mac_audio_reference_2.1_dsp
This function is the first thing I'm trying to get working: https://github.com/tomboland/mac_audio_reference_2.1_dsp/blob/a10b572811bb51540c745f51f78bba553963fd00/lib/dsp_uart.ex#L56
I'm invoking it in this test here: https://github.com/tomboland/mac_audio_reference_2.1_dsp/blob/a10b572811bb51540c745f51f78bba553963fd00/test/dsp_uart_test.exs#L68
This is my first time using Elixir, and I've found it a pleasure to use, but you may find some stuff unidiomatic! I'm up for trying to submit a PR, I'm not bad with C, but I'll probably find it difficult to dive in and get this sorted. I'm hoping someone may have an instinct on it from the behaviour I'm describing! Thanks for any help, and please let me know if I can give you any more information, or be of any help at all (with guidance)! :)
Expected Behavior
I think I should be able to set a custom BAUD rate of 192000 or 200000. These speeds both work in an example python script I'm pasting below, which uses pyserial. I've tried with various other more conventional speeds, like 115200, 230400 and others, and I fail to communicate with my DSP using those speeds in python, but 192000 and 200000 work OK. The original software uses 192000. I think the problem is with the ioctl being used, but I must admit, it's not something I'm confident to make assertions about. The expected behaviour can be seen in the strace output from the python script that I'll put below. I'm also pasting strace output from my elixir program.
Actual Behavior
I get an ENOTTY error and cannot use the serial port at all when I configure a speed of 192000 or 200000.
Steps to Reproduce the Problem
I don't think you'd need my hardware to reproduce this, and actually, if I use tty0tty and try and connect to /dev/tnt0, I also get the ENOTTY error. Please see the strace output below, which is talking to the real hardware. You can see that the python script (where I've basically copypasta'd bits of the original code I'm rewriting) is getting the response I expect from the serialised message. Basically, if I send this binary: <<85, 2, 3, 7, 10>>, I should get back <<0xff>>
Python script
strace output from above srcipt (stdout/DEBUG messages show the expected response being recieved. I've limited the strace to -e trace=ioctl
strace output from elixir running
mix test