The word test is sent sucessfully to the machine running putty but nothing is received. This issue happens with both the pascal and C versions of the code. Anyone familiar with termios able to tell me where i'm going wrong?
i'm pretty sure the hardware is ok because I have tested it using minicom.
pascal version
Code: Select all
program gateway;
uses
baseunix,
unix,
unixutil,
termio; // despite the name the fpc termio unit seems to be an interface to termios
var
device: string;
fd : longint;
config : termios;
count : longint;
buf : array[0..1023] of byte;
begin
device := paramstr(1);
fd := fpopen(device,O_RDWR or O_NOCTTY);
writeln(fd);
if isatty(fd)=0 then begin
writeln('not a tty');
halt(1);
end;
if tcgetattr(fd,config) <0 then begin
writeln('could not get termios attributes');
halt(2);
end;
config.c_iflag := 0;
config.c_oflag := 0;
config.c_cflag := 0;
config.c_lflag := 0;
cfmakeraw(config);
cfsetispeed(config,B19200);
cfsetospeed(config,B19200);
config.c_cc[VMIN] := 1;
config.c_cc[VTIME] := 0;
if tcsetattr(fd,TCSAFLUSH,config) <0 then begin
writeln('could not set termios attributes');
halt(3);
end;
fpwrite(fd,'test'#13#10,6);
while true do begin
writeln(fd);
count := fpread(fd,buf,sizeof(buf));
writeln(count);
fpwrite(fd,buf,count);
// writeln(count);
end;
fpclose(fd);
end.
Code: Select all
#include <termios.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
struct termios config;
char * device;
int fd;
char buf[1024];
int count;
device = argv[1];
fd = open(device,O_RDWR | O_NOCTTY);
printf("%i\n",fd);
if (!isatty(fd)) {
printf("not a tty\n");
return 1;
}
if (tcgetattr(fd,&config) <0) {
printf("could not get termios attributes\n");
return 2;
}
config.c_iflag = 0;
config.c_oflag = 0;
config.c_cflag = 0;
config.c_lflag = 0;
cfmakeraw(&config);
cfsetispeed(&config,B19200);
cfsetospeed(&config,B19200);
config.c_cc[VMIN] = 1;
config.c_cc[VTIME] = 0;
if (tcsetattr(fd,TCSAFLUSH,&config) <0) {
printf("could not set termios attributes\n");
return 3;
}
write(fd,"test\r\n",6);
while (1) {
printf("%i\n",fd);
count = read(fd,&buf,sizeof(buf));
printf("%i\n",count);
write(fd,&buf,count);
// writeln(count);
}
close(fd);
return 0;
}