Created
October 23, 2017 10:16
-
-
Save misternay/6d02422c41dfb748d1d90c3472183533 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 < 100; i++) | |
{//Loop เพื่ออ่านค่า | |
port.WriteLine(Console.ReadLine());//สำหรับใส่ Input นะครับ | |
Console.WriteLine(i + "\t\t\t" + port.ReadLine());//ReadLine ใช้สำหรับอ่านค่านะครับ | |
} | |
port.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment