Writing binary ints to lp 
Author Message
 Writing binary ints to lp

How can I output a bit to /dev/lp0 like I would with outb( 0x1, 0x378
) in C?  I have tried with p=open('/dev/lp0','w') and p.print(0b1),
p.write(0b1) and variants with no success.

Massimiliano



Thu, 22 Apr 2004 07:29:08 GMT  
 Writing binary ints to lp
Hi,

In message "[ruby-talk:24305] Writing binary ints to lp"

|How can I output a bit to /dev/lp0 like I would with outb( 0x1, 0x378
|) in C?  I have tried with p=open('/dev/lp0','w') and p.print(0b1),
|p.write(0b1) and variants with no success.

I've never used outb(2), but p.printf "%c", 0b1 might help you.

                                                        matz.



Sat, 24 Apr 2004 02:16:49 GMT  
 Writing binary ints to lp

Quote:

> How can I output a bit to /dev/lp0 like I would with outb( 0x1, 0x378
> ) in C?  I have tried with p=open('/dev/lp0','w') and p.print(0b1),
> p.write(0b1) and variants with no success.

IO#print and IO#write use Object#to_s to convert non-strings to strings.

You want IO#putc(c), which is basically the same as putc(c,io) in C. When
you do so, remember putc() is buffered (by default) and so only sends the
data every 4096 bytes; this means you have to call #flush or #sync=,

In Linux, you normally wouldn't use outb() to access the parallel port
hardware. Instead you would use the read/write interface of /dev/lp0 for
normal data I/O (this includes #putc and such), and you'd use the ioctl()
interface for all the parallel-port-specific features.

To make hardware-specific features easier for Ruby programmers, I have
written a package called LinuxDevices (see RAA), which supports most
features of /dev/lp, /dev/dsp, and /dev/mixer.

________________________________________________________________
Mathieu Bouchard                   http://hostname.2y.net/~matju



Sat, 24 Apr 2004 02:22:10 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. reading in ints from binary files

2. using floats/ints in print and write

3. Reading a binary file / writing binary data to a file

4. Journal of LP for Assoc. for LP members

5. binary file read/write acces

6. Writing double word binary numbers on screen

7. how to write a byte with binary value 0

8. writing in binary to a serial port

9. writing binary data to a socket?

10. Writing Objects to a Binary File

11. reading/writing binary files.

12. Writing, reading, and splitting strings of binary

 

 
Powered by phpBB® Forum Software