| gclib 1.35.5 Communications API for Galil controllers and PLCs |

ip_assigner_example.cpp
Go to the documentation of this file.
1
9 #include "examples.h"
10
11 #include <iostream> //std::cout
12 using namespace std;
13
15
19 int 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
48 rc = ip_assigner(serial_num, 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 }
examples.h
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
G_SMALL_BUFFER
#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
main
int main(int argc, char *argv[])
Main function for Commands Example.
Definition: commands_example.cpp:18
ip_assigner
GReturn ip_assigner(char *serial_num, int address)
Assigns controller an IP Adress given a serial number and a 1 byte address.
Definition: ip_assigner.cpp:26
error
void error(GCon g, GReturn rc)
An example of error handling and debugging information.
Definition: examples.h:40
pause
int pause()
Pauses console apps for a user key stroke.
Definition: examples.h:62