示例#1
0
        private void Button2_Click(object sender, EventArgs e)
        {
            bool is_ok;

            byte[] x = new byte[1];
            if (data.Text == "1")
            {
                x[0] = (byte)1;
                kNX_Connection.SetKnxData(kNX_Connection.KnxCode.Get_knx_addr(addr.Text, out is_ok), 1, x);
            }
            if (data.Text == "0")
            {
                x[0] = (byte)0;
                kNX_Connection.SetKnxData(kNX_Connection.KnxCode.Get_knx_addr(addr.Text, out is_ok), 1, x);
            }
        }
示例#2
0
        private void My_modbus_server_OnDataReceived(object sender, byte[] data)
        {
            byte[] swap = new byte[2];
            if (modbus_buffer != null)
            {
                switch (modbus_buffer[1])///获取命令码
                {
                case ModbusInfo.WriteOneRegister:
                {
                    var set_buff = new byte[1];
                    swap[0] = modbus_buffer[3];
                    swap[1] = modbus_buffer[2];
                    var x = (short)BitConverter.ToUInt16(swap, 0);           //获取数据地址
                    if (modbus_buffer[5] == 1 | modbus_buffer[5] == 0)
                    {
                        set_buff[0] = modbus_buffer[5];
                        knx_Connect.SetKnxData(x, 1, set_buff);
                    }

                    break;
                }

                case ModbusInfo.WriteRegister:
                {
                    var set_buff = new byte[1];
                    swap[0] = modbus_buffer[3];
                    swap[1] = modbus_buffer[2];
                    var x = (short)BitConverter.ToUInt16(swap, 0);           //获取数据地址
                    if (modbus_buffer[8] == 1 | modbus_buffer[8] == 0)
                    {
                        set_buff[0] = modbus_buffer[8];
                        knx_Connect.SetKnxData(x, 1, set_buff);
                    }
                    break;
                }
                }
                modbus_buffer = null;
            }
        }