Results 1 to 8 of 8
Hi All,
How does the write() system call work if it's writing it to a device port and how would I know if the data is being sent immediately and ...
- 05-10-2006 #1Just Joined!
- Join Date
- May 2006
- Posts
- 3
device write() system calls
Hi All,
How does the write() system call work if it's writing it to a device port and how would I know if the data is being sent immediately and not to a buffer? For example,
int fd;
fd = open( "/dev/ttyAM0", 0_RDWR );
write( fd, "abc\r", 4 )
I would imagine that after invoking the above system call, "abc\r" is being immediately sent to the device port at the path "/dev/ttyAM0". Is that true or is "abc\r" sent to somewhere else?
Thanks in advance for the help.
- 05-11-2006 #2
It depends on the device: block devices (hard disks, cdroms, etc...) are buffered while character devices are not.
Since you are dealing with a character device, your string will be sent inmediately. But if you need an "inmediate" writing for block devices, use fflush(filedescriptor).
And remember: you are not working with write() system call, but with write() form libc that performs a lot of tasks before calling the actual write system call.
Best regards
- 05-11-2006 #3Just Joined!
- Join Date
- May 2006
- Posts
- 3
Hi fernape,
Thanks for the reply. One follow-up question, is there a way that I can buffer the characters sent to a character device? So the device that the program talks to can receive "abc\r" at once rather than 'a', 'b', 'c' '\r'.
Cheers!
- 05-11-2006 #4
I think not. You can delay the delivery using a temporary variable, but then, the device will receive the characters one by one.
Best regards
- 05-11-2006 #5Just Joined!
- Join Date
- May 2006
- Posts
- 3
Hi fernape,
When the device receives the character one by one, is this process the same as transmitting a line of text with character delay?
I am trying to mimic the process of Windows' hyperterminal transfering a 3-line text file with 1000 ms line delay and 0 ms char. delay by using the low-level write() system call. Any idea of how I can achieve that? Thanks.
Cheers!
- 05-12-2006 #6
I think yes, but it is possible that if you delay characteres for a long time, the device "closes conection" or performs some action (I'm thinking about a serial modem dealing with AT command.)
I think you can assume that when you send something like "abcdefgh" the delay between characters is 0 unless problems with the line or similar. So you need a way to hold the emission of each complete line (use a string).
Best regards
- 10-30-2008 #7Just Joined!
- Join Date
- Oct 2008
- Posts
- 3
What is the maximum buffer size write uses for blok devices?
Hi All,
This is in continuation with the original question asked by the OP. So, what is the maximum buffer size write() uses for the block devices?
Is this buffer a configurable thing?
Thanks in advance,
Regards,
- 10-30-2008 #8Just Joined!
- Join Date
- Oct 2008
- Posts
- 3
If you want this to be written into a file immediately, use the O_FSYNC option too while opening the file. Or, alternatively you can use fsync() after the write. Hope, this helps,Hi All,
How does the write() system call work if it's writing it to a device port and how would I know if the data is being sent immediately and not to a buffer? For example,
int fd;
fd = open( "/dev/ttyAM0", 0_RDWR );
write( fd, "abc\r", 4 )
I would imagine that after invoking the above system call, "abc\r" is being immediately sent to the device port at the path "/dev/ttyAM0". Is that true or is "abc\r" sent to somewhere else?
Thanks in advance for the help.Last edited by vkv.raju; 10-30-2008 at 04:20 PM. Reason: EDIT1



