jungervin před 7 roky
rodič
revize
5f299b6a81

+ 2 - 1
EsPy/Components/ExScintilla.cs

@@ -437,7 +437,8 @@ namespace EsPy.Components
             this.StyleClearAll(); 
             this.IndentWidth = 4;
             this.IndentationGuides = IndentView.LookForward;
-           
+
+
             this.SetProperty("tab.timmy.whinge.level", "1");
             this.SetProperty("fold", "1");
 

+ 1 - 8
EsPy/Components/Terminal.cs

@@ -131,13 +131,6 @@ namespace EsPy.Components
         char LastMode = (char)0;
         public bool Locked = false;
 
-
-        //public int FindPrompPos()
-        //{
-        //    Line line = this.Lines[this.LineFromPosition(this.CurrentPosition)];
-        //    if()
-        //}
-
         private char C0 = '\0';
         private char C1 = '\0';
         private char C2 = '\0';
@@ -357,7 +350,7 @@ namespace EsPy.Components
 
             if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_SYSKEYDOWN)
             {
-               // if (this.Port is PySerial)
+                if (this.Port is PySerial)
                 {
                     //PythonSerial port = this.Port as PythonSerial;
 

+ 70 - 57
EsPy/Dialogs/EspToolDialog.Designer.cs

@@ -42,10 +42,12 @@
             this.btnWrite = new System.Windows.Forms.Button();
             this.btnClose = new System.Windows.Forms.Button();
             this.button1 = new System.Windows.Forms.Button();
-            this.btnVerify = new System.Windows.Forms.Button();
             this.label4 = new System.Windows.Forms.Label();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.label8 = new System.Windows.Forms.Label();
+            this.cbPort = new System.Windows.Forms.ComboBox();
             this.cbBaudrate = new System.Windows.Forms.ComboBox();
+            this.label7 = new System.Windows.Forms.Label();
             this.label6 = new System.Windows.Forms.Label();
             this.btnMac = new System.Windows.Forms.Button();
             this.btnFlashID = new System.Windows.Forms.Button();
@@ -53,8 +55,7 @@
             this.label5 = new System.Windows.Forms.Label();
             this.linkLabel1 = new System.Windows.Forms.LinkLabel();
             this.linkLabel2 = new System.Windows.Forms.LinkLabel();
-            this.label7 = new System.Windows.Forms.Label();
-            this.cbPort = new System.Windows.Forms.ComboBox();
+            this.label9 = new System.Windows.Forms.Label();
             this.groupBox1.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -67,10 +68,10 @@
             this.label1.TabIndex = 0;
             this.label1.Text = "python.exe";
             // 
-            // txtPython
+            // tbPython
             // 
             this.tbPython.Location = new System.Drawing.Point(75, 46);
-            this.tbPython.Name = "txtPython";
+            this.tbPython.Name = "tbPython";
             this.tbPython.Size = new System.Drawing.Size(502, 20);
             this.tbPython.TabIndex = 1;
             // 
@@ -93,10 +94,10 @@
             this.label2.TabIndex = 0;
             this.label2.Text = "esptool.py";
             // 
-            // txtEsptool
+            // tbEsptool
             // 
             this.tbEsptool.Location = new System.Drawing.Point(75, 72);
-            this.tbEsptool.Name = "txtEsptool";
+            this.tbEsptool.Name = "tbEsptool";
             this.tbEsptool.Size = new System.Drawing.Size(502, 20);
             this.tbEsptool.TabIndex = 3;
             // 
@@ -113,22 +114,22 @@
             // label3
             // 
             this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(9, 101);
+            this.label3.Location = new System.Drawing.Point(9, 121);
             this.label3.Name = "label3";
             this.label3.Size = new System.Drawing.Size(63, 13);
             this.label3.TabIndex = 0;
             this.label3.Text = "frimware.bin";
             // 
-            // txtFirmware
+            // tbFirmware
             // 
-            this.tbFirmware.Location = new System.Drawing.Point(75, 98);
-            this.tbFirmware.Name = "txtFirmware";
+            this.tbFirmware.Location = new System.Drawing.Point(75, 118);
+            this.tbFirmware.Name = "tbFirmware";
             this.tbFirmware.Size = new System.Drawing.Size(502, 20);
             this.tbFirmware.TabIndex = 5;
             // 
             // btnFirmware
             // 
-            this.btnFirmware.Location = new System.Drawing.Point(583, 96);
+            this.btnFirmware.Location = new System.Drawing.Point(583, 116);
             this.btnFirmware.Name = "btnFirmware";
             this.btnFirmware.Size = new System.Drawing.Size(23, 23);
             this.btnFirmware.TabIndex = 6;
@@ -139,17 +140,17 @@
             // textBox4
             // 
             this.textBox4.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.textBox4.Location = new System.Drawing.Point(12, 182);
+            this.textBox4.Location = new System.Drawing.Point(12, 221);
             this.textBox4.Multiline = true;
             this.textBox4.Name = "textBox4";
             this.textBox4.ScrollBars = System.Windows.Forms.ScrollBars.Both;
-            this.textBox4.Size = new System.Drawing.Size(606, 157);
+            this.textBox4.Size = new System.Drawing.Size(612, 185);
             this.textBox4.TabIndex = 0;
             // 
             // btnErase
             // 
             this.btnErase.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnErase.Location = new System.Drawing.Point(306, 346);
+            this.btnErase.Location = new System.Drawing.Point(412, 412);
             this.btnErase.Name = "btnErase";
             this.btnErase.Size = new System.Drawing.Size(100, 23);
             this.btnErase.TabIndex = 4;
@@ -160,7 +161,7 @@
             // btnWrite
             // 
             this.btnWrite.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnWrite.Location = new System.Drawing.Point(412, 346);
+            this.btnWrite.Location = new System.Drawing.Point(518, 412);
             this.btnWrite.Name = "btnWrite";
             this.btnWrite.Size = new System.Drawing.Size(100, 23);
             this.btnWrite.TabIndex = 5;
@@ -171,7 +172,7 @@
             // btnClose
             // 
             this.btnClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnClose.Location = new System.Drawing.Point(468, 387);
+            this.btnClose.Location = new System.Drawing.Point(474, 454);
             this.btnClose.Name = "btnClose";
             this.btnClose.Size = new System.Drawing.Size(75, 23);
             this.btnClose.TabIndex = 7;
@@ -183,24 +184,13 @@
             // 
             this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
             this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.button1.Location = new System.Drawing.Point(549, 387);
+            this.button1.Location = new System.Drawing.Point(555, 454);
             this.button1.Name = "button1";
             this.button1.Size = new System.Drawing.Size(75, 23);
             this.button1.TabIndex = 8;
             this.button1.Text = "Cancel";
             this.button1.UseVisualStyleBackColor = true;
             // 
-            // btnVerify
-            // 
-            this.btnVerify.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnVerify.Location = new System.Drawing.Point(518, 345);
-            this.btnVerify.Name = "btnVerify";
-            this.btnVerify.Size = new System.Drawing.Size(100, 23);
-            this.btnVerify.TabIndex = 6;
-            this.btnVerify.Text = "Verify";
-            this.btnVerify.UseVisualStyleBackColor = true;
-            this.btnVerify.Click += new System.EventHandler(this.btnVerify_Click);
-            // 
             // label4
             // 
             this.label4.BackColor = System.Drawing.Color.DarkRed;
@@ -219,6 +209,8 @@
             // 
             // groupBox1
             // 
+            this.groupBox1.Controls.Add(this.label9);
+            this.groupBox1.Controls.Add(this.label8);
             this.groupBox1.Controls.Add(this.cbPort);
             this.groupBox1.Controls.Add(this.cbBaudrate);
             this.groupBox1.Controls.Add(this.label7);
@@ -232,13 +224,33 @@
             this.groupBox1.Controls.Add(this.btnPython);
             this.groupBox1.Controls.Add(this.btnEsptool);
             this.groupBox1.Controls.Add(this.btnFirmware);
-            this.groupBox1.Location = new System.Drawing.Point(12, 49);
+            this.groupBox1.Location = new System.Drawing.Point(12, 59);
             this.groupBox1.Name = "groupBox1";
-            this.groupBox1.Size = new System.Drawing.Size(612, 127);
+            this.groupBox1.Size = new System.Drawing.Size(612, 156);
             this.groupBox1.TabIndex = 11;
             this.groupBox1.TabStop = false;
             this.groupBox1.Text = "Settings";
             // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.ForeColor = System.Drawing.Color.Maroon;
+            this.label8.Location = new System.Drawing.Point(72, 95);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(285, 13);
+            this.label8.TabIndex = 7;
+            this.label8.Text = "Default location: YourPython\\Lib\\site-packages\\esptool.py";
+            // 
+            // cbPort
+            // 
+            this.cbPort.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.cbPort.FormattingEnabled = true;
+            this.cbPort.Location = new System.Drawing.Point(75, 19);
+            this.cbPort.Name = "cbPort";
+            this.cbPort.Size = new System.Drawing.Size(104, 21);
+            this.cbPort.TabIndex = 0;
+            this.cbPort.Validating += new System.ComponentModel.CancelEventHandler(this.cbBaudrate_Validating);
+            // 
             // cbBaudrate
             // 
             this.cbBaudrate.FormattingEnabled = true;
@@ -259,6 +271,15 @@
             this.cbBaudrate.TabIndex = 0;
             this.cbBaudrate.Validating += new System.ComponentModel.CancelEventHandler(this.cbBaudrate_Validating);
             // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Location = new System.Drawing.Point(14, 22);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(55, 13);
+            this.label7.TabIndex = 6;
+            this.label7.Text = "Serial Port";
+            // 
             // label6
             // 
             this.label6.AutoSize = true;
@@ -271,7 +292,7 @@
             // btnMac
             // 
             this.btnMac.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnMac.Location = new System.Drawing.Point(12, 345);
+            this.btnMac.Location = new System.Drawing.Point(18, 412);
             this.btnMac.Name = "btnMac";
             this.btnMac.Size = new System.Drawing.Size(74, 23);
             this.btnMac.TabIndex = 1;
@@ -282,7 +303,7 @@
             // btnFlashID
             // 
             this.btnFlashID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnFlashID.Location = new System.Drawing.Point(92, 346);
+            this.btnFlashID.Location = new System.Drawing.Point(98, 413);
             this.btnFlashID.Name = "btnFlashID";
             this.btnFlashID.Size = new System.Drawing.Size(74, 23);
             this.btnFlashID.TabIndex = 2;
@@ -293,7 +314,7 @@
             // btnChipID
             // 
             this.btnChipID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.btnChipID.Location = new System.Drawing.Point(172, 346);
+            this.btnChipID.Location = new System.Drawing.Point(178, 413);
             this.btnChipID.Name = "btnChipID";
             this.btnChipID.Size = new System.Drawing.Size(74, 23);
             this.btnChipID.TabIndex = 3;
@@ -304,7 +325,7 @@
             // label5
             // 
             this.label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
-            this.label5.Location = new System.Drawing.Point(12, 375);
+            this.label5.Location = new System.Drawing.Point(18, 442);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(612, 1);
             this.label5.TabIndex = 15;
@@ -313,7 +334,7 @@
             // linkLabel1
             // 
             this.linkLabel1.AutoSize = true;
-            this.linkLabel1.Location = new System.Drawing.Point(12, 381);
+            this.linkLabel1.Location = new System.Drawing.Point(18, 448);
             this.linkLabel1.Name = "linkLabel1";
             this.linkLabel1.Size = new System.Drawing.Size(180, 13);
             this.linkLabel1.TabIndex = 16;
@@ -324,7 +345,7 @@
             // linkLabel2
             // 
             this.linkLabel2.AutoSize = true;
-            this.linkLabel2.Location = new System.Drawing.Point(12, 400);
+            this.linkLabel2.Location = new System.Drawing.Point(18, 467);
             this.linkLabel2.Name = "linkLabel2";
             this.linkLabel2.Size = new System.Drawing.Size(212, 13);
             this.linkLabel2.TabIndex = 17;
@@ -332,30 +353,22 @@
             this.linkLabel2.Text = "http://micropython.org/download#esp8266";
             this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
             // 
-            // label7
-            // 
-            this.label7.AutoSize = true;
-            this.label7.Location = new System.Drawing.Point(14, 22);
-            this.label7.Name = "label7";
-            this.label7.Size = new System.Drawing.Size(55, 13);
-            this.label7.TabIndex = 6;
-            this.label7.Text = "Serial Port";
-            // 
-            // cbPort
+            // label9
             // 
-            this.cbPort.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-            this.cbPort.FormattingEnabled = true;
-            this.cbPort.Location = new System.Drawing.Point(75, 19);
-            this.cbPort.Name = "cbPort";
-            this.cbPort.Size = new System.Drawing.Size(104, 21);
-            this.cbPort.TabIndex = 0;
-            this.cbPort.Validating += new System.ComponentModel.CancelEventHandler(this.cbBaudrate_Validating);
+            this.label9.Image = global::EsPy.Properties.Resources.Warning;
+            this.label9.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            this.label9.Location = new System.Drawing.Point(378, 17);
+            this.label9.Name = "label9";
+            this.label9.Size = new System.Drawing.Size(228, 23);
+            this.label9.TabIndex = 18;
+            this.label9.Text = "       Make sure the selected port is closed!";
+            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
             // 
             // EspToolDialog
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(636, 422);
+            this.ClientSize = new System.Drawing.Size(636, 486);
             this.Controls.Add(this.linkLabel2);
             this.Controls.Add(this.linkLabel1);
             this.Controls.Add(this.label5);
@@ -366,7 +379,6 @@
             this.Controls.Add(this.label4);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.btnClose);
-            this.Controls.Add(this.btnVerify);
             this.Controls.Add(this.btnWrite);
             this.Controls.Add(this.btnErase);
             this.Controls.Add(this.textBox4);
@@ -400,7 +412,6 @@
         private System.Windows.Forms.Button btnWrite;
         private System.Windows.Forms.Button btnClose;
         private System.Windows.Forms.Button button1;
-        private System.Windows.Forms.Button btnVerify;
         private System.Windows.Forms.Label label4;
         private System.Windows.Forms.GroupBox groupBox1;
         private System.Windows.Forms.Button btnMac;
@@ -413,5 +424,7 @@
         private System.Windows.Forms.LinkLabel linkLabel2;
         private System.Windows.Forms.ComboBox cbPort;
         private System.Windows.Forms.Label label7;
+        private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.Label label9;
     }
 }

+ 27 - 7
EsPy/Dialogs/EspToolDialog.cs

@@ -93,8 +93,24 @@ namespace EsPy.Dialogs
             d.Dispose();
         }
 
-         private string Run(string cmd, string args)
+
+       
+
+        private string Run(string cmd, string args)
         {
+            if (this.cbPort.SelectedItem == null)
+            {
+                Helpers.WarningBox("There is not selected serial port!");
+                return "";
+            }
+
+            string portname = this.cbPort.SelectedItem.ToString();
+            if (Utility.Helpers.PortIsOpen(portname))
+            {
+                Helpers.ErrorBox($"{portname} has been alredy opened!");
+                return "";
+            }
+
             this.textBox4.Text = "Please wait...\r\n";
             
             this.Enabled = false;
@@ -181,7 +197,7 @@ namespace EsPy.Dialogs
         {
             if (this.CheckPaths(false))
             {
-                string args = String.Format("{0} -p {1} -b {2} read_mac", this.tbEsptool.Text, this.PortName, this.BaudRate);
+                string args = String.Format("\"{0}\" -p {1} -b {2} read_mac", this.tbEsptool.Text, this.PortName, this.BaudRate);
                 this.textBox4.Text = this.Run(this.tbPython.Text, args);
             }
         }
@@ -190,7 +206,7 @@ namespace EsPy.Dialogs
         {
             if (this.CheckPaths(false))
             {
-                string args = String.Format("{0} -p {1} -b {2} flash_id", this.tbEsptool.Text, this.PortName, this.BaudRate);
+                string args = String.Format("\"{0}\" -p {1} -b {2} flash_id", this.tbEsptool.Text, this.PortName, this.BaudRate);
                 this.textBox4.Text = this.Run(this.tbPython.Text, args);
             }
         }
@@ -199,7 +215,7 @@ namespace EsPy.Dialogs
         {
             if (this.CheckPaths(false))
             {
-                string args = String.Format("{0} -p {1} -b {2} chip_id", this.tbEsptool.Text, this.PortName, this.BaudRate);
+                string args = String.Format("\"{0}\" -p {1} -b {2} chip_id", this.tbEsptool.Text, this.PortName, this.BaudRate);
                 this.textBox4.Text = this.Run(this.tbPython.Text, args);
             }
         }
@@ -210,7 +226,7 @@ namespace EsPy.Dialogs
             {
                 if (MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                 {
-                    string args = String.Format("{0} -p {1} -b {2} erase_flash", this.tbEsptool.Text, this.PortName, this.BaudRate);
+                    string args = String.Format("\"{0}\" -p {1} -b {2} erase_flash", this.tbEsptool.Text, this.PortName, this.BaudRate);
                     this.textBox4.Text = this.Run(this.tbPython.Text, args);
                 }
             }
@@ -222,7 +238,10 @@ namespace EsPy.Dialogs
             {
                 if (MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                 {
-                    string args = String.Format("{0} -p {1} -b {2} write_flash --verify --flash_size=detect 0 {3}", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
+                    string args = String.Format("\"{0}\" -p {1} -b {2} write_flash --verify --flash_size=detect 0 \"{3}\"", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
+
+                    args = String.Format("\"{0}\" -p {1} -b {2} write_flash -fm dio -ff 20m -fs detect 0x0000 \"{3}\"", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
+
                     this.textBox4.Text = this.Run(this.tbPython.Text, args);
                 }
             }
@@ -232,7 +251,8 @@ namespace EsPy.Dialogs
         {
             if (this.CheckPaths())
             {
-                string args = String.Format("{0} -p {1} -b {2} verify_flash 0x40000 {3}", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
+                //string args = String.Format("\"{0}\" -p \"{1}\" -b {2} verify_flash 0x40000 \"{3}\"", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
+                string args = String.Format("\"{0}\" -p \"{1}\" -b {2} verify_flash 0x00000 \"{3}\"", this.tbEsptool.Text, this.PortName, this.BaudRate, this.tbFirmware.Text);
                 this.textBox4.Text = this.Run(this.tbPython.Text, args);
             }
         }

+ 8 - 1
EsPy/EsPy.csproj

@@ -230,11 +230,16 @@
     <None Include="pip.bat">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <Content Include="Helps\images\esp8266-wemos-d1-mini-pinout.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+    <Content Include="Lib\umqtt\simple.py" />
     <Content Include="Lib\ssd1306.py">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
     <Content Include="Release\EsPy.1.0.0.4.7z" />
     <None Include="Release\EsPy.1.0.0.5.7z" />
+    <None Include="Release\EsPy.1.0.0.6.7z" />
     <None Include="Resources\error16.png" />
     <None Include="Resources\info.png" />
     <None Include="Resources\compile.png" />
@@ -369,7 +374,9 @@
     </Content>
   </ItemGroup>
   <ItemGroup>
-    <None Include="App.config" />
+    <None Include="App.config">
+      <SubType>Designer</SubType>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Content Include="Tools\webrepl\FileSaver.js">

+ 3 - 3
EsPy/Forms/EditorForm.cs

@@ -61,7 +61,7 @@ namespace EsPy.Forms
         }
 
         private bool IsRunnable
-        { get { return this.Port != null && this.Port.IsOpen && !this.Port.Busy && this.scintilla.Lexer == Lexer.Python; } }
+        { get { return this.Port != null && this.Port.IsOpen && !this.Port.Busy && this.Lexer == Lexer.Python; } }
 
         private PySerial FPort = null;
         public PySerial Port
@@ -233,7 +233,7 @@ namespace EsPy.Forms
             else
             {
                 this.SaveToFile(this.FileName);
-                this.scintilla.SetSavePoint();
+                //this.scintilla.SetSavePoint();
                 this.UpdateUI();
             }
             return DialogResult.OK;
@@ -259,7 +259,7 @@ namespace EsPy.Forms
 
         private void mnSave_Click(object sender, EventArgs e)
         {
-            if (Helpers.QuestionBox("Would you like to save changes?") == DialogResult.Yes)
+            //if (Helpers.QuestionBox("Would you like to save changes?") == DialogResult.Yes)
             {
                 this.Save();
             }

+ 15 - 13
EsPy/Forms/TerminalForm.Designer.cs

@@ -100,7 +100,7 @@
             this.mnUndo.MergeIndex = 0;
             this.mnUndo.Name = "mnUndo";
             this.mnUndo.ShortcutKeyDisplayString = "Ctrl+Z";
-            this.mnUndo.Size = new System.Drawing.Size(152, 22);
+            this.mnUndo.Size = new System.Drawing.Size(144, 22);
             this.mnUndo.Text = "Undo";
             // 
             // mnRedo
@@ -110,7 +110,7 @@
             this.mnRedo.MergeIndex = 1;
             this.mnRedo.Name = "mnRedo";
             this.mnRedo.ShortcutKeyDisplayString = "Ctrl+Y";
-            this.mnRedo.Size = new System.Drawing.Size(152, 22);
+            this.mnRedo.Size = new System.Drawing.Size(144, 22);
             this.mnRedo.Text = "Redo";
             // 
             // toolStripMenuItem2
@@ -118,7 +118,7 @@
             this.toolStripMenuItem2.MergeAction = System.Windows.Forms.MergeAction.Insert;
             this.toolStripMenuItem2.MergeIndex = 2;
             this.toolStripMenuItem2.Name = "toolStripMenuItem2";
-            this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
+            this.toolStripMenuItem2.Size = new System.Drawing.Size(141, 6);
             // 
             // mnCut
             // 
@@ -127,7 +127,7 @@
             this.mnCut.MergeIndex = 3;
             this.mnCut.Name = "mnCut";
             this.mnCut.ShortcutKeyDisplayString = "Ctrl+X";
-            this.mnCut.Size = new System.Drawing.Size(152, 22);
+            this.mnCut.Size = new System.Drawing.Size(144, 22);
             this.mnCut.Text = "Cut";
             // 
             // mnCopy
@@ -137,7 +137,7 @@
             this.mnCopy.MergeIndex = 4;
             this.mnCopy.Name = "mnCopy";
             this.mnCopy.ShortcutKeyDisplayString = "";
-            this.mnCopy.Size = new System.Drawing.Size(152, 22);
+            this.mnCopy.Size = new System.Drawing.Size(144, 22);
             this.mnCopy.Text = "Copy";
             // 
             // mnPaste
@@ -148,7 +148,7 @@
             this.mnPaste.MergeIndex = 5;
             this.mnPaste.Name = "mnPaste";
             this.mnPaste.ShortcutKeyDisplayString = "Ctrl+V";
-            this.mnPaste.Size = new System.Drawing.Size(152, 22);
+            this.mnPaste.Size = new System.Drawing.Size(144, 22);
             this.mnPaste.Text = "Paste";
             // 
             // mnDelete
@@ -157,7 +157,7 @@
             this.mnDelete.MergeIndex = 6;
             this.mnDelete.Name = "mnDelete";
             this.mnDelete.ShortcutKeyDisplayString = "Del";
-            this.mnDelete.Size = new System.Drawing.Size(152, 22);
+            this.mnDelete.Size = new System.Drawing.Size(144, 22);
             this.mnDelete.Text = "Delete";
             // 
             // mnClean
@@ -166,7 +166,7 @@
             this.mnClean.MergeAction = System.Windows.Forms.MergeAction.Insert;
             this.mnClean.MergeIndex = 7;
             this.mnClean.Name = "mnClean";
-            this.mnClean.Size = new System.Drawing.Size(152, 22);
+            this.mnClean.Size = new System.Drawing.Size(144, 22);
             this.mnClean.Text = "Clean";
             this.mnClean.Click += new System.EventHandler(this.mnClean_Click);
             // 
@@ -175,7 +175,7 @@
             this.toolStripMenuItem3.MergeAction = System.Windows.Forms.MergeAction.Insert;
             this.toolStripMenuItem3.MergeIndex = 8;
             this.toolStripMenuItem3.Name = "toolStripMenuItem3";
-            this.toolStripMenuItem3.Size = new System.Drawing.Size(149, 6);
+            this.toolStripMenuItem3.Size = new System.Drawing.Size(141, 6);
             // 
             // mnSelectAll
             // 
@@ -183,7 +183,7 @@
             this.mnSelectAll.MergeIndex = 9;
             this.mnSelectAll.Name = "mnSelectAll";
             this.mnSelectAll.ShortcutKeyDisplayString = "";
-            this.mnSelectAll.Size = new System.Drawing.Size(152, 22);
+            this.mnSelectAll.Size = new System.Drawing.Size(144, 22);
             this.mnSelectAll.Text = "Select All";
             // 
             // toolStripMenuItem7
@@ -191,7 +191,7 @@
             this.toolStripMenuItem7.MergeAction = System.Windows.Forms.MergeAction.Insert;
             this.toolStripMenuItem7.MergeIndex = 10;
             this.toolStripMenuItem7.Name = "toolStripMenuItem7";
-            this.toolStripMenuItem7.Size = new System.Drawing.Size(149, 6);
+            this.toolStripMenuItem7.Size = new System.Drawing.Size(141, 6);
             // 
             // mnView
             // 
@@ -414,17 +414,19 @@
             this.scintilla.AutoCChooseSingle = true;
             this.scintilla.AutomaticFold = ((ScintillaNET.AutomaticFold)(((ScintillaNET.AutomaticFold.Show | ScintillaNET.AutomaticFold.Click) 
             | ScintillaNET.AutomaticFold.Change)));
+            this.scintilla.CompletionEnabled = false;
             this.scintilla.ContextMenuStrip = this.contextMenuStrip1;
             this.scintilla.Dock = System.Windows.Forms.DockStyle.Fill;
             this.scintilla.EolMode = ScintillaNET.Eol.Cr;
             this.scintilla.IndentationGuides = ScintillaNET.IndentView.LookForward;
             this.scintilla.IndentWidth = 4;
             this.scintilla.Lexer = ScintillaNET.Lexer.Python;
-            this.scintilla.Location = new System.Drawing.Point(0, 24);
+            this.scintilla.Location = new System.Drawing.Point(0, 25);
+            this.scintilla.MouseDwellTime = 500;
             this.scintilla.Name = "scintilla";
             this.scintilla.Port = null;
             this.scintilla.ReadOnly = true;
-            this.scintilla.Size = new System.Drawing.Size(664, 238);
+            this.scintilla.Size = new System.Drawing.Size(664, 237);
             this.scintilla.TabIndex = 2;
             this.scintilla.ViewWhitespace = ScintillaNET.WhitespaceMode.VisibleAlways;
             this.scintilla.UpdateUI += new System.EventHandler<ScintillaNET.UpdateUIEventArgs>(this.terminal_UpdateUI);

+ 1 - 0
EsPy/Forms/TerminalForm.cs

@@ -127,6 +127,7 @@ namespace EsPy.Forms
             this.scintilla.ReadOnly = false;
             this.scintilla.Append($"{this.Port.PortName} {this.Port.BaudRate } Connected...\r\n");
             this.scintilla.Append("Press CTRL + D or Soft Reset Button on the Toolbar\r\n");
+            this.scintilla.Append("Press CTRL + C to interrupt current program.\r\n");
         }
 
         public ToolStrip ToolStrip

+ 12 - 5
EsPy/Helps/help.html

@@ -17,18 +17,25 @@
         <li><a href="http://docs.micropython.org/en/latest/esp8266/">Miropython ESP8266</a></li>
     </ul>
     <h3>Esp Tools</h3>
-    <p>Requirement:<br />
-     Python2.7<br />
-    python -m pip install --upgarde pip<br />
-    python -m pip install esptool</p>
+    <p>
+        Requirement:<br />
+        Python2.7<br />
+        python -m pip install --upgarde pip<br />
+        python -m pip install esptool
+    </p>
     <ul>
         <li><a href="https://github.com/espressif/esptool">ESP8266 ROM Bootloader utility (esptool)</a></li>
     </ul>
 
     <h3>Samples</h3>
     <ul>
-       <li><href ="https://github.com/dhylands/upy-examples">upy-samples</a></li>
+        <li><href ="https://github.com/dhylands/upy-examples">upy-samples</a></li>
         <li><a href="https://github.com/peterhinch/micropython-samples">micropython-samples</a></li>
     </ul>
+
+    <h4><a href="https://wiki.wemos.cc/products:d1:d1_mini">WEMOS D1 mini</a></h4>
+    <h2>Pins</h2>
+    <img style="width:640px" src="images/esp8266-wemos-d1-mini-pinout.png" /> 
+
 </body>
 </html>

binární
EsPy/Helps/images/esp8266-wemos-d1-mini-pinout.png


binární
EsPy/Helps/images/nodemcu_v1_pins.png


+ 5 - 5
EsPy/Lib/machine.py

@@ -1,17 +1,17 @@
-class Pin:
+class Pin():
     #init', 'value', 'low', 'high', 'irq', 'IN', 'OUT', 'OPEN_DRAIN', 'PULL_UP', 'IRQ_RISING', 'IRQ_FALLING'
 
     def __init__(self, pin_id):
         pass
 
-    def value(value):
+    def value(self, value):
         pass
 
-    def low():
+    def low(self):
         pass
 
-    def high():
+    def high(self):
         pass
 
-    def irq():
+    def irq(self):
         pass

+ 204 - 0
EsPy/Lib/umqtt/simple.py

@@ -0,0 +1,204 @@
+import usocket as socket
+import ustruct as struct
+from ubinascii import hexlify
+
+class MQTTException(Exception):
+    pass
+
+class MQTTClient:
+
+    def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0,
+                 ssl=False, ssl_params={}):
+        if port == 0:
+            port = 8883 if ssl else 1883
+        self.client_id = client_id
+        self.sock = None
+        self.server = server
+        self.port = port
+        self.ssl = ssl
+        self.ssl_params = ssl_params
+        self.pid = 0
+        self.cb = None
+        self.user = user
+        self.pswd = password
+        self.keepalive = keepalive
+        self.lw_topic = None
+        self.lw_msg = None
+        self.lw_qos = 0
+        self.lw_retain = False
+
+    def _send_str(self, s):
+        self.sock.write(struct.pack("!H", len(s)))
+        self.sock.write(s)
+
+    def _recv_len(self):
+        n = 0
+        sh = 0
+        while 1:
+            b = self.sock.read(1)[0]
+            n |= (b & 0x7f) << sh
+            if not b & 0x80:
+                return n
+            sh += 7
+
+    def set_callback(self, f):
+        self.cb = f
+
+    def set_last_will(self, topic, msg, retain=False, qos=0):
+        assert 0 <= qos <= 2
+        assert topic
+        self.lw_topic = topic
+        self.lw_msg = msg
+        self.lw_qos = qos
+        self.lw_retain = retain
+
+    def connect(self, clean_session=True):
+        self.sock = socket.socket()
+        addr = socket.getaddrinfo(self.server, self.port)[0][-1]
+        self.sock.connect(addr)
+        if self.ssl:
+            import ussl
+            self.sock = ussl.wrap_socket(self.sock, **self.ssl_params)
+        premsg = bytearray(b"\x10\0\0\0\0\0")
+        msg = bytearray(b"\x04MQTT\x04\x02\0\0")
+
+        sz = 10 + 2 + len(self.client_id)
+        msg[6] = clean_session << 1
+        if self.user is not None:
+            sz += 2 + len(self.user) + 2 + len(self.pswd)
+            msg[6] |= 0xC0
+        if self.keepalive:
+            assert self.keepalive < 65536
+            msg[7] |= self.keepalive >> 8
+            msg[8] |= self.keepalive & 0x00FF
+        if self.lw_topic:
+            sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg)
+            msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3
+            msg[6] |= self.lw_retain << 5
+
+        i = 1
+        while sz > 0x7f:
+            premsg[i] = (sz & 0x7f) | 0x80
+            sz >>= 7
+            i += 1
+        premsg[i] = sz
+
+        self.sock.write(premsg, i + 2)
+        self.sock.write(msg)
+        #print(hex(len(msg)), hexlify(msg, ":"))
+        self._send_str(self.client_id)
+        if self.lw_topic:
+            self._send_str(self.lw_topic)
+            self._send_str(self.lw_msg)
+        if self.user is not None:
+            self._send_str(self.user)
+            self._send_str(self.pswd)
+        resp = self.sock.read(4)
+        assert resp[0] == 0x20 and resp[1] == 0x02
+        if resp[3] != 0:
+            raise MQTTException(resp[3])
+        return resp[2] & 1
+
+    def disconnect(self):
+        self.sock.write(b"\xe0\0")
+        self.sock.close()
+
+    def ping(self):
+        self.sock.write(b"\xc0\0")
+
+    def publish(self, topic, msg, retain=False, qos=0):
+        pkt = bytearray(b"\x30\0\0\0")
+        pkt[0] |= qos << 1 | retain
+        sz = 2 + len(topic) + len(msg)
+        if qos > 0:
+            sz += 2
+        assert sz < 2097152
+        i = 1
+        while sz > 0x7f:
+            pkt[i] = (sz & 0x7f) | 0x80
+            sz >>= 7
+            i += 1
+        pkt[i] = sz
+        #print(hex(len(pkt)), hexlify(pkt, ":"))
+        self.sock.write(pkt, i + 1)
+        self._send_str(topic)
+        if qos > 0:
+            self.pid += 1
+            pid = self.pid
+            struct.pack_into("!H", pkt, 0, pid)
+            self.sock.write(pkt, 2)
+        self.sock.write(msg)
+        if qos == 1:
+            while 1:
+                op = self.wait_msg()
+                if op == 0x40:
+                    sz = self.sock.read(1)
+                    assert sz == b"\x02"
+                    rcv_pid = self.sock.read(2)
+                    rcv_pid = rcv_pid[0] << 8 | rcv_pid[1]
+                    if pid == rcv_pid:
+                        return
+        elif qos == 2:
+            assert 0
+
+    def subscribe(self, topic, qos=0):
+        assert self.cb is not None, "Subscribe callback is not set"
+        pkt = bytearray(b"\x82\0\0\0")
+        self.pid += 1
+        struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid)
+        #print(hex(len(pkt)), hexlify(pkt, ":"))
+        self.sock.write(pkt)
+        self._send_str(topic)
+        self.sock.write(qos.to_bytes(1, "little"))
+        while 1:
+            op = self.wait_msg()
+            if op == 0x90:
+                resp = self.sock.read(4)
+                #print(resp)
+                assert resp[1] == pkt[2] and resp[2] == pkt[3]
+                if resp[3] == 0x80:
+                    raise MQTTException(resp[3])
+                return
+
+    # Wait for a single incoming MQTT message and process it.
+    # Subscribed messages are delivered to a callback previously
+    # set by .set_callback() method. Other (internal) MQTT
+    # messages processed internally.
+    def wait_msg(self):
+        res = self.sock.read(1)
+        self.sock.setblocking(True)
+        if res is None:
+            return None
+        if res == b"":
+            raise OSError(-1)
+        if res == b"\xd0":  # PINGRESP
+            sz = self.sock.read(1)[0]
+            assert sz == 0
+            return None
+        op = res[0]
+        if op & 0xf0 != 0x30:
+            return op
+        sz = self._recv_len()
+        topic_len = self.sock.read(2)
+        topic_len = (topic_len[0] << 8) | topic_len[1]
+        topic = self.sock.read(topic_len)
+        sz -= topic_len + 2
+        if op & 6:
+            pid = self.sock.read(2)
+            pid = pid[0] << 8 | pid[1]
+            sz -= 2
+        msg = self.sock.read(sz)
+        self.cb(topic, msg)
+        if op & 6 == 2:
+            pkt = bytearray(b"\x40\x02\0\0")
+            struct.pack_into("!H", pkt, 2, pid)
+            self.sock.write(pkt)
+        elif op & 6 == 4:
+            assert 0
+
+    # Checks whether a pending message from server is available.
+    # If not, returns immediately with None. Otherwise, does
+    # the same processing as wait_msg.
+    def check_msg(self):
+        self.sock.setblocking(False)
+        return self.wait_msg()

+ 29 - 11
EsPy/MainForm.Designer.cs

@@ -97,6 +97,8 @@
             this.vS2015DarkTheme1 = new WeifenLuo.WinFormsUI.Docking.VS2015DarkTheme();
             this.vS2015LightTheme1 = new WeifenLuo.WinFormsUI.Docking.VS2015LightTheme();
             this.visualStudioToolStripExtender1 = new WeifenLuo.WinFormsUI.Docking.VisualStudioToolStripExtender(this.components);
+            this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
+            this.JediState = new System.Windows.Forms.ToolStripStatusLabel();
             this.menuStrip1.SuspendLayout();
             this.toolStrip1.SuspendLayout();
             this.statusStrip1.SuspendLayout();
@@ -144,7 +146,7 @@
             this.mnNewOther});
             this.mnNew.Image = ((System.Drawing.Image)(resources.GetObject("mnNew.Image")));
             this.mnNew.Name = "mnNew";
-            this.mnNew.Size = new System.Drawing.Size(121, 22);
+            this.mnNew.Size = new System.Drawing.Size(152, 22);
             this.mnNew.Text = "New";
             // 
             // mnNewPython
@@ -205,20 +207,20 @@
             // 
             this.mnOpen.Image = ((System.Drawing.Image)(resources.GetObject("mnOpen.Image")));
             this.mnOpen.Name = "mnOpen";
-            this.mnOpen.Size = new System.Drawing.Size(121, 22);
+            this.mnOpen.Size = new System.Drawing.Size(152, 22);
             this.mnOpen.Text = "Open...";
             this.mnOpen.Click += new System.EventHandler(this.mnOpen_Click);
             // 
             // toolStripSeparator4
             // 
             this.toolStripSeparator4.Name = "toolStripSeparator4";
-            this.toolStripSeparator4.Size = new System.Drawing.Size(118, 6);
+            this.toolStripSeparator4.Size = new System.Drawing.Size(149, 6);
             // 
             // mnSave
             // 
             this.mnSave.Enabled = false;
             this.mnSave.Name = "mnSave";
-            this.mnSave.Size = new System.Drawing.Size(121, 22);
+            this.mnSave.Size = new System.Drawing.Size(152, 22);
             this.mnSave.Text = "Save";
             this.mnSave.Click += new System.EventHandler(this.mnSave_Click);
             // 
@@ -226,7 +228,7 @@
             // 
             this.mnSaveAs.Enabled = false;
             this.mnSaveAs.Name = "mnSaveAs";
-            this.mnSaveAs.Size = new System.Drawing.Size(121, 22);
+            this.mnSaveAs.Size = new System.Drawing.Size(152, 22);
             this.mnSaveAs.Text = "Save as...";
             this.mnSaveAs.Click += new System.EventHandler(this.mnSaveAs_Click);
             // 
@@ -234,20 +236,21 @@
             // 
             this.mnSaveAll.Image = global::EsPy.Properties.Resources.saveall;
             this.mnSaveAll.Name = "mnSaveAll";
-            this.mnSaveAll.Size = new System.Drawing.Size(121, 22);
+            this.mnSaveAll.Size = new System.Drawing.Size(152, 22);
             this.mnSaveAll.Text = "Save all";
             this.mnSaveAll.Click += new System.EventHandler(this.mnSaveAll_Click);
             // 
             // toolStripMenuItem2
             // 
             this.toolStripMenuItem2.Name = "toolStripMenuItem2";
-            this.toolStripMenuItem2.Size = new System.Drawing.Size(118, 6);
+            this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
             // 
             // exitToolStripMenuItem
             // 
             this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
-            this.exitToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
+            this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
             this.exitToolStripMenuItem.Text = "Exit";
+            this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
             // 
             // mnEdit
             // 
@@ -262,7 +265,7 @@
             this.settingsToolStripMenuItem.Enabled = false;
             this.settingsToolStripMenuItem.MergeIndex = 20;
             this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
-            this.settingsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+            this.settingsToolStripMenuItem.Size = new System.Drawing.Size(125, 22);
             this.settingsToolStripMenuItem.Text = "Settings...";
             this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click);
             // 
@@ -325,7 +328,6 @@
             // 
             // mnEspTool
             // 
-            this.mnEspTool.Enabled = false;
             this.mnEspTool.Name = "mnEspTool";
             this.mnEspTool.Size = new System.Drawing.Size(148, 22);
             this.mnEspTool.Text = "EspTool...";
@@ -628,7 +630,9 @@
             // 
             this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.toolStripStatusLabel4,
-            this.toolStripStatusLabel2});
+            this.toolStripStatusLabel2,
+            this.toolStripStatusLabel1,
+            this.JediState});
             this.statusStrip1.Location = new System.Drawing.Point(0, 398);
             this.statusStrip1.Name = "statusStrip1";
             this.statusStrip1.Size = new System.Drawing.Size(522, 22);
@@ -666,6 +670,18 @@
             // 
             this.visualStudioToolStripExtender1.DefaultRenderer = null;
             // 
+            // toolStripStatusLabel1
+            // 
+            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
+            this.toolStripStatusLabel1.Size = new System.Drawing.Size(30, 17);
+            this.toolStripStatusLabel1.Text = "Jedi:";
+            // 
+            // JediState
+            // 
+            this.JediState.Name = "JediState";
+            this.JediState.Size = new System.Drawing.Size(22, 17);
+            this.JediState.Text = "---";
+            // 
             // MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -763,6 +779,8 @@
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator7;
         private System.Windows.Forms.ToolStripMenuItem mnErrorList;
         public WeifenLuo.WinFormsUI.Docking.DockPanel dockPanel1;
+        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
+        private System.Windows.Forms.ToolStripStatusLabel JediState;
     }
 }
 

+ 7 - 7
EsPy/MainForm.cs

@@ -70,9 +70,6 @@ namespace EsPy
             this.DragEnter += MainForm_DragEnter;
             this.DragDrop += MainForm_DragDrop;
             this.DragOver += MainForm_DragOver;
-
-            
-
         }
 
         private void MainForm_DragOver(object sender, DragEventArgs e)
@@ -361,6 +358,7 @@ namespace EsPy
         {
   
             this.mnTerminal.Enabled = this.TerminalForm == null;
+            this.JediState.Text = Globals.PyClient != null ? "Connected" : "Not connected";
         }
 
         private void SetSchema(object sender, System.EventArgs e)
@@ -740,7 +738,7 @@ namespace EsPy
 
             if (!this.ComportIsExists)
             {
-                this.btnConnect.Enabled = false;
+                //this.btnConnect.Enabled = false;
                 MessageBox.Show($"Serialport \"{this.CurretPortName}\" does not exists!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 return;
             }
@@ -884,7 +882,7 @@ namespace EsPy
                 this.mnPorts.DropDownItems.Add(mi);
             }
 
-            this.mnEspTool.Enabled = this.Port == null && this.ComportIsExists;
+            //this.mnEspTool.Enabled = this.Port == null && this.ComportIsExists;
         }
 
         private bool ComportIsExists
@@ -941,7 +939,6 @@ namespace EsPy
             if (File.Exists(p))
                 System.Diagnostics.Process.Start(p);
             else MessageBox.Show("Help file does not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
-
         }
 
         private void btnFlashing_Click(object sender, EventArgs e)
@@ -1014,6 +1011,9 @@ namespace EsPy
             d.Dispose();
         }
 
-       
+        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
+        {
+
+        }
     }
 }

+ 2 - 2
EsPy/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.5")]
-[assembly: AssemblyFileVersion("1.0.0.5")]
+[assembly: AssemblyVersion("1.0.0.6")]
+[assembly: AssemblyFileVersion("1.0.0.6")]

+ 60 - 44
EsPy/Python/PyClient.cs

@@ -43,29 +43,39 @@ namespace EsPy.Python
                  "python", this.ScriptPath);
 
                 inf.UseShellExecute = false;
-                inf.CreateNoWindow = true;  //!Properties.Settings.Default.ShowPyServer;
+#if DEBUG
+                inf.CreateNoWindow = false;
+#else
+                inf.CreateNoWindow = true;
+#endif
                 this.Process = new System.Diagnostics.Process();
                 this.Process.StartInfo = inf;
                 try
                 {
                     this.Process.Start();
-
-                    int p = 5;
+                    Thread.Sleep(1000);
+                    
+                    int p = 10;
                     while (p-- > 0)
                     {
                         Thread.Sleep(1000);
                         try
                         {
                             JToken res = Globals.PyClient.DoRequest<JToken>("jedi", "hello");
-                            break;
+                            if (res != null)
+                            {
+                                return true;
+                            }
                         }
                         catch
                         { }
                     }
                     return p > 0;
                 }
-                catch
-                { }
+                catch (Exception ex)
+                {
+                    Console.WriteLine(ex.Message);
+                }
             }
             return false;
         }
@@ -78,14 +88,15 @@ namespace EsPy.Python
                 {
                     if (this.Client != null)
                     {
-                        Globals.PyClient.DoRequest<JToken>("jedi", "bye");
+                        JToken res = this.DoRequest<JToken>("jedi", "bye");
+                        //if (res != null)
                         this.Client.Close();
                         this.Client.Dispose();
                     }
                 }
-                catch// (Exception e)
+                catch (Exception e)
                 {
-                    //Helpers.ErrorBox(e);
+                    Helpers.ErrorBox(e);
                 }
 
                 if (this.Process != null)
@@ -94,9 +105,9 @@ namespace EsPy.Python
                     this.Process.Dispose();
                 }
             }
-            catch //(Exception ee)
+            catch (Exception ee)
             {
-                //Helpers.ErrorBox(ee);
+                Helpers.ErrorBox(ee);
             }
 
         }
@@ -131,49 +142,55 @@ namespace EsPy.Python
         {
             this.Connect();
 
-            NetworkStream ns = this.Client.GetStream();
-            byte[] buff = Encoding.UTF8.GetBytes(text);
-            ns.Write(BitConverter.GetBytes(buff.Length), 0, sizeof(Int32));
-            ns.Write(buff, 0, buff.Length);
+            if (this.Client != null && this.Client.Connected)
+            {
 
-            byte[] rec = new byte[4];
-            ns.Read(rec, 0, sizeof(Int32));
-            int len = BitConverter.ToInt32(rec, 0);
+                NetworkStream ns = this.Client.GetStream();
+                byte[] buff = Encoding.UTF8.GetBytes(text);
+                ns.Write(BitConverter.GetBytes(buff.Length), 0, sizeof(Int32));
+                ns.Write(buff, 0, buff.Length);
 
-            if (len > this.InpBuffer.Length)
-            {
-                Array.Resize(ref this.InpBuffer, len);
-            }
-            //byte[] inb = new byte[len];
+                byte[] rec = new byte[4];
+                ns.Read(rec, 0, sizeof(Int32));
+                int len = BitConverter.ToInt32(rec, 0);
 
-            //while (this.Client.Available < len)
-            //{
-            //    Thread.Sleep(10);
-            //}
+                if (len > this.InpBuffer.Length)
+                {
+                    Array.Resize(ref this.InpBuffer, len);
+                }
+                //byte[] inb = new byte[len];
 
-            int count = 0;
-            int p = MAX_WAIT;
-            while (count < len)
-            {
+                //while (this.Client.Available < len)
+                //{
+                //    Thread.Sleep(10);
+                //}
 
-                if (this.Client.Available == 0)
+                int count = 0;
+                int p = MAX_WAIT;
+                while (count < len)
                 {
-                    Thread.Sleep(10);
-                    if (p-- <= 0)
+
+                    if (this.Client.Available == 0)
                     {
-                        throw new TimeoutException("MAX_WAIT Timeout!");
+                        Thread.Sleep(10);
+                        if (p-- <= 0)
+                        {
+                            throw new TimeoutException("MAX_WAIT Timeout!");
+                        }
+                    }
+                    else
+                    {
+                        count += ns.Read(this.InpBuffer, count, this.Client.Available);
+                        p = MAX_WAIT;
                     }
                 }
-                else
-                {
-                    count += ns.Read(this.InpBuffer, count, this.Client.Available);
-                    p = MAX_WAIT;
-                }
-            }
 
-            //Console.WriteLine($"SOCKET: {count}/{len}");          
+                //Console.WriteLine($"SOCKET: {count}/{len}");          
 
-            return System.Text.Encoding.UTF8.GetString(this.InpBuffer, 0, len);
+                return System.Text.Encoding.UTF8.GetString(this.InpBuffer, 0, len);
+            }
+
+            return "";
         }
 
         public T DoRequest<T>(PyRequest req)
@@ -187,7 +204,6 @@ namespace EsPy.Python
         {
             PyRequest req = new PyRequest(module, method);
             return DoRequest<T>(req);
-
         }
     }
 }

+ 42 - 31
EsPy/Scripts/PyHost.py

@@ -1,4 +1,14 @@
 import socket
+
+TCP_IP = '127.0.0.1'
+TCP_PORT = 5005
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.bind((TCP_IP, TCP_PORT))
+s.listen(1)
+conn, addr = s.accept()
+print 'Connection address:', addr
+
 from struct import *
 import json
 import jedi
@@ -9,22 +19,21 @@ jedi.settings.no_completion_duplicates = True
 jedi.settings.use_filesystem_cache = True
 
 print(os.path.dirname(os.path.realpath(__file__)))
-lib = os.path.dirname(os.path.realpath(__file__)) + '\\..\\' + 'Lib'
+lib = os.path.dirname(os.path.realpath(__file__)) + '\..\Lib'
+sys.path = []
 sys.path.append(lib)
 modules = []
-modules.append(lib + "\\machine.py")
-modules.append(lib + "\\onewire.py")
-jedi.preload_module(modules)
-
+modules.append(lib + "\machine.py")
+modules.append(lib + "\onewire.py")
+modules.append(lib + "\umqtt\simple.py")
+#jedi.preload_module(modules)
 print(sys.path)
+print(modules)
 
 class Proc(object):
     def __init__(self, j):
         self.__dict__ = json.loads(j)
          
-TCP_IP = '127.0.0.1'
-TCP_PORT = 5005
-
 def serialize_completions(completions):
     items = []
     params ={}
@@ -39,27 +48,28 @@ def serialize_completions(completions):
             if hasattr(completion, 'params'):
                 for p in completion.params:
                     params.append(p.name)
+
             item = {
                 #'column': completion.column,
+                'name': completion.name, 
                 'complete': completion.complete, 
-                'description': completion.description, 
-                'doc': completion.doc,
-                'docstring': completion.docstring(False), 
-                # #'follow_definition': item.follow_definition(), 
-                 'full_name': completion.full_name, 
-                # #'goto_assignments': item.goto_assignments(), 
-                # 'in_builtin_module': completion.in_builtin_module, 
+                #'description': completion.description,
+                #'doc': completion.doc,
+                #'docstring': completion.docstring(False), 
+                ## #'follow_definition': item.follow_definition(), 
+                #'full_name': completion.full_name, 
+                ## #'goto_assignments': item.goto_assignments(), 
+                ## 'in_builtin_module': completion.in_builtin_module, 
                 'is_keyword': completion.is_keyword, 
-                #'line': completion.line, 
-                'module_name': completion.module_name, 
-                'module_path': completion.module_path, 
-                'name': completion.name, 
-                'name_with_symbols': completion.name_with_symbols, 
-                'parameters': params, #completion.params, 
-                #'parent': completion.parent, 
-                #'raw_doc': completion.raw_doc, 
-                #'start_pos': completion.start_pos,
-                'type': completion.type
+                ##'line': completion.line, 
+                #'module_name': completion.module_name, 
+                #'module_path': completion.module_path, 
+                #'name_with_symbols': completion.name_with_symbols, 
+                ##'parameters': params, #completion.params, 
+                ##'parent': completion.parent, 
+                ##'raw_doc': completion.raw_doc, 
+                ##'start_pos': completion.start_pos,
+                #'type': completion.type
             }
             items.append(item)
         return json.dumps({'completions': items})
@@ -67,11 +77,6 @@ def serialize_completions(completions):
         print("EXCEPTION: ", e)
         return "ERR"
 
-s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-s.bind((TCP_IP, TCP_PORT))
-s.listen(1)
-conn, addr = s.accept()
-print 'Connection address:', addr
 
 while 1:
     data = conn.recv(4)
@@ -89,10 +94,16 @@ while 1:
     if obj.Module == 'jedi':
         if obj.Method == 'completion':
                 script = jedi.Script(obj.Script['Source'], obj.Script['Line'], obj.Script['Column']) 
-                result = serialize_completions(script.completions())
+                comp = script.completions()
+                print(comp)
+                result = serialize_completions(comp)
         elif obj.Method == "hello":
             result = json.dumps({"respose": "hello"})
         elif obj.Method == "bye":
+            print("bye")
+            conn.close()
+            #input("Press Enter to continue...")
+            sys.exit()
             #result = json.dumps({"respose": "bye"})
             break
 

+ 1 - 1
EsPy/Units/StatVfs.cs

@@ -66,7 +66,7 @@ namespace EsPy.Units
             get
             {
                 if (this.TotalBytes != 0)
-                    return this.FreeBytes / this.TotalBytes;
+                    return 1 - (this.FreeBytes / this.TotalBytes);
                 return float.NaN;
             }
         }

+ 25 - 0
EsPy/Utility/Helpers.cs

@@ -11,6 +11,31 @@ namespace EsPy.Utility
 {
     public static class Helpers
     {
+        public static bool PortIsOpen(string port_name)
+        {
+            System.IO.Ports.SerialPort p = new System.IO.Ports.SerialPort();
+            p.PortName = port_name;
+
+            try
+            {
+                p.Open();
+                p.Close();
+                return false;
+            }
+            catch
+            {
+                return true;
+            }
+            finally
+            {
+                if (p != null)
+                {
+                    p.Dispose();
+                    p = null;
+                }
+            }
+        }
+
         public static string GetPythonPath()
         {
             string[] paths = Environment.GetEnvironmentVariable("PATH").Split(new char[] { ';' });

+ 4 - 3
EsPy/Utility/TextHelper.cs

@@ -23,7 +23,7 @@ namespace EsPy.Utility
             {
                 MatchCollection items = re.Matches(text);
                 string[] res = new string[items.Count];
-                for(int i = 0; i < items.Count; i++)
+                for (int i = 0; i < items.Count; i++)
                 {
                     res[i] = items[i].Groups[1].Value;
                 }
@@ -36,10 +36,11 @@ namespace EsPy.Utility
         {
             Words words = new Words();
             if (from >= 1)
-            {words.Pos = from;
+            {
+                words.Pos = from;
                 from--;
                 int dot = 0;
-                
+
                 while (from >= 0)
                 {
                     char c = text[from];