|
@@ -170,7 +170,6 @@ type
|
|
procedure cbDataChange(Sender: TObject);
|
|
procedure cbDataChange(Sender: TObject);
|
|
procedure cbHardwareEmuChange(Sender: TObject);
|
|
procedure cbHardwareEmuChange(Sender: TObject);
|
|
procedure cbIgnDlyChange(Sender: TObject);
|
|
procedure cbIgnDlyChange(Sender: TObject);
|
|
- procedure cbSerialNamesChange(Sender: TObject);
|
|
|
|
procedure cbTPSVersionChange(Sender: TObject);
|
|
procedure cbTPSVersionChange(Sender: TObject);
|
|
procedure FormActivate(Sender: TObject);
|
|
procedure FormActivate(Sender: TObject);
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|
@@ -232,6 +231,8 @@ type
|
|
procedure enableMicrobit(enable: boolean);
|
|
procedure enableMicrobit(enable: boolean);
|
|
procedure outputMicrobit();
|
|
procedure outputMicrobit();
|
|
procedure inputMicrobit();
|
|
procedure inputMicrobit();
|
|
|
|
+ function checkSerialEmu(): boolean;
|
|
|
|
+ procedure log4SerialEmu(line : string);
|
|
public
|
|
public
|
|
{ public declarations }
|
|
{ public declarations }
|
|
end;
|
|
end;
|
|
@@ -956,7 +957,8 @@ begin
|
|
outputSps();
|
|
outputSps();
|
|
selectAddress(0);
|
|
selectAddress(0);
|
|
activateSps(False);
|
|
activateSps(False);
|
|
- if SdpoSerial1.Active then begin
|
|
|
|
|
|
+ if SdpoSerial1.Active then
|
|
|
|
+ begin
|
|
SdpoSerial1.Close;
|
|
SdpoSerial1.Close;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -1175,7 +1177,7 @@ begin
|
|
while ((not SdpoSerial1.DataAvailable) and (TimeOut > 0)) do
|
|
while ((not SdpoSerial1.DataAvailable) and (TimeOut > 0)) do
|
|
begin
|
|
begin
|
|
Dec(TimeOut);
|
|
Dec(TimeOut);
|
|
- Sleep(1000);
|
|
|
|
|
|
+ Sleep(100);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
if (Timeout > 0) then
|
|
if (Timeout > 0) then
|
|
@@ -1391,12 +1393,13 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TForm1.cbHardwareEmuChange(Sender: TObject);
|
|
procedure TForm1.cbHardwareEmuChange(Sender: TObject);
|
|
-var line : String;
|
|
|
|
- comServices : TStringList;
|
|
|
|
|
|
+var
|
|
|
|
+ line: string;
|
|
|
|
+ comServices: TStringList;
|
|
begin
|
|
begin
|
|
if cbHardwareEmu.Checked then
|
|
if cbHardwareEmu.Checked then
|
|
begin
|
|
begin
|
|
- cbSerialNames.Enabled:=true;
|
|
|
|
|
|
+ cbSerialNames.Enabled := True;
|
|
line := GetSerialPortNames;
|
|
line := GetSerialPortNames;
|
|
comServices := TStringList.Create;
|
|
comServices := TStringList.Create;
|
|
MCSStrings.DelimTextToStringlist(line, ',', comServices);
|
|
MCSStrings.DelimTextToStringlist(line, ',', comServices);
|
|
@@ -1404,7 +1407,6 @@ begin
|
|
cbSerialNames.Items.AddStrings(comServices);
|
|
cbSerialNames.Items.AddStrings(comServices);
|
|
cbSerialNames.Text := line;
|
|
cbSerialNames.Text := line;
|
|
comServices.Free;
|
|
comServices.Free;
|
|
- cbSerialNamesChange(sender);
|
|
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1413,47 +1415,6 @@ begin
|
|
sps.SetIgnoreDelay(cbIgnDly.Checked);
|
|
sps.SetIgnoreDelay(cbIgnDly.Checked);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TForm1.cbSerialNamesChange(Sender: TObject);
|
|
|
|
-var retries : integer;
|
|
|
|
- error : boolean;
|
|
|
|
- line : string;
|
|
|
|
-begin
|
|
|
|
- SdpoSerial1.Active := False;
|
|
|
|
- SdpoSerial1.BaudRate := br__9600;
|
|
|
|
- if cbTPSVersion.ItemIndex = 5 then
|
|
|
|
- begin
|
|
|
|
- // Micro:bit V2 auto programm
|
|
|
|
- SdpoSerial1.BaudRate := br115200;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- SdpoSerial1.Device := cbSerialNames.Text;
|
|
|
|
- SdpoSerial1.Active := True;
|
|
|
|
- retries := 10;
|
|
|
|
- error := True;
|
|
|
|
- while retries > 0 do
|
|
|
|
- begin
|
|
|
|
- SdpoSerial1.WriteData('p');
|
|
|
|
- if (readString(line, True)) then
|
|
|
|
- begin
|
|
|
|
- if (pos('command', line) > 0) then
|
|
|
|
- begin
|
|
|
|
- retries := 0;
|
|
|
|
- error := False;
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
- if error then
|
|
|
|
- begin
|
|
|
|
- Form2.Memo1.Append('>h');
|
|
|
|
- SdpoSerial1.WriteData('h');
|
|
|
|
- end;
|
|
|
|
- Dec(retries);
|
|
|
|
- end;
|
|
|
|
- if (error) then
|
|
|
|
- begin
|
|
|
|
- LSUAutoMsgBox('Messages', 'ID_NOT_READY', MB_OK + MB_ICONERROR);
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
procedure TForm1.cbTPSVersionChange(Sender: TObject);
|
|
procedure TForm1.cbTPSVersionChange(Sender: TObject);
|
|
begin
|
|
begin
|
|
if (cbTPSVersion.ItemIndex = 0) then
|
|
if (cbTPSVersion.ItemIndex = 0) then
|
|
@@ -1482,6 +1443,7 @@ begin
|
|
ADC2.Value := 0;
|
|
ADC2.Value := 0;
|
|
ADC2.MaxValue := 15;
|
|
ADC2.MaxValue := 15;
|
|
enableMicrobit(False);
|
|
enableMicrobit(False);
|
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
end;
|
|
end;
|
|
if (cbTPSVersion.ItemIndex = 1) then
|
|
if (cbTPSVersion.ItemIndex = 1) then
|
|
begin
|
|
begin
|
|
@@ -1509,6 +1471,7 @@ begin
|
|
ADC2.Value := 0;
|
|
ADC2.Value := 0;
|
|
ADC2.MaxValue := 15;
|
|
ADC2.MaxValue := 15;
|
|
enableMicrobit(False);
|
|
enableMicrobit(False);
|
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
end;
|
|
end;
|
|
if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
|
|
if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
|
|
begin
|
|
begin
|
|
@@ -1519,6 +1482,7 @@ begin
|
|
acUpload.Enabled := False;
|
|
acUpload.Enabled := False;
|
|
Label5.Visible := False;
|
|
Label5.Visible := False;
|
|
btnTone.Visible := False;
|
|
btnTone.Visible := False;
|
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
@@ -1527,6 +1491,7 @@ begin
|
|
acUpload.Enabled := True;
|
|
acUpload.Enabled := True;
|
|
Label5.Visible := True;
|
|
Label5.Visible := True;
|
|
btnTone.Visible := True;
|
|
btnTone.Visible := True;
|
|
|
|
+ cbHardwareEmu.Enabled:= true;
|
|
end;
|
|
end;
|
|
|
|
|
|
Label2.Visible := True;
|
|
Label2.Visible := True;
|
|
@@ -1576,6 +1541,7 @@ begin
|
|
ADC2.Value := 0;
|
|
ADC2.Value := 0;
|
|
ADC2.MaxValue := 15;
|
|
ADC2.MaxValue := 15;
|
|
enableMicrobit(False);
|
|
enableMicrobit(False);
|
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
end;
|
|
end;
|
|
|
|
|
|
if (cbTPSVersion.ItemIndex = 5) then
|
|
if (cbTPSVersion.ItemIndex = 5) then
|
|
@@ -1604,6 +1570,7 @@ begin
|
|
ADC2.Value := 0;
|
|
ADC2.Value := 0;
|
|
ADC2.MaxValue := 15;
|
|
ADC2.MaxValue := 15;
|
|
enableMicrobit(True);
|
|
enableMicrobit(True);
|
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
end;
|
|
end;
|
|
|
|
|
|
cbCommand.Items.Clear;
|
|
cbCommand.Items.Clear;
|
|
@@ -1728,6 +1695,69 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TForm1.checkSerialEmu(): boolean;
|
|
|
|
+var
|
|
|
|
+ retries: integer;
|
|
|
|
+ error: boolean;
|
|
|
|
+ line: string;
|
|
|
|
+begin
|
|
|
|
+ if cbHardwareEmu.Checked then
|
|
|
|
+ begin
|
|
|
|
+ if not SdpoSerial1.Active then
|
|
|
|
+ begin
|
|
|
|
+ mmLogMessages.Lines.Insert(0, 'start comunication');
|
|
|
|
+ SdpoSerial1.BaudRate := br__9600;
|
|
|
|
+ if cbTPSVersion.ItemIndex = 5 then
|
|
|
|
+ begin
|
|
|
|
+ // Micro:bit V2 auto programm
|
|
|
|
+ SdpoSerial1.BaudRate := br115200;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ SdpoSerial1.Device := cbSerialNames.Text;
|
|
|
|
+ SdpoSerial1.Active := True;
|
|
|
|
+ retries := 10;
|
|
|
|
+ error := True;
|
|
|
|
+ while retries > 0 do
|
|
|
|
+ begin
|
|
|
|
+ SdpoSerial1.WriteData('p' + CRLF);
|
|
|
|
+ if (readString(line, True)) then
|
|
|
|
+ begin
|
|
|
|
+ if (pos('command', line) > 0) then
|
|
|
|
+ begin
|
|
|
|
+ retries := 0;
|
|
|
|
+ error := False;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ if error then
|
|
|
|
+ begin
|
|
|
|
+ SdpoSerial1.WriteData('h' + CRLF);
|
|
|
|
+ end;
|
|
|
|
+ Dec(retries);
|
|
|
|
+ end;
|
|
|
|
+ if (error) then
|
|
|
|
+ begin
|
|
|
|
+ LSUAutoMsgBox('Messages', 'ID_NOT_READY', MB_OK + MB_ICONERROR);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ Result := True;
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ if SdpoSerial1.Active then
|
|
|
|
+ SdpoSerial1.Close;
|
|
|
|
+ Result := False;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TForm1.log4SerialEmu(line: string);
|
|
|
|
+begin
|
|
|
|
+ while mmLogMessages.Lines.Count > 100 do
|
|
|
|
+ begin
|
|
|
|
+ mmLogMessages.Lines.Delete(mmLogMessages.Lines.Count-1);
|
|
|
|
+ end;
|
|
|
|
+ mmLogMessages.Lines.Insert(0, line);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TForm1.outputMicrobit();
|
|
procedure TForm1.outputMicrobit();
|
|
var
|
|
var
|
|
image: TMBImage;
|
|
image: TMBImage;
|
|
@@ -2018,25 +2048,56 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TForm1.inputSps;
|
|
procedure TForm1.inputSps;
|
|
-var line : string;
|
|
|
|
- value : longint;
|
|
|
|
|
|
+var
|
|
|
|
+ line: string;
|
|
|
|
+ Value: longint;
|
|
begin
|
|
begin
|
|
- if cbHardwareEmu.Checked then begin
|
|
|
|
|
|
+ if checkSerialEmu() then
|
|
|
|
+ begin
|
|
while SdpoSerial1.DataAvailable do
|
|
while SdpoSerial1.DataAvailable do
|
|
begin
|
|
begin
|
|
- readString(line, false);
|
|
|
|
- mmLogMessages.Lines.Insert(0, line);
|
|
|
|
|
|
+ readString(line, False);
|
|
|
|
+ log4SerialEmu(line);
|
|
end;
|
|
end;
|
|
- SdpoSerial1.WriteData('i');
|
|
|
|
- readString(line, true);
|
|
|
|
|
|
+ SdpoSerial1.WriteData('i' + CR + LF);
|
|
|
|
+ readString(line, True);
|
|
|
|
+ line := StringReplace(line, CR + LF, '', [rfReplaceAll]);
|
|
|
|
+ log4SerialEmu(line + ' ' + IntToHex(Value, 2));
|
|
line := RightstrPos(line, 3);
|
|
line := RightstrPos(line, 3);
|
|
- value := HexToInt(line);
|
|
|
|
- mmLogMessages.Lines.Insert(0, line + ' ' + IntToHex(value, 2));
|
|
|
|
|
|
+ Value := HexToInt(line);
|
|
|
|
+
|
|
|
|
+ Din1.Checked := (Value and $01) > 0;
|
|
|
|
+ Din2.Checked := (Value and $02) > 0;
|
|
|
|
+ Din3.Checked := (Value and $04) > 0;
|
|
|
|
+ Din4.Checked := (Value and $08) > 0;
|
|
|
|
+
|
|
|
|
+ SdpoSerial1.WriteData('b' + CR + LF);
|
|
|
|
+ readString(line, True);
|
|
|
|
+ line := StringReplace(line, CR + LF, '', [rfReplaceAll]);
|
|
|
|
+ log4SerialEmu(line + ' ' + IntToHex(Value, 2));
|
|
|
|
+ line := RightstrPos(line, 3);
|
|
|
|
+ Value := HexToInt(line);
|
|
|
|
+
|
|
|
|
+ tbPrg.Checked := not ((Value and $01) > 0);
|
|
|
|
+ tbSel.Checked := not ((Value and $02) > 0);
|
|
|
|
|
|
- Din1.Checked:= (value and $01) > 0;
|
|
|
|
- Din2.Checked:= (value and $02) > 0;
|
|
|
|
- Din3.Checked:= (value and $04) > 0;
|
|
|
|
- Din4.Checked:= (value and $08) > 0;
|
|
|
|
|
|
+ SdpoSerial1.WriteData('a1' + CR + LF);
|
|
|
|
+ readString(line, True);
|
|
|
|
+ line := StringReplace(line, CR + LF, '', [rfReplaceAll]);
|
|
|
|
+ log4SerialEmu(line + ' ' + IntToHex(Value, 2));
|
|
|
|
+ line := RightstrPos(line, 4);
|
|
|
|
+ Value := HexToInt(line);
|
|
|
|
+
|
|
|
|
+ ADC1.Value := Value;
|
|
|
|
+
|
|
|
|
+ SdpoSerial1.WriteData('a2' + CR + LF);
|
|
|
|
+ readString(line, True);
|
|
|
|
+ line := StringReplace(line, CR + LF, '', [rfReplaceAll]);
|
|
|
|
+ log4SerialEmu(line + ' ' + IntToHex(Value, 2));
|
|
|
|
+ line := RightstrPos(line, 4);
|
|
|
|
+ Value := HexToInt(line);
|
|
|
|
+
|
|
|
|
+ ADC2.Value := Value;
|
|
end;
|
|
end;
|
|
sps.setDin1(Din1.Checked);
|
|
sps.setDin1(Din1.Checked);
|
|
sps.setDin2(Din2.Checked);
|
|
sps.setDin2(Din2.Checked);
|
|
@@ -2054,7 +2115,33 @@ procedure TForm1.outputSps;
|
|
var
|
|
var
|
|
List: TStrings;
|
|
List: TStrings;
|
|
i: integer;
|
|
i: integer;
|
|
|
|
+ Value: integer;
|
|
|
|
+ line : string;
|
|
begin
|
|
begin
|
|
|
|
+ if checkSerialEmu() then
|
|
|
|
+ begin
|
|
|
|
+ Value := 0;
|
|
|
|
+ if sps.isDout1() then
|
|
|
|
+ Value := Value + 1;
|
|
|
|
+ if sps.isDout2() then
|
|
|
|
+ Value := Value + 2;
|
|
|
|
+ if sps.isDout3() then
|
|
|
|
+ Value := Value + 4;
|
|
|
|
+ if sps.isDout4() then
|
|
|
|
+ Value := Value + 8;
|
|
|
|
+ line := 'o' + IntToHex(Value, 1);
|
|
|
|
+ SdpoSerial1.WriteData(line);
|
|
|
|
+ log4SerialEmu(line);
|
|
|
|
+
|
|
|
|
+ line := 'd1:' + IntToHex(sps.getPWM1(), 2);
|
|
|
|
+ SdpoSerial1.WriteData(line);
|
|
|
|
+ log4SerialEmu(line);
|
|
|
|
+
|
|
|
|
+ line := 'd2:' + IntToHex(sps.getPWM2(), 2);
|
|
|
|
+ SdpoSerial1.WriteData(line);
|
|
|
|
+ log4SerialEmu(line);
|
|
|
|
+ end;
|
|
|
|
+
|
|
if sps.isDout1() then
|
|
if sps.isDout1() then
|
|
ShapeOut1.Brush.Color := clRed
|
|
ShapeOut1.Brush.Color := clRed
|
|
else
|
|
else
|
|
@@ -2123,7 +2210,6 @@ begin
|
|
finally
|
|
finally
|
|
List.Free;
|
|
List.Free;
|
|
end;
|
|
end;
|
|
-
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
end.
|
|
end.
|