USB PoS Printer advise

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

USB PoS Printer advise

Post by AndyGable »

Hi all

I need some advise. I have a fully working module that talks to my Epson TM-88IV thermal printer on comport and it works perfectly

And now I want to try and use a USB version of it

So I have found on my system /dev/usb/lp1 and I can echo to it with no problems

The problem I seem to have is when I try to open the port in my status module I get a error message saying "Stream is closed"

Do I handle usb connected devices differently then serial? Some advice would be welcomed.

I can easily add a option for usb to the current module as long as I know what I need to update (I assume one the dev is open it should still communicate the same within the code)

If anyone needs to see the actual module I can upload that

Andy
Attachments
Settings file (sorry for it being so far away)
Settings file (sorry for it being so far away)
image.jpg (4.17 MiB) Viewed 2352 times
Error message on screen
Error message on screen
image.jpg (3.79 MiB) Viewed 2352 times
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: USB PoS Printer advise

Post by BruceSteers »

how exactly do you try to open it?
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: USB PoS Printer advise

Post by cogier »

From what I can see, there is a Linux Printer driver for your printer. Why not install that and just send a page to the printer or as I do with a Zebra Printer, create a PDF file and send that to the printer?
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: USB PoS Printer advise

Post by AndyGable »

cogier wrote: Wednesday 28th February 2024 4:46pm From what I can see, there is a Linux Printer driver for your printer. Why not install that and just send a page to the printer or as I do with a Zebra Printer, create a PDF file and send that to the printer?
If I used the driver I loose all control
Over the printer and I will not get any status about the cash drawer etc from the printer.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: USB PoS Printer advise

Post by AndyGable »

BruceSteers wrote: Wednesday 28th February 2024 4:51am how exactly do you try to open it?
I was trying to open it just like a Serial Printer

    Global.PrinterPort = New SerialPort As "PrinterPort"

    With Global.PrinterPort
        Try .Close
        .PortName = Global.PortName
        .Speed = Global.BandRate

        Select Case Global.FlowControl
            Case "Hardware"
                .FlowControl = Global.PrinterPort.Hardware

            Case "Software"
                .FlowControl = Global.PrinterPort.Software

            Case "None"
                .FlowControl = Global.PrinterPort.None
        End Select

        .DataBits = Global.DataBits
        .StopBits = Global.StopBits

        Select Case Global.Parity
            Case "None"
                .Parity = Global.PrinterPort.None

            Case "Odd"
                .Parity = Global.PrinterPort.Odd

            Case "Even"
                .Parity = Global.PrinterPort.Even
        End Select
    End With
    
    Select Case ConnectionType
        Case "Open"
            Try Global.PrinterPort.Open

        Case "Close"
            Try Global.PrinterPort.Close
    End Select

    If Error Then 
        Global.AddToScreenList("Error connecting to printer")
    Else
        Global.AddToScreenList("Connected to printer")
        EpsonPrinterInitialize        
    End If


I know it is not a Serial device so I would need to do some update to my code to work with the USB Printer
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: USB PoS Printer advise

Post by cogier »

If I used the driver I loose all control
Over the printer and I will not get any status about the cash drawer etc from the printer.
I found this command online tail -f /var/log/syslog. If you run the command in Terminal, then change the cash draw status, you may be able to see it as it happens. (Press [Ctrl]+C to exit). Every time I changed a USB, or turned a printer on, data poured in.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: USB PoS Printer advise

Post by AndyGable »

cogier wrote: Thursday 29th February 2024 10:48am
If I used the driver I loose all control
Over the printer and I will not get any status about the cash drawer etc from the printer.
I found this command online tail -f /var/log/syslog. If you run the command in Terminal, then change the cash draw status, you may be able to see it as it happens. (Press [Ctrl]+C to exit). Every time I changed a USB, or turned a printer on, data poured in.
Hi @cogier I tried that and I get nothing showing up

I have install my development IDE (gamabs3) onto the PoS Terminal that has the USB printer attached (/dev/usb/lp0) I have chmod 777 the port so anyone can access it and when I run the printer module now insde the IDE I get the following error message "Unable to get configuration: Inappropriate ioctl for device"

I was setting it to /dev/usb/lp0 and speed of 115200

am I thinking along the right lines for the USB Printer or do I need to re think this?
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: USB PoS Printer advise

Post by AndyGable »

After a lot of googling and asking ChatGPT I have come up with the following code (Still needs work though)

    Global.PrinterPort = New SerialPort As "PrinterPort"

    With Global.PrinterPort
        Try .Close
        .PortName = Global.PortName
    End With
    
    Select Case ConnectionType
        Case "Open"
            Try Global.PrinterPort.Open

        Case "Close"
            Try Global.PrinterPort.Close
    End Select

    If Error Then 
        Global.AddToScreenList("Error connecting to USB Printer")
    Else
        Global.AddToScreenList("Connected to USB Printer")
        EpsonPrinterInitialize        
    End If  


But I am still getting a Error connecting to USB Printer and then the same error message steam is closed (#53) could some one have a look and see if I am on the right lines (should the device not show up as a /dev/ttyUSB and not /dev/usb/lp1 (im on debian))


Chatgpt came up with this one

Public sub Main()
 Dim SerialPort as Serial

SerialPort = New Serial("/dev/usb/lp1")

if serialport.open() then
  'Send Commands
  Serial.write ("your commands here")
  serial.close
else
  Print "Error Opening Serial (USB) Device"
End if


Of course I have had to update it to work
Post Reply