Skip to content

Commit e42164e

Browse files
committed
Version 0.90
Fixed lost comm port bug and added features
1 parent 0b9815d commit e42164e

File tree

12 files changed

+165
-34
lines changed

12 files changed

+165
-34
lines changed

LuaLoader.zip

-1.42 KB
Binary file not shown.

Source/LuaLoader.res

0 Bytes
Binary file not shown.

Source/LuaLoaderMain.dfm

140 Bytes
Binary file not shown.

Source/LuaLoaderMain.pas

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
// TODO - add tmr.stop on restart automatically, also resume higher baud rate
1919

20+
// 0.90 manually add a COM port that is not detected automatically + user OpenKeyReadOnly to get W10 HARDWARE key
21+
// 0.90 change to ini files instead of registry
22+
// 0.89 removed Hard Restart and Soft Restart messages which appeared out of sequence and confused
23+
// 0.88 allow more baud rates, fix the reset to 9600
2024
// 0.87 set default DTR and RTS on each connect
2125

2226
// 0.86 changed the default value of DTR and RTS to false = HI
@@ -138,7 +142,7 @@ interface
138142
uses
139143
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,SerialNG,
140144
StdCtrls, ExtCtrls, ComCtrls, ImgList, Buttons, URLLabel, ClipBrd, Registry,
141-
Menus, ShellAPI, SuperTimer, Math;
145+
Menus, ShellAPI, SuperTimer, Math, IniFiles;
142146

143147
type
144148
TForm1 = class(TForm)
@@ -303,6 +307,7 @@ TForm1 = class(TForm)
303307
ListallM: TMenuItem;
304308
ReadRateM: TPopupMenu;
305309
Setrepeatrateforread1: TMenuItem;
310+
NodeMCUCustomBuilds1: TMenuItem;
306311
procedure AdvSettingsBtnClick(Sender: TObject);
307312
procedure SerialPortNG1RxClusterEvent(Sender: TObject);
308313
procedure SerialPortNG1ProcessError(Sender: TObject; Place,Code: DWord; Msg: String);
@@ -428,6 +433,7 @@ TForm1 = class(TForm)
428433
procedure DecodeDL(Sender: TObject);
429434
procedure ListlcMClick(Sender: TObject);
430435
procedure ListallMClick(Sender: TObject);
436+
procedure NodeMCUCustomBuilds1Click(Sender: TObject);
431437
private
432438
{ Private declarations }
433439
RxDCharStartTimer : Boolean;
@@ -490,7 +496,7 @@ TForm1 = class(TForm)
490496
CustomLuaFile : string;
491497

492498
const
493-
ThisVersion = '0.87 '; // change with each version
499+
ThisVersion = '0.90 '; // change with each version
494500
CRLF = #$0d#$0a ;
495501

496502
implementation
@@ -572,7 +578,7 @@ function FileTime( filename : string) : integer;
572578

573579
procedure TForm1.FormCreate(Sender: TObject);
574580
var
575-
Regx : TRegIniFile;
581+
Regx : TIniFile;
576582
timers : string;
577583
i,n : integer;
578584
ws : string;
@@ -608,7 +614,7 @@ procedure TForm1.FormCreate(Sender: TObject);
608614

609615
Caption := 'ESP8266 LuaLoader '+ThisVersion;
610616

611-
Regx := TRegIniFile.Create( 'Software\Benlo.com' );
617+
Regx := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
612618
Top := Regx.ReadInteger('LuaLoader','Top',Top);
613619
Left := Regx.ReadInteger('LuaLoader','Left',Left);
614620
Width := Regx.ReadInteger('LuaLoader','Width',Width);
@@ -708,7 +714,7 @@ procedure TForm1.ShowHint(Sender : TObject);
708714

709715
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
710716
var
711-
Regx : TRegIniFile;
717+
Regx : TIniFile;
712718
i : integer;
713719
timers : string;
714720
Temp : TStringList;
@@ -720,7 +726,7 @@ procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
720726
SerialPortNG1.WriteSettings('Software\Benlo.com','LuaLoader');
721727
SerialPortNG1.Active := False;
722728

723-
Regx := TRegIniFile.Create( 'Software\Benlo.com' );
729+
Regx := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
724730
Regx.WriteInteger('LuaLoader','Top',Top);
725731
Regx.WriteInteger('LuaLoader','Left',Left);
726732
Regx.WriteInteger('LuaLoader','Width',Width);
@@ -1011,10 +1017,10 @@ procedure TForm1.SerialPortNG1RxClusterEvent(Sender: TObject);
10111017
if (0 < Pos('NODEMCU ',UpperCase(line))) and (0 < Pos('owered by Lua',line)) then
10121018
begin
10131019
line := Trim(Copy(line,9,Length(LatestNodeMCU)));
1014-
if not SoftRestart then
1015-
begin
1016-
Show('Hard Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
1017-
end;
1020+
// if not SoftRestart then
1021+
// begin
1022+
// Show('Hard Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
1023+
// end;
10181024
SoftRestart := False;
10191025
if line < Trim(LatestNodeMCU) then
10201026
begin
@@ -1233,6 +1239,12 @@ function TForm1.Upload(fname : string) : boolean;
12331239
if FastUp.Checked and (SerialPortNG1.BaudRate <> 921600) then
12341240
begin
12351241
newrate := 921600;
1242+
SerialPortNG1.BaudRate := newrate;
1243+
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
1244+
if i >= 0 then
1245+
BaudRate.ItemIndex := i
1246+
else
1247+
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
12361248
BaudRate.ItemIndex := 8;
12371249
Show('Baud rate changed to '+IntToStr(newrate),1);
12381250
end;
@@ -1461,6 +1473,8 @@ procedure TForm1.NodeHeapBtnClick(Sender: TObject);
14611473
end;
14621474

14631475
procedure TForm1.RestartBtnClick(Sender: TObject);
1476+
var
1477+
i : integer;
14641478
begin
14651479
RepeatTimer.Enabled := False;
14661480
if HideRestartGarbageM.checked then
@@ -1475,10 +1489,14 @@ procedure TForm1.RestartBtnClick(Sender: TObject);
14751489
begin
14761490
SerialPortNG1.BaudRate := 9600;
14771491
StatusBar.SimpleText := 'Baud rate reduced to 9600';
1478-
BaudRate.ItemIndex := 0;
1492+
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
1493+
if i >= 0 then
1494+
BaudRate.ItemIndex := i
1495+
else
1496+
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
14791497
end;
14801498

1481-
Show('Soft Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
1499+
//Show('Soft Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
14821500
SoftRestart := True;
14831501
end;
14841502

@@ -1748,9 +1766,9 @@ procedure TForm1.CheckLLVersion(Sender: TObject; filename : string; error : word
17481766

17491767
APIrevision := '';
17501768
if Items.Count > 1 then APIrevision := Items[1];
1751-
NodeMcuLua1.Caption := 'NodeMCU Lua API ';
1752-
if length(APIrevision) > 5 then
1753-
NodeMcuLua1.Caption := NodeMcuLua1.Caption +' (revised '+APIrevision+ ')' ;
1769+
NodeMcuLua1.Caption := 'NodeMCU Lua API '+LatestNodeMCU;
1770+
//if length(APIrevision) > 5 then
1771+
// NodeMcuLua1.Caption := NodeMcuLua1.Caption +' (revised '+APIrevision+ ')' ;
17541772
Items.Free;
17551773
end;
17561774

@@ -1947,10 +1965,16 @@ procedure TForm1.WifiStatusBtnClick(Sender: TObject);
19471965
procedure TForm1.ResetBaudTimerStop(Sender: TObject);
19481966
var
19491967
newrate : string;
1968+
i : integer;
19501969
begin
19511970
if BaudRate.Text <> '9600' then
19521971
begin
1953-
BaudRate.ItemIndex := 0;
1972+
SerialPortNG1.BaudRate := 9600;
1973+
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
1974+
if i >= 0 then
1975+
BaudRate.ItemIndex := i
1976+
else
1977+
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
19541978
newrate := Trim(BaudRate.Items[BaudRate.ItemIndex]);
19551979
SerialPortNG1.BaudRate := StrToIntDef(newrate,9600);
19561980
Show('Baud rate changed to '+newrate,1);
@@ -2509,23 +2533,25 @@ procedure TForm1.DoFileCompiledClick(Sender: TObject);
25092533

25102534
procedure TForm1.DownLoadBtnClick(Sender: TObject);
25112535
var
2512-
newrate : integer;
25132536
fname : string;
2537+
i : integer;
25142538
begin
25152539
DLCapture := '';
25162540

2517-
newrate := SerialPortNG1.BaudRate;
25182541
if FastUp.Checked and (SerialPortNG1.BaudRate <> 921600) then
25192542
begin
2520-
newrate := 921600;
2521-
BaudRate.ItemIndex := 8;
2522-
Show('Baud rate changed to '+IntToStr(newrate),1);
2543+
SerialPortNG1.BaudRate := 921600;
2544+
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
2545+
if i >= 0 then
2546+
BaudRate.ItemIndex := i
2547+
else
2548+
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
2549+
Show('Baud rate changed to '+IntToStr(SerialPortNG1.BaudRate),1);
25232550
end;
25242551

2525-
Send('uart.setup(0,'+IntToStr(newrate)+',8,0,1,1)'+CRLF,0);
2552+
Send('uart.setup(0,'+IntToStr(SerialPortNG1.BaudRate)+',8,0,1,1)'+CRLF,0);
25262553
Pause(300); // allow command to be sent
25272554

2528-
SerialPortNG1.BaudRate := newrate;
25292555
SerialPortNG1.WriteSettings('Software\Benlo.com','LuaLoader');
25302556

25312557
AwaitPrompt(2000);
@@ -2680,4 +2706,10 @@ procedure TForm1.ListallMClick(Sender: TObject);
26802706
ListallM.Checked := not ListAllM.Checked;
26812707
end;
26822708

2709+
procedure TForm1.NodeMCUCustomBuilds1Click(Sender: TObject);
2710+
begin
2711+
ShowMessage('Save the latest bin file in the same folder as the flasher app');
2712+
ShowURL('http://nodemcu-build.com/');
2713+
end;
2714+
26832715
end.

Source/SerialNG.pas

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface
4646

4747
uses
4848
Windows, Messages, SysUtils, Classes,
49-
Graphics, Controls, Forms, Dialogs;
49+
Graphics, Controls, Forms, Dialogs, IniFiles;
5050

5151
// Definitions for the DCB found in windows.pas for reference only
5252
// All of the baud rates that the DCB supports.
@@ -441,7 +441,7 @@ procedure Register;
441441
procedure GetCommNames(CommNames : TStrings);
442442

443443
implementation
444-
uses Registry;
444+
uses Registry, SerialNGAdv;
445445

446446
var VersionInfo : TOSVersionInfo;
447447

@@ -483,7 +483,8 @@ procedure GetCommNames(CommNames : TStrings);
483483
CommStr : string;
484484
const
485485
CommPNPKey : string = '\Enum\BIOS\*PNP0501';
486-
HardwareKey : string = '\hardware\devicemap\serialcomm';
486+
HardwareKey : string = 'HARDWARE\DEVICEMAP\SERIALCOMM';
487+
// HardwareKey : string = '\hardware\serialcomm';
487488
var
488489
LogStr : String;
489490
S : String;
@@ -515,8 +516,10 @@ procedure GetCommNames(CommNames : TStrings);
515516
else
516517
LogStr := LogStr + ' Unable to open ' + CommPNPKey + #13;
517518
SerPtSL.Clear; // to use for hardware value names
519+
518520
{check the hardware entries}
519-
if OpenKey(HardwareKey, false) then begin
521+
522+
if OpenKeyReadOnly(HardwareKey) then begin
520523
LogStr := Format('%s %s opened%s', [LogStr, HardwareKey, #13]);
521524
{get the value names for the commports - NT is "Serialn" W95 is "COMn"}
522525
GetValueNames(SerPtSL);
@@ -542,6 +545,10 @@ procedure GetCommNames(CommNames : TStrings);
542545
Free; // TFegistry
543546
end;
544547
SerPtSL.Free;
548+
//if (SerialNGAdvDLG.ManualPort.Text <> '') and (CommNames.IndexOf(SerialNGAdvDLG.ManualPort.Text) < 0) then
549+
// begin
550+
// CommNames.Add(SerialNGAdvDLG.ManualPort.Text);
551+
// end;
545552
end;
546553

547554
//
@@ -1352,9 +1359,9 @@ procedure TSerialPortNG.XTODefault;
13521359
// will save to HKEY_CURRENT_USER\Software\DomIS\SerialAdvDemo
13531360
procedure TSerialPortNG.WriteSettings(Regkey, RegSubKey : String);
13541361

1355-
var FIniFile : TRegIniFile;
1362+
var FIniFile : TIniFile;
13561363
begin
1357-
FIniFile := TRegIniFile.Create(RegKey);
1364+
FIniFile := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
13581365
try
13591366
try
13601367
with FIniFile do
@@ -1400,7 +1407,7 @@ procedure TSerialPortNG.WriteSettings(Regkey, RegSubKey : String);
14001407
// e.g. ReadSettings('Software/DomIS','SerialNGAdvDemo')
14011408
// will read from HKEY_CURRENT_USER\Software\DomIS\SerialAdvDemo
14021409
procedure TSerialPortNG.ReadSettings(Regkey, RegSubKey : String);
1403-
var FIniFile : TRegIniFile;
1410+
var FIniFile : TIniFile;
14041411
function CharFromStr(S : String):Char;
14051412
begin
14061413
if Length(S) > 0 then
@@ -1410,7 +1417,7 @@ procedure TSerialPortNG.ReadSettings(Regkey, RegSubKey : String);
14101417
end;
14111418

14121419
begin
1413-
FIniFile := TRegIniFile.Create(RegKey);
1420+
FIniFile := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
14141421
try
14151422
try
14161423
with FIniFile do

Source/SerialNGAdv.dfm

130 Bytes
Binary file not shown.

Source/SerialNGAdv.pas

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ TSerialNGAdvDLG = class(TForm)
3030
Label6: TLabel;
3131
Label7: TLabel;
3232
Label8: TLabel;
33-
CBOpenPort: TCheckBox;
3433
Label1: TLabel;
3534
Label2: TLabel;
3635
Label9: TLabel;
@@ -59,11 +58,14 @@ TSerialNGAdvDLG = class(TForm)
5958
Label17: TLabel;
6059
EventCharEdit: TEdit;
6160
PortBtn: TButton;
61+
ManualPort: TEdit;
62+
Label18: TLabel;
6263
procedure ValidateCharInput(Sender: TObject);
6364
procedure ValidateInteger(Sender: TObject);
6465
procedure FormCreate(Sender: TObject);
6566
procedure FormShow(Sender: TObject);
6667
procedure PortBtnClick(Sender: TObject);
68+
procedure ManualPortExit(Sender: TObject);
6769
private
6870
{ Private declarations }
6971
public
@@ -185,7 +187,7 @@ procedure TSerialNGAdvDLG.SetDLGData(SerialPortNG : TSerialPortNG);
185187
else
186188
CBFlow.ItemIndex := 0;
187189
end;
188-
CBOpenPort.Checked := SerialPortNG.Active;
190+
// CBOpenPort.Checked := SerialPortNG.Active;
189191
// Page 2 Timing
190192
WTOCharDelayEdit.Text := IntToStr(SerialPortNG.WTOCharDelayTime);
191193
RTOCharDelayEdit.Text := IntToStr(SerialPortNG.RTOCharDelayTime);
@@ -238,7 +240,7 @@ procedure TSerialNGAdvDLG.GetDLGData(SerialPortNG : TSerialPortNG);
238240
SerialPortNG.StripNullChars := CBStripNullChars.Checked;
239241
SerialPortNG.ErrorNoise := CBReport.Itemindex;
240242
// Try to Open the Port if wished
241-
SerialPortNG.Active := CBOpenPort.Checked;
243+
// SerialPortNG.Active := CBOpenPort.Checked;
242244
end;
243245

244246
procedure TSerialNGAdvDLG.FormCreate(Sender: TObject);
@@ -256,4 +258,13 @@ procedure TSerialNGAdvDLG.PortBtnClick(Sender: TObject);
256258
net.ShowURL('http://benlo.com/esp8266/index.html#faq');
257259
end;
258260

261+
procedure TSerialNGAdvDLG.ManualPortExit(Sender: TObject);
262+
begin
263+
ManualPort.Text := UpperCase(ManualPort.Text);
264+
if (ManualPort.Text <> '') and (CBPort.Items.IndexOf(ManualPort.Text) < 0) then
265+
begin
266+
CBPort.Items.Add(ManualPort.Text);
267+
end;
268+
end;
269+
259270
end.

version 0.90/LLbin.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LLbin = nil
2+
function LLbin(fname) file.open(fname,'w+') uart.on("data", "\r", function(data) a = {} if string.find(data,'EOF') then uart.on("data","\r",function(data) end,1) file.flush() file.close()
3+
else for x in string.gmatch(data, "[^%s]+") do table.insert(a,x) end if a[3] then addr = a[1] dat = a[2] csum = 0 for byte in dat:gmatch'%x%x' do x = tonumber(byte,16) csum = csum + x end
4+
if tonumber(a[3]) == csum then uart.write(0,'>') else uart.write(0,'!') print(a[3]..' '..csum) end sdat = '' for byte in dat:gmatch'%x%x' do sdat = sdat..string.char(tonumber(byte,16)) end
5+
file.seek("set",addr) file.write(sdat) end end end , 0) end

version 0.90/LuaLoader.exe

602 KB
Binary file not shown.

0 commit comments

Comments
 (0)