Example SPOOLER.PRT
; SPOOLER
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; Verify if a file exists; if it is so and the file is writable (it is not locked for update),
; process it by sending strings (e.g. commands to create a label on a barcode printer) merged with
; data available in the file.
; The printer where data are to be sent is specified by network address and port.
;
; Working parameters are at the beginning of the program and are the following:
; - Filename = data file name
; - NetAddr = printer address
; - NetPort = printer port

#!proteus -z -j

!include "win32.prt"
!include "socket.prt"

; When run as a service, use constant parameters; otherwise, extract them from command line
!ifdef SERVICE
  Filename = "c:\\spool\\DATI.TXT"
  NetAddr = "172.16.0.82"
  NetPort = 9090
!else
  IF LT(ARGC, 7)
    CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " datafile address port"
    CONSOLELN ""
    CONSOLELN "Purpose: use datafile for printing labels to the printer (address, port)"
    ABORT 0
  FI
  Filename = ARGV(5)
  NetAddr = ARGV(6)
  NetPort = ARGV(7)
!endif

WHILE 1
  ; Wait 0.5 seconds
  SLEEP(0.5)

  IF ISFILE(Filename)

    H2 = FOPEN(Filename, 4)

    IF EQ(H2, -1)
      ; File locked, it is being written
      CONTINUE
    FI
       
    HSock = W32SOCKET(AF_INET, SOCK_STREAM, IPPROTO_TCP)
    
    IF EQ(HSock, -1)
      Message("Errore creating socket")
      Message("Socket error: " W32LASTSOCKETERR())
      FCLOSE(H2)
      CONTINUE
    FI
    
    Result = W32CONNECT(HSock, AF_INET, NetPort, NetAddr)
    IF EQ(Result, -1)
      Message("Error connecting socket")
      Message("Socket error: " W32LASTSOCKETERR())
      W32SHUTDOWN(HSock, SD_BOTH)
      W32CLOSESOCKET(HSock)
      FCLOSE(H2)
      CONTINUE
    FI
    
    Errore = 0
    WHILE NOT(FEOF(H2))
      S2 = FREADLN(H2)
      IF NOT(ISEMPTY(S2))
        ; Suppose the file holds (in each line) a text to be printed as a barcode and 
        ; the number of labels to be printed, separated by a comma
        BarCode = TOKEN(S2, 1, ",")
        NumLabels = TOKEN(S2, 2, ",")

        IF ISEMPTY(NumLabels)
          NumLabels = 1
        FI

        ; Prepara i dati da inviare alla stampante (codice di esempio FingerPrint per stampanti Intermec)
        S = "\r\nCLIP ON\r\nDIR 1\r\nAN 7\r\nPP 100, 100\r\nBT \"CODE39\"\r\n" \
            "BARRATIO 2,1 : BARHEIGHT 120 : BARMAG 3 : BARFONT \"Swiss 721 BT\" ON\r\n" \
            "PB \""  BarCode "\"\r\nPF " NumLabels "\r\n"

        Result = W32SEND(HSock, S, 0)
        IF EQ(Result, -1)
          Message("Send error")
          Message("Socket error: " W32LASTSOCKETERR())
          W32SHUTDOWN(HSock, SD_BOTH)
          W32CLOSESOCKET(HSock)
          Errore = 1
          BREAK
        FI
      FI
    LOOP
    
    FCLOSE(H2)
    
    IF EQ(Errore, 0)
      W32SHUTDOWN(HSock, SD_BOTH)
      W32CLOSESOCKET(HSock)
      Message("Send completed.")
      FREMOVE(Filename)
    FI
  FI
LOOP  

ABORT 0


FUNCTION Message(s)

; If run as a service, save message to a log file;
; otherwise, print message to video
!ifdef SERVICE
  FAPPEND("c:\\spooler\\log.txt", s "\r\n")
!else
  CONSOLELN s
!endif      
RETURN
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell