Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO.Ports;
- namespace ArduinoSensor_Writter
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] ports = SerialPort.GetPortNames();
- List<string> portlist = new List<string>(ports);
- Console.WriteLine("Available COM ports:\n");
- PrintArray(portlist);
- String input = Console.ReadLine();
- if (portlist.Contains(input))
- {
- Print("\nConnecting to COM PORT:" + input);
- OpenCOM(input);
- } else
- {
- Print("Sorry... exiting");
- Console.ReadKey();
- }
- }
- private static void OpenCOM(String COM, int BaudRate = 9600)
- {
- // try ? lel fuck mifdsgsnhsdhgfa just do it
- SerialPort mySerialPort = new SerialPort(COM);
- mySerialPort.BaudRate = BaudRate;
- mySerialPort.Open();
- while (true)
- {
- string data = mySerialPort.ReadLine();
- Print(data);
- data = data + "\n";
- System.IO.File.AppendAllText("WriteText.txt", data);
- }
- }
- private static void PrintArray(List<string> arr)
- {
- arr.ForEach(delegate (String name) {
- Console.WriteLine(name);
- });
- }
- private static void Print(String s)
- {
- Console.WriteLine(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement