16 typedef std::vector<string> tokens;
18 tokens
string_split(
const string& str,
const string& token);
29 bool controller_found =
false;
33 cout <<
"Searching...\n";
38 }
while (strlen(buf) <= 1);
43 for (tokens::iterator it = controllers.begin(); it != controllers.end(); it++)
45 const string& controller = *it;
47 tokens controller_params =
string_split(controller,
", ");
50 if (controller_params.size() < 5)
52 cerr <<
"Unexpected controller format";
53 return GALIL_EXAMPLE_ERROR;
55 const char* mac = controller_params[2].c_str();
56 const char* ip = controller_params[4].c_str();
58 if (
string(serial_num) == controller_params[1])
60 controller_found =
true;
61 int ip1 = 0, ip2 = 0, ip3 = 0, ip4 = 0;
63 sscanf(ip,
"%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
67 sprintf(ipaddress,
"%d.%d.%d.%d", ip1, ip2, ip3, address);
87 if (!controller_found)
89 cout <<
"No controller matched the entered serial number";
92 return GALIL_EXAMPLE_OK;
99 int prev_position = 0 - token.length();
100 int position = str.find(token);
102 while (position != string::npos)
105 split.push_back(str.substr(prev_position + token.length(),
106 position - prev_position - token.length()));
107 prev_position = position;
108 position = str.find(token, prev_position + token.length());
112 if (str.length() > prev_position + token.length())
115 split.push_back(str.substr(prev_position + token.length(),
116 str.length() - prev_position - token.length()));
GCLIB_DLL_EXPORTED GReturn GCALL GAssign(GCStringIn ip, GCStringIn mac)
Uses GUtility(), G_UTIL_GCAPS_ASSIGN or G_UTIL_ASSIGN to assign an IP address over the Ethernet to a ...
GCLIB_DLL_EXPORTED GReturn GCALL GIpRequests(GCStringOut requests, GSize requests_len)
Uses GUtility(), G_UTIL_GCAPS_IPREQUEST or G_UTIL_IPREQUEST to provide a list of all Galil controller...
GCLIB_DLL_EXPORTED GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
GCLIB_DLL_EXPORTED GReturn GCALL GCmd(GCon g, GCStringIn command)
Wrapper around GCommand for use when the return value is not desired.
GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon *g)
Open a connection to a Galil Controller.
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
GReturn ip_assigner(char *serial_num, int address)
Assigns controller an IP Adress given a serial number and a 1 byte address.
tokens string_split(const string &str, const string &token)
Splits a string into a vector based on a token.