14

我正在尝试创建一个原型,以将文本文件的位图数据打印到启用 LAN 的 epson pos 打印机 TM-T88V。

虽然我发送文本和文本格式说明没有问题,但我不明白我必须做什么才能让我的打印机打印Arecibo 消息的数据。

前几行:

00000010101010000000000
00101000001010000000100
10001000100010010110010
10101010101010100100100
00000000000000000000000
00000000000011000000000
00000000001101000000000
00000000001101000000000
00000000010101000000000
00000000011111000000000
00000000000000000000000
11000011100011000011000
10000000000000110010000
11010001100011000011010
11111011111011111011111
00000000000000000000000
00010000000000000000010
00000000000000000000000
00001000000000000000001

该消息有 73 行和 23 列,产生 1679 个图片元素。这些元素中的每一个都由黑色的 1 或白色的 0 定义,并且应打印为 8x8(或 16x16)点的正方形。结果将导致

阿雷西博留言
(来源:satsig.net

从打印机的规格:

在此处输入图像描述

虽然 - 正如我所说 - 连接和发送到打印机没有问题,但我只是不明白这条指令想告诉我什么。在 Arecibo 消息的情况下会是什么

我必须将哪些号码发送到打印机?我需要发送每个点吗?是什么nL, nH specify the number of dots of the image data in the horizontal direction as (nL + nH × 256).意思?

这是我用于原型设计的简单 Python 程序:

# -*- coding: utf-8 -*-
import struct
import socket

def sendInstructions(mySocket,l):
    for x in l:
        mySocket.send(struct.pack('h', *[x]),1)


def emphasizeOn(mySocket):
    sendInstructions(mySocket,[27,33,48])


def emphasizeOff(mySocket):
    sendInstructions(mySocket,[27,33,0])


def lineFeed(mySocket,number):
    for i in range(number):
        sendInstructions(mySocket,[0x0a,])


def paperCut(mySocket):
    sendInstructions(mySocket,[29,86,0])

def sendText(mySocket,string):
    mySocket.send(string.encode('UTF-8'))


def main():
    mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
    mySocket.connect(('192.168.1.15',9100))    


    lines = ["Hello,","World!"]
    emphasizeOff(mySocket)
    lineFeed(mySocket,2)
    for l in lines: 
        if lines.index(l) == 0:
            emphasizeOn(mySocket)
        else:
            emphasizeOff(mySocket)

        sendText(mySocket,l)
        lineFeed(mySocket,2)

    lineFeed(mySocket,4)
    paperCut(mySocket)

    mySocket.close()

if __name__=="__main__":
    main()
4

1 回答 1

7

此命令一次生成一个图像的水平条。条带的高度为 8 或 24 点,具体取决于 m 的值。

nL 和 nH 是整数的低字节和高字节,指定图像水平条带的宽度(以点为单位)。该宽度计算为 nL + nH * 256,因此如果您希望图像为 550 点宽,则 nH=2 且 nL=38。

参数 d 是位图数据;如果图像条高 8 点,则每个字节代表条中的一列。如果条带高 24 点,则三个字节代表一列。

因此,假设您在整数的 WxH numpy 数组中有 arecibo,1 或 0。您将:

data = np.zeros((W, H), dtype=np.ubyte)
## (fill in data here)

## Use m=33 since this is apparently the only mode with 
## square pixels and also the highest resolution 
## (unless it prints too slowly for your liking)
m = 33

nH = W // 256  ## note this is integer division, but SO's 
               ## syntax hilighting thinks it looks like a comment.
nL = W % 256

## Divide the array into sections with shape Wx24:
for n in range(data.shape[1] // 24):
    ## Note that if the image height is not a multiple of 24, 
    ## you'll have to pad it with zeros somehow.

    strip = data[:, n*24:(n+1)*24]

    ## Convert each strip into a string of bytes:

    strip = strip.reshape(W, 3, 8)
    bytes = (strip * (2**np.arange(8)[np.newaxis, np.newaxis, :])).sum(axis=2) # magic
    byteString = bytes.astype(np.ubyte).tostring()

    ## Send the command to POS
于 2012-07-14T03:15:18.987 回答