misc
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
void sWrite(int port, char string[], size_t length)
|
||||
{
|
||||
if(port != -1) write(port, string, length);
|
||||
|
||||
}
|
||||
|
||||
void sWrite(int port, const char string[], size_t length)
|
||||
@ -42,18 +41,10 @@ std::cout<<"Rates:\n"\
|
||||
}
|
||||
#endif
|
||||
|
||||
int serialport_init(const char* device, int baud)
|
||||
int serialport_set_config(int fd, int baud)
|
||||
{
|
||||
int fd;
|
||||
struct termios toptions;
|
||||
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("init_serialport: Unable to open port ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tcgetattr(fd, &toptions) < 0)
|
||||
struct termios toptions;
|
||||
if (tcgetattr(fd, &toptions) < 0)
|
||||
{
|
||||
perror("init_serialport: Couldn't get term attributes");
|
||||
return -1;
|
||||
@ -93,6 +84,24 @@ int serialport_init(const char* device, int baud)
|
||||
perror("init_serialport: Couldn't set term attributes");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serialport_init(const char* device, int baud, bool block = false)
|
||||
{
|
||||
int fd;
|
||||
fd = open(device, O_RDWR | O_NOCTTY | (block ? 0 : O_NONBLOCK));
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("init_serialport: Unable to open port ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(serialport_set_config(fd, baud) != 0)
|
||||
{
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user