You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey everyone, I'm new to Rust and Tauri. I'm currently working on a kiosk machine project that involves integrating a bank card reader. I have a Nuxt3 frontend and a Tauri backend. In my Tauri backend, I'm loading a DLL that contains comm_open and enter_card functions. However, when I call these functions, the app becomes unresponsive, and the card reader waits for user input. Eventually, the app crashes when a credit card is inserted into the card reader, giving error code 3221225477. I suspect it's a memory issue. How can I handle this? Thanks in advance!
#[tauriCommand]asyncfnopen_comm(window:Window,port:String){let port = Arc::new(port);let(tx, rx) = mpsc::sync_channel(1);// Use sync_channel with a buffer size of 1let port_clone = Arc::clone(&port);let tx_clone = tx.clone();let handle = thread::spawn(move || {info!("Thread started");let result = std::panic::catch_unwind(|| {unsafe{let dll = matchLibrary::new("M100_DLL.dll"){Ok(dll) => dll,Err(e) => {error!("Failed to load DLL: {}", e);return;}};let port_name = matchCString::new(port_clone.as_str()){Ok(port_name) => port_name,Err(e) => {error!("Failed to create CString: {}", e);return;}};let open_comm_fn:Symbol<unsafeextern"C"fn(*const libc::c_char) -> i32> = dll
.get(b"M100_CommOpen").expect("Failed to load M100_CommOpen function");let enter_card:Symbol<unsafeextern"C"fn(i32,u8,u8) -> i32> = dll
.get(b"M100_EnterCard").expect("Failed to load M100_EnterCard function");let port_open = open_comm_fn(port_name.as_ptr());if port_open == 0{error!("Failed to open communication port");return;}let enter_card_result = enter_card(port_open,0x30,0);info!("M100_EnterCard result: {}", enter_card_result);
tx_clone.send(()).unwrap();}});ifletErr(err) = result {error!("Thread panicked: {:?}", err);// You can also use `tx_clone.send(Err(err))` to send the error back to the main threadreturn;}});let timeout = Duration::from_secs(10);// Set a timeout of 10 secondsmatch rx.recv_timeout(timeout){Ok(track_data) => {// Emit the data to the frontendletmut progress = 0;
window.emit("card-enter",Payload{ progress }).unwrap();}Err(e) => {error!("Failed to receive data from thread: {}", e);}}// Join the thread to ensure it finishes execution
handle.join().unwrap();}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone, I'm new to Rust and Tauri. I'm currently working on a kiosk machine project that involves integrating a bank card reader. I have a Nuxt3 frontend and a Tauri backend. In my Tauri backend, I'm loading a DLL that contains comm_open and enter_card functions. However, when I call these functions, the app becomes unresponsive, and the card reader waits for user input. Eventually, the app crashes when a credit card is inserted into the card reader, giving error code 3221225477. I suspect it's a memory issue. How can I handle this? Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions