Просмотр исходного кода

new version for uploading to serial connection

Wilfried Klaas 6 лет назад
Родитель
Сommit
8ab8bc5c8e
12 измененных файлов с 152 добавлено и 94 удалено
  1. 6 0
      Beispiele/SimpleServo.tps
  2. 1 1
      SPS_EMU.000
  3. 3 1
      SPS_EMU.001
  4. 3 1
      SPS_EMU.044
  5. 3 1
      SPS_EMU.049
  6. 1 1
      SPS_Emu.lpi
  7. BIN
      SPS_Emu.lsu
  8. 1 1
      SPS_Emu.xml
  9. 36 13
      ugui.lfm
  10. 89 40
      ugui.pas
  11. 9 33
      uselectcom.lfm
  12. 0 2
      uselectcom.pas

+ 6 - 0
Beispiele/SimpleServo.tps

@@ -10,3 +10,9 @@
 0x08,A,2,""
 0x09,F,F,""
 0x0A,0,0,""
+0x0B,0,0,""
+0x0C,0,0,""
+0x0D,0,0,""
+0x0E,0,0,""
+0x0F,0,0,""
+0x10,0,0,""

+ 1 - 1
SPS_EMU.000

@@ -3,7 +3,7 @@ LSUTextFile=1
 Copyrigth=MCS Media Computer Software
 [LSUInfo]
 CompileDate=18.11.2018
-CompileTime=10:31:39
+CompileTime=23:51:58
 Name=Wilfried Klaas
 LSUBinFile=E:\daten\git-sourcen\SPS_Emulator\SPS_Emu.lsu
 LSUTextFile=E:\daten\git-sourcen\SPS_Emulator\SPS_Emu.

+ 3 - 1
SPS_EMU.001

@@ -19,6 +19,7 @@ ID_ABOUT=&About
 ID_RESETPRESETS=R
 ID_SAVEPRESETS=S
 ID_LOADPRESETS=L
+ID_NEXT_INSERT=
 
 [form1ButtonHints]
 ID_EXIT=Exit the program
@@ -38,6 +39,7 @@ ID_ABOUT=About this program
 ID_RESETPRESETS=reset all presets
 ID_SAVEPRESETS=save presets to file
 ID_LOADPRESETS=load presets from file
+ID_NEXT_INSERT=goto next row, add row if necessary
 
 [infobox]
 ID_APPTITLE=TPS/PLC Emulator
@@ -165,7 +167,7 @@ SAVE_CHANGESM=The program has been changed. Do you want to save the changes?
 [frmSelectComCaptions]
 ID_COMPORT=Port
 ID_ARDUINO_INST=Arduino installation
-ID_COMMENT=Please select the port of the arduino and the path to the arduino installtion.
+ID_COMMENT=Please select the port of the arduino.
 
 [frmSelectComHints]
 ID_COMPORT=Com Port

+ 3 - 1
SPS_EMU.044

@@ -19,6 +19,7 @@ ID_ABOUT=&About
 ID_RESETPRESETS=R
 ID_SAVEPRESETS=S
 ID_LOADPRESETS=L
+ID_NEXT_INSERT=
 
 [form1ButtonHints]
 ID_EXIT=Exit the program
@@ -38,6 +39,7 @@ ID_ABOUT=About this program
 ID_RESETPRESETS=reset all presets
 ID_SAVEPRESETS=save presets to file
 ID_LOADPRESETS=load presets from file
+ID_NEXT_INSERT=goto next row, add row if necessary
 
 [infobox]
 ID_APPTITLE=TPS/PLC Emulator
@@ -165,7 +167,7 @@ SAVE_CHANGESM=The program has been changed. Do you want to save the changes?
 [frmSelectComCaptions]
 ID_COMPORT=Port
 ID_ARDUINO_INST=Arduino installation
-ID_COMMENT=Please select the port of the arduino and the path to the arduino installtion.
+ID_COMMENT=Please select the port of the arduino.
 
 [frmSelectComHints]
 ID_COMPORT=Com Port

+ 3 - 1
SPS_EMU.049

@@ -19,6 +19,7 @@ ID_ABOUT=&Über
 ID_RESETPRESETS=R
 ID_SAVEPRESETS=S
 ID_LOADPRESETS=L
+ID_NEXT_INSERT=
 
 [form1ButtonHints]
 ID_EXIT=Beenden
@@ -38,6 +39,7 @@ ID_ABOUT=Über dieses Programm
 ID_RESETPRESETS=Einstellungen zurücksetzen
 ID_LOADPRESETS=Presets aus Datei laden
 ID_SAVEPRESETS=Presets in Datei speichern
+ID_NEXT_INSERT=nächste Zeile, wenn nötig, lege neue Zeile an
 
 [infobox]
 ID_APPTITLE=TPS/SPS Emulator
@@ -165,7 +167,7 @@ SAVE_CHANGESM=Die Datei wurde geändert. Wollen Sie die Änderungen speichern?
 [frmSelectComCaptions]
 ID_COMPORT=Schnittstelle
 ID_ARDUINO_INST=Arduinoinstallation
-ID_COMMENT=Bitte wählen Sie die Schnittstelle des Arduino und den Ort der Arduinodateien aus.
+ID_COMMENT=Bitte wählen Sie die Schnittstelle des Arduino.
 
 [frmSelectComHints]
 ID_COMPORT=

+ 1 - 1
SPS_Emu.lpi

@@ -22,7 +22,7 @@
       <AutoIncrementBuild Value="True"/>
       <MinorVersionNr Value="2"/>
       <RevisionNr Value="1"/>
-      <BuildNr Value="55"/>
+      <BuildNr Value="56"/>
       <Language Value="0407"/>
       <StringTable CompanyName="MCS" FileDescription="TPS/SPS Emulator" InternalName="SPS_EMU" LegalCopyright="MCS (C) Wilfried Klaas" OriginalFilename="SPS_EMU.exe" ProductName="TPS/SPS Emulator" ProductVersion="0.2"/>
     </VersionInfo>


Разница между файлами не показана из-за своего большого размера
+ 1 - 1
SPS_Emu.xml


+ 36 - 13
ugui.lfm

@@ -1,12 +1,12 @@
 object Form1: TForm1
-  Left = 235
+  Left = 234
   Height = 582
-  Top = 107
-  Width = 691
+  Top = 104
+  Width = 717
   AllowDropFiles = True
   Caption = 'SPS Emulator'
   ClientHeight = 582
-  ClientWidth = 691
+  ClientWidth = 717
   Constraints.MinHeight = 582
   Constraints.MinWidth = 684
   OnCloseQuery = FormCloseQuery
@@ -16,7 +16,7 @@ object Form1: TForm1
   ShowHint = True
   LCLVersion = '1.8.4.0'
   object Panel1: TPanel
-    Left = 367
+    Left = 393
     Height = 533
     Top = 26
     Width = 324
@@ -702,7 +702,7 @@ object Form1: TForm1
     Left = 0
     Height = 26
     Top = 0
-    Width = 691
+    Width = 717
     ButtonHeight = 22
     ButtonWidth = 22
     Caption = 'ToolBar1'
@@ -870,25 +870,25 @@ object Form1: TForm1
     Left = 0
     Height = 23
     Top = 559
-    Width = 691
+    Width = 717
     Panels = <>
   end
   object Panel2: TPanel
     Left = 0
     Height = 533
     Top = 26
-    Width = 367
+    Width = 393
     Align = alClient
     BevelOuter = bvNone
     Caption = 'Panel2'
     ClientHeight = 533
-    ClientWidth = 367
+    ClientWidth = 393
     TabOrder = 3
     object StringGrid1: TStringGrid
       Left = 0
       Height = 499
       Top = 0
-      Width = 367
+      Width = 393
       Align = alClient
       Columns = <      
         item
@@ -928,12 +928,12 @@ object Form1: TForm1
       Left = 0
       Height = 34
       Top = 499
-      Width = 367
+      Width = 393
       Align = alBottom
       BevelInner = bvLowered
       BevelOuter = bvNone
       ClientHeight = 34
-      ClientWidth = 367
+      ClientWidth = 393
       TabOrder = 1
       object cbCommand: TComboBox
         Left = 64
@@ -1011,11 +1011,18 @@ object Form1: TForm1
         Caption = 'ID_MNE_DATA'
         ParentColor = False
       end
+      object SpeedButton1: TSpeedButton
+        Left = 344
+        Height = 22
+        Top = 4
+        Width = 23
+        Action = acNextInsert
+      end
     end
   end
   object ActionList1: TActionList
     Images = ImageList1
-    left = 464
+    left = 472
     top = 496
     object acExit: TAction
       Category = 'File'
@@ -1142,6 +1149,11 @@ object Form1: TForm1
       Dialog.Filter = 'ini files|*.ini|all files|*.*'
       OnAccept = acPresetSaveAccept
     end
+    object acNextInsert: TAction
+      Caption = 'ID_NEXT_INSERT'
+      ImageIndex = 5
+      OnExecute = acNextInsertExecute
+    end
   end
   object ImageList1: TImageList
     Height = 20
@@ -51893,4 +51905,15 @@ object Form1: TForm1
       07FF111108FF434322FF7F7F40FF
     }
   end
+  object SdpoSerial1: TSdpoSerial
+    Active = False
+    BaudRate = br_57600
+    DataBits = db8bits
+    Parity = pNone
+    FlowControl = fcNone
+    StopBits = sbOne
+    Device = 'COM1'
+    left = 656
+    top = 496
+  end
 end

+ 89 - 40
ugui.pas

@@ -28,6 +28,7 @@ type
     acFileSave: TAction;
     acHelpAbout: TAction;
     acHexFile: TAction;
+    acNextInsert: TAction;
     acUpload: TAction;
     ActionList1: TActionList;
     acFileOpen: TFileOpen;
@@ -79,6 +80,7 @@ type
     ADC2: TSpinEdit;
     SaveDialog1: TSaveDialog;
     SaveHexFile: TSaveDialog;
+    SdpoSerial1: TSdpoSerial;
     Servo1: TLabeledEdit;
     Servo2: TLabeledEdit;
     EditA: TLabeledEdit;
@@ -94,6 +96,7 @@ type
     ShapeOut2: TShape;
     ShapeOut3: TShape;
     ShapeOut4: TShape;
+    SpeedButton1: TSpeedButton;
     StatusBar1: TStatusBar;
     StringGrid1: TStringGrid;
     tbPrg: TToggleBox;
@@ -143,6 +146,7 @@ type
     procedure acHexFileExecute(Sender: TObject);
     procedure acNewExecute(Sender: TObject);
     procedure acNewRowExecute(Sender: TObject);
+    procedure acNextInsertExecute(Sender: TObject);
     procedure acNextStepExecute(Sender: TObject);
     procedure acPresetLoadAccept(Sender: TObject);
     procedure acPresetSaveAccept(Sender: TObject);
@@ -185,6 +189,7 @@ type
     procedure inputSps;
     procedure outputSps;
     procedure uploadFile;
+    function serialUpload: string;
     procedure setDirty(Value: boolean);
     function checkDirty: boolean;
     procedure checkPresets;
@@ -519,6 +524,17 @@ begin
   renumberGrid();
 end;
 
+procedure TForm1.acNextInsertExecute(Sender: TObject);
+var
+  myPos: integer;
+begin
+  myPos := StringGrid1.Row;
+  if (myPos = StringGrid1.RowCount - 1) then
+    acNewRow.Execute;
+  StringGrid1.Row := myPos + 1;
+  renumberGrid();
+end;
+
 procedure TForm1.programSps;
 var
   x, i: integer;
@@ -728,8 +744,70 @@ end;
 procedure TForm1.acUploadExecute(Sender: TObject);
 begin
   uploadFile();
+  //serialUpload;
 end;
 
+function TForm1.serialUpload: string;
+var
+  hexFileSource: TStringList;
+  hexFile, tmp, line: string;
+  pos, x: integer;
+begin
+  pos := 0;
+  line := '';
+  hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
+  hexFileSource := TStringList.Create;
+
+  for x := 1 to StringGrid1.RowCount - 1 do
+  begin
+    if (pos = 0) then
+    begin
+      line := line + 'd ';
+    end;
+    tmp := StringGrid1.Cells[1, x];
+    line := line + tmp;
+
+    tmp := StringGrid1.Cells[2, x];
+    line := line + tmp;
+
+    Inc(pos);
+    if (pos = 8) then
+    begin
+      hexFileSource.Add(line);
+      line := '';
+      pos := 0;
+    end
+    else
+    begin
+      line := line + ',';
+    end;
+  end;
+  if (pos = 0) then
+  begin
+    line := hexFileSource.Strings[hexFileSource.Count - 1];
+    hexFileSource.Delete(hexFileSource.Count - 1);
+    pos := 8;
+  end;
+  if (pos <= 7) then
+  begin
+    for x := pos to 7 do
+    begin
+      line := line + '00';
+      if (x < 7) then
+        line := line + ',';
+    end;
+  end;
+  line := line + '*';
+  hexFileSource.Add(line);
+
+  MCSIO.StrToFile(hexFile, hexFileSource.Text);
+
+  hexFileSource.Free;
+
+  Result := hexFile;
+end;
+
+
 procedure TForm1.uploadFile;
 var
   line: string;
@@ -746,6 +824,7 @@ var
   cmd, config, mcu: string;
   KeyName, StringValue: string;
   Res: WideString;
+  Lines: TStringList;
 
 begin
   line := GetSerialPortNames;
@@ -759,57 +838,27 @@ begin
     frmSelectCom.cbServices.Items.AddStrings(comServices);
     frmSelectCom.cbServices.Text := line;
 
-    line := XMLPropStorage1.ReadString('ArduinoBin', '');
-    if (line = '') then
-    begin
-      KeyName := 'SOFTWARE\WOW6432Node\Arduino';
-      StringValue := 'Install_Dir';
-      Res := RegistryReadString(HKEY_LOCAL_MACHINE, WideString(KeyName), WideString(StringValue));
-      if Res <> '' then
-      begin
-        line := string(Res);
-      end;
-    end;
-    frmSelectCom.deArduino.Text := line;
-
     return := frmSelectCom.ShowModal;
 
     comService := frmSelectCom.cbServices.Text;
     XMLPropStorage1.WriteString('ComPort', comService);
-    line := frmSelectCom.deArduino.Text;
-    arduinoPath := MCSIO.GetNormPath(line);
-    XMLPropStorage1.WriteString('ArduinoBin', line);
     comServices.Free;
+
     if (return = mrOk) then
     begin
-      hexFile := MCSIO.CreateUniqueFile(MCSIO.GetTempDir, 'TPS', '.hex');
-      makeHexFile(hexFile);
-      cmd := arduinoPath + 'hardware\tools\avr\bin\avrdude';
-      XMLPropStorage1.WriteString('avrdude', cmd);
+      hexFile := serialUpload;
 
-      config := arduinoPath + 'hardware\tools\avr\etc\avrdude.conf';
-      XMLPropStorage1.WriteString('avrdudeconf', config);
+      SdpoSerial1.Device := comService;
+      SdpoSerial1.Active := True;
 
-      if (cbTPSVersion.ItemIndex = 3) then
+      Lines := TStringList.Create;
+      Lines.LoadFromFile(hexFile);
+      for x := 0 to Lines.Count - 1 do
       begin
-        mcu := 'atmega328p';
-      end
-      else if (cbTPSVersion.ItemIndex = 2) then
-      begin
-        mcu := 'attiny84';
+        SdpoSerial1.WriteData(Lines.Strings[x]);
+        SdpoSerial1.WriteData(CRLF);
       end;
-
-      XMLPropStorage1.WriteString('arduinomcu', mcu);
-
-      line :=
-        '-C%AVRCONF% -v -v -v -p%MCU% -carduino -P\\.\%COM% -b57600 -D -Ueeprom:w:%FILE%:i';
-
-      line := Replace2('%AVRCONF%', config, line);
-      line := Replace2('%MCU%', mcu, line);
-      line := Replace2('%COM%', comService, line);
-      line := Replace2('%FILE%', hexFile, line);
-
-      ExecuteProcess(cmd, line);
+      SdpoSerial1.Active := False;
       DeleteFile(hexFile);
     end;
   end;

+ 9 - 33
uselectcom.lfm

@@ -9,11 +9,11 @@ object frmSelectCom: TfrmSelectCom
   OnCreate = FormCreate
   OnShow = FormShow
   Position = poMainFormCenter
-  LCLVersion = '1.0.14.0'
+  LCLVersion = '1.8.4.0'
   object ButtonPanel1: TButtonPanel
     Left = 6
-    Height = 38
-    Top = 128
+    Height = 34
+    Top = 132
     Width = 389
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
@@ -30,27 +30,27 @@ object frmSelectCom: TfrmSelectCom
     AnchorSideTop.Control = cbServices
     AnchorSideTop.Side = asrCenter
     AnchorSideRight.Side = asrBottom
-    Left = 60
-    Height = 21
+    Left = 78
+    Height = 15
     Top = 52
-    Width = 91
+    Width = 73
     Anchors = [akTop, akRight]
     Caption = 'ID_COMPORT'
     ParentColor = False
   end
   object cbServices: TComboBox
     Left = 160
-    Height = 28
+    Height = 23
     Top = 48
     Width = 100
-    ItemHeight = 20
+    ItemHeight = 15
     Style = csDropDownList
     TabOrder = 1
   end
   object Label2: TLabel
     AnchorSideRight.Side = asrBottom
     Left = 0
-    Height = 21
+    Height = 15
     Top = 0
     Width = 401
     Align = alTop
@@ -58,28 +58,4 @@ object frmSelectCom: TfrmSelectCom
     ParentColor = False
     WordWrap = True
   end
-  object deArduino: TDirectoryEdit
-    Left = 160
-    Height = 28
-    Top = 88
-    Width = 192
-    ShowHidden = False
-    ButtonWidth = 23
-    NumGlyphs = 0
-    MaxLength = 0
-    TabOrder = 2
-  end
-  object Label3: TLabel
-    AnchorSideTop.Control = deArduino
-    AnchorSideTop.Side = asrCenter
-    AnchorSideRight.Side = asrBottom
-    Left = 26
-    Height = 21
-    Top = 92
-    Width = 125
-    Anchors = [akTop, akRight]
-    Caption = 'ID_ARDUINO_INST'
-    ParentColor = False
-    WordWrap = True
-  end
 end

+ 0 - 2
uselectcom.pas

@@ -15,10 +15,8 @@ type
   TfrmSelectCom = class(TForm)
     ButtonPanel1: TButtonPanel;
     cbServices: TComboBox;
-    deArduino: TDirectoryEdit;
     Label1: TLabel;
     Label2: TLabel;
-    Label3: TLabel;
     procedure FormCreate(Sender: TObject);
     procedure FormShow(Sender: TObject);
   private

Некоторые файлы не были показаны из-за большого количества измененных файлов