The Labjack API provided by ljacklm is, quite frankly, dog doodoo. I say this as disrespectfully as possible. A lot of the API calls take specific (implictly sized) arrays that must be 0-filled just so the API can loop over them and fill them with a different number. Everything parameter is either long or a float (and I think the use of long is a carryover from the insane Win32 ABI where long is a 32 bit integer rather than 64 bit, which it is on most Posix platforms). The functions have a tendency to do 15 different things in a single call, and most of the function parameters are out parameters or even better, inout parameters. Some functions take arrays where other ones require the user to manually bitpack an integer. I've got the source for it right here and could rewrite it, but I don't hate myself enough to do that. The API surface I need is minimal, so I've just wrapped the parts I will be using. Ideally I will not need to touch this again, but it does still need to be tested with actual hardware, so we're not out of the woods yet.
26 lines
803 B
Zig
26 lines
803 B
Zig
const std = @import("std");
|
|
|
|
const ljack = @import("./ljacklm.zig");
|
|
|
|
pub fn main() !void {
|
|
const ver = ljack.getDriverVersion();
|
|
std.debug.print("Driver version: {d}\n", .{ver});
|
|
|
|
const device = ljack.Labjack.autodetect();
|
|
|
|
const in = try device.analogReadOne(.{ .channel = .diff_01, .gain = 2 });
|
|
std.debug.print("Read voltage: {d}. Overvolt: {}\n", .{ in.voltage, in.over_voltage });
|
|
try device.digitalWriteOne(.{ .channel = .{ .io = 0 }, .level = true });
|
|
|
|
const sample = try device.readAnalogWriteDigital(
|
|
2,
|
|
.{ .{ .channel = .diff_01, .gain = 2 }, .{ .channel = .diff_23, .gain = 2 } },
|
|
.{false} ** 4,
|
|
true,
|
|
);
|
|
|
|
for (sample, 0..) |input, idx| {
|
|
std.debug.print(" channel {d}: {d} V\n", .{ idx, input.voltage });
|
|
}
|
|
}
|