Pārlūkot izejas kodu

增加PCM接收功能

pc 3 gadi atpakaļ
vecāks
revīzija
7dd3d3792e

BIN
exe/apps/Tps_LQ_Transmitter/Tps_LQ_Transmitter.dll


BIN
exe/apps/Tps_LQ_Transmitter/Tps_LQ_Transmitter.pdb


BIN
tps/TpsLabStudio/.vs/TpsLabStudio/v16/.suo


+ 198 - 2
tps/TpsLabStudio/DebuggingForm.Designer.cs

@@ -123,6 +123,22 @@ namespace Tps_LQ_Transmitter
             this.btnPcmSetting = new DevComponents.DotNetBar.ButtonX();
             this.txtbPcmSend = new DevComponents.DotNetBar.Controls.TextBoxX();
             this.btnPcmSendx = new DevComponents.DotNetBar.ButtonX();
+            this.checkBoxX1 = new DevComponents.DotNetBar.Controls.CheckBoxX();
+            this.txtbBaudrate = new DevComponents.DotNetBar.Controls.TextBoxX();
+            this.labelX33 = new DevComponents.DotNetBar.LabelX();
+            this.rbtnRise = new System.Windows.Forms.RadioButton();
+            this.rbtnFall = new System.Windows.Forms.RadioButton();
+            this.gpbHdlcTr = new System.Windows.Forms.GroupBox();
+            this.gpbUartCheck = new System.Windows.Forms.GroupBox();
+            this.rbtnNone = new System.Windows.Forms.RadioButton();
+            this.rbtnEven = new System.Windows.Forms.RadioButton();
+            this.rbtnOdd = new System.Windows.Forms.RadioButton();
+            this.gpbSendMode = new System.Windows.Forms.GroupBox();
+            this.rbtnHdlcMode = new System.Windows.Forms.RadioButton();
+            this.rbtnUartMode = new System.Windows.Forms.RadioButton();
+            this.gpbHdlcTr.SuspendLayout();
+            this.gpbUartCheck.SuspendLayout();
+            this.gpbSendMode.SuspendLayout();
             this.SuspendLayout();
             // 
             // btnPowCh_1
@@ -1423,7 +1439,7 @@ namespace Tps_LQ_Transmitter
             this.btnPcmSetting.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
             this.btnPcmSetting.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
             this.btnPcmSetting.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnPcmSetting.Location = new System.Drawing.Point(308, 524);
+            this.btnPcmSetting.Location = new System.Drawing.Point(166, 702);
             this.btnPcmSetting.Name = "btnPcmSetting";
             this.btnPcmSetting.Size = new System.Drawing.Size(98, 48);
             this.btnPcmSetting.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
@@ -1459,11 +1475,169 @@ namespace Tps_LQ_Transmitter
             this.btnPcmSendx.Text = "发送";
             this.btnPcmSendx.Click += new System.EventHandler(this.btnPcmSendx_Click);
             // 
+            // checkBoxX1
+            // 
+            // 
+            // 
+            // 
+            this.checkBoxX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
+            this.checkBoxX1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.checkBoxX1.Location = new System.Drawing.Point(146, 425);
+            this.checkBoxX1.Name = "checkBoxX1";
+            this.checkBoxX1.Size = new System.Drawing.Size(75, 23);
+            this.checkBoxX1.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
+            this.checkBoxX1.TabIndex = 1;
+            this.checkBoxX1.Text = "通道1";
+            this.checkBoxX1.CheckedChanged += new System.EventHandler(this.chkStCh_1_CheckedChanged);
+            // 
+            // txtbBaudrate
+            // 
+            // 
+            // 
+            // 
+            this.txtbBaudrate.Border.Class = "TextBoxBorder";
+            this.txtbBaudrate.Border.CornerType = DevComponents.DotNetBar.eCornerType.Square;
+            this.txtbBaudrate.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.txtbBaudrate.Location = new System.Drawing.Point(257, 553);
+            this.txtbBaudrate.Name = "txtbBaudrate";
+            this.txtbBaudrate.PreventEnterBeep = true;
+            this.txtbBaudrate.Size = new System.Drawing.Size(112, 31);
+            this.txtbBaudrate.TabIndex = 2;
+            this.txtbBaudrate.Text = "230400";
+            this.txtbBaudrate.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+            // 
+            // labelX33
+            // 
+            // 
+            // 
+            // 
+            this.labelX33.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square;
+            this.labelX33.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.labelX33.Location = new System.Drawing.Point(157, 561);
+            this.labelX33.Name = "labelX33";
+            this.labelX33.Size = new System.Drawing.Size(75, 23);
+            this.labelX33.TabIndex = 3;
+            this.labelX33.Text = "波特率";
+            this.labelX33.TextAlignment = System.Drawing.StringAlignment.Far;
+            // 
+            // rbtnRise
+            // 
+            this.rbtnRise.AutoSize = true;
+            this.rbtnRise.Location = new System.Drawing.Point(29, 24);
+            this.rbtnRise.Name = "rbtnRise";
+            this.rbtnRise.Size = new System.Drawing.Size(59, 16);
+            this.rbtnRise.TabIndex = 12;
+            this.rbtnRise.TabStop = true;
+            this.rbtnRise.Text = "上升沿";
+            this.rbtnRise.UseVisualStyleBackColor = true;
+            // 
+            // rbtnFall
+            // 
+            this.rbtnFall.AutoSize = true;
+            this.rbtnFall.Location = new System.Drawing.Point(130, 24);
+            this.rbtnFall.Name = "rbtnFall";
+            this.rbtnFall.Size = new System.Drawing.Size(59, 16);
+            this.rbtnFall.TabIndex = 12;
+            this.rbtnFall.TabStop = true;
+            this.rbtnFall.Text = "下降沿";
+            this.rbtnFall.UseVisualStyleBackColor = true;
+            // 
+            // gpbHdlcTr
+            // 
+            this.gpbHdlcTr.Controls.Add(this.rbtnFall);
+            this.gpbHdlcTr.Controls.Add(this.rbtnRise);
+            this.gpbHdlcTr.Location = new System.Drawing.Point(166, 590);
+            this.gpbHdlcTr.Name = "gpbHdlcTr";
+            this.gpbHdlcTr.Size = new System.Drawing.Size(203, 50);
+            this.gpbHdlcTr.TabIndex = 13;
+            this.gpbHdlcTr.TabStop = false;
+            // 
+            // gpbUartCheck
+            // 
+            this.gpbUartCheck.Controls.Add(this.rbtnNone);
+            this.gpbUartCheck.Controls.Add(this.rbtnEven);
+            this.gpbUartCheck.Controls.Add(this.rbtnOdd);
+            this.gpbUartCheck.Location = new System.Drawing.Point(166, 646);
+            this.gpbUartCheck.Name = "gpbUartCheck";
+            this.gpbUartCheck.Size = new System.Drawing.Size(203, 50);
+            this.gpbUartCheck.TabIndex = 13;
+            this.gpbUartCheck.TabStop = false;
+            // 
+            // rbtnNone
+            // 
+            this.rbtnNone.AutoSize = true;
+            this.rbtnNone.Location = new System.Drawing.Point(130, 24);
+            this.rbtnNone.Name = "rbtnNone";
+            this.rbtnNone.Size = new System.Drawing.Size(35, 16);
+            this.rbtnNone.TabIndex = 12;
+            this.rbtnNone.TabStop = true;
+            this.rbtnNone.Text = "无";
+            this.rbtnNone.UseVisualStyleBackColor = true;
+            // 
+            // rbtnEven
+            // 
+            this.rbtnEven.AutoSize = true;
+            this.rbtnEven.Location = new System.Drawing.Point(81, 24);
+            this.rbtnEven.Name = "rbtnEven";
+            this.rbtnEven.Size = new System.Drawing.Size(35, 16);
+            this.rbtnEven.TabIndex = 12;
+            this.rbtnEven.TabStop = true;
+            this.rbtnEven.Text = "偶";
+            this.rbtnEven.UseVisualStyleBackColor = true;
+            // 
+            // rbtnOdd
+            // 
+            this.rbtnOdd.AutoSize = true;
+            this.rbtnOdd.Location = new System.Drawing.Point(29, 24);
+            this.rbtnOdd.Name = "rbtnOdd";
+            this.rbtnOdd.Size = new System.Drawing.Size(35, 16);
+            this.rbtnOdd.TabIndex = 12;
+            this.rbtnOdd.TabStop = true;
+            this.rbtnOdd.Text = "奇";
+            this.rbtnOdd.UseVisualStyleBackColor = true;
+            // 
+            // gpbSendMode
+            // 
+            this.gpbSendMode.Controls.Add(this.rbtnHdlcMode);
+            this.gpbSendMode.Controls.Add(this.rbtnUartMode);
+            this.gpbSendMode.Location = new System.Drawing.Point(166, 500);
+            this.gpbSendMode.Name = "gpbSendMode";
+            this.gpbSendMode.Size = new System.Drawing.Size(203, 47);
+            this.gpbSendMode.TabIndex = 13;
+            this.gpbSendMode.TabStop = false;
+            // 
+            // rbtnHdlcMode
+            // 
+            this.rbtnHdlcMode.AutoSize = true;
+            this.rbtnHdlcMode.Location = new System.Drawing.Point(130, 24);
+            this.rbtnHdlcMode.Name = "rbtnHdlcMode";
+            this.rbtnHdlcMode.Size = new System.Drawing.Size(47, 16);
+            this.rbtnHdlcMode.TabIndex = 12;
+            this.rbtnHdlcMode.TabStop = true;
+            this.rbtnHdlcMode.Text = "HDLC";
+            this.rbtnHdlcMode.UseVisualStyleBackColor = true;
+            this.rbtnHdlcMode.CheckedChanged += new System.EventHandler(this.rbtnHdlcMode_CheckedChanged);
+            // 
+            // rbtnUartMode
+            // 
+            this.rbtnUartMode.AutoSize = true;
+            this.rbtnUartMode.Location = new System.Drawing.Point(29, 24);
+            this.rbtnUartMode.Name = "rbtnUartMode";
+            this.rbtnUartMode.Size = new System.Drawing.Size(47, 16);
+            this.rbtnUartMode.TabIndex = 12;
+            this.rbtnUartMode.TabStop = true;
+            this.rbtnUartMode.Text = "UART";
+            this.rbtnUartMode.UseVisualStyleBackColor = true;
+            this.rbtnUartMode.CheckedChanged += new System.EventHandler(this.rbtnUartMode_CheckedChanged);
+            // 
             // DebuggingForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1604, 881);
+            this.ClientSize = new System.Drawing.Size(1028, 749);
+            this.Controls.Add(this.gpbUartCheck);
+            this.Controls.Add(this.gpbSendMode);
+            this.Controls.Add(this.gpbHdlcTr);
             this.Controls.Add(this.btnPcmSendx);
             this.Controls.Add(this.txtbPcmSend);
             this.Controls.Add(this.btnPcmSetting);
@@ -1498,6 +1672,7 @@ namespace Tps_LQ_Transmitter
             this.Controls.Add(this.labelX16);
             this.Controls.Add(this.labelX17);
             this.Controls.Add(this.labelX14);
+            this.Controls.Add(this.labelX33);
             this.Controls.Add(this.labelX8);
             this.Controls.Add(this.labelX13);
             this.Controls.Add(this.labelX7);
@@ -1524,6 +1699,7 @@ namespace Tps_LQ_Transmitter
             this.Controls.Add(this.txtbCurrCh_3);
             this.Controls.Add(this.txtbCurrCh_2);
             this.Controls.Add(this.txtbCurrSetValue);
+            this.Controls.Add(this.txtbBaudrate);
             this.Controls.Add(this.txtbVoltSetValue);
             this.Controls.Add(this.txtbCurrCh_1);
             this.Controls.Add(this.txtbVoltCh_1);
@@ -1548,6 +1724,7 @@ namespace Tps_LQ_Transmitter
             this.Controls.Add(this.chkBxCh_1);
             this.Controls.Add(this.chkAyCh_1);
             this.Controls.Add(this.ChkPowerOnOff);
+            this.Controls.Add(this.checkBoxX1);
             this.Controls.Add(this.chkStCh_1);
             this.Controls.Add(this.btnPowCh_8);
             this.Controls.Add(this.btnPowCh_7);
@@ -1561,6 +1738,12 @@ namespace Tps_LQ_Transmitter
             this.Name = "DebuggingForm";
             this.Text = "DebuggingForm";
             this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.DebuggingForm_FormClosed);
+            this.gpbHdlcTr.ResumeLayout(false);
+            this.gpbHdlcTr.PerformLayout();
+            this.gpbUartCheck.ResumeLayout(false);
+            this.gpbUartCheck.PerformLayout();
+            this.gpbSendMode.ResumeLayout(false);
+            this.gpbSendMode.PerformLayout();
             this.ResumeLayout(false);
 
         }
@@ -1661,5 +1844,18 @@ namespace Tps_LQ_Transmitter
         private DevComponents.DotNetBar.ButtonX btnPcmSetting;
         private DevComponents.DotNetBar.Controls.TextBoxX txtbPcmSend;
         private DevComponents.DotNetBar.ButtonX btnPcmSendx;
+        private DevComponents.DotNetBar.Controls.CheckBoxX checkBoxX1;
+        private DevComponents.DotNetBar.Controls.TextBoxX txtbBaudrate;
+        private DevComponents.DotNetBar.LabelX labelX33;
+        private System.Windows.Forms.RadioButton rbtnRise;
+        private System.Windows.Forms.RadioButton rbtnFall;
+        private System.Windows.Forms.GroupBox gpbHdlcTr;
+        private System.Windows.Forms.GroupBox gpbUartCheck;
+        private System.Windows.Forms.RadioButton rbtnEven;
+        private System.Windows.Forms.RadioButton rbtnOdd;
+        private System.Windows.Forms.RadioButton rbtnNone;
+        private System.Windows.Forms.GroupBox gpbSendMode;
+        private System.Windows.Forms.RadioButton rbtnHdlcMode;
+        private System.Windows.Forms.RadioButton rbtnUartMode;
     }
 }

+ 98 - 3
tps/TpsLabStudio/DebuggingForm.cs

@@ -23,7 +23,8 @@ namespace Tps_LQ_Transmitter
         PcGpio gpio = new PcGpio();
         RainwormPower power = new RainwormPower();
         PcmControl pcm = new PcmControl();
-
+        ThreadStart SeriesPortChildref = null;
+        Thread SeriesPortChildThread = null;
         public DebuggingForm()
         {
             InitializeComponent();
@@ -35,16 +36,38 @@ namespace Tps_LQ_Transmitter
                 dio.SupplySwitch(i, DioControlClass.State.OFF);//将所有供电开关关闭
             }
             power.powerOnoff(RainwormPower.State.OFF);
-            
+            SeriesPortThread();
+        }
+
+        public void SeriesPortThread()
+        {
+
+            SeriesPortChildref = new ThreadStart(Displaywhile);
+            SeriesPortChildThread = new Thread(SeriesPortChildref);
+            SeriesPortChildThread.Start();
         }
         private void DebuggingForm_FormClosed(object sender, FormClosedEventArgs e)
         {
             dio.portClose();
             power.portClose();
+            pcm.portClose();
             
             
         }
+        string tamp="";
+        public void Displaywhile()
+        {
+            string st;
+            while (true)
+            {
+                st = BytesToHexString(pcm.OnlyRead());
+                if (st != "" && st != tamp)
+                {
+                    tamp = st;
+                }
+            }
 
+        }
 
         #region 8路供电开关控制(+28V)代码
         private void btnPowCh_1_Click(object sender, EventArgs e)
@@ -667,7 +690,79 @@ namespace Tps_LQ_Transmitter
 
         private void btnPcmSetting_Click(object sender, EventArgs e)
         {
-            pcm.Setting("UART","ODD",230400);
+            string mode = "UART";
+            string choice = "NONE";
+            int baud = 230400;
+            if (rbtnUartMode.Checked==true && rbtnHdlcMode.Checked==false)
+            {
+                mode = "UART";
+                gpbHdlcTr.Enabled = false;
+                gpbUartCheck.Enabled = true;
+            }
+            else if (rbtnUartMode.Checked == false && rbtnHdlcMode.Checked == true)
+            {
+                mode = "HDLC";
+                gpbHdlcTr.Enabled = true;
+                gpbUartCheck.Enabled = false;
+            }
+
+            if (rbtnRise.Checked == true && rbtnHdlcMode.Checked == true)
+            {
+                choice = "RISE";
+            }
+            else if (rbtnRise.Checked == false && rbtnHdlcMode.Checked == true)
+            {
+                choice = "FALL";
+            }
+
+            if (rbtnOdd.Checked==true && rbtnUartMode.Checked == true)
+            {
+                choice = "ODD";
+            }
+            else if (rbtnEven.Checked==true && rbtnUartMode.Checked == true)
+            {
+                choice = "EVEN";
+            }
+            else if (rbtnNone.Checked==true && rbtnUartMode.Checked == true)
+            {
+                choice = "NONE";
+            }
+            baud = int.Parse(txtbBaudrate.Text);
+            pcm.Setting(mode, choice, baud);
+        }
+
+        private void rbtnUartMode_CheckedChanged(object sender, EventArgs e)
+        {
+            if (rbtnUartMode.Checked == true)
+            {
+                gpbHdlcTr.Enabled = false;
+                gpbUartCheck.Enabled = true;
+                rbtnNone.Checked = true;
+            }
+            else if (rbtnHdlcMode.Checked == true)
+            {
+
+                gpbHdlcTr.Enabled = true;
+                gpbUartCheck.Enabled = false;
+                rbtnRise.Checked = true;
+            }
+        }
+
+        private void rbtnHdlcMode_CheckedChanged(object sender, EventArgs e)
+        {
+            if (rbtnUartMode.Checked == true)
+            {
+                gpbHdlcTr.Enabled = false;
+                gpbUartCheck.Enabled = true;
+                rbtnNone.Checked = true;
+            }
+            else if (rbtnHdlcMode.Checked == true)
+            {
+
+                gpbHdlcTr.Enabled = true;
+                gpbUartCheck.Enabled = false;
+                rbtnRise.Checked = true;
+            }
         }
     }
 }

+ 2 - 5
tps/TpsLabStudio/com/MySerial.cs

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
 
 namespace Tps_LQ_Transmitter.com
 {
-    public class MySerial
+    public class MySerial:SerialPort
     {
         SerialPort serial;
         public bool IsOpen
@@ -109,9 +109,6 @@ namespace Tps_LQ_Transmitter.com
             return crc;
         }
 
-        private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
-        {
-            
-        }
+        
     }
 }

+ 28 - 7
tps/TpsLabStudio/com/PcmControl.cs

@@ -24,6 +24,7 @@ namespace Tps_LQ_Transmitter.com
             serial.Parity = Parity.None;//获取奇偶校验选项的值
             serial.ReadTimeout = 1000;    //读取等待时间1000
             serial.RtsEnable = true;
+            //this.DataReceived += new System.IO.Ports.SerialErrorReceivedEventHandler(this.Serial_DataReceived);
             if (!serial.IsOpen)
             {
                 serial.Open();
@@ -70,6 +71,21 @@ namespace Tps_LQ_Transmitter.com
                 return null;
             }
         }
+
+        public byte[] OnlyRead()
+        {
+            
+            if (serial.BytesToRead > 0)
+            {
+                byte[] dat = new byte[serial.BytesToRead];
+                serial.Read(dat, 0, dat.Length);
+                return dat;
+            }
+            else
+            {
+                return null;
+            }
+        }
         /// <summary>
         /// PCM设置命令发送
         /// </summary>
@@ -80,32 +96,32 @@ namespace Tps_LQ_Transmitter.com
         public bool Setting(string mode,string choice,int baudrate )
         {
             int u = 0;
-            if (mode=="UART")
+            if (mode.ToUpper()=="UART")
             {
                 u = u | 0x01;
             }
-            else if (mode == "HDLC")
+            else if (mode.ToUpper() == "HDLC")
             {
                 u = u | 0x41;
             }
 
-            if (choice == "ODD")//奇校验
+            if (choice.ToUpper() == "ODD")//奇校验
             {
                 u = u | 0x02;
             }
-            else if (choice == "EVEN")//偶校验
+            else if (choice.ToUpper() == "EVEN")//偶校验
             { 
                 u = u | 0x04;
             }
-            else if (choice == "NONE")//无校验
+            else if (choice.ToUpper() == "NONE")//无校验
             {
                 u = u | 0x00;
             }
-            else if (choice == "FALL")//下降沿
+            else if (choice.ToUpper() == "FALL")//下降沿
             {
                 u = u | 0x08;
             }
-            else if (choice == "RISE")//上升沿
+            else if (choice.ToUpper() == "RISE")//上升沿
             {
                 u = u | 0x00;
             }
@@ -183,5 +199,10 @@ namespace Tps_LQ_Transmitter.com
             }
             return bolrd;
         }
+        public void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            //
+            //
+        }
     }
 }

BIN
tps/TpsLabStudio/obj/Debug/DesignTimeResolveAssemblyReferences.cache


BIN
tps/TpsLabStudio/obj/Debug/TpsLabStudio.csproj.GenerateResource.cache


BIN
tps/TpsLabStudio/obj/Debug/Tps_LQ_Transmitter.dll


BIN
tps/TpsLabStudio/obj/Debug/Tps_LQ_Transmitter.pdb