FORUM › Forums › Software › CLS2SIM Software › API INTERFACE WITH BRUNNER AC DRIVE
- This topic has 1 reply, 2 voices, and was last updated 3 weeks, 4 days ago by Diego Bürgin.
-
AuthorPosts
-
29/11/2024 at 08:29 #3985VenkatParticipant
#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 ?29/11/2024 at 11:37 #3986Diego BürginKeymasterHi 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 -
AuthorPosts
- You must be logged in to reply to this topic.