Created
October 23, 2017 09:56
-
-
Save misternay/e1723b14f29c392dd327aa8e5cf8e363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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