Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.IO.Ports;
- using System.Threading;
- using System.Reflection;
- namespace Scratchpad
- {
- class gpsTest
- {
- SerialPort gpsPort;
- public gpsTest()
- {
- gpsPort = new SerialPort();
- if (gpsPort != null)
- {
- gpsPort.ReadTimeout = 2000;
- gpsPort.BaudRate = 9600;
- }
- }
- internal bool openPort(string _portName, ref string error)
- {
- error = string.Empty;
- bool opened = false;
- gpsPort.PortName = _portName;
- try
- {
- if (!gpsPort.IsOpen)
- {
- //ndl_gps.SerialPortFixer.Execute(gpsPort.PortName);
- gpsPort.Open();
- opened = true;
- }
- }
- catch (Exception ex)
- {
- error = ex.Message;
- }
- return opened;
- }
- internal bool closePort()
- {
- bool closed = false;
- try
- {
- if (gpsPort.IsOpen)
- {
- gpsPort.Close();
- closed = true;
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- return closed;
- }
- public List<string> findAvailablePorts()
- {
- List<string> ports = new List<string>();
- foreach (string str in SerialPort.GetPortNames())
- ports.Add(str);
- return ports;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement