I have an application where I open a serial device ( GSM Modem ) and I create a pseudo-terminal. I would like to read from the serial device, filter the data and send it throught the pseudo-terminal, so another process can read it, like as it would be a simple 'raw' serial line.
ptFd
- pseudo terminal filedescriptor
devFd
- serial device filedescriptor
I'm using posix_openpt( O_RDWR | O_NOCTTY )
, grantpt(ptFd)
, unlockpt(ptFd)
for pseudo-terminal and lots of custom setting for the serial line. For first try I wouldn't post it here, but I will do if it would help anyone to solve this problem.
My problem is the following:
Read devFd:
056405c0020001009e59
Read ptFd:
5e45645e45c05e425e405e415e409e59
Read devFd:
056405c0020001009e59
Read ptFd:
5e45645e45c05e425e405e415e409e59
I'm writing the bytes i got from device on the pseudo-terminal and:
05 changes to 5e45
00 changes to 5e40
01 changes to 5e41
02 changes to 5e42
But all bytes not starting with 0 in hex ( >=16 decimal ) are transferred just fine.
And first of all... when I'm writing on a pseudo terminal and reading from it in the same process it shouldn't reflect those bytes I just wrote on it, right?
I'm not familiar with these terminal, but I imagine as I open a terminal, getting the slave's name with ptsname function. From another process I can open that name ( like /dev/pts/3 ) and from that point it works as a 'stream'.
Most probably I'm wrong, but can you please give me a brief clarification? Thanks in advance.
This is similar to how when you press Ctrl+C at a terminal, ^C
is echoed. The equivalent behaviour for a pty is that if the ASCII character generated by Ctrl+C, i.e., 0x03, is written to the master end, then it's echoed back as ^C
, i.e., 0x5E 0x03.
This behaviour can be turned off for Ctrl+C and other control characters by unsetting the ECHOCTL
flag in the c_lflag
field of the terminal attributes.
You can also disable echoing entirely by unsetting the ECHO
flag. (I wasn't sure whether you wanted to do this; it wasn't clear to me what you're doing)