C#输出文字到LED屏幕

解题思路:

1.添加Loaded事件动态获取串口

2.将输入文字推送到LED屏上

界面图效果图:

前台代码: <Label Content="串口号" HorizontalAlignment="Left" Margin="50,31,0,0" VerticalAlignment="Top"/> <ComboBox x:Name="cboPortName" HorizontalAlignment="Left" Margin="123,31,0,0" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.274,3.215"/> <TextBox x:Name="txtLedText" HorizontalAlignment="Left" Height="222" Margin="26,88,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="567"/> <Button x:Name="btnPut" Content="推送" HorizontalAlignment="Left" Margin="504,34,0,0" VerticalAlignment="Top" Width="75" Click="btnPut_Click"/>

后台代码:

1.1 添加Loaded事件动态获取串口

//动态绑定串口 cboPortName.ItemsSource = SerialPort.GetPortNames(); //对串口进行判空,如果非空则选择第一个 if(cboPortName.Items.Count>0) { //默认选择第一个串口
cboPortName.SelectedIndex = 0; }

1.2 将输入文字推送到LED屏上,设置推送Click事件

LEDLibrary.LEDPlayer led = new LEDLibrary.LEDPlayer(cboPortName.Text); led.DisplayText(txtLedText.Text); led.Close();

原文链接:https://blog.csdn.net/weixin_43890904/article/details/89050451