/// <summary>
        /// Toggle Lighting State
        /// </summary>
        /// <param name="fiDeviceID"></param>
        /// <param name="fbToggleStatus"></param>
        private void ToggleLutronLight(int fiDeviceID, bool fbToggleStatus)
        {
            using (var loESDLutronEntities = new ESDLutronEntities())
            {
                var loBACnetDeviceDetail = loESDLutronEntities.BACnetDevices
                                           .Where(x => x.device_id == fiDeviceID &&
                                                  x.object_instance == (int?)LutronObjectType.Lighting_State)
                                           .Select(x => x).FirstOrDefault();

                if (loBACnetDeviceDetail != null && loBACnetDeviceDetail.object_instance != null)
                {
                    BacnetAddress loBacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.network_id);
                    loBacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.routed_source, (ushort)loBACnetDeviceDetail.routed_net);

                    IList <BacnetValue> loBacnetValueList;
                    moBacnetClient.ReadPropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_PRESENT_VALUE, out loBacnetValueList);


                    BacnetValue   loBacnetNewValue = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED, fbToggleStatus == true ? 1 : 0);
                    BacnetValue[] loWriteValue     = { loBacnetNewValue };

                    moBacnetClient.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_PRESENT_VALUE, loWriteValue);

                    //BacnetValue[] loNewBacnetValue = { new BacnetValue(Convert.ToSingle(111)) };

                    ////bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_ACTION, loNewBacnetValue);
                    ////bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewBacnetValue);
                    //bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewBacnetValue);
                }
            }

            //bool ret = WriteScalarValue(1, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 2), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewValue);
        }
        public static LightLevelEntity SetConfLightLevel(LightLevelEntity lightLevelEntity)
        {
            var bacnetDeviceFromDB = lutronEntities.BACnetDevices
                                     .Where(x => x.device_id == lightLevelEntity.DeviceID &&
                                            x.object_instance == (int?)LutronObjectType.Lighting_Level)
                                     .Select(x => x).FirstOrDefault();

            if (bacnetDeviceFromDB != null && bacnetDeviceFromDB.bacnet_device_id > 0)
            {
                BacnetAddress bacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.network_id);
                bacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.routed_source,
                                                               (ushort)bacnetDeviceFromDB.routed_net);


                BacnetValue   newLightLevel      = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_REAL, Convert.ToSingle(lightLevelEntity.LightLevel));
                BacnetValue[] writeNewLightLevel = { newLightLevel };
                if (bacNetClient == null)
                {
                    bacNetClient = BackNetClientInit.NewBackNetClient();
                }
                bacNetClient.WritePropertyRequest(bacnetAddress,
                                                  new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, (uint)LutronObjectType.Lighting_Level),
                                                  BacnetPropertyIds.PROP_PRESENT_VALUE, writeNewLightLevel);
            }



            return(BackNetReadAction.GetConfLightLevel(lightLevelEntity.DeviceID));
        }
        private void WriteObjectsPropertiesReferences()
        {
            List <BacnetValue> values = new List <BacnetValue>();

            if (listReferences.Items.Count != 0)
            {
                values = new List <BacnetValue>();

                foreach (ListViewItem lvi in listReferences.Items)
                {
                    BacnetDeviceObjectPropertyReference b = (BacnetDeviceObjectPropertyReference)lvi.Tag;
                    values.Add(new BacnetValue(b));
                }
            }

            comm.WritePropertyRequest(adr, schedule_id, BacnetPropertyIds.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, values);
        }
Esempio n. 4
0
        private async void Write_ClickAsync(object sender, EventArgs e)
        {
            var address     = txt_address.Text?.Trim();
            var value       = txt_value.Text?.Trim();
            var addressPart = address.Split('_');

            BacProperty rpop   = null;
            BacNode     bacnet = null;

            if (addressPart.Length == 1)
            {
                rpop   = devicesList.SelectMany(t => t.Properties).Where(t => t.PROP_OBJECT_NAME == address).FirstOrDefault();
                bacnet = devicesList.Where(t => t.Properties.Any(p => p.PROP_OBJECT_NAME == address)).FirstOrDefault();
            }
            else if (addressPart.Length == 2)
            {
                rpop = devicesList.SelectMany(t => t.Properties)
                       .Where(t => t.ObjectId.Instance == uint.Parse(addressPart[0]) && t.ObjectId.Type == (BacnetObjectTypes)int.Parse(addressPart[1]))
                       .FirstOrDefault();
                bacnet = devicesList
                         .Where(t => t.Properties.Any(p => p.ObjectId.Instance == uint.Parse(addressPart[0]) && p.ObjectId.Type == (BacnetObjectTypes)int.Parse(addressPart[1])))
                         .FirstOrDefault();
            }
            else
            {
                Log("请输入正确的地址");
                return;
            }

            if (rpop == null)
            {
                Log("没有找到对应的点");
                return;
            }

            BacnetValue[] NoScalarValue = { new BacnetValue(value.ToDataFormType(rpop.DataType)) };
            int           retry         = 0;//重试

tag_retry:
            try
            {
                await Task.Delay(retry * 200);

                Bacnet_client.WritePropertyRequest(bacnet.Address, rpop.ObjectId, BacnetPropertyIds.PROP_PRESENT_VALUE, NoScalarValue);
                ShwoText(string.Format("[写入成功][{2}] 点:{0,-15} 值:{1}", address, value, retry));
            }
            catch (Exception ex)
            {
                retry++;
                if (retry < 4)
                {
                    goto tag_retry;           //强行重试
                }
                Log($"写入失败:{ex.Message} [{retry - 1}]");
            }
        }
Esempio n. 5
0
 private void WriteCalendar()
 {
     try
     {
         List <BacnetValue> v = new List <BacnetValue>();
         v.Add(new BacnetValue(calendarEntries));
         comm.WritePropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DATE_LIST, v);
     }
     catch { }
 }
Esempio n. 6
0
        private void WriteProperties()
        {
            try // Write Priorities
            {
                List <BacnetValue> PropVal = new List <BacnetValue>();

                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Off.Text)));
                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Fault.Text)));
                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Normal.Text)));

                comm.WritePropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRIORITY, PropVal);
            }
            catch { }
            try  // Write recipient List
            {
                List <BacnetValue> PropVal = new List <BacnetValue>();
                foreach (TabPage t in RecipientsTab.Controls)
                {
                    if (t.Name != "Not Set") // Entry is OK ?
                    {
                        RecipientUserCtrl        r = (RecipientUserCtrl)t.Controls[0];
                        DeviceReportingRecipient newrp;
                        if (r.adr != null) // recipient is an IP address
                        {
                            newrp = new DeviceReportingRecipient(r.WeekOfDay, r.fromTime.Value, r.toTime.Value, r.adr, Convert.ToUInt16(r.ProcessId.Text), r.AckRequired.Checked, r.EventType);
                        }
                        else // recipient is a deviceId
                        {
                            newrp = new DeviceReportingRecipient(r.WeekOfDay, r.fromTime.Value, r.toTime.Value, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, r.deviceid), Convert.ToUInt16(r.ProcessId.Text), r.AckRequired.Checked, r.EventType);
                        }

                        PropVal.Add(new BacnetValue(newrp));
                    }
                }

                comm.WritePropertyRequest(adr, object_id, BacnetPropertyIds.PROP_RECIPIENT_LIST, PropVal);
            }
            catch { }
        }
        /*****************************************************************************************************/
        static bool WriteScalarValue(int device_id, BacnetObjectId BacnetObjet, BacnetPropertyIds Propriete, BacnetValue Value)
        {
            BacnetAddress adr;

            // Looking for the device
            adr = DeviceAddr((uint)device_id);
            if (adr == null)
            {
                return(false);              // not found
            }
            // Property Write
            BacnetValue[] NoScalarValue = { Value };
            if (bacnet_client.WritePropertyRequest(adr, BacnetObjet, Propriete, NoScalarValue) == false)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        private async void button2_ClickAsync(object sender, EventArgs e)
        {
            var key   = textBox3.Text?.Trim();
            var value = textBox2.Text?.Trim();
            var rpop  = devicesList.SelectMany(t => t.Properties)
                        .Where(t => t.PROP_OBJECT_NAME == key)
                        .FirstOrDefault();
            var bacnet = devicesList.Where(t => t.Properties.Any(p => p.PROP_OBJECT_NAME == key))
                         .FirstOrDefault();

            if (rpop == null)
            {
                Log("没有找到对应的点");
                return;
            }

            BacnetValue[] NoScalarValue = { new BacnetValue(value.ToDataFormType(rpop.DataType)) };
            int           retry         = 0;//重试

tag_retry:
            try
            {
                await Task.Delay(retry * 200);

                Bacnet_client.WritePropertyRequest(bacnet.Address, rpop.ObjectId, BacnetPropertyIds.PROP_PRESENT_VALUE, NoScalarValue, 0);
                //Bacnet_client.WritePropertyRequest(bacnet.Address, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, rpop.ObjectId.instance), BacnetPropertyIds.PROP_PRESENT_VALUE, NoScalarValue, 0);
                ShwoText(string.Format("[写入成功][{2}] 点:{0,-15} 值:{1}", key, value, retry));
            }
            catch (Exception ex)
            {
                retry++;
                if (retry < 4)
                {
                    goto tag_retry;           //强行重试
                }
                Log($"写入失败:{ex.Message} [{retry - 1}]");
            }
        }