int main(int argc, const char * argv[]) { string errmsg; string target; YVoltage *sensor; YVoltage *sensorAC; YVoltage *sensorDC; YModule *m; if (argc < 2) { usage(); } target = (string) argv[1]; YAPI::DisableExceptions(); // Setup the API to use local USB devices if (YAPI::RegisterHub("usb", errmsg) != YAPI_SUCCESS) { cerr << "RegisterHub error: " << errmsg << endl; return 1; } if (target == "any") { // retreive any voltage sensor (can be AC or DC) sensor = YVoltage::FirstVoltage(); if (sensor == NULL) { cerr << "No module connected (Check cable)" << endl; exit(1); } } else { sensor = YVoltage::FindVoltage(target + ".voltage1"); } // we need to retreive both DC and AC voltage from the device. if (sensor->isOnline()) { m = sensor->get_module(); sensorDC = YVoltage::FindVoltage(m->get_serialNumber() + ".voltage1"); sensorAC = YVoltage::FindVoltage(m->get_serialNumber() + ".voltage2"); } else { cerr << "No module connected (Check cable)" << endl; exit(1); } while(1) { if (!sensorDC->isOnline()) { cout << "Module disconnected" << endl; break; } cout << "Voltage, DC : " << sensorDC->get_currentValue() << " v"; cout << " AC : " << sensorAC->get_currentValue() << " v"; cout << " (press Ctrl-C to exit)" << endl; YAPI::Sleep(1000, errmsg); }; yFreeAPI(); return 0; }
int main(int argc, const char * argv[]) { string target,errmsg; int power; YMotor *motor; YCurrent *current; YVoltage *voltage; YTemperature *temperature; // parse command line if (argc < 2) { usage(); } target = (string) argv[1]; power = atoi(argv[2]); // Setup the API to use local USB devices if (YAPI::RegisterHub("usb", errmsg) != YAPI_SUCCESS) { cerr << "RegisterHub error: " << errmsg << endl; return 1; } if (target == "any") { // find the serial# of the first available motor motor = YMotor::FirstMotor(); if (motor == NULL) { cout << "No module connected (check USB cable)" << endl; return 1; } target= motor->get_module()->get_serialNumber(); } // retreive motor, current, voltage and temperature features from the device motor = YMotor::FindMotor(target + ".motor"); current = YCurrent::FindCurrent(target + ".current"); voltage = YVoltage::FindVoltage(target + ".voltage"); temperature = YTemperature::FindTemperature(target + ".temperature"); // lets start the motor if (motor->isOnline()) { // if motor is in error state, reset it. if (motor->get_motorStatus()>=YMotor::MOTORSTATUS_LOVOLT) { motor->resetStatus(); } motor->drivingForceMove(power,2000); // ramp up to power in 2 seconds while (1) { // display motor status cout << "Status=" << motor->get_advertisedValue() << " " << "Voltage=" << voltage->get_currentValue() << "V " << "Current=" << current->get_currentValue()/1000 << "A " << "Temp=" << temperature->get_currentValue() << "deg C" << endl; YAPI::Sleep(1000, errmsg); // wait for one second } } else { cout << "Module not connected (check identification and USB cable)"<< endl; } return 0; }