Проблема с запуском службы для выполнения исполняемого файла c на Raspberry Pi 4. ⇐ Linux
-
Anonymous
Проблема с запуском службы для выполнения исполняемого файла c на Raspberry Pi 4.
I wrote a C program that reads data from a CAN socket and sends it through an RF module (LoRa SX1262) connected via a USB cable to the Raspberry Pi. The code runs perfectly fine when I run it manually in the terminal, but when it runs as a service triggered by a path, it gives an error that it can't write to the USB port.
Error Message: Feb 07 10:42:49 driver lora-linux-main.out[893]: ERRO writing msg failed: Bad file descriptor
path file:
[Unit] Description= Path unit for USB network interface usb0 [Path] PathExists=/sys/class/net/usb0 Unit=your_service_name.service [Install] WantedBy=multi_user.target service file:
[Unit] Description=Your Service Description After=usb_trigger.path network.target [Service] Type=simple User=fstlisboa Group=dialout ExecStart=/home/fstlisboa/software-13/lora/bin/lora-linux-main.out Restart=always [Install] WantedBy=multi_user.target C code:
void send_msg(Lora lora, char *str) { char msg[strlen(str) + 4]; int serial_port_fd = 0; serial_port_fd = open_port(USB_PORT); if (msg == NULL) { perror("ERROR memory allocation failed"); exit(EXIT_FAILURE); } msg[0] = lora.dest_adress_high; msg[1] = lora.dest_adresss_low; msg[2] = lora.dest_freq; for (int i = 3; str != '\0'; i++) { msg = str; } if (write(serial_port_fd, (unsigned const char *)msg, strlen(str) + 4) < 0) { perror("ERRO writing msg failed"); return; } close(serial_port_fd); } I tried changing both the user permissions, changing the user, and changing the group and its permissions, but it didn't work.
Источник: https://stackoverflow.com/questions/780 ... berry-pi-4
I wrote a C program that reads data from a CAN socket and sends it through an RF module (LoRa SX1262) connected via a USB cable to the Raspberry Pi. The code runs perfectly fine when I run it manually in the terminal, but when it runs as a service triggered by a path, it gives an error that it can't write to the USB port.
Error Message: Feb 07 10:42:49 driver lora-linux-main.out[893]: ERRO writing msg failed: Bad file descriptor
path file:
[Unit] Description= Path unit for USB network interface usb0 [Path] PathExists=/sys/class/net/usb0 Unit=your_service_name.service [Install] WantedBy=multi_user.target service file:
[Unit] Description=Your Service Description After=usb_trigger.path network.target [Service] Type=simple User=fstlisboa Group=dialout ExecStart=/home/fstlisboa/software-13/lora/bin/lora-linux-main.out Restart=always [Install] WantedBy=multi_user.target C code:
void send_msg(Lora lora, char *str) { char msg[strlen(str) + 4]; int serial_port_fd = 0; serial_port_fd = open_port(USB_PORT); if (msg == NULL) { perror("ERROR memory allocation failed"); exit(EXIT_FAILURE); } msg[0] = lora.dest_adress_high; msg[1] = lora.dest_adresss_low; msg[2] = lora.dest_freq; for (int i = 3; str != '\0'; i++) { msg = str; } if (write(serial_port_fd, (unsigned const char *)msg, strlen(str) + 4) < 0) { perror("ERRO writing msg failed"); return; } close(serial_port_fd); } I tried changing both the user permissions, changing the user, and changing the group and its permissions, but it didn't work.
Источник: https://stackoverflow.com/questions/780 ... berry-pi-4
Мобильная версия