lifeemotions / knx.net Goto Github PK
View Code? Open in Web Editor NEWKNX.net provides a KNX API for .NET
License: MIT License
KNX.net provides a KNX API for .NET
License: MIT License
I really like this library and it seems to be very well written. But I noticed that sending actions is kind of slow. Digging around the code in KnxLockManager.cs I found that PerformLockedOperation does a Thread.Sleep(200).
How did you come up with this value? I tried 50 and even 20 and it still works on my installation. Is this required by the KNX spec?
I don't know what I am doing wrong. I cloned your project and tried the test project with the tunneling. I changed the IP to the IP of my KNX/IP Gateway and port 3671. The same as ETS is using.
I get a notification from the firewall, when I start the application and I accept the firewall rule.
But the app hangs when I try to call an Action to switch light on and off. It just hangs foreever. No exception. Nothing. It does not return from the function.
Hi, I want to take feedback and print a textboxa or comboboxa.But I didn't get any information about what I did, can you help?
private void button7_Click(object sender, EventArgs e)
{
_connection = new KnxConnectionRouting { Debug = false, ActionMessageCode = 0x29 };
_connection.KnxConnectedDelegate += Connected;
_connection.KnxDisconnectedDelegate += Disconnected;
_connection.KnxEventDelegate += Event;
_connection.KnxStatusDelegate += Status;
_connection.Connect();
_connection.Action("5/0/8", 0x3E);
//_connection.Action(LightOnOffAddress2, false);
Thread.Sleep(200);
_connection.RequestStatus("5/0/7");
int state = 0;
float xxx = (float)_connection.FromDataPoint("9.001",.... );
_connection.RequestStatus("5/0/7");
comboBox1.Items.Add(....);
_connection.Disconnect();
}
Hey,
I am working on a vb.net project where one connected appliance, lets say a lightbulb for example can be turned on by my program, but also by a lightswitch. I was looking through the code to find out if there exists a statusrequest of my bus(adress). Of course, i found the "connection".statusrequest but this doesn't seem to return a value.
Is there a way in which I can read the status of an adress?
Kind regards,
Thomas
Hello, I want to print the status information of an address to the textbox. But I just couldn't. Can you help?
5/0/7 tempature set feedback
}
string state;
private void button7_Click(object sender, EventArgs e)
{
_connection = new KnxConnectionRouting { Debug = false, ActionMessageCode = 0x29 };
_connection.KnxConnectedDelegate += Connected;
_connection.KnxDisconnectedDelegate += Disconnected;
_connection.KnxEventDelegate += Event;
_connection.KnxStatusDelegate += Status;
_connection.Connect();
_connection.Action("5/0/8", 0x3E); //tempature setpoint
//_connection.Action(LightOnOffAddress2, false);
Thread.Sleep(200);
try
{
_connection.RequestStatus("5/0/7");
int xxx = (int)_connection.FromDataPoint("9.001", state);
comboBox1.Items.Add(xxx);
_connection.Disconnect();
}
catch (Exception)
{
}
The last code I prepared but I could not run it again please help :(
//5/0/8 temp set
//5/0/7 current temp. feedback
public void Event(string address, string state)
{
if (address=="5/0/7")
{
var temp1 = (decimal)_connection.FromDataPoint("9.001", state);
txt.Text = "Temperature: " + temp1;
comboBox1.Items.Add(temp1);
}
else if (address=="5/0/7")
{
var temp2 = (decimal)_connection.FromDataPoint("9.001", state);
txt.Text = "Temperature: " + temp2;
}
else
{
}
_connection.Disconnect();
}
private static KnxConnection _connection;
private void button7_Click(object sender, EventArgs e)
{
_connection = new KnxConnectionRouting { Debug = false, ActionMessageCode = 0x29 };
_connection.Connect();
_connection.KnxEventDelegate += new KnxConnection.KnxEvent(Event);
_connection.KnxStatusDelegate += new KnxConnection.KnxStatus(Event);
_connection.Action("5/0/8", _connection.ToDataPoint("9.001", 24.0f));
_connection.Disconnect();
}
For example, I mean this: https://github.com/lifeemotions/knx.net/blob/master/src/KNXLib/KnxReceiverTunneling.cs#L178-L186
knxDatagram
is never used, are you going to finish writing or just forgot to remove this variable?
How do I implement the
connection.KnxEventDelegate += Event;
in VB.NET?
Hi,
I was wondering if there is any way to receive the status of a device directly to a variable, like this:
string state = connection.RequestStatus("0/0/1");
Thanks
Dear,
We are now getting an "event" for the correct address when we execute a "requestStatus" call. How do we go about receiving an event when a switch is set manually ?
Kind regards,
Thomas
The apci, reaching over 2bytes, will use the last byte fully, when the payload is greater than 6 bits. The bits are then ignored. Currently the code checks wether the first byte of the payload is using only the lower 6 bits, which is not according to the knx trainee handbook and confirms with the received package in the network.
Greetings,
Marcel
I try to use KnxConnectionTunneling from Azure web app but I cannot connect to remote IP gateway. I get this error when calling Connect():
ConnectionErrorException: Error connecting to xx.xx.xx.xx:3671 The requested address is not valid in its context
Same web app is working fine from my PC (visual studio) connecting to remote IP gateway over VPN.
Is there anyone that can guide me about Azure web app networkig setup here?
Anyone who got this knx.net package working from an Azure web app?
My relevant code:
var localIP = Dns.GetHostEntry("mysite.azurewebsites.net").AddressList.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First().ToString();
var connection = new KnxConnectionTunneling([RemoteKnxGatewayIp], 3671, localIP, 3671);
connection.Connect() -> this line fails with error above
When requesting the status of an invalid group address, the CreateRequestStatusDatagram(destinationAddress) function call in
KnxSender.cs:RequestStatus(string) will return null.
SendData will be called with null, causing the backend to fail with an exception.
At this point when you caught the exception in the main program the next knx action will be encountering the lock that was previously set, causing the program to hang indefinitely
Test case:
// TunnelingConnection conn opened somewhere here
{
try
{
// causes exception: argumentnullexception, because udpSend was trying to send byte array with null
// should be argumentexception, "groupaddress invalid" or something.
conn.RequestStatus("12/50/255"); // exception, middle group valid in [0..7]
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
try
{
// this now locks up
conn.RequestStatus("12/5/255"); // is valid
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
And while we are at it, a nice, public check knx addr function that returns true if the address is valid and false otherwise would be a really nice addition.
Hello,
Is it possible to see the source adresse in the KnxEventDelegate ?
I'm creating a window service that will monitor knx events.
Should I do something manually to keep alive the connection, like requesting a status every minute, or isn't it needed?
ı dont write text.box.Why?
public void Event(string address, string state)
{
decimal temp = (decimal)_connection.FromDataPoint("9.001", state);
if (address == "5/0/7")
{
decimal set_temp = (decimal)_connection.FromDataPoint("9.001", state);
MessageBox.Show("Güncellenen Durum" + address + " " + set_temp);
textBox1.Text = set_temp.toSting();
return;
}
if (address == "5/0/0")
{
decimal current_temp = (decimal)_connection.FromDataPoint("9.001", state);
MessageBox.Show("Güncellenen Durum" + address + " " + current_temp);
return;
}
}
Nice project, but are there any plans to make it compatible with ".NET Core"?
I have needed to communicate with a group address 24/4/1..250 and I have verified that the KnxHelper class was not ready and with a few small modifications and got it working.
I share my modifications in case you find them interesting.
KnxHelper.cs
`
using System;
using System.Linq;
using KNXLib.Exceptions;
namespace KNXLib
{
internal class KnxHelper
{
#region Address Processing
// +-----------------------------------------------+
// 16 bits | INDIVIDUAL ADDRESS |
// +-----------------------+-----------------------+
// | OCTET 0 (high byte) | OCTET 1 (low byte) |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | Subnetwork Address | |
// +-----------+-----------+ Device Address |
// |(Area Adrs)|(Line Adrs)| |
// +-----------------------+-----------------------+
// -- up to ETS3 --------------------------------------------+
// +-----------------------------------------------+
// 16 bits | GROUP ADDRESS (3 level) |
// +-----------------------+-----------------------+
// | OCTET 0 (high byte) | OCTET 1 (low byte) |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// up to ETS3| | Main Grp | Midd G | Sub Group |
// as of ETS4| Main Grp | Midd G | Sub Group |
// +--+--------------------+-----------------------+
// +-----------------------------------------------+
// 16 bits | GROUP ADDRESS (2 level) |
// +-----------------------+-----------------------+
// | OCTET 0 (high byte) | OCTET 1 (low byte) |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// up to ETS3| | Main Grp | Sub Group |
// as of ETS4| Main Grp | Sub Group |
// +--+--------------------+-----------------------+
// These tables clearly show why ETS3 can only visualize 16 MaGs (0...15).
// The reason is that the MaGs are coded in 4 bits. As of ETS4,
// the entire range of usable GAs is doubled by using one more bit.
// The 15th bit increases the number of group addresses by 32768 entries (2^16 - 2^15).
public static bool IsAddressIndividual(string address)
{
return address.Contains('.');
}
public static string GetIndividualAddress(byte[] addr)
{
return GetAddress(addr, '.', false);
}
public static string GetGroupAddress(byte[] addr, bool threeLevelAddressing)
{
return GetAddress(addr, '/', threeLevelAddressing);
}
private static string GetAddress(byte[] addr, char separator, bool threeLevelAddressing)
{
var group = separator.Equals('/');
string address;
if (group && !threeLevelAddressing)
{
// 2 level group
address = (addr[0] >> 3).ToString();
address += separator;
address += (((addr[0] & 0x07) << 8) + addr[1]).ToString(); // this may not work, must be checked
}
else
{
// 3 level individual or group
// up to ETS3
// address = group
// ? ((addr[0] & 0x7F) >> 3).ToString()
// : (addr[0] >> 4).ToString();
// as of ETS4
address = group
? (addr[0] >> 3).ToString()
: (addr[0] >> 4).ToString();
address += separator;
if (group)
address += (addr[0] & 0x07).ToString();
else
address += (addr[0] & 0x0F).ToString();
address += separator;
address += addr[1].ToString();
}
return address;
}
public static byte[] GetAddress(string address)
{
try
{
var addr = new byte[2];
var threeLevelAddressing = true;
string[] parts;
var group = address.Contains('/');
if (!group)
{
// individual address
parts = address.Split('.');
if (parts.Length != 3 || parts[0].Length > 2 || parts[1].Length > 2 || parts[2].Length > 3)
throw new InvalidKnxAddressException(address);
}
else
{
// group address
parts = address.Split('/');
if (parts.Length != 3 || parts[0].Length > 2 || parts[1].Length > 1 || parts[2].Length > 3)
{
if (parts.Length != 2 || parts[0].Length > 2 || parts[1].Length > 4)
throw new InvalidKnxAddressException(address);
threeLevelAddressing = false;
}
}
if (!threeLevelAddressing)
{
var part = int.Parse(parts[0]);
// -- up to ETS3
// if (part > 15)
// -- as of ETS4
if (part > 31)
throw new InvalidKnxAddressException(address);
addr[0] = (byte)(part << 3);
part = int.Parse(parts[1]);
if (part > 2047)
throw new InvalidKnxAddressException(address);
var part2 = BitConverter.GetBytes(part);
if (part2.Length > 2)
throw new InvalidKnxAddressException(address);
addr[0] = (byte)(addr[0] | part2[0]);
addr[1] = part2[1];
}
else
{
var part = int.Parse(parts[0]);
// -- up to ETS3
// if (part > 15)
// -- as of ETS4
if (part > 31)
throw new InvalidKnxAddressException(address);
addr[0] = group
? (byte)(part << 3)
: (byte)(part << 4);
part = int.Parse(parts[1]);
if ((group && part > 7) || (!group && part > 15))
throw new InvalidKnxAddressException(address);
addr[0] = (byte)(addr[0] | part);
part = int.Parse(parts[2]);
if (part > 255)
throw new InvalidKnxAddressException(address);
addr[1] = (byte)part;
}
return addr;
}
catch (Exception)
{
throw new InvalidKnxAddressException(address);
}
}
#endregion
#region Control Fields
// Bit order
// +---+---+---+---+---+---+---+---+
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// +---+---+---+---+---+---+---+---+
// Control Field 1
// Bit |
// ------+---------------------------------------------------------------
// 7 | Frame Type - 0x0 for extended frame
// | 0x1 for standard frame
// ------+---------------------------------------------------------------
// 6 | Reserved
// |
// ------+---------------------------------------------------------------
// 5 | Repeat Flag - 0x0 repeat frame on medium in case of an error
// | 0x1 do not repeat
// ------+---------------------------------------------------------------
// 4 | System Broadcast - 0x0 system broadcast
// | 0x1 broadcast
// ------+---------------------------------------------------------------
// 3 | Priority - 0x0 system
// | 0x1 normal (also called alarm priority)
// ------+ 0x2 urgent (also called high priority)
// 2 | 0x3 low
// |
// ------+---------------------------------------------------------------
// 1 | Acknowledge Request - 0x0 no ACK requested
// | (L_Data.req) 0x1 ACK requested
// ------+---------------------------------------------------------------
// 0 | Confirm - 0x0 no error
// | (L_Data.con) - 0x1 error
// ------+---------------------------------------------------------------
// Control Field 2
// Bit |
// ------+---------------------------------------------------------------
// 7 | Destination Address Type - 0x0 individual address
// | - 0x1 group address
// ------+---------------------------------------------------------------
// 6-4 | Hop Count (0-7)
// ------+---------------------------------------------------------------
// 3-0 | Extended Frame Format - 0x0 standard frame
// ------+---------------------------------------------------------------
public enum KnxDestinationAddressType
{
INDIVIDUAL = 0,
GROUP = 1
}
public static KnxDestinationAddressType GetKnxDestinationAddressType(byte control_field_2)
{
return (0x80 & control_field_2) != 0
? KnxDestinationAddressType.GROUP
: KnxDestinationAddressType.INDIVIDUAL;
}
#endregion
#region Data Processing
// In the Common EMI frame, the APDU payload is defined as follows:
// +--------+--------+--------+--------+--------+
// | TPCI + | APCI + | Data | Data | Data |
// | APCI | Data | | | |
// +--------+--------+--------+--------+--------+
// byte 1 byte 2 byte 3 ... byte 16
// For data that is 6 bits or less in length, only the first two bytes are used in a Common EMI
// frame. Common EMI frame also carries the information of the expected length of the Protocol
// Data Unit (PDU). Data payload can be at most 14 bytes long. <p>
// The first byte is a combination of transport layer control information (TPCI) and application
// layer control information (APCI). First 6 bits are dedicated for TPCI while the two least
// significant bits of first byte hold the two most significant bits of APCI field, as follows:
// Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 8 Bit 1 Bit 2
// +--------+--------+--------+--------+--------+--------+--------+--------++--------+----....
// | | | | | | | | || |
// | TPCI | TPCI | TPCI | TPCI | TPCI | TPCI | APCI | APCI || APCI |
// | | | | | | |(bit 1) |(bit 2) ||(bit 3) |
// +--------+--------+--------+--------+--------+--------+--------+--------++--------+----....
// + B Y T E 1 || B Y T E 2
// +-----------------------------------------------------------------------++-------------....
//Total number of APCI control bits can be either 4 or 10. The second byte bit structure is as follows:
// Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit 8 Bit 1 Bit 2
// +--------+--------+--------+--------+--------+--------+--------+--------++--------+----....
// | | | | | | | | || |
// | APCI | APCI | APCI/ | APCI/ | APCI/ | APCI/ | APCI/ | APCI/ || Data | Data
// |(bit 3) |(bit 4) | Data | Data | Data | Data | Data | Data || |
// +--------+--------+--------+--------+--------+--------+--------+--------++--------+----....
// + B Y T E 2 || B Y T E 3
// +-----------------------------------------------------------------------++-------------....
public static string GetData(int dataLength, byte[] apdu)
{
switch (dataLength)
{
case 0:
return string.Empty;
case 1:
return Convert.ToChar(0x3F & apdu[1]).ToString();
case 2:
return Convert.ToChar(apdu[2]).ToString();
default:
var data = string.Empty;
for (var i = 2; i < apdu.Length; i++)
data += Convert.ToChar(apdu[i]);
return data;
}
}
public static int GetDataLength(byte[] data)
{
if (data.Length <= 0)
return 0;
if (data.Length == 1 && data[0] < 0x3F)
return 1;
if (data[0] < 0x3F)
return data.Length;
return data.Length + 1;
}
public static void WriteData(byte[] datagram, byte[] data, int dataStart)
{
if (data.Length == 1)
{
if (data[0] < 0x3F)
{
datagram[dataStart] = (byte)(datagram[dataStart] | data[0]);
}
else
{
datagram[dataStart + 1] = data[0];
}
}
else if (data.Length > 1)
{
if (data[0] < 0x3F)
{
datagram[dataStart] = (byte)(datagram[dataStart] | data[0]);
for (var i = 1; i < data.Length; i++)
{
datagram[dataStart + i] = data[i];
}
}
else
{
for (var i = 0; i < data.Length; i++)
{
datagram[dataStart + 1 + i] = data[i];
}
}
}
}
#endregion
#region Service Type
public enum SERVICE_TYPE
{
//0x0201
SEARCH_REQUEST,
//0x0202
SEARCH_RESPONSE,
//0x0203
DESCRIPTION_REQUEST,
//0x0204
DESCRIPTION_RESPONSE,
//0x0205
CONNECT_REQUEST,
//0x0206
CONNECT_RESPONSE,
//0x0207
CONNECTIONSTATE_REQUEST,
//0x0208
CONNECTIONSTATE_RESPONSE,
//0x0209
DISCONNECT_REQUEST,
//0x020A
DISCONNECT_RESPONSE,
//0x0310
DEVICE_CONFIGURATION_REQUEST,
//0x0311
DEVICE_CONFIGURATION_ACK,
//0x0420
TUNNELLING_REQUEST,
//0x0421
TUNNELLING_ACK,
//0x0530
ROUTING_INDICATION,
//0x0531
ROUTING_LOST_MESSAGE,
// UNKNOWN
UNKNOWN
}
public static SERVICE_TYPE GetServiceType(byte[] datagram)
{
switch (datagram[2])
{
case (0x02):
{
switch (datagram[3])
{
case (0x06):
return SERVICE_TYPE.CONNECT_RESPONSE;
case (0x09):
return SERVICE_TYPE.DISCONNECT_REQUEST;
case (0x0a):
return SERVICE_TYPE.DISCONNECT_RESPONSE;
case (0x08):
return SERVICE_TYPE.CONNECTIONSTATE_RESPONSE;
}
}
break;
case (0x04):
{
switch (datagram[3])
{
case (0x20):
return SERVICE_TYPE.TUNNELLING_REQUEST;
case (0x21):
return SERVICE_TYPE.TUNNELLING_ACK;
}
}
break;
}
return SERVICE_TYPE.UNKNOWN;
}
public static int GetChannelId(byte[] datagram)
{
if (datagram.Length > 6)
return datagram[6];
return -1;
}
#endregion
}
}
`
I've been using the example code provided in the form of
conn = new KnxConnectionTunneling(remoteIp, 3671, localIp, 3672);
// create event handlers
conn.KnxConnectedDelegate += Connected;
conn.KnxEventDelegate += Event;
conn.KnxStatusDelegate += Status;
conn.KnxDisconnectedDelegate += Disconnected;
conn.Connect();
where conn is a private field of type KnxConnection
now with Disconnected being:
private static void Disconnected()
{
if (conn == null)
{
Console.WriteLine("ERR: KNX Disconnected. Connection NULL");
}
else
{
Console.WriteLine("Disconnected from KNX.");
Console.WriteLine("Disconnected. Attempting Reconnect in 5 seconds.");
Thread.Sleep(5000);
conn.Connect();
}
}
I've had no troubles for a good while. But at some point the knx ip gateway was disconnected (physically) and not reconnected. and after a while I got a lovely System.OutOfMemoryException.
I traced back the problem to Connect().
so I tried (knx detached)
while(true)
{
conn.Connect();
}
and within a minute or so memory went through the roof, eventually throwing the same exception.
I tried calling GC.Collect() after each connection attempt, and then it took 2 minutes instead of one to die.
Then I tried calling disconnect before calling GC.Collect(); and then making a brand new connection object.
The same problem persists.
try
{
while (true)
{
if (conn != null)
{
conn.Disconnect();
}
conn = null;
GC.Collect();
conn = new KnxConnectionTunneling(remoteIp, 3671, localIp, 3672);
// create event handlers
conn.KnxConnectedDelegate += Connected;
conn.KnxEventDelegate += Event;
conn.KnxStatusDelegate += Status;
conn.KnxDisconnectedDelegate += Disconnected;
conn.Connect();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
throw e;
}
Result:
System.OutOfMemoryException: Eine Ausnahme vom Typ "System.OutOfMemoryException" wurde ausgelöst.
bei System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)
bei System.Threading.Thread.Start(StackCrawlMark& stackMark)
bei System.Threading.Thread.Start()
bei KNXLib.KnxReceiver.Start()
bei KNXLib.KnxConnectionTunneling.Connect()
bei XXX.XXX.Main(String[] args) in C:\Users\<user>\Desktop\XXX\XXX\XXX.cs:Zeile 125.
Then I tried to remove the delegates by setting them null before disconnecting and calling GC.Collect().
That didn't help either. So I'm all out of ideas for a workaround.
I'm using this library in a critical application and can't have it crash on me.
Please fix your stuff.
It'd be nice to have a function to check wether a given address is valid or not.
There is KnxHelper.GetAddress, but that only throws exceptions, and that class is marked internal.
KnxConnectionRouting not fire KnxDisconnected event only need to add "base.Disconnected();", like de code below:
public class KnxConnectionRouting : KnxConnection { public override void Disconnect() { KnxReceiver.Stop(); foreach (UdpClient client in _udpClients) { client.DropMulticastGroup(ConnectionConfiguration.IpAddress); client.Close(); } base.Disconnected(); } }
Could you add a License file please?
Perhaps something like the MIT license? (https://github.com/angular/angular.js/blob/master/LICENSE)
Because as it currently is, nobody can contribute since you hold all copyright because there is no license file
Hello everybody :)
First of all, I'm sorry if my english is bad.
I'm Ana Katarina from Croatia and I really, really need solution for my problem. I would be very thankful if you could help me :)
My task is to make a desktop application that will be able to connect with the KNX / IP router and receive telegram from weather station and save that parameters to database.
I'm using Schneider knx router and ETS 3 software. What should I do? I have no one to ask, KNX is in Croatia still unknown, and I promise that I'm just a student who is stuck with this problem.
I'm using Visual Studio 2013 pro and these classes of Mr. David.
I'm sending you guys how I wrote code for that solution, but it doesn't work.
using KNXLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace zavrsni
{
public partial class Form1 : Form
{
string IPadresa;
string Port;
private static KnxConnection _connection;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void btnPotvrda_Click(object sender, EventArgs e)
{
IPadresa = txtIPadresa.Text;
Port = txtPort.Text;
int port = Convert.ToInt32(Port);
try
{
_connection = new KnxConnectionRouting(IPadresa, port);
_connection.Connect();
_connection.KnxEventDelegate += new KnxConnection.KnxEvent(Event);
_connection.KnxStatusDelegate += new KnxConnection.KnxStatus(Event);
_connection.Action("4/1/1", _connection.ToDataPoint("9.001", 24.0f));
}
catch (Exception es)
{
txtStatus.Text = es.Message;
}
}
private void Event(string address, string state)
{
float temp = (float)_connection.FromDataPoint("9.001", state);
txtStatus.Text = "Temperature: " + temp;
}
}
}
How do you get the status(e.g. false or true on a switch) from a group address?
I think you accidently swapped the datapoints 3.007 and 3.008.
I don't know if it's just in your documentation or in the library too.
Check here: PDF document (page 12)
Is it possible to discover the interface automatically?
Do you know which mechanism ETS is using to discover the KNX IP interface?
Thanks for the library. Worked from my first try.
How can I put the "temp" definition to a textbox or label, whatever I did did not work. Can you help?
static void Event(object sender, KnxEventArgs args)
{
if (args.DestinationAddress.Equals(new KnxThreeLevelGroupAddress(1, 1, 16)))
{
decimal temp = (decimal)connection.FromDataPoint("9.001", args.State);
textbox1.text=temp.tostring();
return;
}
if (args.DestinationAddress.ToString() == "1/1/17")
{
int perc = (int)connection.FromDataPoint("5.001", args.State);
Console.WriteLine($"New Event: device {args.DestinationAddress} has status {perc}");
return;
}
}
Hi,
if I send a write command (5.001) to my dimmer with a value <24%, my actuator ignore the command:
byte[] b1 = _connection.ToDataPoint("5.001", 20);
_connection.Action("3/1/38", b1);
If I look into ETS groupadress-monitor he shows a „False“ command ($14 False) instead of ($14 20%). All bigger than 24 values looking fine.
I created a workaround appending a 0 byte before:
byte[] b1 = _connection.ToDataPoint("5.001", 20);
b1 = new byte[] { 0x00, b1[0] };
_connection.Action("3/1/38", b1);
Do you have any idea why this behavior happens?
Hello,
I tested this program with the latest version 1.1.10:
1- The name Status does not exist , so I removed the line.
2- when I remove the cable , the Disconnected respond after 20 to 40 sec .
3- after I return the cable , the connected respond after 20 to 40 sec .
with the following Exception :
please help.
Thanks
using System;
using KNXLib;
using System.Threading;
namespace KNXTest
{
class Program
{
public static int u1;
static KnxConnectionTunneling conn;
static void Main(string[] args)
{ u1 = 0;
try
{
conn = new KnxConnectionTunneling("172.21.2.85", 3671, "172.21.3.32", 3671);
conn.SetLockIntervalMs(10);
conn.Connect(); Console.WriteLine(" conn try wait 1 ");
Thread.Sleep(1000);
conn.KnxConnectedDelegate += Connected;
// conn.KnxStatusDelegate += Status;
conn.KnxDisconnectedDelegate += Disconnected;
conn.KnxEventDelegate += Event;
while (true)
{
conn.RequestStatus("2/2/4"); Thread.Sleep(10);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
throw e;
}
}
private static void Connected()
{
// if (u1 == 0)
{
Console.WriteLine(" conection is now " );
u1 = 1;
}
}
private static void Disconnected()
{
// if (u1 == 1)
{
u1 = 0;
if (conn == null)
{
Console.WriteLine("ERR: KNX Disconnected. Connection NULL");
}
else
{
Console.WriteLine("Disconnected from KNX.");
Console.WriteLine("Disconnected. Attempting Reconnect in 1 seconds.");
Thread.Sleep(1000);
conn.Connect();
conn.Connect(); Console.WriteLine(" wait 1 "); Thread.Sleep(1000);
}
}
}
static void Event(string address, string state)
{
Console.WriteLine("New Event: device " + address + " has status " + state);
if (address == "2/2/4")
{
decimal temp = (decimal)conn.FromDataPoint("9.001", state);
Console.WriteLine("New Event: sensor " + address + " has status " + temp);
}
if (address == "2/1/50")
{
Console.WriteLine("New Event: sw 50 " + address + " has status ");
decimal temp = (decimal)conn.FromDataPoint("5.001", state);
Console.WriteLine(temp);
}
if (address == "2/1/51")
{
Console.WriteLine("New Event: sw 51 " + address + " has status ");
decimal temp = (decimal)conn.FromDataPoint("5.001", state);
Console.WriteLine(temp);
}
}
}
}
Sorry, I posted in another place
Is there a way to check the status of the knx connection?
If the network interrupts KnxDisconnectedDelegate is not fired.
I made a shell script to launch my program in a loop in case my programm exits for any reason. While rare, the programm occasionally encounters a situation in which it has to reset. One of those situations is when it fails to connect to the KNX-Tunneling interface 10 times in a row. Then I decide to just restart the program and have everything in a known state.
Just today I had checked in on my project and found the service running, but no data being logged for 5 days.
Examining the journal I found this:
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:27.113: ID: KNXLib.KnxReceiverTunnelingMSG: A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: No knx-connection during main loop. Attempted reconnects so far: 10
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:27.223: ID: KNXLib.KnxReceiverTunnelingMSG: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:27.226: ID: KNXLib.KnxReceiverTunnelingMSG: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:04:27 logger-pi KNX_Logger.sh[13144]: [DELEGATE] Disconnected.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: 6/0/80 received data from 7.1.11 but it is not tracked.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Data: 0x33 0x14 (00110011 00010100)
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.219: ID: KNXLib.KnxReceiverTunnelingMSG: A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.226: ID: KNXLib.KnxReceiverTunnelingMSG: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.228: ID: KNXLib.KnxReceiverTunnelingMSG: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [DELEGATE] Disconnected.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: ================================================================================
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: EXCEPTION
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Exception time: 18.07.2019 20:04:32.608
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Exception message: Reconnect failed 11 times in a row.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Exception source: KNX_Logger
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Data:
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Help link:
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: ================================================================================
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Stack Trace:
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNX_Logger.KNX_Logger.Main (System.String[] args) [0x00574] in <Path>\KnxLogger\KNX_Logger\KNX_Logger.cs:299
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: ================================================================================
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Disconnecting normally.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: Shutdown complete. Exiting.
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.738: ID: KNXLib.KnxReceiverTunnelingMSG: A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.754: ID: KNXLib.KnxReceiverTunnelingMSG: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: [E-KNX] 18.07.2019 20: 04:32.759: ID: KNXLib.KnxReceiverTunnelingMSG: at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags flags, System.Net.EndPoint& remote_end, System.Boolean throwOnError, System.Int32& error) [0x00076] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags, System.Net.EndPoint& remoteEP) [0x00029] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
After which I restarted...
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint& remoteEP) [0x0000d] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint& remoteEP) [0x00014] in <bd46d4d4f7964dfa9beea098499ab597>:0
Jul 18 20:04:32 logger-pi KNX_Logger.sh[13144]: at KNXLib.KnxReceiverTunneling.ReceiverThreadFlow () [0x00000] in <Path>\KnxLogger\knx.net\src\KNXLib\KnxReceiverTunneling.cs:42
Jul 24 13:29:45 logger-pi systemd[1]: Stopping Service logging data from KNX IP-Interface...
Jul 24 13:29:45 logger-pi systemd[1]: Stopped Service logging data from KNX IP-Interface.
Jul 24 13:29:45 logger-pi systemd[1]: Started Service logging data from KNX IP-Interface.
Jul 24 13:29:45 logger-pi KNX_Logger.sh[27799]: [I]Working Directory: <Path>/KNX_Logger/bin
Jul 24 13:29:45 logger-pi KNX_Logger.sh[27799]: [I]Starting KNX_Logger shell loop script
There are some issues here that I don't fully understand:
Shutdown complete. Exiting.
and return 0
in the Main
function,null
at that point.The most pressing issue is that the shell script output that runs the program in a loop never triggered, meaning the shell script hung on the program launch. and systemd told me the program was running.
I suspect some thread was at work here and didn't quit properly when the main programm returned from execution, letting the program "hang" in a state where it should've exited.
Could you please look into this and please mark all threads as IsBackground = true
.
The code I use for quitting is this:
Main:
try
{
while(true) // not exactly, but practically it is. it's not supposed to stop.
{
// do logging and other things
}
}
catch (Exception e)
{
Helper.PrintException(e);
}
finally
{
if (knx != null)
{
Console.WriteLine("Disconnecting normally.");
// remove disconnect handler so it doesn't try to reconnect
knx.DisconnectForGood();
}
Console.WriteLine("Shutdown complete. Exiting.");
}
return 0;
KNX
/// <summary>
/// Disconnect, will not attempt reconnect. connection is set null
/// </summary>
public void DisconnectForGood()
{
conn.KnxDisconnectedDelegate -= Disconnected;
conn.Disconnect();
// clean up
conn = null;
}
My shell script:
#!/bin/sh
cd <Path>/KNX_Logger/bin
echo [I]Working Directory: $(pwd)
echo [I]Starting KNX_Logger shell loop script
sleep 2
echo [I]Converting debug information for mono
for f in *.pdb
do
if [ -r "${f%.pdb}.dll" ]
then
echo "[I]${f%.pdb}.dll"
pdb2mdb "${f%.pdb}.dll"
else
if [ -r "${f%.pdb}.exe" ]
then
echo "[I]${f%.pdb}.exe"
pdb2mdb "${f%.pdb}.exe"
else
echo "[W]${f%.pdb} has no corresponding dll or exe. Ignoring."
fi
fi
done
echo [I]Done converting.
sleep 2
echo [I]Entering loop
while (true)
do
sleep 10
echo -n "Started " >> <Path>/KNX_Logger/log/startLog.log
date >> <Path>/KNX_Logger/log/startLog.log
echo starting KNX_Logger.exe
mono --debug <Path>/KNX_Logger/bin/KNX_Logger.exe
echo -n "Stopped " >> <Path>/KNX_Logger/log/startLog.log
date >> <Path>/KNX_Logger/log/startLog.log
done
"Stopped" was never written to startLog
You can set up a connection like so:
conn = new KnxConnectionTunneling(knxIp, 3671, ownIp, 3672);
conn.KnxConnectedDelegate += Connected;
conn.KnxEventDelegate += Event;
conn.KnxStatusDelegate += Status;
conn.KnxDisconnectedDelegate += Disconnected;
conn.Connect();
And when the connection can't be established (I turned off my knx test setup for this),
you can still do
conn.Action(GA, val)
this in turn will cause the application to hang indefenitely at KnxLockManager.cs (60) private void SendLock() _sendLock.Wait()
Just to let you know I integrated your library in https://github.com/genielabs/HomeGenie .
As I don't have any knx hardware can't tell if it's working like it should. Hope you like it.
Kind regards,
Gene.
Godday
I've been using this since it's by far the simplest KNX library to get your head around.
Though I wonder if there is possible to get the status from a group address and save it in a bool. I would like to change a few visual stuff depending on if the bus is active or not.
I've tried calling functions or setting variables from Event/Status but that does not work.
any help would be appriciated.
Edit:
"Although you can implement a wrapper function that would lock until the value expected is received"
Found this comment in a closed thread but I can't seem to make such a function. and I'm unsure of what I'm missing.
A call like this:
string state = connection.RequestStatus(address);
Is what I would like to end up with
It would be convenient to have this library in nuget, is there any plan for it?
I used the knxlib to connect to two different knx gateways (tunneling connection to ethernet interface) on the same knx-bus with the same machine and with the same network adapter.
they are physically different gateways.
connection works fine with the first connection.
when connecting to the second interface (using a different program but from the same machine) the connection opens briefly. I even get a package or three. but then it just disconnects.
the reason why I have multiple knx gateways in the first place is because i want to use different machines on the same bus. (which works). but for testing I wanted to run the program on a machine that's already connected.
I use linux on a raspberry pi and mono to run the .net application.
I use a simple test program to inject and log knx messages. here is the output of that test program when running wit with another connection open at the same time:
16:44:37.167 [ERROR] KNXLib.KnxConnectionTunneling: Cannot access a disposed object.
Object name: 'System.Net.Sockets.UdpClient'.
16:44:37.181 [ERROR] KNXLib.KnxConnectionTunneling: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.UdpClient'.
at System.Net.Sockets.UdpClient.CheckDisposed () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0
at System.Net.Sockets.UdpClient.Send (System.Byte[] dgram, System.Int32 bytes, System.Net.IPEndPoint endPoint) [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0
at KNXLib.KnxSenderTunneling.SendData (System.Byte[] datagram) [0x00000] in <SOMEPATH>\knx.net\src\KNXLib\KnxSenderTunneling.cs:36
at KNXLib.KnxConnectionTunneling.DisconnectRequest () [0x000b3] in <SOMEPATH>\knx.net\src\KNXLib\KnxConnectionTunneling.cs:257
at KNXLib.KnxConnectionTunneling.Disconnect () [0x00006] in <SOMEPATH>\knx.net\src\KNXLib\KnxConnectionTunneling.cs:128
16:44:37.208 [ERROR] KNXLib.KnxConnectionTunneling: at System.Net.Sockets.UdpClient.CheckDisposed () [0x00016] in <bd46d4d4f7964dfa9beea098499ab597>:0
at System.Net.Sockets.UdpClient.Send (System.Byte[] dgram, System.Int32 bytes, System.Net.IPEndPoint endPoint) [0x00000] in <bd46d4d4f7964dfa9beea098499ab597>:0
at KNXLib.KnxSenderTunneling.SendData (System.Byte[] datagram) [0x00000] in <SOMEPATH>\knx.net\src\KNXLib\KnxSenderTunneling.cs:36
at KNXLib.KnxConnectionTunneling.DisconnectRequest () [0x000b3] in <SOMEPATH>\knx.net\src\KNXLib\KnxConnectionTunneling.cs:257
at KNXLib.KnxConnectionTunneling.Disconnect () [0x00006] in <SOMEPATH>\knx.net\src\KNXLib\KnxConnectionTunneling.cs:128
16:44:37.229 Disonnected
16:44:37.260 [DEBUG] KNXLib.KnxConnection: KNX is disconnected
16:44:37.266 [DEBUG] KNXLib.KnxConnection: Send locked - 0 free locks
16:44:37.276 [INFO] KNXLib.KnxConnectionTunneling: KNXLib connecting...
16:44:37.302 Connected
16:44:37.310 [DEBUG] KNXLib.KnxConnection: KNX is connected. Unlocking send - 1 free locks
16:44:39.453 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:44:39.471 [DEBUG] KNXLib.KnxReceiver: 29-00-BC-D0-14-31-34-15-03-00-80-0C-4E
16:44:39.483 [DEBUG] KNXLib.KnxReceiver: Event Header Length: 6
16:44:39.495 [DEBUG] KNXLib.KnxReceiver: Event Protocol Version: 10
16:44:39.510 [DEBUG] KNXLib.KnxReceiver: Event Service Type: 0x0420
16:44:39.523 [DEBUG] KNXLib.KnxReceiver: Event Total Length: 23
16:44:39.540 [DEBUG] KNXLib.KnxReceiver: Event Message Code: 29
16:44:39.558 [DEBUG] KNXLib.KnxReceiver: Event Aditional Info Length: 0
16:44:39.574 [DEBUG] KNXLib.KnxReceiver: Event Control Field 1: 10111100
16:44:39.583 [DEBUG] KNXLib.KnxReceiver: Event Control Field 2: 11010000
16:44:39.593 [DEBUG] KNXLib.KnxReceiver: Event Source Address: 1.4.49
16:44:39.602 [DEBUG] KNXLib.KnxReceiver: Event Destination Address: 6/4/21
16:44:39.611 [DEBUG] KNXLib.KnxReceiver: Event Data Length: 3
16:44:39.619 [DEBUG] KNXLib.KnxReceiver: Event APDU: 0x00800C4E
16:44:39.636 [DEBUG] KNXLib.KnxReceiver: Event Data: 0x0C4E
16:44:39.644 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:44:39.815 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:44:39.826 [DEBUG] KNXLib.KnxReceiver: 29-00-BC-D0-14-64-0C-7C-03-00-80-02-BC
16:44:39.836 [DEBUG] KNXLib.KnxReceiver: Event Header Length: 6
16:44:39.843 [Event] 1.4.49 ==( 0x00000C4E [2] )==> 6/4/21
16:44:39.850 [DEBUG] KNXLib.KnxReceiver: Event Protocol Version: 10
16:44:39.857 [DEBUG] KNXLib.KnxConnection: Device 1.4.49 sent event 0x0C4E to 6/4/21
16:44:39.864 [DEBUG] KNXLib.KnxReceiver: Event Service Type: 0x0420
16:44:39.882 [DEBUG] KNXLib.KnxReceiver: Event Total Length: 23
16:44:39.890 [DEBUG] KNXLib.KnxReceiver: Event Message Code: 29
16:44:39.911 [DEBUG] KNXLib.KnxReceiver: Event Aditional Info Length: 0
16:44:39.919 [DEBUG] KNXLib.KnxReceiver: Event Control Field 1: 10111100
16:44:39.926 [DEBUG] KNXLib.KnxReceiver: Event Control Field 2: 11010000
16:44:39.935 [DEBUG] KNXLib.KnxReceiver: Event Source Address: 1.4.100
16:44:39.945 [DEBUG] KNXLib.KnxReceiver: Event Destination Address: 1/4/124
16:44:39.954 [DEBUG] KNXLib.KnxReceiver: Event Data Length: 3
16:44:39.962 [DEBUG] KNXLib.KnxReceiver: Event APDU: 0x008002BC
16:44:39.971 [DEBUG] KNXLib.KnxReceiver: Event Data: 0x02BC
16:44:39.979 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:44:39.989 [Event] 1.4.100 ==( 0x000002BC [2] )==> 1/4/124
[...]
16:45:19.076 [DEBUG] KNXLib.KnxConnection: Device 1.2.10 sent event 0x00C8 to 1/2/4
16:45:20.375 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:45:20.402 [DEBUG] KNXLib.KnxReceiver: 29-00-BC-D0-1C-28-09-22-03-00-80-00-C8
16:45:20.427 [DEBUG] KNXLib.KnxReceiver: Event Header Length: 6
16:45:20.450 [DEBUG] KNXLib.KnxReceiver: Event Protocol Version: 10
16:45:20.468 [DEBUG] KNXLib.KnxReceiver: Event Service Type: 0x0420
16:45:20.487 [DEBUG] KNXLib.KnxReceiver: Event Total Length: 23
16:45:20.501 [DEBUG] KNXLib.KnxReceiver: Event Message Code: 29
16:45:20.516 [DEBUG] KNXLib.KnxReceiver: Event Aditional Info Length: 0
16:45:20.531 [DEBUG] KNXLib.KnxReceiver: Event Control Field 1: 10111100
16:45:20.545 [DEBUG] KNXLib.KnxReceiver: Event Control Field 2: 11010000
16:45:20.560 [DEBUG] KNXLib.KnxReceiver: Event Source Address: 1.12.40
16:45:20.575 [DEBUG] KNXLib.KnxReceiver: Event Destination Address: 1/1/34
16:45:20.603 [DEBUG] KNXLib.KnxReceiver: Event Data Length: 3
16:45:20.617 [DEBUG] KNXLib.KnxReceiver: Event APDU: 0x008000C8
16:45:20.631 [DEBUG] KNXLib.KnxReceiver: Event Data: 0x00C8
16:45:20.645 [DEBUG] KNXLib.KnxReceiver: -----------------------------------------------------------------------------------------------------
16:45:20.662 [Event] 1.12.40 ==( 0x000000C8 [2] )==> 1/1/34
16:45:20.677 [DEBUG] KNXLib.KnxConnection: Device 1.12.40 sent event 0x00C8 to 1/1/34
16:45:22.127 [DEBUG] KNXLib.KnxReceiverTunneling: Received connection state response - No active connection with channel ID 92
16:45:22.153 Disonnected
16:45:22.177 [DEBUG] KNXLib.KnxConnection: KNX is disconnected
16:45:22.203 [DEBUG] KNXLib.KnxConnection: Send locked - 0 free locks
sometimes the connection lasts 2 minutes, sometimes it dies right away after just a few seconds.
DPT values from 3.xxx to 9.xxx are supported. But how can I use DPT for 10.001?
The following code in the KnxReceiverTunneling.cs is supposed to make sure you do not duplicate telegrams that were processed already:
lock (_rxSequenceNumberLock)
{
if (sequenceNumber <= _rxSequenceNumber)
process = false;
_rxSequenceNumber = sequenceNumber;
}
However sequenceNumber is a byte value and it gets reset after reaching 255. This results in loosing every 256th telegram. I'd rather have duplicate telegrams than missing some. Does it make sense to remove the 'process' variable and the associated logic?
Hi,
I guess the StateRequesterTimer checks the connection is alive every 60 seconds in KnxConnectionTunnelling. It executes the StateRequest method and send datagram to the device. Everythings seems fine. But whats the answer that should we get ? I dont see any answer after the StateRequest. If I am all wrong please could u explain me the StateRequest workflow ?
Thanks
I am using the Routing approach and i am not able to request a status.
Sending, Eventing works fine. But when i do a _connection.RequestStatus("1/2/3/"); the status event is not fired. just nothing happens.
any idea what might be wrong?
When i do switch on the lamp the status ga is updated and i do receive this update through the "Event" - event successfully.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.