首页

c# WPF串口模拟自动生成数据

c#

2020-9-7

向串口自动发送数据,正弦,随机,直线等数据


private void sendDataAuto()
        {
            //bool isBusy=false;
            int i = 0;
            Random random = new Random();
            string senddataType = "";
            DateTime time = DateTime.Now;
            while (true)
            {
                if (isSend)
                {
                    Thread.Sleep(interval);
                    try
                    {
                        cbCurveType.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            senddataType=cbCurveType.Text;
                            
                        }));
                        if (senddataType!=""&&senddataType!=null)
                        {
                            switch (senddataType)
                            {
                                case "自增":
                                    SendCommand(i "\r\n");
                                    if (i==100)
                                    {
                                        i = 0;
                                    }
                                    break;
                                case "100以内随机数":
                                    SendCommand(random.Next(100) "\r\n");
                                    break;
                                case "正弦":
                                    TimeSpan ts=DateTime.Now - time;
                                    SendCommand(((float)Math.Sin(ts.TotalMilliseconds*0.001)*50 50) "\r\n");
                                    break;
                            }
                        }
                        
                        
                    }
                    catch (Exception ex)
                    {
                        //isBusy = true;
                        MessageBox.Show("发送数据错误");
                        //MessageBox.Show("发送数据错误:" ex.ToString());
                        break;
                    }

                    
                }
               
            }

资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
SerialPortSendAuto/SerialPortSendAuto/App.config , 187
SerialPortSendAuto/SerialPortSendAuto/App.xaml , 329
SerialPortSendAuto/SerialPortSendAuto/App.xaml.cs , 345
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.exe , 150016
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.exe.config , 187
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.pdb , 34304
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.vshost.exe , 22984
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.vshost.exe.config , 187
SerialPortSendAuto/SerialPortSendAuto/bin/Debug/SerialPortSendAuto.vshost.exe.manifest , 490
SerialPortSendAuto/SerialPortSendAuto/Circle.ico , 67646
SerialPortSendAuto/SerialPortSendAuto/MainWindow.xaml , 1610
SerialPortSendAuto/SerialPortSendAuto/MainWindow.xaml.cs , 6931
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/App.g.cs , 2342
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/App.g.i.cs , 2342
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 7152
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/MainWindow.baml , 1936
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/MainWindow.g.cs , 6150
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/MainWindow.g.i.cs , 6150
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.csproj.FileListAbsolute.txt , 1337
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.csproj.GenerateResource.Cache , 917
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.csprojResolveAssemblyReference.cache , 2352
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.exe , 150016
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.g.resources , 69848
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.pdb , 34304
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto.Properties.Resources.resources , 180
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto_Content.g.i.cs , 522
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto_MarkupCompile.cache , 309
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/SerialPortSendAuto_MarkupCompile.i.cache , 308
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs , 0
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs , 0
SerialPortSendAuto/SerialPortSendAuto/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs , 0
SerialPortSendAuto/SerialPortSendAuto/Properties/AssemblyInfo.cs , 2189
SerialPortSendAuto/SerialPortSendAuto/Properties/Resources.Designer.cs , 2888
SerialPortSendAuto/SerialPortSendAuto/Properties/Resources.resx , 5612
SerialPortSendAuto/SerialPortSendAuto/Properties/Settings.Designer.cs , 1105
SerialPortSendAuto/SerialPortSendAuto/Properties/Settings.settings , 201
SerialPortSendAuto/SerialPortSendAuto/SerialPortSendAuto.csproj , 4593
SerialPortSendAuto/SerialPortSendAuto.sln , 944
SerialPortSendAuto/SerialPortSendAuto.v11.suo , 56832
没有账号? 忘记密码?

社交账号快速登录