Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO.Ports;
- namespace ConsoleApplication2
- {
- class Program
- {
- //public static string[] ports;
- public static SerialPort port;
- static void Main(string[] args)
- {
- //ports = SerialPort.GetPortNames(); ;//เก็บพอร์ตที่เชื่อมต่อนะครับ//ใช้สำหรับ Form
- port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);//ตรง com4 ใส่ port ของตัวเองนะครับ
- // port.DataReceived += port_Data; //ใช้สำหรับ Command
- port.Open();
- for (int i = 0; i < 100; i++)
- {//Loop เพื่ออ่านค่า
- port.WriteLine(Console.ReadLine());//สำหรับใส่ Input นะครับ
- Console.WriteLine(i + "\t\t\t" + port.ReadLine());//ReadLine ใช้สำหรับอ่านค่านะครับ
- }
- port.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment