Programma di esempio SENDLPT.PRT |
; SENDLPT
;
; Programma per Proteus
;
; (C) 2003 Simone Zanella Productions
;
; Invia un file sulla porta parallela (invio diretto, senza passare per driver di Windows).
#!proteus -z
!include "win32.prt"
!include "console.prt"
; Parametri di default: LPT1
LptPort = "LPT1"
H2 = FOPEN(ARGV(5), 1)
IF EQ(H2, -1)
IF GE(ARGC, 5)
CONSOLELN "File " ARGV(5) " NON trovato."
FI
CONSOLELN ""
CONSOLELN "Sintassi: " ARGV(1) " " ARGV(2) " nomefile [/Pporta]"
CONSOLELN ""
CONSOLELN "Scopo: invia il file specificato sulla porta parallela richiesta."
CONSOLELN ""
CONSOLELN "Default: LPT1"
CONSOLELN ""
CONSOLELN "/Pporta porta = 1, 2, 3, .."
CONSOLELN ""
ABORT 0
FI
FOR X = 6 TO ARGC
ElaboraParametri(ARGV(X))
NEXT
ConvalidaParametri()
H = W32CREATEFILE(LptPort, W32_GENERIC_WRITE, 0, \
W32_OPEN_EXISTING, 0)
IF EQ(H, -1)
CONSOLELN "Impossibile aprire " LptPort "."
ABORT 2
FI
DISPSET(DISP_BLINK, DISP_BLINK_OFF)
DISPSET(DISP_FOREG, YELLOW)
DISPSET(DISP_BACKG, BLUE)
DISPSET(DISP_UNSFG, YELLOW)
DISPSET(DISP_SELBG, GREEN)
DISPSET(DISP_JUST, DISP_JUST_NONE)
DISPSET(DISP_JLEN, 0)
DISPSET(DISP_SHADOW, DISP_SHADOW_RIGHT)
DISPSET(DISP_SOUND, 0)
DISPSET(DISP_JLEN, 17)
DISPCLS()
DISPWRITE(1, 1, "Porta parallela: " LptPort)
DISPWRITE(1, 2, "Caricamento in corso di: " ARGV(5))
Total = FSIZE(H2)
Prev = -1
Prev = ProgressBar(0, Total, 5, 1, Prev, 50, 3)
WHILE NOT(FEOF(H2))
N = FSEEK(H2, 0, 1)
L = FREAD(H2, 1024)
IF EQ(W32WRITEFILE(H, L), -1)
DISPWRITE(1, 8, "Errore nell'invio.")
W32CLOSEHANDLE(H)
FCLOSE(H2)
ABORT 0
FI
Prev = ProgressBar(N, Total, 5, 1, Prev, 50, 3)
LOOP
Prev = ProgressBar(Total, Total, 5, 1, Prev, 50, 3)
W32CLOSEHANDLE(H)
FCLOSE(H2)
DISPWRITE(1, 8, "Fatto.")
ABORT 0
FUNCTION ProgressBar(value, total, starty, startx, prev, len, altezza)
; Procedura per il disegno di una barra di progresso
IF EQ(prev, -1)
FOR y1 = starty TO DEC(ADD(starty, altezza))
FOR x = startx TO DEC(ADD(startx, len))
DISPWRITE(x, y1, CHR(0xB0))
NEXT
NEXT
x = startx
ELSE
x = prev
FI
end = ADD(startx, IIF(total, FDIV(MUL(len, value), total), len))
FOR y1 = starty TO DEC(ADD(starty, altezza))
FOR x1 = x TO DEC(end)
DISPWRITE(x1, y1, CHR(0xDB))
NEXT
NEXT
RETURN end
FUNCTION ConvalidaParametri()
; Convalida i parametri
RETURN
FUNCTION ElaboraParametri(s)
; Legge i parametri per la porta
s = RESTFROM(s, 2)
SWITCH LEFT(s, 1) STRIEQ
ON "P"
; Seleziona la porta
IF OR(LT(RESTFROM(s, 2), 1), GT(RESTFROM(s, 2), 20))
CONSOLELN "Porta errata: /" s
ABORT 1
FI
_LptPort = "LPT" RESTFROM(s, 2)
OTHER
CONSOLELN "Parametro non riconosciuto: /" s
ABORT 1
OFF
RETURN