Memindahkan fungsi komputer meja ke sini
This commit is contained in:
1 parent
f2dcab4ca4
commit
9acba79ec4
2 files changed
+23
-2
No files matched your search
@@ -21,6 +21,7 @@ debug = false
|
|||||||
tauri = { version = "2.11.5" }
|
tauri = { version = "2.11.5" }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
|
serialport = "4.9.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-plugin = { version = "2.6.3", features = ["build"] }
|
tauri-plugin = { version = "2.6.3", features = ["build"] }
|
||||||
+22
-2
@@ -1,3 +1,5 @@
|
|||||||
|
use std::{mem, time::Duration};
|
||||||
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tauri::{AppHandle, Runtime, plugin::PluginApi};
|
use tauri::{AppHandle, Runtime, plugin::PluginApi};
|
||||||
|
|
||||||
@@ -15,10 +17,28 @@ pub struct Bluclas<R: Runtime>(AppHandle<R>);
|
|||||||
|
|
||||||
impl<R: Runtime> Bluclas<R> {
|
impl<R: Runtime> Bluclas<R> {
|
||||||
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasResponDaftarPerangkat> {
|
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasResponDaftarPerangkat> {
|
||||||
return Ok(SBlueclasResponDaftarPerangkat { data: vec![] });
|
let port = serialport::available_ports().unwrap_or(Vec::new());
|
||||||
|
let mut daftar_res: Vec<SDaftarPerangkatBlueclasResponDaftarPerangkat> = Vec::new();
|
||||||
|
for i in port {
|
||||||
|
let res = SDaftarPerangkatBlueclasResponDaftarPerangkat {
|
||||||
|
nama: i.port_name.clone(),
|
||||||
|
alamat: i.port_name,
|
||||||
|
};
|
||||||
|
daftar_res.push(res);
|
||||||
|
}
|
||||||
|
return Ok(SBlueclasResponDaftarPerangkat { data: daftar_res });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kirim(&self, _: SBlueclasMuatanKirim) -> crate::Result<()> {
|
pub fn kirim(&self, muatan: SBlueclasMuatanKirim) -> crate::Result<()> {
|
||||||
|
let mut pencetak = match serialport::new(&muatan.alamat, 9600)
|
||||||
|
.timeout(Duration::from_secs(4))
|
||||||
|
.open()
|
||||||
|
{
|
||||||
|
Ok(it) => it,
|
||||||
|
Err(_) => return Ok(()),
|
||||||
|
};
|
||||||
|
pencetak.write(&muatan.data).unwrap();
|
||||||
|
mem::drop(pencetak);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user