public static void StartActivity(DeviceObject _device) { deviceId = _device.PROP_OBJECT_IDENTIFIER.Instance; device = _device; using (var loggerFactory = LoggerFactory.Create(b => { b.AddConsole(c => { c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] "; }); })) { // Bacnet on UDP/IP/Ethernet bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, loggerFactory: loggerFactory), loggerFactory: loggerFactory); } bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam); bacnet_client.OnReadPropertyRequest += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest); bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest); bacnet_client.OnWritePropertyRequest += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest); bacnet_client.OnSubscribeCOV += new BacnetClient.SubscribeCOVRequestHandler(handler_OnSubscribeCOV); bacnet_client.OnSubscribeCOVProperty += new BacnetClient.SubscribeCOVPropertyRequestHandler(handler_OnSubscribeCOVProperty); bacnet_client.OnReadRange += new BacnetClient.ReadRangeHandler(handler_OnReadRange); bacnet_client.OnAtomicWriteFileRequest += new BacnetClient.AtomicWriteFileRequestHandler(handler_OnAtomicWriteFileRequest); bacnet_client.OnAtomicReadFileRequest += new BacnetClient.AtomicReadFileRequestHandler(handler_OnAtomicReadFileRequest); // A sample to shows CreateObject & DeleteObject bacnet_client.OnCreateObjectRequest += new BacnetClient.CreateObjectRequestHandler(handler_OnCreateObjectRequest); device.m_PROP_PROTOCOL_SERVICES_SUPPORTED = device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_CREATE_OBJECT, true); bacnet_client.OnDeleteObjectRequest += new BacnetClient.DeleteObjectRequestHandler(handler_OnDeleteObjectRequest); device.m_PROP_PROTOCOL_SERVICES_SUPPORTED = device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_DELETE_OBJECT, true); BaCSharpObject.OnExternalCOVNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnCOVManagementNotify); bacnet_client.Start(); // go // Send Iam bacnet_client.Iam(deviceId, new BacnetSegmentations()); bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs); if ((_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS)) || (_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_SCHEDULE))) { bacnet_client.WhoIs(); // Send WhoIs : needed BY Notification & Schedule for deviceId<->IP endpoint device.SetIpEndpoint(bacnet_client); // Register the endpoint for IP Notification usage with IP:Port } }
public void StartActivity(DeviceObject _device) { deviceId = _device.PROP_OBJECT_IDENTIFIER.instance; device = _device; // Bacnet on UDP/IP/Ethernet bacnet_client = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false)); bacnet_client.OnIam += new BacnetClient.IamHandler(handler_OnIam); bacnet_client.OnReadPropertyRequest += new BacnetClient.ReadPropertyRequestHandler(handler_OnReadPropertyRequest); bacnet_client.OnReadPropertyMultipleRequest += new BacnetClient.ReadPropertyMultipleRequestHandler(handler_OnReadPropertyMultipleRequest); bacnet_client.OnWritePropertyRequest += new BacnetClient.WritePropertyRequestHandler(handler_OnWritePropertyRequest); bacnet_client.OnSubscribeCOV += new BacnetClient.SubscribeCOVRequestHandler(handler_OnSubscribeCOV); bacnet_client.OnSubscribeCOVProperty += new BacnetClient.SubscribeCOVPropertyRequestHandler(handler_OnSubscribeCOVProperty); bacnet_client.OnReadRange += new BacnetClient.ReadRangeHandler(handler_OnReadRange); // A sample to shows CreateObject & DeleteObject bacnet_client.OnCreateObjectRequest += new BacnetClient.CreateObjectRequestHandler(handler_OnCreateObjectRequest); device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_CREATE_OBJECT, true); bacnet_client.OnDeleteObjectRequest += new BacnetClient.DeleteObjectRequestHandler(handler_OnDeleteObjectRequest); device.m_PROP_PROTOCOL_SERVICES_SUPPORTED.SetBit((byte)BacnetServicesSupported.SERVICE_SUPPORTED_DELETE_OBJECT, true); BaCSharpObject.OnExternalCOVNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnCOVManagementNotify); try { bacnet_client.Start(); // go // Send Iam bacnet_client.Iam(deviceId, BacnetSegmentations.SEGMENTATION_BOTH, 61440); bacnet_client.OnWhoIs += new BacnetClient.WhoIsHandler(handler_OnWhoIs); if ((_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS)) || (_device.FindBacnetObjectType(BacnetObjectTypes.OBJECT_SCHEDULE))) { bacnet_client.WhoIs(); // Send WhoIs : needed BY Notification & Schedule for deviceId<->IP endpoint device.SetIpEndpoint(bacnet_client); // Register the endpoint for IP Notification usage with IP:Port } } catch { if (Environment.UserInteractive) { Console.WriteLine("\nSocket Error, Udp Port already in used in exclusive mode ?"); } } }