Skip to content

Commit

Permalink
Version 0.90
Browse files Browse the repository at this point in the history
Fixed lost comm port bug and added features
  • Loading branch information
GeoNomad committed Jan 15, 2016
1 parent 0b9815d commit e42164e
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 34 deletions.
Binary file modified LuaLoader.zip
Binary file not shown.
Binary file modified Source/LuaLoader.res
Binary file not shown.
Binary file modified Source/LuaLoaderMain.dfm
Binary file not shown.
78 changes: 55 additions & 23 deletions Source/LuaLoaderMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

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

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

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

type
TForm1 = class(TForm)
Expand Down Expand Up @@ -303,6 +307,7 @@ TForm1 = class(TForm)
ListallM: TMenuItem;
ReadRateM: TPopupMenu;
Setrepeatrateforread1: TMenuItem;
NodeMCUCustomBuilds1: TMenuItem;
procedure AdvSettingsBtnClick(Sender: TObject);
procedure SerialPortNG1RxClusterEvent(Sender: TObject);
procedure SerialPortNG1ProcessError(Sender: TObject; Place,Code: DWord; Msg: String);
Expand Down Expand Up @@ -428,6 +433,7 @@ TForm1 = class(TForm)
procedure DecodeDL(Sender: TObject);
procedure ListlcMClick(Sender: TObject);
procedure ListallMClick(Sender: TObject);
procedure NodeMCUCustomBuilds1Click(Sender: TObject);
private
{ Private declarations }
RxDCharStartTimer : Boolean;
Expand Down Expand Up @@ -490,7 +496,7 @@ TForm1 = class(TForm)
CustomLuaFile : string;

const
ThisVersion = '0.87 '; // change with each version
ThisVersion = '0.90 '; // change with each version
CRLF = #$0d#$0a ;

implementation
Expand Down Expand Up @@ -572,7 +578,7 @@ function FileTime( filename : string) : integer;

procedure TForm1.FormCreate(Sender: TObject);
var
Regx : TRegIniFile;
Regx : TIniFile;
timers : string;
i,n : integer;
ws : string;
Expand Down Expand Up @@ -608,7 +614,7 @@ procedure TForm1.FormCreate(Sender: TObject);

Caption := 'ESP8266 LuaLoader '+ThisVersion;

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

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
Regx : TRegIniFile;
Regx : TIniFile;
i : integer;
timers : string;
Temp : TStringList;
Expand All @@ -720,7 +726,7 @@ procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
SerialPortNG1.WriteSettings('Software\Benlo.com','LuaLoader');
SerialPortNG1.Active := False;

Regx := TRegIniFile.Create( 'Software\Benlo.com' );
Regx := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
Regx.WriteInteger('LuaLoader','Top',Top);
Regx.WriteInteger('LuaLoader','Left',Left);
Regx.WriteInteger('LuaLoader','Width',Width);
Expand Down Expand Up @@ -1011,10 +1017,10 @@ procedure TForm1.SerialPortNG1RxClusterEvent(Sender: TObject);
if (0 < Pos('NODEMCU ',UpperCase(line))) and (0 < Pos('owered by Lua',line)) then
begin
line := Trim(Copy(line,9,Length(LatestNodeMCU)));
if not SoftRestart then
begin
Show('Hard Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
end;
// if not SoftRestart then
// begin
// Show('Hard Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
// end;
SoftRestart := False;
if line < Trim(LatestNodeMCU) then
begin
Expand Down Expand Up @@ -1233,6 +1239,12 @@ function TForm1.Upload(fname : string) : boolean;
if FastUp.Checked and (SerialPortNG1.BaudRate <> 921600) then
begin
newrate := 921600;
SerialPortNG1.BaudRate := newrate;
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
if i >= 0 then
BaudRate.ItemIndex := i
else
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
BaudRate.ItemIndex := 8;
Show('Baud rate changed to '+IntToStr(newrate),1);
end;
Expand Down Expand Up @@ -1461,6 +1473,8 @@ procedure TForm1.NodeHeapBtnClick(Sender: TObject);
end;

procedure TForm1.RestartBtnClick(Sender: TObject);
var
i : integer;
begin
RepeatTimer.Enabled := False;
if HideRestartGarbageM.checked then
Expand All @@ -1475,10 +1489,14 @@ procedure TForm1.RestartBtnClick(Sender: TObject);
begin
SerialPortNG1.BaudRate := 9600;
StatusBar.SimpleText := 'Baud rate reduced to 9600';
BaudRate.ItemIndex := 0;
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
if i >= 0 then
BaudRate.ItemIndex := i
else
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
end;

Show('Soft Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
//Show('Soft Restart '+FormatDateTime('dddddd hh:nn:ss',Now),1);
SoftRestart := True;
end;

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

APIrevision := '';
if Items.Count > 1 then APIrevision := Items[1];
NodeMcuLua1.Caption := 'NodeMCU Lua API ';
if length(APIrevision) > 5 then
NodeMcuLua1.Caption := NodeMcuLua1.Caption +' (revised '+APIrevision+ ')' ;
NodeMcuLua1.Caption := 'NodeMCU Lua API '+LatestNodeMCU;
//if length(APIrevision) > 5 then
// NodeMcuLua1.Caption := NodeMcuLua1.Caption +' (revised '+APIrevision+ ')' ;
Items.Free;
end;

Expand Down Expand Up @@ -1947,10 +1965,16 @@ procedure TForm1.WifiStatusBtnClick(Sender: TObject);
procedure TForm1.ResetBaudTimerStop(Sender: TObject);
var
newrate : string;
i : integer;
begin
if BaudRate.Text <> '9600' then
begin
BaudRate.ItemIndex := 0;
SerialPortNG1.BaudRate := 9600;
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
if i >= 0 then
BaudRate.ItemIndex := i
else
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
newrate := Trim(BaudRate.Items[BaudRate.ItemIndex]);
SerialPortNG1.BaudRate := StrToIntDef(newrate,9600);
Show('Baud rate changed to '+newrate,1);
Expand Down Expand Up @@ -2509,23 +2533,25 @@ procedure TForm1.DoFileCompiledClick(Sender: TObject);

procedure TForm1.DownLoadBtnClick(Sender: TObject);
var
newrate : integer;
fname : string;
i : integer;
begin
DLCapture := '';

newrate := SerialPortNG1.BaudRate;
if FastUp.Checked and (SerialPortNG1.BaudRate <> 921600) then
begin
newrate := 921600;
BaudRate.ItemIndex := 8;
Show('Baud rate changed to '+IntToStr(newrate),1);
SerialPortNG1.BaudRate := 921600;
i := BaudRate.Items.IndexOf(IntToStr(SerialPortNG1.BaudRate));
if i >= 0 then
BaudRate.ItemIndex := i
else
BaudRate.Text := IntToStr(SerialPortNG1.BaudRate);
Show('Baud rate changed to '+IntToStr(SerialPortNG1.BaudRate),1);
end;

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

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

AwaitPrompt(2000);
Expand Down Expand Up @@ -2680,4 +2706,10 @@ procedure TForm1.ListallMClick(Sender: TObject);
ListallM.Checked := not ListAllM.Checked;
end;

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

end.
23 changes: 15 additions & 8 deletions Source/SerialNG.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface

uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs;
Graphics, Controls, Forms, Dialogs, IniFiles;

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

implementation
uses Registry;
uses Registry, SerialNGAdv;

var VersionInfo : TOSVersionInfo;

Expand Down Expand Up @@ -483,7 +483,8 @@ procedure GetCommNames(CommNames : TStrings);
CommStr : string;
const
CommPNPKey : string = '\Enum\BIOS\*PNP0501';
HardwareKey : string = '\hardware\devicemap\serialcomm';
HardwareKey : string = 'HARDWARE\DEVICEMAP\SERIALCOMM';
// HardwareKey : string = '\hardware\serialcomm';
var
LogStr : String;
S : String;
Expand Down Expand Up @@ -515,8 +516,10 @@ procedure GetCommNames(CommNames : TStrings);
else
LogStr := LogStr + ' Unable to open ' + CommPNPKey + #13;
SerPtSL.Clear; // to use for hardware value names

{check the hardware entries}
if OpenKey(HardwareKey, false) then begin

if OpenKeyReadOnly(HardwareKey) then begin
LogStr := Format('%s %s opened%s', [LogStr, HardwareKey, #13]);
{get the value names for the commports - NT is "Serialn" W95 is "COMn"}
GetValueNames(SerPtSL);
Expand All @@ -542,6 +545,10 @@ procedure GetCommNames(CommNames : TStrings);
Free; // TFegistry
end;
SerPtSL.Free;
//if (SerialNGAdvDLG.ManualPort.Text <> '') and (CommNames.IndexOf(SerialNGAdvDLG.ManualPort.Text) < 0) then
// begin
// CommNames.Add(SerialNGAdvDLG.ManualPort.Text);
// end;
end;

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

var FIniFile : TRegIniFile;
var FIniFile : TIniFile;
begin
FIniFile := TRegIniFile.Create(RegKey);
FIniFile := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
try
try
with FIniFile do
Expand Down Expand Up @@ -1400,7 +1407,7 @@ procedure TSerialPortNG.WriteSettings(Regkey, RegSubKey : String);
// e.g. ReadSettings('Software/DomIS','SerialNGAdvDemo')
// will read from HKEY_CURRENT_USER\Software\DomIS\SerialAdvDemo
procedure TSerialPortNG.ReadSettings(Regkey, RegSubKey : String);
var FIniFile : TRegIniFile;
var FIniFile : TIniFile;
function CharFromStr(S : String):Char;
begin
if Length(S) > 0 then
Expand All @@ -1410,7 +1417,7 @@ procedure TSerialPortNG.ReadSettings(Regkey, RegSubKey : String);
end;

begin
FIniFile := TRegIniFile.Create(RegKey);
FIniFile := TIniFile.Create( ChangeFileExt(ParamStr(0),'.ini') );
try
try
with FIniFile do
Expand Down
Binary file modified Source/SerialNGAdv.dfm
Binary file not shown.
17 changes: 14 additions & 3 deletions Source/SerialNGAdv.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ TSerialNGAdvDLG = class(TForm)
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
CBOpenPort: TCheckBox;
Label1: TLabel;
Label2: TLabel;
Label9: TLabel;
Expand Down Expand Up @@ -59,11 +58,14 @@ TSerialNGAdvDLG = class(TForm)
Label17: TLabel;
EventCharEdit: TEdit;
PortBtn: TButton;
ManualPort: TEdit;
Label18: TLabel;
procedure ValidateCharInput(Sender: TObject);
procedure ValidateInteger(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure PortBtnClick(Sender: TObject);
procedure ManualPortExit(Sender: TObject);
private
{ Private declarations }
public
Expand Down Expand Up @@ -185,7 +187,7 @@ procedure TSerialNGAdvDLG.SetDLGData(SerialPortNG : TSerialPortNG);
else
CBFlow.ItemIndex := 0;
end;
CBOpenPort.Checked := SerialPortNG.Active;
// CBOpenPort.Checked := SerialPortNG.Active;
// Page 2 Timing
WTOCharDelayEdit.Text := IntToStr(SerialPortNG.WTOCharDelayTime);
RTOCharDelayEdit.Text := IntToStr(SerialPortNG.RTOCharDelayTime);
Expand Down Expand Up @@ -238,7 +240,7 @@ procedure TSerialNGAdvDLG.GetDLGData(SerialPortNG : TSerialPortNG);
SerialPortNG.StripNullChars := CBStripNullChars.Checked;
SerialPortNG.ErrorNoise := CBReport.Itemindex;
// Try to Open the Port if wished
SerialPortNG.Active := CBOpenPort.Checked;
// SerialPortNG.Active := CBOpenPort.Checked;
end;

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

procedure TSerialNGAdvDLG.ManualPortExit(Sender: TObject);
begin
ManualPort.Text := UpperCase(ManualPort.Text);
if (ManualPort.Text <> '') and (CBPort.Items.IndexOf(ManualPort.Text) < 0) then
begin
CBPort.Items.Add(ManualPort.Text);
end;
end;

end.
5 changes: 5 additions & 0 deletions version 0.90/LLbin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LLbin = nil
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()
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
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
file.seek("set",addr) file.write(sdat) end end end , 0) end
Binary file added version 0.90/LuaLoader.exe
Binary file not shown.
Loading

0 comments on commit e42164e

Please sign in to comment.