node-snap7 icon indicating copy to clipboard operation
node-snap7 copied to clipboard

converting raw data to proper data types

Open miladghasemid opened this issue 4 years ago • 0 comments

Data read from DBs are in the form of byte array. these bytes can be converted into more meaningful types such as REAL or INTEGER just like the way they are define in VAT in simatic manager. But due to efficiency, it seems to be better to read multiple data items from a DB(if they have consecutive addresses) and save it in an array of bytes, making possible for user to read each portion of buffer and convert it to data types. here is the example: suppose user wants to read two REALs, from DB100,DBD0 and DB100,DBD4. for the sake of efficiency, a function reads 8bytes of data from DB100 and saves it into a local variable. another function call on that variable can convert data to more meaningful data.

class DataItems{
   vector<char> itemsBuffer;
   float rawData2REAL(int index)
}

user can access data using some code like this.

DataItems items = new DataItems();
s7client.readArea(DB100,8,&items);
float value01 =items.rawData2Real(0);
float value02 =items.rawData2Real(4);

but i think data does not need to be converted to node js objects until the raw value is completely converted to primitive data types, meaning itemsBuffer does not need to be visible in javascript code

miladghasemid avatar Sep 28 '19 17:09 miladghasemid