From 7005210fcc77668dafc5a5a48b809dfe3cedb0f1 Mon Sep 17 00:00:00 2001 From: esarver Date: Wed, 9 Oct 2024 13:47:51 -0400 Subject: [PATCH] Remove USBTMC (#27) --- Cargo.lock | 235 ++++++++++--------------------- Cargo.toml | 2 - src/error.rs | 16 --- src/interface/connection_addr.rs | 6 - src/interface/mod.rs | 1 - src/interface/usbtmc.rs | 188 ------------------------- src/lib.rs | 2 +- 7 files changed, 77 insertions(+), 373 deletions(-) delete mode 100644 src/interface/usbtmc.rs diff --git a/Cargo.lock b/Cargo.lock index ef294f3..8fbb2c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -52,9 +52,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -89,12 +89,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "bytes" version = "1.7.2" @@ -103,9 +97,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.21" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -231,9 +225,9 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -241,33 +235,33 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", "futures-io", @@ -292,9 +286,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "h2" @@ -317,9 +311,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "hermit-abi" @@ -363,9 +357,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "hyper" @@ -422,9 +416,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -435,7 +429,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", "tower-service", "tracing", ] @@ -475,9 +468,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", @@ -485,9 +478,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "itoa" @@ -512,21 +505,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libusb1-sys" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da050ade7ac4ff1ba5379af847a10a10a8e284181e060105bf8d86960ce9ce0f" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "linux-raw-sys" @@ -606,7 +587,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -653,23 +634,23 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "openssl" @@ -694,7 +675,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -751,7 +732,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -763,26 +744,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.77", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -797,9 +758,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "predicates" @@ -838,9 +799,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -871,9 +832,9 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", @@ -949,16 +910,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "rusb" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9f9ff05b63a786553a4c02943b74b34a988448671001e9a27e2f0565cc05a4" -dependencies = [ - "libc", - "libusb1-sys", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -980,9 +931,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.13" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", "rustls-pki-types", @@ -993,19 +944,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64", "rustls-pki-types", ] [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" @@ -1043,9 +993,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -1065,9 +1015,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -1090,7 +1040,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1196,9 +1146,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -1237,9 +1187,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -1256,22 +1206,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1289,16 +1239,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tmc" -version = "0.1.1" -source = "git+https://github.com/esarver/rusb-usbtmc#0ed58c406a9ec7f1c48672a74531d8cd70957ac7" -dependencies = [ - "byteorder", - "rusb", - "thiserror", -] - [[package]] name = "tokio" version = "1.40.0" @@ -1356,36 +1296,15 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.21" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -1411,7 +1330,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1442,20 +1361,18 @@ dependencies = [ "phf", "reqwest", "rpassword", - "rusb", "serde", "serde_json", "thiserror", - "tmc", "tracing", "visa-rs", ] [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" @@ -1569,7 +1486,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -1603,7 +1520,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1813,9 +1730,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 3ba4040..90cb279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,7 @@ rpassword = "7" serde = { version = "1", features = ["derive"] } serde_json = "1" thiserror = "1" -tmc = { git = "https://github.com/esarver/rusb-usbtmc" } tracing = { version = "0.1", features = ["async-await"] } -rusb = "0.9" chrono = "0.4" minidom = "0.15" reqwest = { version = "0.12", features = ["blocking"] } diff --git a/src/error.rs b/src/error.rs index bc5a97d..106048e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -92,13 +92,6 @@ pub enum InstrumentError { source: ParseIntError, }, - /// An error with communicating through rusb to the instrument - #[error("rusb error: {source}")] - RusbError { - #[from] - source: rusb::Error, - }, - /// The TSP error that was received from the instrument was malformed. #[error("unable to parse TSP error from instrument {error}")] TspErrorParseError { @@ -106,15 +99,6 @@ pub enum InstrumentError { error: String, }, - /// Converts a [`tmc::TMCError`] to a [`TeaspoonInterfaceError`] - #[error("USBTMC error: {source}")] - TmcError { - /// The [`tmc::TMCError`] from which this [`TeaspoonInterfaceError::TmcError`] - /// was derived. - #[from] - source: tmc::TMCError, - }, - /// The queried instrument returned an unknown model number #[error("\"{model}\" is not a recognized model number")] UnknownInstrumentModel { diff --git a/src/interface/connection_addr.rs b/src/interface/connection_addr.rs index d68b2f2..00b044e 100644 --- a/src/interface/connection_addr.rs +++ b/src/interface/connection_addr.rs @@ -1,8 +1,6 @@ use std::fmt::Display; use std::net::SocketAddr; -use crate::interface::usbtmc::UsbtmcAddr; - #[cfg(feature = "visa")] use visa_rs::VisaString; @@ -18,9 +16,6 @@ pub enum ConnectionAddr { /// a port for the connection. Lan(SocketAddr), - /// A USBTMC connection is created with a [`UsbtmcAddr`]. - Usbtmc(UsbtmcAddr), - #[cfg(feature = "visa")] /// A VISA resource string Visa(VisaString), @@ -33,7 +28,6 @@ impl Display for ConnectionAddr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { Self::Lan(lan_info) => lan_info.to_string(), - Self::Usbtmc(usb_info) => usb_info.to_string(), #[cfg(feature = "visa")] Self::Visa(visa_info) => visa_info.to_string(), diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 76934ed..e003c4e 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -12,7 +12,6 @@ use std::{ pub mod async_stream; pub mod connection_addr; -pub mod usbtmc; /// Defines a marker trait that we will implement on each device interface pub trait Interface: NonBlock + Read + Write + Info {} diff --git a/src/interface/usbtmc.rs b/src/interface/usbtmc.rs deleted file mode 100644 index cc3ce67..0000000 --- a/src/interface/usbtmc.rs +++ /dev/null @@ -1,188 +0,0 @@ -use std::{ - fmt::Display, - hash::Hash, - io::{ErrorKind, Read, Write}, - str::FromStr, - time::Duration, -}; - -use rusb::{Context, DeviceList}; -use tmc::InstrumentHandle; - -use crate::{ - error::Result, - instrument::{info::InstrumentInfo, Info}, - interface, - interface::NonBlock, - InstrumentError, -}; - -const KEITHLEY_VID: u16 = 0x05e6; - -/// An address representing how to connect to a USBTMC device. -#[allow(clippy::module_name_repetitions)] -#[derive(Debug, Clone)] -pub struct UsbtmcAddr { - pub device: rusb::Device, - pub model: String, - pub serial: String, -} - -impl Hash for UsbtmcAddr { - fn hash(&self, state: &mut H) { - format!("{}:{}:{}", "USB", self.model, self.serial).hash(state); - } -} - -impl Eq for UsbtmcAddr {} - -impl PartialEq for UsbtmcAddr { - fn eq(&self, other: &Self) -> bool { - self.serial == other.serial && self.model == other.model - } -} - -impl Display for UsbtmcAddr { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "USB:{}:{}", self.model, self.serial) - } -} - -impl FromStr for UsbtmcAddr { - type Err = InstrumentError; - - fn from_str(s: &str) -> std::result::Result { - //USB:2450:01234567 - let split: Vec<&str> = s.split(':').collect(); - if split.len() != 3 { - return Err(InstrumentError::AddressParsingError { - unparsable_string: s.to_string(), - }); - } - - let (ix, model, serial) = (split[0], split[1], split[2]); - - if ix.trim() != "USB" { - return Err(InstrumentError::AddressParsingError { - unparsable_string: s.to_string(), - }); - } - let context = rusb::Context::new()?; - for device in DeviceList::new_with_context(context)?.iter() { - let desc = device.device_descriptor()?; - if desc.vendor_id() == KEITHLEY_VID - && desc.product_id() == u16::from_str_radix(model, 16)? - { - let handle = device.open()?; - let languages = handle.read_languages(Duration::from_millis(100))?; - let Some(language) = languages.first() else { - continue; - }; - let sn = handle.read_serial_number_string( - *language, - &desc, - Duration::from_millis(100), - )?; - if *serial == sn { - return Ok(Self { - device, - model: model.to_string(), - serial: serial.to_string(), - }); - } - } - } - - Err(InstrumentError::ConnectionError { - details: format!( - "USB device with model '{model}' and serial number '{serial}' could not be found" - ), - }) - } -} - -#[derive(Debug)] -pub struct Stream { - handle: InstrumentHandle, - nonblocking: bool, -} - -impl TryFrom for Stream { - type Error = InstrumentError; - - fn try_from(addr: UsbtmcAddr) -> std::result::Result { - Ok(Self { - handle: tmc::Instrument::new(addr.device)? - .ok_or(InstrumentError::ConnectionError { - details: "unable to connect to USB instrument".to_string(), - })? - .open()?, - nonblocking: false, - }) - } -} - -impl TryFrom> for Stream { - type Error = InstrumentError; - fn try_from(handle: InstrumentHandle) -> std::result::Result { - Ok(Self { - handle, - nonblocking: false, - }) - } -} - -impl NonBlock for Stream { - fn set_nonblocking(&mut self, enable: bool) -> Result<()> { - self.nonblocking = enable; - Ok(()) - } -} - -impl Write for Stream { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.handle.write_raw(buf)?; - Ok(buf.len()) - } - - fn flush(&mut self) -> std::io::Result<()> { - //Nothing to force-flush on USBTMC, handled by `write_raw` above - Ok(()) - } -} - -impl Info for Stream { - // write all methods for Info trait here - fn info(&mut self) -> Result { - //get_info(self) - todo!("TODO implement info for Stream") - } -} - -impl Read for Stream { - fn read(&mut self, buf: &mut [u8]) -> std::io::Result { - let message_available = if self.nonblocking { - self.handle.read_stb(Some(Duration::from_millis(10)))? - } else { - while !self.handle.read_stb(Some(Duration::from_millis(10)))? {} - true - }; - - if message_available { - let msg = self.handle.read_raw(Some(match u32::try_from(buf.len()) { - Ok(v) => v, - Err(e) => { - return Err(std::io::Error::new( - ErrorKind::Other, - format!("buffer larger than can be read: {e}"), - )); - } - }))?; - msg.take(buf.len() as u64).read(buf) - } else { - Ok(0) - } - } -} - -impl interface::Interface for Stream {} diff --git a/src/lib.rs b/src/lib.rs index 308eb24..a888b06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ pub(crate) mod test_util; pub use error::InstrumentError; pub use instrument::firmware::Flash; -pub use interface::{connection_addr::ConnectionAddr, usbtmc, Interface}; +pub use interface::{connection_addr::ConnectionAddr, Interface}; pub use model::{ki2600, tti, versatest}; pub mod protocol;