| gclib 556 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 return GALIL_EXAMPLE_ERROR;
31 }
32 else
33 {
34 char* serial_num = argv[1];
35
36 //Retrieve address from the command line and convert to int
37 char* end;
38 int address = strtol(argv[2], &end, 10);
39 if (*end != '\0' || address < 0 || address > 255) //If invalid address
40 {
41 cerr << "Please enter a number between 0 and 255 for the address."
42 " This will be used as the last number in the IP Address\n"
43 "Usage: ipassigner_example.exe <SERIAL #> <1 Byte Address>\n";
44 return GALIL_EXAMPLE_ERROR;
45 }
46 //Assigns controller an IP Adress given a serial number and a 1 byte address
47 rc = ip_assigner(serial_num, address);
48 }
49 }
50 catch (GReturn gr)
51 {
52 GError(gr, buf, G_SMALL_BUFFER); //Get Error Information
53 cout << buf << '\n'; //further context
54 return GALIL_EXAMPLE_ERROR;
55 }
56
57
58 return rc;
59 }
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
examples.h
main
int main(int argc, char *argv[])
Main function for Commands Example.
Definition: commands_example.cpp:20
GError
GCLIB_DLL_EXPORTED void GCALL GError(GReturn rc, GCStringOut error, GSize error_len)
Provides a human-readable description string for return codes.
Definition: gclibo.c:459
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:87
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:91