Title: Working with the dreaded Invalid Engine Code ( printers )
Question: Let's say that we have a common printer, such as a Lexmark Printer. Let's also say that we want to be able to download the LATEST VERSION ( which changes periodically ) Engine Code, and want to update it to the printer. This can be done via FTP/Parallel. How do we do it?
Answer:
//This program assumes that the FTP Directory is set up to work with it.
//Also, this also asumes that they have placed the pjl files in the directory
//indicated in the code. This will NOT WORK UNLESS they have the actual Engine
//Codes ( pjl files ) out on the net. This will work with ANY VERSION they
//release. And please, if you decide to use it, give credit where credit is
//due =) ENJOY!
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Psock, NMFtp, shellapi, UrlMon, Menus, FileCtrl,
ComCtrls;
implementation
uses Main, Step2, Note, AboutBox;
{$R *.dfm}
Function IsUserConnected : string;
Begin
// If we can't connected to the ftp, then the user must not have a connection, so we show the message according to that...
With Application Do
Begin
NormalizeTopMosts;
MessageBox('Please make sure you are connected to the internet before pressing Finish.', 'Engine Code Unsuccessfully Downloaded', MB_OK);
RestoreTopMosts;
ShowMessage('If you continue having problems, please contact us at 1-555-555-5555');
End;
End;
Function DownloadFile(Source, Dest: string): Boolean;
Begin
// EditJon : This function is set so that I can specify EXACTLY in our FTP directory where we are downloading from and
// where the file will end up on the users' hardrive...
Try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
Except
Result := False;
End;
End;
procedure TForm3.Button3Click(Sender: TObject);
begin
Form3.Release;
Form2.Release;
Form1.Close;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
// Back Button
Form2.Show;
Form3.Close;
end;
Procedure TForm3.Button2Click(Sender: TObject);
//This is called when the user clicks finish
Var
i:integer;
Bob1:string;
Bob2:string;
Bob3:string;
Bob4:string;
Bob5:string;
Bob6:string;
Bob7:string;
Bob8:string;
Begin
// Set directory that will be used to do all actions with engine code.
DirectoryListBox1.Directory := 'C:\lexmark4';
// Everything is disabled so that the user cannot stop the process by clicking the box.
// The user will HAVE to end the task before the program stops, so that the user is taking responsiblity for doing so...
Button2.Enabled := False;
Button1.Enabled := False;
Button3.Enabled := False;
// Changes cancel to Exit ECU
Button3.Caption := 'Exit ECU';
Form3.Enabled := False;
Begin
Try
// The following 11 lines assings each string to a variable that searches for the engine code, no matter the version #..
For i := 7870 To 9999 Do
Begin
Bob1:=Format('%dB15L.PJL',[i]);
Bob2:=Format('%dB20L.PJL',[i]);
Bob3:=Format('%dB25L.PJL',[i]);
Bob4:=Format('%dB35L.PJL',[i]);
Bob5:=Format('%dG20L.PJL',[i]);
Bob6:=Format('%dG25L.PJL',[i]);
Bob7:=Format('%dF30L.PJL',[i]);
Bob8:=Format('%dF40L.PJL',[i]);
End;
// Downloads the Engine Code for the printer the user specifies.....
If form1.ComboBox1.Text = 'Optra S1250' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_V.PJL'),('c:\lexmark4\AE6055_V.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S1255' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_V.PJL'),('c:\lexmark4\AE6055_V.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S1620' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_R.PJL'),('c:\lexmark4\AE6055_R.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S1650' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_R.PJL'),('c:\lexmark4\AE6055_R.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S1625' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_R.PJL'),('c:\lexmark4\AE6055_R.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S1855' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_S.PJL'),('c:\lexmark4\AE6055_S.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S2420' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_L.PJL'),('c:\lexmark4\AE6055_L.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S2450' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_L.PJL'),('c:\lexmark4\AE6055_L.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra S2455' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/AE6055_L.PJL'),('c:\lexmark4\AE6055_L.PJL')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra 3455' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/DD6685_D.PJL'),('c:\lexmark4\dd6685_d.pjl')) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
If form1.ComboBox1.Text = 'Optra T610' Then
Begin
If DownloadFile(('ftp.lexmark.com/'+Bob1),('c:\lexmark4\'+Bob1)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'Optra T612' Then
Begin
If DownloadFile(('ftp.lexmark.com/'+Bob2),('c:\lexmark4\'+Bob2)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'Optra T614' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/'+Bob3),('c:\lexmark4\'+Bob3)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'Optra T616' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/'+Bob4),('c:\lexmark4\'+Bob4)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBOx1.Text ='Lexmark T520' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/'+Bob5),('c:\lexmark4\'+Bob5)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'LexmarkT522' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/'+Bob6),('c:\lexmark4\'+Bob6)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'LexmarkT620' Then
Begin
If DownloadFile(('ftp.lexmark.com/laser_dos/eng/'+Bob7),('c:\lexmark4\'+Bob7)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End
Else
If form1.ComboBox1.Text = 'LexmarkT6722' Then
Begin
If DownloadFile(('ftp.Lexmarkb.com/'+Bob8),('c:\lexmark4\'+Bob8)) Then
ShowMessage('Engine Code Downloaded Successfully. Updating Engine Code...')
Else
IsUserConnected;
End;
Except
End;
// After downloaded, check to see if user selected Parallel or Network, and copy file accordingly.
// Once file is copied over to printer, rename the pjl file to t0n22 so we can then remove it from their system...
Try
If Form2.ParallelOpt.Checked = True then
Begin
If Form1.ComboBox1.Text = 'Optra T616' Then
Begin
WinExec(('COMMAND.COM /C copy /b *.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T614' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 1);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T612' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T610' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S3455' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2455' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2450' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2420' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1855' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1625' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1650' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1620' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1255' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1250' Then
Begin
WinExec(('COMMAND.COM /C copy /b c:\*.pjl lpt1'), 0);
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End;
End;
Except
End;
Try
If form2.NetworkOpt.Checked = True then
Begin
Try
If Form1.ComboBox1.Text = 'Optra T616' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\'+Bob4 , Bob4);
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T614' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\'+Bob3 , Bob3);
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T612' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\'+Bob2 , Bob2);
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra T610' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\'+Bob1 , Bob1);
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S3455' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\DD6685_D.PJL','DD6685_D.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2455' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_L.PJL','AE6055_L.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2450' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_L.PJL','AE6055_L.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S2420' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_L.PJL','AE6055_L.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1855' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_S.PJL','AE6055_S.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1625' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_R.PJL','AE6055_R.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1650' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_R.PJL','AE6055_R.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1620' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_R.PJL','AE6055_R.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1255' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_V.PJL','AE6055_V.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End
Else
If Form1.ComboBox1.Text = 'Optra S1250' Then
Begin
NMFTP1.Host := Form2.PrintIP.Text;
NMFtp1.Connect;
NMFTP1.Upload('c:\t0nebobl\AE6055_V.PJL','AE6055_V.PJL');
NMFtp1.Disconnect;
WinExec(('COMMAND.COM /C rename *.pjl t0n22.pjl'),0);
End;
Except
End;
End;
Except
End;
End;
// Once the procedure is done, enable everything again so that the user can decide if they need to go back, redo, or exit.
Form3.Enabled := True;
Button2.Enabled := True;
Button1.Enabled := True;
Button3.Enabled := True;
// This file is deleted after the process is ended. To see where it is loaded, please view the Button2.OnClick Procedure
DeleteFile('t0n22.pjl');
End;
procedure TForm3.Exit1Click(Sender: TObject);
begin
DeleteFile('t0n22.pjl');
Form1.Close;
end;
procedure TForm3.AboutECU1Click(Sender: TObject);
begin
About.Show;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// on exit, remove all files we downloaded....
Form1.Close;
end;
end.