Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

466
Visualizações
How to create virtual CAN port on linux? (C++)

I want to create program that would emulate CAN port for testing purposes for another big application. Program should send previously recorded data through this virtual CAN. Anyone has any experience with such thing?

I'm thinking to establish virtual COM, and send through it data packed in CAN Frames. Could it work? And how could I establish virtual COM on linux? Found this thread Virtual Serial Port for Linux but sadly I don't get how could it be implemented into source code of program (beginner linux user and programmer under linux).

Would love to read your experience and suggestions.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need SocketCAN driver, that is available on modern Linux distributions like Ubuntu etc. SocketCAN provides a virtual CAN port driver:

sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

Now you can send and receive CAN frames over vcan0 device. Wikipedia article provides simple code example on how to use SocketCAN.

You'll also need can-utils for testing purposes.

You'll find more information about SocketCAN and its usage on eLinux.org

over 4 years ago · Santiago Trujillo Relatório

0

Tutorial

PART 1 - Creating a program to emulate CAN


  • You can use the following bash program to create a virtual CAN port (vcan) in Linux:

    setup_vcan.sh

    #!/bin/bash
    
    # Using can1 as an example
    CAN_PORT="can1"
    
    sudo modprobe vcan
    sudo ip link add dev $CAN_PORT type vcan
    sudo ip link set up $CAN_PORT
    
  • Make the bash program executable:

    chmod +x setup_vcan.sh
    
  • Run the bash program:

    ./setup_vcan.sh
    

PART 2 - Recording and Playback of CAN messages


  • Record the CAN messages into a log file (Replace $CAN_PORT with the name of your CAN port):

    candump -L $CAN_PORT > myfile.log
    
  • Playback the CAN messages from the log file:

    canplayer -I myfile.log
    
  • You can verify the playback by checking the output of candump:

    candump $CAN_PORT
    

References

  • @yegorich's Answer
  • Canplayer won't replay candump files
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda