On Thu, 30 Aug 2012 05:51:56 -0700 (PDT), "Adam W."

<(E-Mail Removed)> declaimed the following in

gmane.comp.python.general:

>

> Interesting, so what if I only wanted to send 4bits as a hex value? Also can I somehow throw in some binary alongside of hex? At some point in my program I'm going to need to send some commands preferably in hex along with the binary image data.
You will never be able to send something less than 8-bits. I suspect

the printer treats each byte as one column of dots, so you'd probably be

sending \xF0 or \x0F depending on which bit is "top" or "bottom" -- this

would give a half column of ink and the other half would be blank.

\x?? is the Python notation to represent a binary value in a

string/byte LITERAL.

Your previous attempt with the "F" was sending ASCII F characters,

hex value 46 (01000110) [was your striped layout one skinny stripe, and

three widths lower a double-width stripe?].

As long as your image data is in on/off (B/W) bytes (unsigned, or to

simplify, integers in the range 0..255), it should be no problem.

>>> import random

>>> data = [random.randint(0, 255) for i in range(32)]

>>> data
[25, 134, 166, 159, 253, 121, 114, 110, 18, 122, 197, 233, 127, 216,

188, 89, 10, 201, 250, 32, 231, 32, 99, 7, 227, 122, 166, 172, 21, 78,

17, 166]

>>> bar = bytearray(data)

>>> bar
bytearray(b'\x19\x86\xa6\x9f\xfdyrn\x12z\xc5\xe9\x 7f\xd8\xbcY\n\xc9\xfa

\xe7 c\x07\xe3z\xa6\xac\x15N\x11\xa6')

>>> bytes(bar)
'\x19\x86\xa6\x9f\xfdyrn\x12z\xc5\xe9\x7f\xd8\xbcY \n\xc9\xfa \xe7

c\x07\xe3z\xa6\xac\x15N\x11\xa6'

>>>

>>> bbar = bytes(bar)

>>> for b in bbar:
.... print "Decimal: %4.4s:\tHex: \\x%2.2X\t%s" % (ord(b), ord(b), b)

....

Decimal: 25: Hex: \x19

Decimal: 134: Hex: \x86 ?

Decimal: 166: Hex: \xA6 ?

Decimal: 159: Hex: \x9F ?

Decimal: 253: Hex: \xFD ??

Decimal: 121: Hex: \x79 y

Decimal: 114: Hex: \x72 r

Decimal: 110: Hex: \x6E n

Decimal: 18: Hex: \x12

Decimal: 122: Hex: \x7A z

Decimal: 197: Hex: \xC5 ?

Decimal: 233: Hex: \xE9 ?

Decimal: 127: Hex: \x7F

Decimal: 216: Hex: \xD8 ?

Decimal: 188: Hex: \xBC ?

Decimal: 89: Hex: \x59 Y

Decimal: 10: Hex: \x0A

Decimal: 201: Hex: \xC9 ?

Decimal: 250: Hex: \xFA ??

Decimal: 32: Hex: \x20

Decimal: 231: Hex: \xE7 ?

Decimal: 32: Hex: \x20

Decimal: 99: Hex: \x63 c

Decimal: 7: Hex: \x07

Decimal: 227: Hex: \xE3 ?

Decimal: 122: Hex: \x7A z

Decimal: 166: Hex: \xA6 ?

Decimal: 172: Hex: \xAC °

Decimal: 21: Hex: \x15

Decimal: 78: Hex: \x4E N

Decimal: 17: Hex: \x11

Decimal: 166: Hex: \xA6 ?

>>>
You might be able to go directly:

bbar = bytes(data)

based on the documentation for Python 3.2.3. I can't even find bytes()

in the 2.7 documentation.

I suspect your biggest problem will be in converting your image

format (at the minimum, it may be row oriented and you need to generate

columns of 8-rows at a time)

Try:

data = [ 22,

0, 1, 3, 7, 15, 31, 63, 127, 255,

127, 63, 31, 15, 7, 3, 1, 0 ]

bbar = bytes(data)

Set data length to 17, and send bbar...

If my guess is right, this should put up an equilateral triangle.

--

Wulfraed Dennis Lee Bieber AF6VN

(E-Mail Removed) HTTP://wlfraed.home.netcom.com/