FORUM Forums Software CLS2SIM Software API INTERFACE WITH BRUNNER AC DRIVE

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3985
    Venkat
    Participant

    #include <iostream>
    #include <cstring>
    #include <cstdint>
    #include “CanPluginBase.h” // Include the CAN plugin header

    // Define constants for command types
    const uint32_t SDO_READ_COMMAND = 0xCA;
    const uint32_t SDO_WRITE_COMMAND = 0xCB;

    // Define response status codes
    const uint8_t STATUS_SUCCESS = 0x00;
    const uint8_t STATUS_SDO_ABORT = 0x01;
    const uint8_t STATUS_SDO_TIMEOUT = 0x02;
    const uint8_t STATUS_GENERAL_ERROR = 0x03;

    // Function to read SDO
    bool readSDO(CanPluginBase& canInterface, uint32_t nodeId, uint16_t index, uint8_t subindex, uint16_t timeout) {
    uint8_t request[8];
    uint8_t response[8];
    size_t responseLength = sizeof(response);

    // Prepare SDO Read request
    request[0] = SDO_READ_COMMAND; // Command
    request[1] = static_cast<uint8_t>(nodeId); // Node ID
    request[2] = static_cast<uint8_t>(index & 0xFF); // Index LSB
    request[3] = static_cast<uint8_t>((index >> 8) & 0xFF); // Index MSB
    request[4] = subindex; // Subindex
    request[5] = timeout & 0xFF; // Timeout LSB
    request[6] = (timeout >> 8) & 0xFF; // Timeout MSB

    // Send the SDO Read request
    canInterface.sendMessage(0x200 + nodeId, request, sizeof(request));

    // Receive the SDO Read response
    if (canInterface.receiveMessage(response, responseLength)) {
    if (response[1] == STATUS_SUCCESS) {
    // Process the response data (SDO Content)
    std::cout << “SDO Read Success: “;
    for (int i = 0; i < 4; i++) {
    std::cout << std::hex << static_cast<int>(response[2 + i]) << ” “;
    }
    std::cout << std::dec << std::endl;
    return true;
    }
    else {
    std::cerr << “SDO Read Failed: ” << static_cast<int>(response[1]) << std::endl;
    return false;
    }
    }
    std::cerr << “Failed to receive SDO Read response” << std::endl;
    return false;
    }

    // Function to write SDO
    bool writeSDO(CanPluginBase& canInterface, uint32_t nodeId, uint16_t index, uint8_t subindex, const uint8_t* value, uint8_t size, uint16_t timeout) {
    uint8_t request[8 + 4]; // 8 bytes for header + 4 bytes for value
    uint8_t response[8];
    size_t responseLength = sizeof(response);

    // Prepare SDO Write request
    request[0] = SDO_WRITE_COMMAND; // Command
    request[1] = static_cast<uint8_t>(nodeId); // Node ID
    request[2] = static_cast<uint8_t>(index & 0xFF); // Index LSB
    request[3] = static_cast<uint8_t>((index >> 8) & 0xFF); // Index MSB
    request[4] = subindex; // Subindex
    request[5] = size; // Size of value
    std::memcpy(&request[6], value, size); // Copy the value
    request[6 + size] = timeout & 0xFF; // Timeout LSB
    request[7 + size] = (timeout >> 8) & 0xFF; // Timeout MSB

    // Send the SDO Write request
    canInterface.sendMessage(0x200 + nodeId, request, sizeof(request));

    // Receive the SDO Write response
    if (canInterface.receiveMessage(response, responseLength)) {
    if (response[1] == STATUS_SUCCESS) {
    std::cout << “SDO Write Success” << std::endl return true;
    }
    else {
    std::cerr << “SDO Write Failed: ” << static_cast<int>(response[1]) << std::endl;
    return false;
    }
    }
    std::cerr << “Failed to receive SDO Write response” << std::endl;
    return false;
    }

    int main() {
    CanPluginBase canInterface; // Create an instance of the CAN interface
    uint32_t nodeId = 1; // Example Node ID
    uint16_t index = 0x2000; // Example Index
    uint8_t subindex = 0x01; // Example Subindex
    uint16_t timeout = 1000; // Timeout in milliseconds

    // Example value to write (4 bytes)
    uint8_t valueToWrite[4] = { 0x01, 0x02, 0x03, 0x04 };

    // Read SDO
    readSDO(canInterface, nodeId, index, subindex, timeout);

    // Write SDO
    writeSDO(canInterface, nodeId, index, subindex, valueToWrite, sizeof(valueToWrite), timeout);

    return 0;
    }

    HOW TO DRIVE THE AC DRIVE MOTOR USING C++ USING CODE ,
    WHICH LIBRARY WANT TO INCLUDE WITH CLS BRUNNER APPLICATION TO COMMUNICATE WITH THE C++ CODE AND BRUNNER CONTROLLLER,
    PLS SUGGEST ME ?

    #3986
    Diego Bürgin
    Keymaster

    Hi Venkat

    If you want to interact with Brunner hardware via CLS2Sim, you may use the network protocol described in the online help:
    https://cls2sim.brunner-innovation.swiss/
    There are no plug-and-play libraries provided.
    You have to write the network code on your own.

    If however you want to interact directly on the CAN bus,
    help with the CAN interface is only provided as paid support per hour.
    Please contact sales@brunner-innovation.swiss and request a support hour package.
    Once you have acquired support hours,
    you may open a ticket at https://helpdesk.brunner-innovation.ch/

    Kind Regards
    Diego

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

BRUNNER Forum​

In the BRUNNER forum you will find various discussions on different topics, such as setup, software use or general questions and concerns. 

Discuss with forum mebers, share your knowledge and experience or find answers to frequently asked questions that are answered directly by our Brunner team.

Go to BRUNNER Forum.

BRUNNER Helpdesk​

Do you have questions about a product you have already purchased or are you facing technical issues? 

Check our FAQs for quick help. The most common questions or problems are described there, including instructions.

If you are still stuck, please contact our BRUNNER Helpdesk. Open a ticket here.

BRUNNER Simulation​

BRUNNER is a leading manufacturer of flight simulation devices for the professional as well as the enthusiast sector.

Unlike other manufacturers, Brunner offers a realistic flight experience with the help of Force Feedback Technology and Control Loading System.

Discover the BRUNNER Shop.

BRUNNER Simulation

Industriestrasse 27
8335 Hittnau


+41 (0)44 953 10 10
info@brunner-innovation.swiss

© 2023 BRUNNER Elektronik AG | Privacy Policy |  Legal notice