public static void SendStringToCustomerDisplay(string displayLine1, string displayLine2, GodSerialPort serialPort)
        {
            serialPort.ClearScreen();

            serialPort.SetCursorToLine(Line.One);
            serialPort.WriteAsciiString(displayLine1);

            serialPort.SetCursorToLine(Line.Two);
            serialPort.WriteAsciiString(displayLine2);

            serialPort.Close();
        }
Example #2
0
 /// <summary>
 /// 发送Ascii字符串
 /// </summary>
 /// <param name="str"></param>
 public void WriteAsciiString(string str)
 {
     if (null != _port && _port.IsOpen)
     {
         _port.WriteAsciiString(str);
     }
     else
     {
         throw new Exception("请先打开串口");
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            Console.Write("input serialport name:");
            string read = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(read))
            {
                Exit();
            }

            GodSerialPort gsp = new GodSerialPort(x => {
                x.PortName = read;
            });

            gsp.UseDataReceived(true, (sp, bytes) => {
                if (bytes != null && bytes.Length > 0)
                {
                    string buffer = string.Join(" ", bytes);
                    Console.WriteLine("receive data:" + buffer);
                }
            });

            bool flag = gsp.Open();

            if (!flag)
            {
                Exit();
            }

            Console.WriteLine("serialport opend");

            Console.WriteLine("press any thing as data to send,press key 'q' to quit.");

            string data = null;

            while (data == null || data.ToLower() != "q")
            {
                if (!string.IsNullOrEmpty(data))
                {
                    Console.WriteLine("send data:" + data);
                    gsp.WriteAsciiString(data);
                }
                data = Console.ReadLine();
            }
        }
Example #4
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            Console.Write("input serialport number(only 0-9):");
            string read = Console.ReadLine();
            bool   flag = uint.TryParse(read, out uint num);

            if (!flag)
            {
                Exit();
            }

            GodSerialPort gsp = new GodSerialPort("COM" + num, 9600);

            gsp.UseDataReceived((bytes) => {
                if (bytes != null && bytes.Length > 0)
                {
                    string buffer = string.Join(" ", bytes);
                    Console.WriteLine("receive data:" + buffer);
                }
            });
            flag = gsp.Open();

            if (!flag)
            {
                Exit();
            }

            Console.WriteLine("serialport opend");

            Console.WriteLine("press any thing as data to send,press key 'q' to quit.");

            string data = null;

            while (data == null || data.ToLower() != "q")
            {
                if (!string.IsNullOrEmpty(data))
                {
                    Console.WriteLine("send data:" + data);
                    gsp.WriteAsciiString(data);
                }
                data = Console.ReadLine();
            }
        }