This article is written on the assumption that you know the concept of the Pointer
In Linux (or Unix) System, ‘fd’ is a concept that ‘process’ handles a file. As if, abstract value when the ‘process’ accesses to a specific file.
The ‘fd’ is usually used for matching the File’s specific Number. The specific Number is given by OS system, and the Number is 0 or positive integer(0~ max).
With the Diagram.
’fd’ is a integer (0~max) value. But we can check the value of it is negative integer when it doesn’t work(~-1). So we can use its value for ‘if’ grammer.
#include <unistd.h>
...
fd = std::system("ls /dev | grep EtherCAT* > /dev/null");
if(fd){
printf( "Opening EtherCAT master...");
std::system("cd ~; sudo ethercatctl start");
usleep(2e6);
fd = std::system("ls /dev | grep EtherCAT* > /dev/null");
if(fd){
printf( "Error : EtherCAT device not found.");
return -1;
}else {
return 0 ;
}
}
return 0 ;