@oota_torao (太田 とらお)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

RaspberryPi CUPSを使用してのプリンター状態の取得について

RaspberryPiでPython,CUPSを使用してテキストや画像を印刷するアプリを作成しています。

現在は以下のように印刷をしており、印刷自体は問題ありません。
ただ、プリンタの状態がわからず用紙切れ、トナー切れ等のエラーが発生した場合にも
正常終了になってしまい、プログラム上からエラーが検出できず
困っております。
何か解決策はあるでしょうか?

例)
import os
import cups
import time

# テキストファイルを生成
f = open( 'test_print.txt', 'w' )
f.write( 'something' )
f.close()

# プリンタ制御開始
conn = cups.Connection()
printer_name = conn.getDefault()
print( printer_name )
printer_returns = conn.printFile( printer_name, 'test_print.txt', 'test', {} )
while conn.getJobs().get( printer_returns, None ) is not None:
    time.sleep(1)

print( str(printer_returns) )

調べたこととして

cupsLastErrorStringというものがありそうなのですが
使用できませんでした・・・

0 likes

1Answer

情報追記です。
subprocessにてlpstat -l -p printernameを実行し返ってきた文字列の中に
'プリンターが使用可能になるのを待っています。'の文字列があった場合に
エラー状態との認識はできました。

しかし、エラーの内容が用紙切れなのか、トナー(インク切れ)なのかの
判断ができておりません。

エラーを特定することはできないでしょうか?

0Like

Your answer might help someone💌