Guest User

Untitled

a guest
Oct 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.IO.Ports;
  3. namespace ConsoleApplication2
  4. {
  5. class Program
  6. {
  7. //public static string[] ports;
  8. public static SerialPort port;
  9. static void Main(string[] args)
  10. {
  11. //ports = SerialPort.GetPortNames(); ;//เก็บพอร์ตที่เชื่อมต่อนะครับ//ใช้สำหรับ Form
  12. port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);//ตรง com4 ใส่ port ของตัวเองนะครับ
  13. // port.DataReceived += port_Data; //ใช้สำหรับ Command
  14. port.Open();
  15. for (int i = 0; i < 100; i++)
  16. {//Loop เพื่ออ่านค่า
  17. port.WriteLine(Console.ReadLine());//สำหรับใส่ Input นะครับ
  18. Console.WriteLine(i + "\t\t\t" + port.ReadLine());//ReadLine ใช้สำหรับอ่านค่านะครับ
  19. }
  20. port.Close();
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment