static SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); //定义一个串口类的串口变量 #endregion Fields #region Methods static void Main(string[] args) { Menu menu = new Menu("串口通信示例"); menu.AddCommand("status", new Function(ShowStatus)); menu.AddCommand("switch", new Function(SwitchPort)); menu.AddCommand("set", new Function(SetPort)); menu.AddCommand("send", new Function(SendData)); menu.Start(); }
internal static IEnumerable<IMenu> ToMenuList(this IEnumerable<IMenuItem> menuItems, string instructionalText, int maxAllowed = Menu.MaxOnScreen) { var source = menuItems.ToNumberedMenuItems(maxAllowed).ToList(); var currentMenu = new Menu(instructionalText); foreach (var menuItem in source) { currentMenu.AddMenuItem(menuItem); if (menuItem.IsMore) { yield return currentMenu; currentMenu = new Menu(instructionalText); } } if (!source.Last().IsMore) { yield return currentMenu; } }