Menu

How I can Write SingleBit

Ersin
2015-09-09
2015-09-09
  • Ersin

    Ersin - 2015-09-09

    I can read single bit M100.1 this way on the c# but i want to write signle bit can you help me please?

    private void PlcMerkerRead()
    {
    int Result;
    byte[] Buffer = new byte[1];
    Result = PLC.MBRead( 100, 1, Buffer);
    TxtDump.Text = Convert.ToString(GetBit(Buffer[0], 0));
    }

            public bool GetBit(byte byt, int index)
        {
            if (index < 0 || index > 7)
                throw new ArgumentOutOfRangeException();
            byte bitMask = (byte)(1 << index);
            byte masked = (byte)(byt & bitMask);
            return masked != 0;
        }
    
     

    Last edit: Ersin 2015-09-09
  • Davide Nardella

    Davide Nardella - 2015-09-09

    Use Read/WriteArea that can address a single bit

     
    • Ersin

      Ersin - 2015-09-09

      Can you give to me one sample

       

Log in to post a comment.