Coder Social home page Coder Social logo

Comments (6)

belono avatar belono commented on July 18, 2024

Hi @rodhoff !

Well, I think you are not using our python-escpos library but some other escpos library written in python.

Anyway, your issue looks like a permission problem.
Did you try to run your script as an administrator?

Sadly, I can't help you much more.

from python-escpos.

rodhoff avatar rodhoff commented on July 18, 2024

Hi @belono !

Sorry for the mistake, I'm trying several approaches to understand why it's not working. I have tried to run this sample code for the python-escpos even though:

from escpos.printer import Serial
p = Serial(devfile='COM2',
           baudrate=9600,
           bytesize=8,
           parity='N',
           stopbits=1,
           timeout=1.00,
           dsrdtr=True)

p.text("Hello World\n")
p.qr("You can readme from your smartphone")
p.cut()

And I got the same error message, even running from an elevated powershell:

(c:\Users\rodri\dev\pycoupon\v-fatura) C:\Users\rodri\dev\pycoupon [main +3 ~1 -0 !]> python serial-test-3.py
Traceback (most recent call last):
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\printer\serial.py", line 136, in open
    self.device: Optional[serial.Serial] = serial.Serial(
                                           ^^^^^^^^^^^^^^
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\serial\serialwin32.py", line 33, in __init__
    super(Serial, self).__init__(*args, **kwargs)
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\serial\serialutil.py", line 244, in __init__
    self.open()
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\serial\serialwin32.py", line 64, in open
    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM2': PermissionError(13, 'Acesso negado.', None, 5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\rodri\dev\pycoupon\serial-test-3.py", line 10, in <module>
    p.text("Hello World\n")
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\escpos.py", line 863, in text
    self.magic.write(str(txt))
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\magicencode.py", line 282, in write
    self.write_with_encoding(encoding, to_write)
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\magicencode.py", line 304, in write_with_encoding
    self.driver._raw(
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\printer\serial.py", line 163, in _raw
    assert self.device
           ^^^^^^^^^^^
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\escpos.py", line 146, in device
    self.open()
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\printer\serial.py", line 50, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\rodri\dev\pycoupon\v-fatura\Lib\site-packages\escpos\printer\serial.py", line 150, in open
    raise DeviceNotFoundError(
escpos.exceptions.DeviceNotFoundError: Device not found (Unable to open serial printer on COM2:
could not open port 'COM2': PermissionError(13, 'Access denied.', None, 5))

I'm using VSPE to emulate the COM2 - COM5 pair and the Bematech printer emulator.

from python-escpos.

rodhoff avatar rodhoff commented on July 18, 2024

As I'm using VSPE, and emulated a pair of com ports (COM2<=>COM5) I believe it will use COM2 to emulate the printer, and would listen for requests from COM5... When I changed COM2 to COM5, I don't get any error - but don't get anything printed as well...

from python-escpos.

belono avatar belono commented on July 18, 2024

It seems that Bematech doesn't support ESC/POS commands, so you can't print with this library on a Bematech printer.

Did you choose a Bematech emulator because you have to support a printer of that specific model?

EDIT:
Sorry, seems that I was wrong. --> See chapter 4

Some Bematech printers have dual command set support ESCBema/ESCPOS, so you could print with the help of python-escpos.

from python-escpos.

rodhoff avatar rodhoff commented on July 18, 2024

Thanks @belono !

No specific reason for using Bematech, it's only that I've found it first. Is there any other reasonable one which you know I could use?

from python-escpos.

belono avatar belono commented on July 18, 2024

Depending on your needs, there are some tools more or less related to our library that you can use to check your code is working.

  1. If you just want to check you are sending well-formatted commands to python-escpos you simply can make use of our Dummy printer connector and check the raw output it would be sent to your printer.
    Documentation of the Dummy printer connector

  2. A more similar approach to a virtual printer where you can use a real connection to a 'virtual network device' and see some simple output is the escpos-printer-simulator that is quite straightforward to use. Just download the binary and run it in java, it starts a server at a port that listens to escpos commands and renders to a window the raw output you send using our Network printer connector.

  3. If you would like to see some final output with limited support to images and some complex layout then esc2html would be your choice. It could render an html representation of the Dummy.output(). To tell the truth I've never used this tool but, if I'm not wrong, just save the output to a binary file and open it up with esc2html to get an html file that you can then open up in a web browser.

Surely, there are more and maybe better tools to simulate an escpos printer but these are the ones I know.
More suggestions are welcome from my side.

from python-escpos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.