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

s7client return a object instead of data #97

Closed
veliadiguzel opened this issue Mar 27, 2024 · 3 comments
Closed

s7client return a object instead of data #97

veliadiguzel opened this issue Mar 27, 2024 · 3 comments

Comments

@veliadiguzel
Copy link

veliadiguzel commented Mar 27, 2024

Greetings first of all thanks for such a library i try to read just 1 bit but return object

const snap7 = require('node-snap7');
// Bağlantı yapılacak PLC'nin IP adresi ve diğer bağlantı bilgileri
const s7client = new snap7.S7Client();

const ip = '176.16.11.45'; // PLC'nin IP adresi
const rack = 0; // PLC rack numarası
const slot = 3; // PLC slot numarası


s7client.ConnectTo(ip, rack, slot, (err) => {
    if (err) {
        console.error('Connection error: ' + err);
        return;
    }
    else console.log('Connetion established...');


    //    plc.DBRead(215, 256, 1, (err, data) => {
    s7client.ReadArea(s7client.S7AreaDB, 215, 256, 1, s7client.S7WLBit, (err, data) => {

        if (err) {
            console.error('Read Error: ' + err);
            s7client.Disconnect();
            return;
        }
        // Okunan veri DB215.DBX.256.01 adresinde bulunur
        console.log('Read data: ' + data);
        console.log(typeof (data));
        // Bağlantıyı kapat
        s7client.Disconnect();
    });
});

if i use DBRead and 1 byte get %

PS C:\Users\veli.adiguzel\Desktop\PLC\eaf-status> node .\eaf.js
Connetion established...
Read data: **%**
object      
PS C:\Users\veli.adiguzel\Desktop\PLC\eaf-status> node .\eaf.js
Connetion established...
Read data: 
object     
PS C:\Users\veli.adiguzel\Desktop\PLC\eaf-status> 
@veliadiguzel
Copy link
Author

I can access the data in the form of data[0], but when I ran the first code, I was getting the normal direct data.

@mathiask88
Copy link
Owner

mathiask88 commented Mar 27, 2024

ReadArea() always returns a buffer object (For S7WLBit either 0x00 or 0x01). Issue with your code is that you force a type change in your console.log('Read data: ' + data); by concatenating the buffer object with a string and 0x00 or 0x01 are no printable utf8 characters.

Try console.log('Read data: ', data); instead.

@veliadiguzel
Copy link
Author

I apologize for keeping you busy for something so simple. I'm sorry for switching from Delphi programming language to new internet technologies.

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

2 participants