https://github.com/shubham0x13/serialportwatcher
Detect serial port connection and disconnection events in Windows using WMI and C#.
https://github.com/shubham0x13/serialportwatcher
c-sharp serialport serialport-events watcher
Last synced: 3 months ago
JSON representation
Detect serial port connection and disconnection events in Windows using WMI and C#.
- Host: GitHub
- URL: https://github.com/shubham0x13/serialportwatcher
- Owner: shubham0x13
- License: mit
- Created: 2024-07-14T10:43:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-15T06:27:45.000Z (about 1 year ago)
- Last Synced: 2025-05-29T10:26:21.913Z (4 months ago)
- Topics: c-sharp, serialport, serialport-events, watcher
- Language: C#
- Homepage:
- Size: 8.79 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SerialPortWatcher
[](LICENSE)
Detects serial port connection and disconnection events in Windows using WMI (Windows Management Instrumentation). This library monitors serial port availability in real-time, enabling dynamic response to new port connections and disconnections.
## Installation
Install the NuGet package from [here](https://www.nuget.org/packages/SerialPortWatcher).## Usage/Examples
Here's an example of how to use `SerialPortWatcher` in your application:
```cs
namespace SerialPortWatcher.Example
{
internal class Program
{
static void Main(string[] args)
{
SerialPortEventWatcher serialPortEventWatcher = new SerialPortEventWatcher();
serialPortEventWatcher.PortConnected += SerialPortEventWatcher_PortConnected;
serialPortEventWatcher.PortDisconnected += SerialPortEventWatcher_PortDisconnected;
serialPortEventWatcher.Start();Console.WriteLine("Watching Serial Port Connect/Disconnect Events.");
Console.ReadKey();serialPortEventWatcher.Stop();
serialPortEventWatcher.Dispose();
}private static void SerialPortEventWatcher_PortConnected(object? sender, SerialPortWatcherEventArgs e)
{
Console.WriteLine($"Serial Port Connected : {e.PortName}.");
}
private static void SerialPortEventWatcher_PortDisconnected(object? sender, SerialPortWatcherEventArgs e)
{
Console.WriteLine($"Serial Port Disconnected : {e.PortName}.");
}
}
}
```