Writing to /dev/ttyS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I am trying to write data through a
serial com port, but continuously get an error returned by the function
call. Basically, my code is simple and looks like this:
// includes go here
int main()
{
int
res, fd1;
char
buf1[255];
fd1
= open("/dev/ttyS2", O_RDWR| O_NOCTTY | O_NDELAY);
printf("fd1
= %d\n", fd1);
//
prepare outgoing message
sprintf(buf1,
"this is a test", sizeof("this is a test"));
res
= write(fd1, buf1, strlen(buf1));
printf("res
= %d, errno = %d\n", res, errno);
return
0;
}
When I run the program, res comes up
as -1 and errno as 9 (EBADF). When I checked the value of this EBADF, it
turned out to be "fd is not a valid file descriptor or is not
open for writing".
This is the output I get:
fd1 = 3
buf1 : this is a test
res = -1, errno = 9
Although here is what I get when I check
the settings of that port with setserial:
# setserial -g /dev/ttyS2
/dev/ttyS2, UART: 16650, Port: 0x03e8,
IRQ: 4
which appears to be OK, plus the fact
that the open() command returned a value of 3 for the file descriptor.
TIA.
[Index of Archives]
[Newbies FAQ]
[Linux Kernel Mentors]
[Linux Kernel Development]
[IETF Annouce]
[Git]
[Networking]
[Security]
[Bugtraq]
[Yosemite]
[MIPS Linux]
[ARM Linux]
[Linux RAID]
[Linux SCSI]
[Linux ACPI]