Here is my PB code:
Code: Select all
Structure res
volts1res.f
EndStructure
Dim resStruc.res(1)
ImportC "/usr/lib/libpmcomm.so"
PMOpenConnectionSerial(*conn)
PMReadDisplayFormatted(*conn, *res, *resStruc)
EndImport
conn = PMOpenConnectionSerial("/dev/ttyUSBPM")
PMReadDisplayFormatted(conn, PM_D1, resStruc(0)\volts1res)
Debug resStruc(0)\volts1res
Code: Select all
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <stack>
#include <time.h>
#include "libpmcomm.h"
using namespace std;
int displaysLoopMain(PMConnection *conn);
int main() {
/* For serial port (Unix style) */
struct PMConnection *conn = PMOpenConnectionSerial("/dev/ttyUSBPM");
if(conn == NULL) {
cerr << "connection failed" << endl;
return 1;
}
return displaysLoopMain(conn);
}
/* This function demonstrates how to read display and program data. It displays
a set of different types of data in a loop. */
int displaysLoopMain(PMConnection *conn) {
while(1) {
struct PMDisplayValue volts1res, amps1res;
/* Read volts 1 (D1) */
int32_t error = PMReadDisplayFormatted(conn, PM_D1, &volts1res);
if(error) {
cerr << "read error" << endl;
return 1;
}
/* Read amps 1 (D7) */
error = PMReadDisplayFormatted(conn, PM_D7, &s1res);
if(error) {
cerr << "read error" << endl;
return 1;
}
/* Print results. Note that the precisions of the amps channels
may not be correct for your system. When the large (500A/500mV) shunt
is used, one digit is available, and with the small (100A/100mV) shunt
two digits are available. This can be determined automatically using
PMReadProgramFormatted() to look at the shunt type. */
cout << "Volts: " << fixed << setprecision(1) << (volts1res.val / 10.0)
<< ", Amps 1: " << setprecision(1) << (amps1res.val / 100.0) << endl;
/* Reading a program value */
union PMProgramData capacity;
error = PMReadProgramFormatted(conn, PM_P14, &capacity);
if(error) {
cerr << "read error" << endl;
return 1;
}
cout << "Capacity: " << (int) capacity.batCapacity << endl;
}
return 0;
}