I can obtain this data correctly using Hyper Terminal in windows, so i believe the device is correctly configured. Does anyone know why this might be happening?
int
open_port(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/ser1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ser1 - ");
}
else
printf ("port opened\n");
return (fd);
As you can see, i have not set baud, parity etc, which is prob causing my problems. What is the best way to set these, i am new to C and cannot find out how to do it.
Hi,
I tried to write a test-application to gain access on device-files.
It should be used to check whether driver works correctly for the device.
Yet, I just try to read out some sample-devices.
For example I tried to read out /dev/ser1 or also /dev/kbd.
I have an ps2ser keyboard and a ps2ser mouse plugged in, but not loaded any drivers or stacks (USB…) additionally.
I can open the files but after read() errno tells me “Ressource temporarily unavailable”!!!
Are these actually the corrct device-files, for the serial mouse/ keyboard???
Or do I have to load any drivers first??? Which and How???
And then there was something about baud-rate and parity. What settings do I have to use???
Here is my source-code:
/* Dies gibt eine Testapplikation, die auf Gerätedateien zugreifen kann */
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
int main( int argc, char *argv[] )
{
int fd; /* File descriptor for the port */
#if 1
int numRead=0; /* #gelesener Bytes */
char buffer[255]; /* Buffer */
char letter; /* Buchstabe */
int i; /* Index */
int errvalue; /* ErrorCode */
#endif
/* open port */
fd = open("/dev/kbd", O_RDONLY | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/* Could not open the port. */
perror("open_port: Unable to open /dev/kbd - ");
}
else
{
/* Statusausgabe */
printf("/dev/kbd opened!!\n");
#if 1
/* weiterverarbeiten */
/* reserviere Pufferspeicher */
memset(buffer, 0, sizeof(buffer));
/* lese Datei, schreibe gelesene Daten in den Puffer und gib aus wieviele Bytes gelesen wurden */
numRead = read(fd, buffer, sizeof(buffer));
errvalue = errno;
printf( "The error generated was %d\n", errvalue );
printf( "That means: %s\n", strerror( errvalue ) );
/* gib aus, wieviel gelesen wurde */
printf("fd..%i numRead..%i\n",fd,numRead);
/* print the data read from dev/kbd to screen */
for (i=0; i<=254; i++)
{
letter = buffer[i];
printf("%c",letter);
}
printf("\n");
#endif
/* und wieder schließen */
close(fd);
/* Statusausgabe */
printf("/dev/kbd closed!!!\n");
}
return 0;
}