Skip to content
Snippets Groups Projects
Commit a02dc61e authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added an example for the bulk read feature.

parent e89257fa
No related branches found
No related tags found
No related merge requests found
...@@ -15,3 +15,9 @@ ADD_EXECUTABLE(test_dynamixel_sync test_dynamixel_sync.cpp) ...@@ -15,3 +15,9 @@ ADD_EXECUTABLE(test_dynamixel_sync test_dynamixel_sync.cpp)
# edit the following line to add the necessary libraries # edit the following line to add the necessary libraries
TARGET_LINK_LIBRARIES(test_dynamixel_sync dynamixel) TARGET_LINK_LIBRARIES(test_dynamixel_sync dynamixel)
# edit the following line to add the source code for the example and the name of the executable
ADD_EXECUTABLE(test_dynamixel_bulk_read test_dynamixel_bulk_read.cpp)
# edit the following line to add the necessary libraries
TARGET_LINK_LIBRARIES(test_dynamixel_bulk_read dynamixel)
#include "eventexceptions.h"
#include "dynamixelserver.h"
#include "dynamixel.h"
#include <iostream>
int main(int argc, char *argv[])
{
CDynamixelServer *dyn_server=CDynamixelServer::instance();
CEventServer *event_server=CEventServer::instance();
int i,j,num_servos;
std::vector<int> devices;
std::list<std::string> events;
unsigned char start_addrs=0x00;
unsigned char data[49];
CDynamixel *device;
try{
if(dyn_server->get_num_buses()>0)
{
events.push_back(dyn_server->get_scan_done_event_id());
dyn_server->config_bus(0,1000000);
dyn_server->start_scan();
event_server->wait_first(events);
devices=dyn_server->get_device_ids();
num_servos=devices.size();
for(i=0;i<num_servos;i++)
{
device=dyn_server->get_device(devices[i]);
device->read_registers(start_addrs,data,49);
std::cout << "Servo " << std::dec << devices[i] << " registers:" << std::endl;
for(j=0;j<49;j++)
std::cout << "Register 0x" << std::hex << j << ": 0x" << (int)data[j] << std::endl;
data[0]=0x00;
data[1]=0x00;
data[2]=0xFF;
data[3]=0x03;
device->write_registers(0x06,data,4);
device->read_registers(start_addrs,data,49);
std::cout << "Servo " << std::dec << devices[i] << " registers:" << std::endl;
for(j=0;j<49;j++)
std::cout << "Register 0x" << std::hex << j << ": 0x" << (int)data[j] << std::endl;
dyn_server->free_device(devices[i]);
}
}
}catch(CException &e){
std::cout << e.what() << std::endl;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment