Cleric-K / vJoySerialFeeder

Feed Virtual Joystick driver with data from a serial port
GNU General Public License v3.0
252 stars 55 forks source link

Linux version only runs on Ubuntu 16.04 #56

Closed yakupkaya closed 2 years ago

yakupkaya commented 2 years ago

Hello,

First of all thank you very much for all your efforts. I am using this tool on Windows without a problem. I am using it for connecting my Radiolink AT9S transmitter to simulators using SBUS on the receiver and Arduino UNO (with the sbus_invert sketch).

My problem is, on Linux I was only able to run it on Ubuntu 16.04. Later versions did not work. I first tried Manjaro and assumed it is a problem about Manjaro. Then I made a fresh insatll of Ubuntu 20.04 and it did not work. Looking at the release date, I assumed you tried it on Ubuntu 18.04 or 16.04 and tried to get it running on both with fresh installs and the same procedure/same Arduino. Only 16.04 worked.

I guess something changed after the Ubuntu version 16.04.

Do you have any idea about this?

Thanks and regards

Cleric-K commented 2 years ago

Hi, recently I haven't tested with Linux. Do you get any specific error?

yakupkaya commented 2 years ago

Hi,

The bottom bar of the app says: "Connected, Failsafe (Serial Port Read Timeout), 10 Updates per second / 100 ms between Updates". I am trying with the standart configuration for SBUS on the app (OpenTX and 8E2 100000 baud rate).

I have seen on another issue a discussion you made and I tried to get a dump of the port /dev/ttyACM0 and look whether I see the SBUS 25 byte packets that you mentioned, which should start with 0F and end with 00.

I used cutecom program for that purpose, and it seems the sbus information is coming to the serial port /dev/ttyACM0 on both versions of Ubuntu.

Ubuntu 16.04

000031f0: 09 0b 59 08 40 00 02 10   80 00 00 0f e6 ab 1f 60 
00003200: d3 27 13 99 c8 44 26 32   21 09 0b 59 08 40 00 02 
00003210: 10 80 00 00 0f e5 ab 1f   60 d3 27 13 99 c8 44 26 
00003220: 32 21 09 0b 59 08 40 00   02 10 80 00 00 0f e5 b3 
00003230: 1f 60 d3 27 13 99 c8 44   26 32 21 09 0b 59 08 40 
00003240: 00 02 10 80 00 00 0f e5   b3 1f 60 d3 27 13 99 c8 
00003250: 44 26 32 21 09 0b 59 08   40 00 02 10 80 00 00 0f 
00003260: e5 ab 1f 60 d3 27 13 99   c8 44 26 32 21 09 0b 59 
00003270: 08 40 00 02 10 80 00 00   0f e5 ab 1f 60 d3 27 13 
00003280: 99 c8 44 26 32 21 09 0b   59 08 40 00 02 10 80 00 
00003290: 00 0f e5 ab 1f 60 d3 27   13 99 c8 44 26 32 21 09 
000032a0: 0b 59 08 40 00 02 10 80   00 00 0f e5 ab 1f 60 d3 
000032b0: 27 13 99 c8 44 26 32 21   09 0b 59 08 40 00 02 10 

Ubuntu 20.04

00006304 40 00 02 10 80 00 00 0f   e6 b3 1f 60 d3 27 13 99  @
00006320 c8 44 26 32 21 09 0b 59   08 40 00 02 10 80 00 00  .D&2!␉␋Y  ␈@
00006336 0f e5 b3 1f 60 d3 27 13   99 c8 44 26 32 21 09 0b  ␏..␟`.'␓  ..D&2!␉␋
00006352 59 08 40 00 02 10 80 00   00 0f e5 b3 1f 60 d3 27  Y␈@
00006368 13 99 c8 44 26 32 21 09   0b 59 08 40 00 02 10 80  ␓..D&2!␉  ␋Y␈@
00006384 00 00 0f e6 ab 1f 60 d3   27 13 99 c8 44 26 32 21  
00006400 09 0b 59 08 40 00 02 10   80 00 00 0f e6 ab 1f 60  ␉␋Y␈@
00006416 d3 27 13 99 c8 44 26 32   21 09 0b 59 08 40 00 02  .'␓..D&2  !␉␋Y␈@
00006432 10 80 00 00 0f e5 ab 1f   60 d3 27 13 99 c8 44 26  ␐.
00006448 32 21 09 0b 59 08 40 00   02 10 80 00 00 0f e5 ab  2!␉␋Y␈@
00006464 1f 60 d3 27 13 99 c8 44   26 32 21 09 0b 59 08 40  ␟`.'␓..D  &2!␉␋Y␈@
00006480 00 02 10 80 00 00 0f e5   ab 1f 60 d3 27 13 99 c8  

I am really not experienced on serial communication or SBUS. So that was the only thing I was able to see.

Regards, Yakup

Cleric-K commented 2 years ago

Hm, data looks OK. Probably the app can't set the port mode properly. Have you tried executing vjsf as root?

yakupkaya commented 2 years ago

I tried it now with the root user, but it does not seem to be working either.

image

Cleric-K commented 2 years ago

I'm not sure what this might be let's do an experiment. Install socat sudo apt install socat. Then in terminal execute

sudo socat /dev/ttyACM0,rawer,b100000,parenb=1,cstopb=1 pty,link=/dev/ttyACMX,rawer

This practically creates virtual ttyACMX, which is piped to ACM0. First try from another terminal something like sudo hd /dev/ttyACMX to see some hex dump if data looks fine. If it does, try in vjsf to open ttyACMX instead. You may set the serial parameters to something like 115200N1. Generally these don't matter, because ACMX is not a real port but simply to make sure they are some standard values. Some pseudo terminals may refuse to set baud rate of 100000 (which is non-standard).

Cleric-K commented 2 years ago

You may add mode to the pty part: sudo socat /dev/ttyACM0,rawer,b100000,parenb=1,cstopb=1 pty,link=/dev/ttyACMX,rawer,mode=777

In this way the virtual port won't need root to be accessed.

yakupkaya commented 2 years ago

$ sudo socat /dev/ttyACM0,rawer,b100000,parenb=1,cstopb=1 pty,link=/dev/ttyACMX,rawer,mode=777 2022/02/24 12:30:53 socat[4144] E parseopts(): unknown option "b100000"

It does not accept the b option I guess.

yakupkaya commented 2 years ago

I can set the standard values though, like 9600 or 115200.

When I run for example:

sudo socat /dev/ttyACM0,rawer,b115200,parenb=1,cstopb=1 pty,link=/dev/ttyACMX,rawer,mode=777

I get this from hexdump with "sudo hd /dev/ttyACMX":

00005d80  13 b1 10 80 00 02 20 00  00 00 1f ce e3 3f 49 a1  |...... ......?I.|
00005d90  4f 23 31 83 8c 4e 66 41  11 13 b1 10 80 00 02 20  |O#1..NfA....... |
00005da0  00 00 00 1f ce e3 3f 4d  a1 4f 23 39 90 8c 4e 62  |......?M.O#9..Nb|
00005db0  41 11 17 b1 10 80 00 02  20 00 00 00 1f ce e3 3f  |A....... ......?|
00005dc0  4d 13 73 dc b8 3a 7e cc  e6 ce 10 11 13 b9 18 80  |M.s..:~.........|
00005dd0  00 02 20 00 00 00 1f ce  e3 3f 4d a1 4f 23 39 90  |.. ......?M.O#9.|
00005de0  8c 4e 62 41 11 13 b1 10  80 00 02 20 00 00 00 1f  |.NbA....... ....|
00005df0  c9 e7 3f 49 a1 4f 27 31  98 84 4e 66 41 11 13 b1  |..?I.O'1..NfA...|
00005e00  10 80 00 02 20 00 00 00  1f ce e3 3f 4d a1 4f 23  |.... ......?M.O#|
00005e10  31 83 8c 4e 66 41 11 13  b1 10 80 00 02 20 00 00  |1..NfA....... ..|
00005e20  00 1f ce e3 3f 49 a7 4f  23 31 90 88 4e 66 41 11  |....?I.O#1..NfA.|
00005e30  13 b1 18 80 00 06 20 00  00 00 1f ce e3 3f 4d a1  |...... ......?M.|
Cleric-K commented 2 years ago

The standard methods can't set custom baud rate. Let's try this:

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <asm/termios.h>

int main()
{
    int fd, ret;
    struct termios2 config;

    fd = open("/dev/ttyUSB0", O_RDWR);
    if (fd < 0)
        printf("Failed to open /dev/ttyACM0 - fd = %d\n", fd);

    // Set custom buad rate
    ret = ioctl(fd, TCGETS2, &config);
     if (!ret) {
        config.c_cflag &= ~CBAUD;
        config.c_cflag |= BOTHER;
        config.c_ispeed = 100000;
        config.c_ospeed = 100000;
        ret = ioctl(fd, TCSETS2, &config);
}
    close(fd);
    return ret;

}

Copy-paste the above code and save it into a file, for example setspeed.c Then compile it gcc setspeed.c -o setspeed Ignore warnings then do: sudo stty -F /dev/ttyACM0 raw parenb cstopb the above sets the port in even parity and 2 stop bits sudo ./setspeed the above sets the custom port speed Then do: sudo socat /dev/ttyACM0 pty,link=/dev/ttyACMX,rawer,mode=777 Note we're not providing any options after ACM0 - we set them previously with the commands above.

yakupkaya commented 2 years ago

I get this now:

$  sudo stty -F /dev/ttyACM0 raw parenb cstopb
$  sudo ./setspeed
Failed to open /dev/ttyACM0 - fd = -1
$ ll /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Feb 24 13:12 /dev/ttyACM0
Cleric-K commented 2 years ago

Sorry, my mistake, please edit the .c file. I've replaced ACM for the error message but the actual open call is still USB0 and recompile

yakupkaya commented 2 years ago

This time socat worked. I get this from the hexdump when I listen ttyACMX which looks OK to me:

00006840  9f a5 d1 27 13 99 c8 44  26 32 21 09 0b 59 08 40  |...'...D&2!..Y.@|
00006850  00 02 10 80 00 00 0f e6  73 9f a5 d1 27 13 99 c8  |........s...'...|
00006860  44 26 32 21 09 0b 59 08  40 00 02 10 80 00 00 0f  |D&2!..Y.@.......|
00006870  e6 73 9f a5 d1 27 13 99  c8 44 26 32 21 09 0b 59  |.s...'...D&2!..Y|
00006880  08 40 00 02 10 80 00 00  0f e5 73 9f a5 d1 27 13  |.@........s...'.|
00006890  99 c8 44 26 32 21 09 0b  59 08 40 00 02 10 80 00  |..D&2!..Y.@.....|
000068a0  00 0f e5 73 9f a5 d1 27  13 99 c8 44 26 32 21 09  |...s...'...D&2!.|
000068b0  0b 59 08 40 00 02 10 80  00 00 0f e6 73 9f a5 d1  |.Y.@........s...|
000068c0  27 13 99 c8 44 26 32 21  09 0b 59 08 40 00 02 10  |'...D&2!..Y.@...|
000068d0  80 00 00 0f e6 73 9f a5  d3 27 13 99 c8 44 26 32  |.....s...'...D&2|

But vjsf refuses to open /dev/ttyACMX, evnethough I started it with root user:

image

And ls shows:

$ ll /dev/ttyACMX
lrwxrwxrwx 1 root root 11 Feb 24 14:15 /dev/ttyACMX -> /dev/pts/11
Cleric-K commented 2 years ago

Are you sure hexdump is not working while you try to connect in vjsf?

Also did you set the port options (in vjsf Port Setup) to some sane values like 115200 8N1 ?

yakupkaya commented 2 years ago

Here are the settings:

image

Here is the ps output. Hexdump is not running during the test.

ps -ef | grep ACMX
root       19895    3081  0 14:58 pts/0    00:00:00 sudo socat /dev/ttyACM0 pty,link=/dev/ttyACMX,rawer,mode=777
root       19896   19895  0 14:58 pts/0    00:00:00 socat /dev/ttyACM0 pty,link=/dev/ttyACMX,rawer,mode=777
black      19907    4729  0 14:58 pts/2    00:00:00 grep --color=auto ACMX
Cleric-K commented 2 years ago

Strange stuff. Another experiment: open in vjsf normally ACM0 (stop socat). Then you should get the timeout as before. Then in console try: sudo stty -F /dev/ttyACM0 raw parenb cstopb sudo ./setspeed

I'm not sure if this will work. Basically the attempt is to change the port settings while it is running.

yakupkaya commented 2 years ago

This worked! :)

I changed to normal settings (8E2, 100000) and started vjsf with ttyACM0 as you mentioned. And then ran the two commands. Now I see the movement on channels when I move sticks on my transmitter.

image

Cleric-K commented 2 years ago

That's quite strange. Actually I set the speed of the port in vjsf, in the exact same way as it is in the .c file I've sent you. I have no idea why it fails. But anyway. For the time being you may use this method. I'm planning to work on vjsf in the coming weeks, there are few pending features to be integrated, so I'll try to look into this also.

yakupkaya commented 2 years ago

Thank you very much for all your efforts and fast resolution. And thanks a lot for your time.

Maybe I should also mention one more thing. You probably already know this, but I wanted to share my observation anyway. When I previously followed below steps, I have seen the speed is changed by vjsf.

Basically: 1 - I run "sudo stty -F /dev/ttyACM0 raw parenb cstopb" 2 - I run "sudo socat /dev/ttyACM0 pty,link=/dev/ttyACMX,rawer,mode=777" 3- I run "sudo .setspeed" 4- I check the Hex output and it is OK 5- I try to connect the interface ttyACM0 from vjsf with standart settings. Disconnect. 6- I check the Hex output, and it is NOT OK this time 7- I run the "sudo .setspeed" 8- HEX output is OK again.

Have a nice day, and stay safe! Regards

Cleric-K commented 2 years ago

Thanks for the input. I tried to make a small change: vJoySerialFeeder.zip Can you try with this exe?

yakupkaya commented 2 years ago

This gives an error error unfortunately:

# mono vJoySerialFeeder.exe 

Unhandled Exception:
System.TypeLoadException: Could not load type of field 'vJoySerialFeeder.Lua:script' (1) due to: Could not load file or assembly 'MoonSharp.Interpreter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=921e73ce94aa17f8' or one of its dependencies.
  at vJoySerialFeeder.MainForm.resetProfile () [0x00006] in <d3dc42fbe117463eb5e12d466e516aed>:0 
  at vJoySerialFeeder.MainForm..ctor (System.String[] args) [0x00268] in <d3dc42fbe117463eb5e12d466e516aed>:0 
  at (wrapper remoting-invoke-with-check) vJoySerialFeeder.MainForm..ctor(string[])
  at vJoySerialFeeder.Program.Main (System.String[] args) [0x0000b] in <d3dc42fbe117463eb5e12d466e516aed>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'vJoySerialFeeder.Lua:script' (1) due to: Could not load file or assembly 'MoonSharp.Interpreter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=921e73ce94aa17f8' or one of its dependencies.
  at vJoySerialFeeder.MainForm.resetProfile () [0x00006] in <d3dc42fbe117463eb5e12d466e516aed>:0 
  at vJoySerialFeeder.MainForm..ctor (System.String[] args) [0x00268] in <d3dc42fbe117463eb5e12d466e516aed>:0 
  at (wrapper remoting-invoke-with-check) vJoySerialFeeder.MainForm..ctor(string[])
  at vJoySerialFeeder.Program.Main (System.String[] args) [0x0000b] in <d3dc42fbe117463eb5e12d466e516aed>:0 
yakupkaya commented 2 years ago

Sorry my mistake, I extracted the exe to another place, and exe needs the dll file. Now it works I think :) Thank you so much.

yakupkaya commented 2 years ago

I can also confirm that this new exe works on Manjaro 21.2.3. Thanks a lot again.

Cleric-K commented 2 years ago

Great! So far the code was written in such a way that it first tries to open the port directly with the desired baud rate. If it fails (as it fails with E parseopts(): unknown option "b100000" it tries again by opening with a safe rate 9600 and then goes on to execute the same commands as in the .c file.

It seems that in the new Ubuntus opening the port does not fail but simply silently remains set with some wrong bps. Now I made it to use the .c commands in all cases.

Thanks, we tracked a bug :)

yakupkaya commented 2 years ago

I thank you :) Have a very nice day!

yakupkaya commented 2 years ago

One last comment if I may :) Procedure for Manjaro Linux (or Arch) is a little different from Ubuntu installations. So here are the different steps:

The rest is the same procedure.

Kind regards

Cleric-K commented 2 years ago

Thanks for the info. Yeah it's probably still different on RPM based distros. Anyway, I assume that anyone using Linux will figure out the corresponding packages for their platform like you did ;)

yakupkaya commented 2 years ago

I agree 😄

Cleric-K commented 2 years ago

Hi, this fix has been added to the new release. Thanks for the help!

yakupkaya commented 2 years ago

Hi, this fix has been added to the new release. Thanks for the help!

No problem, it was pleasure for me. I thank you very much for all your time and efforts.