LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   opening a comport in linux (https://www.linuxquestions.org/questions/programming-9/opening-a-comport-in-linux-4175428778/)

batman4 09-24-2012 08:08 AM

opening a comport in linux
 
pls help
i am not able to open the comport in linux
the code is giving error that port cannot be opend

[code[
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>
#include <errno.h>



int main()
{
int fd; /* File descriptor for the port */

fd = open ("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0)
{ /* Could not open the port */
fprintf (stderr, "open_port: Unable to open /dev/ttyS1 - %s\n",
strerror (errno));
printf("error in opening com port\n");
return 0;
}
else
return (fd);
}


}

[/code]

pan64 09-24-2012 08:15 AM

please edit your post and fix the [code[ line (at the beginning)
Can you tell us the error message you got?
do you really want to open /dev/ttyS1111?

batman4 09-24-2012 08:21 AM

Quote:

Originally Posted by pan64 (Post 4787973)
please edit your post and fix the [code[ line (at the beginning)
Can you tell us the error message you got?
do you really want to open /dev/ttyS1111?

DONE

sundialsvcs 09-24-2012 08:35 AM

For one thing ... you almost always want to use a communication-protocol library that will get you as close as possible to the finishing-point of the job that you are trying to do. IMHO, if you are thinking "way down at the device level," you're probably creating far too much work for yourself in most cases. That's why there is such a booming business in the manufacture of prefabricated building-parts, like doors and windows.

suicidaleggroll 09-24-2012 09:12 AM

Make sure the user that's running this code has permission to access the device. You could attempt to open it with minicom to confirm.


All times are GMT -5. The time now is 12:05 AM.