36 device=(
char*)malloc((strlen(pdevice)+10)*
sizeof(char));
42 struct termios params;
45 memset( ¶ms,0,
sizeof(params));
48 printf(
"Opening comm %s ... ",
device);fflush(stdout);
51 {perror(
"Failed to open port");
return;}
56 printf(
"Set new parameters ... ");fflush(stdout);
57 params.c_cflag = B9600 | CS8 | CLOCAL | CREAD | IGNPAR;
58 params.c_iflag = IGNPAR;
61 ret=tcsetattr(
port, TCSANOW, ¶ms );
63 {perror(
"Set serial communication parameters failed");
return;}
85 ret=read(
port,&data,1);
100 ret = write(
port,&msg,
sizeof(msg));
103 strcpy(
err,
"Cannot write to port");
114 if(STATUS ==
ON || STATUS ==
BLINK3)
119 ret = write(
port,&msg,
sizeof(msg));
122 strcpy(
err,
"Cannot write to port");
131 unsigned char msg = 0x00;
133 int nbytes_to_read=0;
138 ret = write(
port,&msg,
sizeof(msg));
141 strcpy(
err,
"Cannot write to port");
145 double ts=ros::Time::now().toSec();
147 while(nbytes_to_read!=1)
149 ret=ioctl(
port,FIONREAD,&nbytes_to_read);
151 tl=ros::Time::now().toSec()-ts;
155 strcpy(
err,
"DIOC is not responding (read timeout)");
163 strcpy(
err,
"Cannot read responce");
176 int nbytes_to_read=0;
178 unsigned char status;
187 strcpy(
err,
"This IO does not respond its current state");
194 ret = write(
port,&msg,
sizeof(msg));
197 strcpy(
err,
"Cannot write to port");
201 double ts=ros::Time::now().toSec();
203 while(nbytes_to_read!=1)
205 ret=ioctl(
port,FIONREAD,&nbytes_to_read);
207 tl=ros::Time::now().toSec()-ts;
211 strcpy(
err,
"DIOC is not responding (read timeout)");
219 strcpy(
err,
"Cannot read responce");
223 status = (data & 0x80) >> 7;
233 printf(
"%s (raising SIGINT)\n",
err);
237 printf(
"Warning!! ");
242 printf(
"%s, ",
err);fflush(stdout);
char * device
Communication device to use.
int ret
Auxiliary return code.
class_dioc(const char *pdevice)
Constructor.
int SetStatus(id_enum ID, status_enum ENUM)
Set the status of a input/output.
bool active
This variable indicates that the communication is active.
int GetStatus(id_enum ID)
Get the status of a input/output.
int port
Communication port to use.
int CommStatus(void)
Get the comm status.
Includes, global vars, function prototypes, etc.
~class_dioc()
De-constructor.
void CleanBuffer(void)
Cleans the buffer.
void perr(int ret)
Print error function.