|
@@ -170,7 +170,6 @@ type
|
|
|
procedure cbDataChange(Sender: TObject);
|
|
|
procedure cbHardwareEmuChange(Sender: TObject);
|
|
|
procedure cbIgnDlyChange(Sender: TObject);
|
|
|
- procedure cbSerialNamesChange(Sender: TObject);
|
|
|
procedure cbTPSVersionChange(Sender: TObject);
|
|
|
procedure FormActivate(Sender: TObject);
|
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|
@@ -232,6 +231,8 @@ type
|
|
|
procedure enableMicrobit(enable: boolean);
|
|
|
procedure outputMicrobit();
|
|
|
procedure inputMicrobit();
|
|
|
+ function checkSerialEmu(): boolean;
|
|
|
+ procedure log4SerialEmu(line : string);
|
|
|
public
|
|
|
{ public declarations }
|
|
|
end;
|
|
@@ -956,7 +957,8 @@ begin
|
|
|
outputSps();
|
|
|
selectAddress(0);
|
|
|
activateSps(False);
|
|
|
- if SdpoSerial1.Active then begin
|
|
|
+ if SdpoSerial1.Active then
|
|
|
+ begin
|
|
|
SdpoSerial1.Close;
|
|
|
end;
|
|
|
end;
|
|
@@ -1175,7 +1177,7 @@ begin
|
|
|
while ((not SdpoSerial1.DataAvailable) and (TimeOut > 0)) do
|
|
|
begin
|
|
|
Dec(TimeOut);
|
|
|
- Sleep(1000);
|
|
|
+ Sleep(100);
|
|
|
end;
|
|
|
end;
|
|
|
if (Timeout > 0) then
|
|
@@ -1391,12 +1393,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
procedure TForm1.cbHardwareEmuChange(Sender: TObject);
|
|
|
-var line : String;
|
|
|
- comServices : TStringList;
|
|
|
+var
|
|
|
+ line: string;
|
|
|
+ comServices: TStringList;
|
|
|
begin
|
|
|
if cbHardwareEmu.Checked then
|
|
|
begin
|
|
|
- cbSerialNames.Enabled:=true;
|
|
|
+ cbSerialNames.Enabled := True;
|
|
|
line := GetSerialPortNames;
|
|
|
comServices := TStringList.Create;
|
|
|
MCSStrings.DelimTextToStringlist(line, ',', comServices);
|
|
@@ -1404,7 +1407,6 @@ begin
|
|
|
cbSerialNames.Items.AddStrings(comServices);
|
|
|
cbSerialNames.Text := line;
|
|
|
comServices.Free;
|
|
|
- cbSerialNamesChange(sender);
|
|
|
end;
|
|
|
end;
|
|
|
|
|
@@ -1413,47 +1415,6 @@ begin
|
|
|
sps.SetIgnoreDelay(cbIgnDly.Checked);
|
|
|
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);
|
|
|
begin
|
|
|
if (cbTPSVersion.ItemIndex = 0) then
|
|
@@ -1482,6 +1443,7 @@ begin
|
|
|
ADC2.Value := 0;
|
|
|
ADC2.MaxValue := 15;
|
|
|
enableMicrobit(False);
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
|
end;
|
|
|
if (cbTPSVersion.ItemIndex = 1) then
|
|
|
begin
|
|
@@ -1509,6 +1471,7 @@ begin
|
|
|
ADC2.Value := 0;
|
|
|
ADC2.MaxValue := 15;
|
|
|
enableMicrobit(False);
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
|
end;
|
|
|
if ((cbTPSVersion.ItemIndex = 2) or (cbTPSVersion.ItemIndex = 3)) then
|
|
|
begin
|
|
@@ -1519,6 +1482,7 @@ begin
|
|
|
acUpload.Enabled := False;
|
|
|
Label5.Visible := False;
|
|
|
btnTone.Visible := False;
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
@@ -1527,6 +1491,7 @@ begin
|
|
|
acUpload.Enabled := True;
|
|
|
Label5.Visible := True;
|
|
|
btnTone.Visible := True;
|
|
|
+ cbHardwareEmu.Enabled:= true;
|
|
|
end;
|
|
|
|
|
|
Label2.Visible := True;
|
|
@@ -1576,6 +1541,7 @@ begin
|
|
|
ADC2.Value := 0;
|
|
|
ADC2.MaxValue := 15;
|
|
|
enableMicrobit(False);
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
|
end;
|
|
|
|
|
|
if (cbTPSVersion.ItemIndex = 5) then
|
|
@@ -1604,6 +1570,7 @@ begin
|
|
|
ADC2.Value := 0;
|
|
|
ADC2.MaxValue := 15;
|
|
|
enableMicrobit(True);
|
|
|
+ cbHardwareEmu.Enabled:= false;
|
|
|
end;
|
|
|
|
|
|
cbCommand.Items.Clear;
|
|
@@ -1728,6 +1695,69 @@ begin
|
|
|
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();
|
|
|
var
|
|
|
image: TMBImage;
|
|
@@ -2018,25 +2048,56 @@ begin
|
|
|
end;
|
|
|
|
|
|
procedure TForm1.inputSps;
|
|
|
-var line : string;
|
|
|
- value : longint;
|
|
|
+var
|
|
|
+ line: string;
|
|
|
+ Value: longint;
|
|
|
begin
|
|
|
- if cbHardwareEmu.Checked then begin
|
|
|
+ if checkSerialEmu() then
|
|
|
+ begin
|
|
|
while SdpoSerial1.DataAvailable do
|
|
|
begin
|
|
|
- readString(line, false);
|
|
|
- mmLogMessages.Lines.Insert(0, line);
|
|
|
+ readString(line, False);
|
|
|
+ log4SerialEmu(line);
|
|
|
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);
|
|
|
- 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;
|
|
|
sps.setDin1(Din1.Checked);
|
|
|
sps.setDin2(Din2.Checked);
|
|
@@ -2054,7 +2115,33 @@ procedure TForm1.outputSps;
|
|
|
var
|
|
|
List: TStrings;
|
|
|
i: integer;
|
|
|
+ Value: integer;
|
|
|
+ line : string;
|
|
|
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
|
|
|
ShapeOut1.Brush.Color := clRed
|
|
|
else
|
|
@@ -2123,7 +2210,6 @@ begin
|
|
|
finally
|
|
|
List.Free;
|
|
|
end;
|
|
|
-
|
|
|
end;
|
|
|
|
|
|
end.
|