Skip to content

Instantly share code, notes, and snippets.

@misternay
Created October 23, 2017 09:56
Show Gist options
  • Save misternay/e1723b14f29c392dd327aa8e5cf8e363 to your computer and use it in GitHub Desktop.
Save misternay/e1723b14f29c392dd327aa8e5cf8e363 to your computer and use it in GitHub Desktop.
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 < 10; i++)
{//Loop เพื่ออ่านค่า
Console.WriteLine(i + "\t\t\t" + port.ReadLine());//ReadLine ใช้สำหรับอ่านค่านะครับ
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment