Generate infinite stream
Is there a way to generate an infinite stream (to a file descriptor) from a (finite) buffer, i.e. repeating the buff开发者_JAVA技巧er, without invoking calls from user-space (except for initially setting up the buffer)? I think I am looking for a way to define a data source like /dev/zero
, only with a user-defined finite buffer as source of values.
(The purpose is to stimulate IO to an external device via a serial connection, in case this sounds like a strange request.)
If you have Perl installed:
perl -e 'print "HELLO" while(1);' > /dev/ttyUSB0
perl -e 'print chr(0x48) while(1);' > /dev/ttyUSB0
perl -e 'print chr(0x48).chr(0x45).chr(0x4c).chr(0x4c).chr(0x4f) while(1);' > /dev/ttyUSB0
Where /dev/ttyUSB0 is your serial device, "HELLO" is an ascii string and chr(0xXX) is a specific byte to output.
精彩评论