【问题标题】:How to display text in row one and row two customer display pole如何在第一行和第二行客户展示杆中显示文字
【发布时间】:2020-01-25 21:49:23
【问题描述】:

正在为一家餐馆开发一个程序,我想要实现的是显示 在第一行购买的商品数量 以及第二行中的总成本,但结果没有按预期出现,请问我错过了什么

Private void DisplayPole(){ SerialPort sp = new SerialPort();
        if (!(Properties.Settings.Default.ComPort == ""))
        {
            using (SerialPort port = new SerialPort(Properties.Settings.Default.ComPort, 9600, Parity.None, 8))
            {
                byte[] bytetosend = new byte[2] { 0x0C, 0x0c };
                port.Open();
                port.Write(bytetosend, 0, 2);
                //port.Write('\0x0C');
            }
            sp.PortName = Properties.Settings.Default.ComPort;
            sp.BaudRate = 9600;
            sp.Parity = Parity.None;
            sp.DataBits = 8;
            sp.StopBits = StopBits.One;
            sp.Open();
            //clear
            //sp.Write(Convert.ToString(chr(12)));
            sp.WriteLine("No of Item: " + lblTotalItem.Text +"\n" + "Total: " + lblTotal.Text);
            sp.Close();
            sp.Dispose();
        }}

【问题讨论】:

  • 你得到的输出是什么?
  • 在显示数据时遇到问题,为什么要发布串口代码?
  • @jdweng 看起来 OP 正在通过串口“打印”到显示杆。
  • 将 WriteLine 分成两条 WriteLine。

标签: c#


【解决方案1】:

WriteLine

WriteLine(字符串、对象、对象)

使用指定的格式信息将指定对象的文本表示形式(后跟当前行终止符)写入标准输出流。

 sp.WriteLine("No of Item: " + lblTotalItem.Text );
 sp.WriteLIne("Total: " + lblTotal.Text);

默认的行终止符是一个字符串,它的值是一个回车后跟一个换行符(“\r\n”)。

你也可以使用

sp.WriteLine("No of Item: " + lblTotalItem.Text + "\r\n" + "Total: " + lblTotal.Text);

【讨论】:

  • 感谢它运行良好,现在一切正常,我真的很感激
猜你喜欢
  • 2022-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 1970-01-01
相关资源
最近更新 更多