Gast
#1621130
moinmoin....
beschäftige mich seit ein paar tagen mit com-ports unter linux...
hab mir scho n wolf gegoogelt... ich finde meinen fehler nicht der
compiler gibt nur n warning wegen der "alten" string deklerationen
ansonsten nciht also kurz gesagt alles funktioniert nur leider kann ich
die baudrate nicht verändern sie läuft immer auf 9600 soll aber in
diesem fall höher werden...
hier der code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <iostream>
//include <sys/wait.h>
#define RXBUFFERSIZE 254
int comdesk;
char rxBuffer[RXBUFFERSIZE];
int initUart(char *portdesk,double baud,char *format)
{
struct termios options;
// Get the current options for the port...
tcgetattr(comdesk, &options);
// Set the baud rate...
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
// Enable the receiver and set local mode(8N1)...
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
// Set the new options for the port...
tcsetattr(comdesk, TCSANOW, &options);
// Open Com Port
comdesk = open(portdesk, O_RDWR | O_NOCTTY | O_NDELAY);
if (comdesk == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
{
fcntl(comdesk, F_SETFL, FNDELAY);
}
return (comdesk);
//close(comdesk);
}
int uartRD(void)
{
int in = read(comdesk, rxBuffer, RXBUFFERSIZE);
rxBuffer[in] = 0x00;
printf("data:%s\n", rxBuffer);
}
int uartWR(void)
{
printf("write...\n", rxBuffer);
write(comdesk, "Hallo Welt !!!", 14);
}
int main(void)
{
initUart("/dev/ttyS1",B115200,"8N1");
while(1)
{
uartRD();
usleep(50000);
uartWR();
}
return 0;
}
währe dankbar für jede form von hilfe
mfg fugitivus