bacnetClient.Start();
BacnetAddress deviceAddress = new BacnetAddress(BacnetAddressTypes.IP, "10.20.30.250:47808");
BacnetObjectId objectId = new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_OUTPUT, 2);
IList<BacnetValue> values;
bool success = bacnetClient.ReadPropertyRequest(deviceAddress, objectId, BacnetPropertyIds.PROP_PRESENT_VALUE, out values);
if (success)
{
string presentValue = values[0].Value.ToString();
Console.WriteLine($"Present Value: {presentValue}");
}
else
{
Console>writeLine("Error occurred while reading from the device.")
}
uint value = 1;
IList<BacnetValue> valtowrite = new BacnetValue[1] { new BacnetValue(value) };
bool successWrite = bacnetClient.WritePropertyRequest(deviceAddress, objectId, BacnetPropertyIds.PROP_PRESENT_VALUE, valtowrite );
if (successWrite)
{
Console.WriteLine($"\nSuccessfully updated the status for OBJECT_BINARY_OUTPUT 2");
bool successRead = bacnetClient.ReadPropertyRequest(deviceAddress, objectId, BacnetPropertyIds.PROP_PRESENT_VALUE, out values);
if (successRead)
{
Console.WriteLine($"\nSuccessfully updated the status for OBJECT_BINARY_OUTPUT 2");
}
else {
Console.WriteLine("\n!! Error occured when reading from BACnet device. !!");
}
}
else
{
Console.WriteLine("\n !! Error occurred while writing to the bacnet device. !!");
}
在我的程序中,首先我启动了连接并从同一个对象读取值,它工作得很好。但是当我尝试写入值时,我收到一条错误消息
系统异常:设备拒绝,原因:INVALID_TAG
在System.IO.BACnet.BacnetClient.WritePropertyRequest(BacnetAddress adr,BacnetObjectId objectId,BacnetPropertyIds propertyId,IEnumerable`1 valueList,Byte invokeId)
我想写入(更新)BinaryOutput对象的值以更改其状态(活动/非活动)
我不知何故成功了。
using System.IO.BACnet;
BacnetClient bacnetClient = new BacnetClient(new BacnetIpUdpProtocolTransport(0xBAC0, false));
//start the connection with the network, which is connected with bacnet device
bacnetClient.Start();
// Define the BACnet address of the device
BacnetAddress deviceAddress = new BacnetAddress(BacnetAddressTypes.IP, "10.20.30.250:47808");
// Define the object identifier (e.g., Analog Input 1)
BacnetObjectId objectId = new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_OUTPUT, 2);
UInt32 newStatus = 1;
// create BacnetValue variable to write, using WritePropertyRequest
BacnetValue valueToWrite = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED, newStatus);
//Sends a request to write the Present_Value property of the specified object.
bool successWrite = bacnetClient.WritePropertyRequest(deviceAddress, objectId, BacnetPropertyIds.PROP_PRESENT_VALUE, new[] { valueToWrite });
if (successWrite)
{
Console.WriteLine($"\nSuccessfully updated the status for OBJECT_BINARY_OUTPUT 2");
}
else
{
Console.WriteLine("\n !! Error occurred while writing to the bacnet device. !!");
}