Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem building example #2

Open
timothey-lemley-koerber opened this issue Feb 14, 2024 · 2 comments
Open

problem building example #2

timothey-lemley-koerber opened this issue Feb 14, 2024 · 2 comments

Comments

@timothey-lemley-koerber

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
Copy link
Author

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
Copy link
Author

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant