Molio bih pomoć
Dakle, imam problem sa half duplex komunikacijom po linuxom...
Izvorni kod preuzet od nekog howto manuala
Ovdje kad posaljem varijablu "31 31" trebao bih dobiti odgovor od 18 bytova.
Primim je i sve radi OK, ali ako ne primim 18 bytova program ceka u nedogled.
Moze li se namjestit recimo, ako se ne pojavi nista na portu u 200 ms...prekini sa cekanjem tih 18 bytova nego posalji opet varijablu?
Dakle, imam problem sa half duplex komunikacijom po linuxom...
Izvorni kod preuzet od nekog howto manuala
Code:
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
struct termios tio;
int main()
{
int fd, status, whichBaud, result,i;
long baud;
char buffer[255];
varijabla[2] = "\x31\x31";
baud = B9600;
fd = open(device ,O_RDWR | O_NOCTTY);
if (fd <0)
{
printf("error");
exit(1);
}
tio.c_cflag = baud | CS8 | CREAD | CLOCAL;
tio.c_iflag = IGNPAR; /* ignore parity errors */
tio.c_oflag = 0; /* set output flag non-canonical, no processing */
tio.c_cc[VTIME] = 18; /* no time delay */
tio.c_cc[VMIN] = 0; /* no char delay */
tcflush(fd, TCIFLUSH); /* flush the buffer */
tcsetattr(fd, TCSANOW, &tio); /* set the attributes *
/* Set up for no delay, ie non-blocking reads will occur.
When we read, we'll get what's in the input buffer or nothing */
fcntl(fd, F_SETFL, FNDELAY);
write(fd,varijabla,2);
result = read(fd,buffer,255);
printf("%c\n",result);
buffer[result] = 0; // zero terminate so printf works
printf("%s\n",buffer);
}
/* close the device file */
close(fd);
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
struct termios tio;
int main()
{
int fd, status, whichBaud, result,i;
long baud;
char buffer[255];
varijabla[2] = "\x31\x31";
baud = B9600;
fd = open(device ,O_RDWR | O_NOCTTY);
if (fd <0)
{
printf("error");
exit(1);
}
tio.c_cflag = baud | CS8 | CREAD | CLOCAL;
tio.c_iflag = IGNPAR; /* ignore parity errors */
tio.c_oflag = 0; /* set output flag non-canonical, no processing */
tio.c_cc[VTIME] = 18; /* no time delay */
tio.c_cc[VMIN] = 0; /* no char delay */
tcflush(fd, TCIFLUSH); /* flush the buffer */
tcsetattr(fd, TCSANOW, &tio); /* set the attributes *
/* Set up for no delay, ie non-blocking reads will occur.
When we read, we'll get what's in the input buffer or nothing */
fcntl(fd, F_SETFL, FNDELAY);
write(fd,varijabla,2);
result = read(fd,buffer,255);
printf("%c\n",result);
buffer[result] = 0; // zero terminate so printf works
printf("%s\n",buffer);
}
/* close the device file */
close(fd);
Ovdje kad posaljem varijablu "31 31" trebao bih dobiti odgovor od 18 bytova.
Primim je i sve radi OK, ali ako ne primim 18 bytova program ceka u nedogled.
Moze li se namjestit recimo, ako se ne pojavi nista na portu u 200 ms...prekini sa cekanjem tih 18 bytova nego posalji opet varijablu?
Potpis
There are 10 types of people in the world:
Those who understand binary and those who don't.
Those who understand binary and those who don't.