最近发现一个奇怪的事情,使用OPC UA进行通讯的时候发现,只要添加了多个点位的订阅UA_Client_runAsync(m_pClient, m_time)
,然后对于其中一个点位进行写操作时直接就断开连接UA_Client_writeValueAttribute(m_pClient, nodeId, myVariant)
。
然后就从网上找问什么,但是网上有关opc ua通讯的文章都少的可怜,大部分还都跟我之前写过了一模一样,不过功夫不负有心人,找到一篇issue,原文如下:
According to Part 4, 5.13.1.1 f, the server is required to send a keepalive after the maximum keep alive count has been reached. Depending on the settings, this could be minutes or even hours after the timeout in config.timeout.
Values for PublishingInterval and MaxKeepAliveCount are only limited by the data types used (double and UInt32). If the server permits large values, using revisedPublishingInterval*revisedMaxKeepAliveCount + config.timeout could lead to manuallySendPublishRequest blocking for a very long time in which the client can’t be used to read/write/call methods (except when sending the publish requests from another thread and using __UA_Client_AsyncService for everything else).
意思重点为:
则使用修订的PublisheringInterval * revisedMaxKeepAliveCount + config.timeout可能导致很长一段时间内手动阻止SendSendRequest的使用,导致客户端无法用于读取/写入/调用方法(除非从另一个客户端发送发布请求)线程并使用__UA_Client_AsyncService进行其他操作)。
从另一个issue中说是在最新0.3版本中已经修正,但是实在不知道0.3版本是几个意思??
索性还有另外一种办法,就是不要对使用订阅的客户端进行读写操作,直接新建两个客户端,一个用于订阅点位变化,一个用于读写操作
未经允许,禁止转载!如有有用,麻烦您给点个赞👍!!!