gclib 2.0.9
Communications API for Galil controllers and PLCs
 
Loading...
Searching...
No Matches
ip_assigner_example.cpp
Go to the documentation of this file.
1
9#include "examples.h"
10
11#include <iostream> //std::cout
12using namespace std;
13
15
19int main(int argc, char * argv[])
20{
21 GReturn rc = GALIL_EXAMPLE_OK;
22 char buf[G_SMALL_BUFFER];
23
24 try
25 {
26 if (argc != 3) //Invalid number of arguments
27 {
28 cerr << "Incorrect number of arguments provided\n";
29 cerr << "Usage: ipassigner_example.exe <SERIAL #> <1 Byte Address>\n";
30 pause();
31 return GALIL_EXAMPLE_ERROR;
32 }
33 else
34 {
35 char* serial_num = argv[1];
36
37 //Retrieve address from the command line and convert to int
38 char* end;
39 int address = strtol(argv[2], &end, 10);
40 if (*end != '\0' || address < 0 || address > 255) //If invalid address
41 {
42 cerr << "Please enter a number between 0 and 255 for the address."
43 " This will be used as the last number in the IP Address\n"
44 "Usage: ipassigner_example.exe <SERIAL #> <1 Byte Address>\n";
45 return GALIL_EXAMPLE_ERROR;
46 }
47 //Assigns controller an IP Adress given a serial number and a 1 byte address
49 }
50 }
51 catch (GReturn gr)
52 {
53 error(nullptr, gr); //see examples.h for error handling
54 pause();
55 return GALIL_EXAMPLE_ERROR;
56 }
57
58 pause();
59 return GALIL_EXAMPLE_OK;
60}
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition gclib.h:93
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition gclib.h:89
int main(int argc, char *argv[])
Main function for Commands Example.
void error(GCon g, GReturn rc)
An example of error handling and debugging information.
Definition examples.h:40
int pause()
Pauses console apps for a user key stroke.
Definition examples.h:62
GReturn ip_assigner(char *serial_num, int address)
Assigns controller an IP Adress given a serial number and a 1 byte address.
GReturn vector(GCon g, char *file)
Puts controller into Vector Mode and accepts a file defining vector points.
Definition vector.cpp:36