Serial Port connection check

This forum is for eXpress++ general support.
Message
Author
ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Serial Port connection check

#1 Post by ampandya »

Hi
Is there any way to keep checking if the serial printer is on and connected, as the program we have here freezes if the printer is off or not connected and then the program needs to be end tasked?

Also, Can you help me to set up the USB thermal printer for the receipt?

Many Thanks for your help in advance.

Ankit

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Serial Port connection check

#2 Post by rdonnay »

Why are you using a serial printer?

To use a USB printer:

oPrinter := XbpPrinter():new()
oPrinter:create(<Printer Name>)

SET PRINTER TO oPrinter
The eXpress train is coming - and it has more cars.

ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Re: Serial Port connection check

#3 Post by ampandya »

Thanks Roger,
It is a POS system and POS thermal printer that is why i have to use serial printer.

Can we check if the printer is connected before it prints or opening cash drawer?


Thanks

Wolfgang Ciriack
Posts: 484
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Serial Port connection check

#4 Post by Wolfgang Ciriack »

Perhaps you can use the COM_ functions of the XBase Tools, f.e.
COM_OPEN and COM_LSR for the Line Status Register.
_______________________
Best Regards
Wolfgang

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Serial Port connection check

#5 Post by rdonnay »

Try using IsPrinter(). This is from the Xbase++ documentation:

Syntax

IsPrinter( [<cLPT>] ) --> lReady

Parameters

<cLPT>

<cLPT> is a character string specifying the print channel whose readiness is determined. By default LPT1 is tested.

Return

The return value of IsPrinter() is .T. (true) if the printer (the device) on the specified print channel is ready, otherwise .F. (false) is returned.

Description

The environment function IsPrinter() tests the readiness of an output device connected to a print or output channel. The function tests LPT1 to LPT<n> or COM1 to COM<n>. When no argument is specified, the readiness of LPT1 is tested.
Caution
When print output occurs using the spooler or print queue, IsPrinter() reports the readiness of the spooler and not of the physical printer. In this situation the function generally returns the value .T. (true). If the actual output device is not ready, the condition is reported by the operating system.

Example

// IsPrinter()
// In the example, a text file is output to the
// printer. Using IsPrinter(), the readiness of the printer
// is tested during the print output. If it is not ready,
// a message is output using Alert() and the user
// decides how to continue.
//

PROCEDURE Main
LOCAL nLineLen := 55
LOCAL nPageLen := 65
LOCAL nPageNum := 1
LOCAL nPos

cString = MemoRead("TEXTFILE.TXT")
SET MARGIN TO 8


DO WHILE Len( cString ) > 0
SET PRINTER OFF
SET CONSOLE ON

DO WHILE .NOT. IsPrinter()
IF Alert( "Printer is not ready", ;
{"Retry","Cancel"} ) == 2
cString := ""
EXIT
ENDIF
ENDDO

IF .NOT. Empty( cString )
@ 0,0 SAY "Print page number:"
?? nPageNum

SET PRINTER ON
SET CONSOLE OFF

? PadL( "Page: "+Str(nPageNum,8), nLineLen )
? PadL( "Date: "+DtoC(Date()) , nLineLen )
? PadL( "Time: "+Time() , nLineLen )

nPos := MlPos( cString, nLineLen, nPageLen )

? SubStr( cString, 1, nPos - 1 )
cString := SubStr( cString, nPos )

nPageNum ++
EJECT
ELSE
EXIT
ENDIF
ENDDO

SET MARGIN TO

SET PRINTER OFF
SET CONSOLE ON


RETURN
The eXpress train is coming - and it has more cars.

ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Re: Serial Port connection check

#6 Post by ampandya »

Thanks Roger,

the isprinter() only check the printer status when the program is starting,
once the program is on and the printer is offline it doesnt check the COM port status? any suggestion?

Thanks

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Serial Port connection check

#7 Post by rdonnay »

I don't understand.

Are you saying that you want to continuously test the printer status, even when not in a print job?

You can start a thread to do this.

Code: Select all

oThread := Thread():new()
oThread:start({||TestPrinter()})

FUNCTION TestPrinter()

DO WHILE .t.

  If !IsPrinter('COM1')
    Msgbox('Printer is offline')
  ENDIF
  Sleep(100)

ENDDO

RETURN nil
The eXpress train is coming - and it has more cars.

ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Re: Serial Port connection check

#8 Post by ampandya »

Roger,
Thread works for the first form(screen), when i click on any button and it open another page it says "Printer is offline".
once the error starts about the printer then it keeps coming even after the printer is on and working.

The printer is connected to COM1 on my pc and when we use the software on the till it can be COM3 or COM4.
The program knows the port using the P_PORT_RECEIPT which is stored in the dbf.

There is a Drawer connected to this thermal printer, what happens at the moment is when the printer is offline the program freezes, either when opening the drawer or when printing a receipt for the customer.

that is the reason we need to keep checking the printer status!

Thank you

ampandya
Posts: 58
Joined: Tue Apr 19, 2016 4:48 am

Re: Serial Port connection check

#9 Post by ampandya »

Hi Roger,
regarding the query:

I have come to know that the previous developer has used WSC4XB and the text to the printer using

nCode = xsioPuts(nPort,@combuf,len(combuf))

Thanks

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Serial Port connection check

#10 Post by c-tec »

Hello,
your sampel shows direct serial printing via RS232 and not with a installed printer driver that eXpress++ use. This is a big difference, here you send text and control characters directly.
If you want to print this way you should look as Wolfgang wrote to the COM funktinons in the tools. I can help you if needed to convert from MarshallSoft to XBTOOLS.
regards
Rudolf
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Post Reply