anton-dutov / snap7

7 stars 3 forks source link

problem building example #2

Open timothey-lemley-koerber opened 8 months ago

timothey-lemley-koerber commented 8 months ago

Hello, I am new to Rust, so this maybe a stupid problem, but when I try to build your example program I get the following error:

error[E0061]: this function takes 1 argument but 0 arguments were supplied --> src\main.rs:22:30 22 handle: unsafe { LibSnap7::Cli_Create() }, ^^^^^^^^^^^^^^^^^^^^-- an argument of type &snap7_sys::LibSnap7 is missing
note: method defined here --> C:\Users\Timothey.Lemley\Documents\tooling\rust\simple\target\debug\build\snap7-sys-16ee191438d9eefb\out/bindings.rs:875:19 875 pub unsafe fn Cli_Create(&self) -> S7Object { ^^^^^^^^^^ help: provide the argument
22 handle: unsafe { LibSnap7::Cli_Create(/ &snap7_sys::LibSnap7 /) },
~~~~~~~~

I do not know what to do here.

timothey-lemley-koerber commented 8 months ago

I had to add a path to the snap7 .dll as a constant string and use that everytime I called a function. I got the program to compile and run, but it's not connecting to my PLC yet.

const PATH_TO_LIB: &str = "C:/Users/xxx/Documents/tooling/c++/snap7-full-1.4.2/snap7-full-1.4.2/build/bin/win64/snap7.dll";

impl Client { pub fn new() -> Self { let lib = unsafe {LibSnap7::Cli_Create(&snap7_sys::LibSnap7::new(Path::new(PATH_TO_LIB)).unwrap())} ;

timothey-lemley-koerber commented 8 months ago

I was able to get the connection working by adding a reference to the library in the struct implementation:

    ```

let snap = unsafe { snap7_sys::LibSnap7::new(Path::new(PATH_TO_LIB)).unwrap() }; let lib = unsafe {LibSnap7::Cli_Create(&snap)} ; Self { snap: snap,