(function(E,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("node:os"),require("koffi")):typeof define=="function"&&define.amd?define(["exports","node:os","koffi"],C):(E=typeof globalThis<"u"?globalThis:E||self,C(E.NiVisa={},E["node:os"],E.koffi))})(this,function(E,C,_){"use strict";var o=(R=>(R[R.VI_SUCCESS_EVENT_EN=1073676290]="VI_SUCCESS_EVENT_EN",R[R.VI_SUCCESS_EVENT_DIS=1073676291]="VI_SUCCESS_EVENT_DIS",R[R.VI_SUCCESS_QUEUE_EMPTY=1073676292]="VI_SUCCESS_QUEUE_EMPTY",R[R.VI_SUCCESS_TERM_CHAR=1073676293]="VI_SUCCESS_TERM_CHAR",R[R.VI_SUCCESS_MAX_CNT=1073676294]="VI_SUCCESS_MAX_CNT",R[R.VI_SUCCESS_DEV_NPRESENT=1073676413]="VI_SUCCESS_DEV_NPRESENT",R[R.VI_SUCCESS_TRIG_MAPPED=1073676414]="VI_SUCCESS_TRIG_MAPPED",R[R.VI_SUCCESS_QUEUE_NEMPTY=1073676416]="VI_SUCCESS_QUEUE_NEMPTY",R[R.VI_SUCCESS_NCHAIN=1073676440]="VI_SUCCESS_NCHAIN",R[R.VI_SUCCESS_NESTED_SHARED=1073676441]="VI_SUCCESS_NESTED_SHARED",R[R.VI_SUCCESS_NESTED_EXCLUSIVE=1073676442]="VI_SUCCESS_NESTED_EXCLUSIVE",R[R.VI_SUCCESS_SYNC=1073676443]="VI_SUCCESS_SYNC",R[R.VI_WARN_QUEUE_OVERFLOW=1073676300]="VI_WARN_QUEUE_OVERFLOW",R[R.VI_WARN_CONFIG_NLOADED=1073676407]="VI_WARN_CONFIG_NLOADED",R[R.VI_WARN_NULL_OBJECT=1073676418]="VI_WARN_NULL_OBJECT",R[R.VI_WARN_NSUP_ATTR_STATE=1073676420]="VI_WARN_NSUP_ATTR_STATE",R[R.VI_WARN_UNKNOWN_STATUS=1073676421]="VI_WARN_UNKNOWN_STATUS",R[R.VI_WARN_NSUP_BUF=1073676424]="VI_WARN_NSUP_BUF",R[R.VI_WARN_EXT_FUNC_NIMPL=1073676457]="VI_WARN_EXT_FUNC_NIMPL",R[R.VI_ERROR_SYSTEM_ERROR=3221159936]="VI_ERROR_SYSTEM_ERROR",R[R.VI_ERROR_INV_OBJECT=3221159950]="VI_ERROR_INV_OBJECT",R[R.VI_ERROR_RSRC_LOCKED=3221159951]="VI_ERROR_RSRC_LOCKED",R[R.VI_ERROR_INV_EXPR=3221159952]="VI_ERROR_INV_EXPR",R[R.VI_ERROR_RSRC_NFOUND=3221159953]="VI_ERROR_RSRC_NFOUND",R[R.VI_ERROR_INV_RSRC_NAME=3221159954]="VI_ERROR_INV_RSRC_NAME",R[R.VI_ERROR_INV_ACC_MODE=3221159955]="VI_ERROR_INV_ACC_MODE",R[R.VI_ERROR_TMO=3221159957]="VI_ERROR_TMO",R[R.VI_ERROR_CLOSING_FAILED=3221159958]="VI_ERROR_CLOSING_FAILED",R[R.VI_ERROR_INV_DEGREE=3221159963]="VI_ERROR_INV_DEGREE",R[R.VI_ERROR_INV_JOB_ID=3221159964]="VI_ERROR_INV_JOB_ID",R[R.VI_ERROR_NSUP_ATTR=3221159965]="VI_ERROR_NSUP_ATTR",R[R.VI_ERROR_NSUP_ATTR_STATE=3221159966]="VI_ERROR_NSUP_ATTR_STATE",R[R.VI_ERROR_ATTR_READONLY=3221159967]="VI_ERROR_ATTR_READONLY",R[R.VI_ERROR_INV_LOCK_TYPE=3221159968]="VI_ERROR_INV_LOCK_TYPE",R[R.VI_ERROR_INV_ACCESS_KEY=3221159969]="VI_ERROR_INV_ACCESS_KEY",R[R.VI_ERROR_INV_EVENT=3221159974]="VI_ERROR_INV_EVENT",R[R.VI_ERROR_INV_MECH=3221159975]="VI_ERROR_INV_MECH",R[R.VI_ERROR_HNDLR_NINSTALLED=3221159976]="VI_ERROR_HNDLR_NINSTALLED",R[R.VI_ERROR_INV_HNDLR_REF=3221159977]="VI_ERROR_INV_HNDLR_REF",R[R.VI_ERROR_INV_CONTEXT=3221159978]="VI_ERROR_INV_CONTEXT",R[R.VI_ERROR_QUEUE_OVERFLOW=3221159981]="VI_ERROR_QUEUE_OVERFLOW",R[R.VI_ERROR_NENABLED=3221159983]="VI_ERROR_NENABLED",R[R.VI_ERROR_ABORT=3221159984]="VI_ERROR_ABORT",R[R.VI_ERROR_RAW_WR_PROT_VIOL=3221159988]="VI_ERROR_RAW_WR_PROT_VIOL",R[R.VI_ERROR_RAW_RD_PROT_VIOL=3221159989]="VI_ERROR_RAW_RD_PROT_VIOL",R[R.VI_ERROR_OUTP_PROT_VIOL=3221159990]="VI_ERROR_OUTP_PROT_VIOL",R[R.VI_ERROR_INP_PROT_VIOL=3221159991]="VI_ERROR_INP_PROT_VIOL",R[R.VI_ERROR_BERR=3221159992]="VI_ERROR_BERR",R[R.VI_ERROR_IN_PROGRESS=3221159993]="VI_ERROR_IN_PROGRESS",R[R.VI_ERROR_INV_SETUP=3221159994]="VI_ERROR_INV_SETUP",R[R.VI_ERROR_QUEUE_ERROR=3221159995]="VI_ERROR_QUEUE_ERROR",R[R.VI_ERROR_ALLOC=3221159996]="VI_ERROR_ALLOC",R[R.VI_ERROR_INV_MASK=3221159997]="VI_ERROR_INV_MASK",R[R.VI_ERROR_IO=3221159998]="VI_ERROR_IO",R[R.VI_ERROR_INV_FMT=3221159999]="VI_ERROR_INV_FMT",R[R.VI_ERROR_NSUP_FMT=3221160001]="VI_ERROR_NSUP_FMT",R[R.VI_ERROR_LINE_IN_USE=3221160002]="VI_ERROR_LINE_IN_USE",R[R.VI_ERROR_LINE_NRESERVED=3221160003]="VI_ERROR_LINE_NRESERVED",R[R.VI_ERROR_NSUP_MODE=3221160006]="VI_ERROR_NSUP_MODE",R[R.VI_ERROR_SRQ_NOCCURRED=3221160010]="VI_ERROR_SRQ_NOCCURRED",R[R.VI_ERROR_INV_SPACE=3221160014]="VI_ERROR_INV_SPACE",R[R.VI_ERROR_INV_OFFSET=3221160017]="VI_ERROR_INV_OFFSET",R[R.VI_ERROR_INV_WIDTH=3221160018]="VI_ERROR_INV_WIDTH",R[R.VI_ERROR_NSUP_OFFSET=3221160020]="VI_ERROR_NSUP_OFFSET",R[R.VI_ERROR_NSUP_VAR_WIDTH=3221160021]="VI_ERROR_NSUP_VAR_WIDTH",R[R.VI_ERROR_WINDOW_NMAPPED=3221160023]="VI_ERROR_WINDOW_NMAPPED",R[R.VI_ERROR_RESP_PENDING=3221160025]="VI_ERROR_RESP_PENDING",R[R.VI_ERROR_NLISTENERS=3221160031]="VI_ERROR_NLISTENERS",R[R.VI_ERROR_NCIC=3221160032]="VI_ERROR_NCIC",R[R.VI_ERROR_NSYS_CNTLR=3221160033]="VI_ERROR_NSYS_CNTLR",R[R.VI_ERROR_NSUP_OPER=3221160039]="VI_ERROR_NSUP_OPER",R[R.VI_ERROR_INTR_PENDING=3221160040]="VI_ERROR_INTR_PENDING",R[R.VI_ERROR_ASRL_PARITY=3221160042]="VI_ERROR_ASRL_PARITY",R[R.VI_ERROR_ASRL_FRAMING=3221160043]="VI_ERROR_ASRL_FRAMING",R[R.VI_ERROR_ASRL_OVERRUN=3221160044]="VI_ERROR_ASRL_OVERRUN",R[R.VI_ERROR_TRIG_NMAPPED=3221160046]="VI_ERROR_TRIG_NMAPPED",R[R.VI_ERROR_NSUP_ALIGN_OFFSET=3221160048]="VI_ERROR_NSUP_ALIGN_OFFSET",R[R.VI_ERROR_USER_BUF=3221160049]="VI_ERROR_USER_BUF",R[R.VI_ERROR_RSRC_BUSY=3221160050]="VI_ERROR_RSRC_BUSY",R[R.VI_ERROR_NSUP_WIDTH=3221160054]="VI_ERROR_NSUP_WIDTH",R[R.VI_ERROR_INV_PARAMETER=3221160056]="VI_ERROR_INV_PARAMETER",R[R.VI_ERROR_INV_PROT=3221160057]="VI_ERROR_INV_PROT",R[R.VI_ERROR_INV_SIZE=3221160059]="VI_ERROR_INV_SIZE",R[R.VI_ERROR_WINDOW_MAPPED=3221160064]="VI_ERROR_WINDOW_MAPPED",R[R.VI_ERROR_NIMPL_OPER=3221160065]="VI_ERROR_NIMPL_OPER",R[R.VI_ERROR_INV_LENGTH=3221160067]="VI_ERROR_INV_LENGTH",R[R.VI_ERROR_INV_MODE=3221160081]="VI_ERROR_INV_MODE",R[R.VI_ERROR_SESN_NLOCKED=3221160092]="VI_ERROR_SESN_NLOCKED",R[R.VI_ERROR_MEM_NSHARED=3221160093]="VI_ERROR_MEM_NSHARED",R[R.VI_ERROR_LIBRARY_NFOUND=3221160094]="VI_ERROR_LIBRARY_NFOUND",R[R.VI_ERROR_NSUP_INTR=3221160095]="VI_ERROR_NSUP_INTR",R[R.VI_ERROR_INV_LINE=3221160096]="VI_ERROR_INV_LINE",R[R.VI_ERROR_FILE_ACCESS=3221160097]="VI_ERROR_FILE_ACCESS",R[R.VI_ERROR_FILE_IO=3221160098]="VI_ERROR_FILE_IO",R[R.VI_ERROR_NSUP_LINE=3221160099]="VI_ERROR_NSUP_LINE",R[R.VI_ERROR_NSUP_MECH=3221160100]="VI_ERROR_NSUP_MECH",R[R.VI_ERROR_INTF_NUM_NCONFIG=3221160101]="VI_ERROR_INTF_NUM_NCONFIG",R[R.VI_ERROR_CONN_LOST=3221160102]="VI_ERROR_CONN_LOST",R[R.VI_ERROR_MACHINE_NAVAIL=3221160103]="VI_ERROR_MACHINE_NAVAIL",R[R.VI_ERROR_NPERMISSION=3221160104]="VI_ERROR_NPERMISSION",R))(o||{});function P(R){const O=o[R];if(O!=null&&!O.startsWith("VI_SUCCESS_")){if(O.startsWith("VI_WARN_")){console.warn(`NI-VISA Warning: ${O} (0x${R.toString(16).toUpperCase()})`);return}if(O.startsWith("VI_ERROR_"))throw new Error(`NI-VISA Error: ${O} (0x${R.toString(16).toUpperCase()})`)}}function a(){const R=C.platform();if(R==="win32")return C.arch()==="x64"?"visa64.dll":"visa32.dll";if(R==="darwin")return"visa.framework/visa";if(R==="linux")return"librsvisa";throw new Error(`Platform '${R}' not supported`)}const V=_.load(a()),I=_.alias("ViUInt32","uint32"),L=_.pointer(I),i=I,N=I,e=I,D=_.pointer(e),W=I,F=_.alias("ViByte","uchar"),f=_.pointer(F),l=V.func("viOpenDefaultRM",i,[_.out(D)]);function B(){const R=Buffer.alloc(4),O=l(R);return P(O),_.decode(R,e)}const d=V.func("viOpen",i,[e,"string",W,I,_.out(D)]);function v(R,O,t=0,n=0){const r=Buffer.alloc(4),s=d(R,O,t,n,r);return P(s),_.decode(r,e)}const H=V.func("viClose",i,[N]);function G(R){const O=H(R);P(O)}const Y=V.func("viWrite",i,[e,"string",I,_.out(L)]);function u(R,O){const t=Buffer.alloc(4),n=Y(R,O,O.length,t);return P(n),_.decode(t,I)}const p=V.func("viRead",i,[e,_.out(f),I,_.out(L)]);function c(R,O=256){const t=Buffer.alloc(O),n=Buffer.alloc(4),r=p(R,t,O,n);P(r);const s=_.decode(n,I);return t.subarray(0,s).toString()}function h(R,O,t=256){if(!O.includes("?"))throw new Error(`Query message must end with '?', but got '${O}'`);return u(R,O),c(R,t)}E.query=h,E.viClose=G,E.viOpen=v,E.viOpenDefaultRM=B,E.viRead=c,E.viWrite=u,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});