Skip to content

AndreiLosev/snap7_dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

import 'dart:typed_data';
import 'package:dart_snap7/dart_snap7.dart';

void main(List<String> args) async {
  final aC = AsyncClient();

  try {
    await aC.init();
    await aC.connect('192.168.100.55', 0, 0);
    final data = await aC.readMultiVars(MultiReadRequest()
      ..readDataBlock(2, 0, 2)
      ..readMerkers(22, 25));

    final bytes = ByteData.view(data[1].$2.buffer);

    final byte = bytes.getUint8(46 - 22);

    print(['datablock 2', data[0].$2]);

    print([
      ':',
      [
        bytes.getUint8(0),
        bytes.getUint16(2),
        bytes.getUint32(4),
        bytes.getInt16(8),
        bytes.getFloat64(32 - 22),
        bytes.getFloat32(40 - 22),
        bytes.getUint16(44 - 22),
        bytes.getUint8(46 - 22)
      ]
    ]);

    print([
      'bits:',
      [
        byte.getBit(0),
        byte.getBit(1),
        byte.getBit(2),
        byte.getBit(3),
        byte.getBit(4),
        byte.getBit(5),
        byte.getBit(6),
        byte.getBit(7),
      ]
    ]);
  } finally {
    await aC.disconnect();
    await aC.destroy();
  }
}

extension BitMap on int {
  bool getBit(int pos) {
    final x = this >> pos;
    return x & 1 == 1;
  }

  int setBit(int pos, bool bit) {
    final x = 1 << pos;
    if (bit) {
      return this | x;
    }

    return getBit(pos) ? this ^ x : this;
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages