Skip to content

Commit 394bf7c

Browse files
authored
Merge pull request #9 from lachlanm-git/port-info-windows
[Windows] add support for port information
2 parents ed06f7a + cb6586f commit 394bf7c

File tree

3 files changed

+399
-1
lines changed

3 files changed

+399
-1
lines changed

build.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ pub fn build(b: *std.build.Builder) void {
2525
});
2626
list_exe.addModule("serial", serial_mod);
2727
b.installArtifact(list_exe);
28+
29+
// TODO: Linux and MacOS port info support
30+
const os_tag = list_exe.target_info.target.os.tag;
31+
if (os_tag == .windows) {
32+
const port_info_exe = b.addExecutable(.{
33+
.name = "serial-list-info",
34+
.root_source_file = .{ .path = "examples/list_port_info.zig" },
35+
.target = target,
36+
.optimize = optimize,
37+
});
38+
port_info_exe.addModule("serial", serial_mod);
39+
b.installArtifact(port_info_exe);
40+
}
2841
}

examples/list_port_info.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const std = @import("std");
2+
const zig_serial = @import("serial");
3+
4+
pub fn main() !u8 {
5+
var iterator = try zig_serial.list_info();
6+
defer iterator.deinit();
7+
8+
while (try iterator.next()) |info| {
9+
std.debug.print("\nPort name: {s}\n", .{info.port_name});
10+
std.debug.print(" - System location: {s}\n", .{info.system_location});
11+
std.debug.print(" - Friendly name: {s}\n", .{info.friendly_name});
12+
std.debug.print(" - Description: {s}\n", .{info.description});
13+
std.debug.print(" - Manufacturer: {s}\n", .{info.manufacturer});
14+
std.debug.print(" - Serial #: {s}\n", .{info.serial_number});
15+
std.debug.print(" - HW ID: {s}\n", .{info.hw_id});
16+
std.debug.print(" - VID: 0x{X:0>4} PID: 0x{X:0>4}\n", .{ info.vid, info.pid });
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)