基于共享内存的数据分发库
项目描述
自述文件
项目范围:
内存共享:
基于数据结构文件在共享内存中创建数据结构。读写数据结构标签。数据结构标签可以在系统范围内访问。
普罗康:
生产商:
创建一个套接字服务器并连接或创建共享数据结构。消费者可以连接到生产者,数据结构中的所有数据将定期传输给连接的消费者。
消费者:
连接到生产者,创建或连接到共享数据结构。共享数据结构将定期被覆盖,因此共享数据结构在消费者站点上是只读的。
dmsg
生产者和消费者之间的直接基于事件的消息。消息将在发送前使用 pickle 进行序列化,并在返回消息之前使用 pickle 进行反序列化。
数据结构.xml文件:
<config>
<connection_status LENGTH="2" TYPE="int" INIT_VALUE="0" DESCRIPTION="connection of status" > </connection_status>
<tag_1 LENGTH="10" TYPE="int" > </tag_1>
<timestamp LENGTH="20" TYPE="float" > </timestamp>
<status LENGTH="100" TYPE="string" ></status>
</config>
必需的标签:
对于生产/消费数据结构,需要“connection_status”。
所需成员:
tag_1 = 引用名称,用于从数据结构中读取或写入。
LENGTH = 标签长度,以字节为单位,最小值为 2
可选成员
TYPE = 标签类型,INIT_VALUE = 初始标签值
描述 = 标签的描述
用法:
写入标签:
from comram import ramshare
test = ramshare.RamShare("share_name", data_type="/path_to_structure/test_structure.xml")
test.write_to_tag("tag_1", 99)
从标签中读取:
from comram import ramshare
test = ramshare.RamShare("share_name", data_type="/path_to_structure/test_structure.xml")
tag_1 = test.read_tag("tag_1")
产生数据结构:
from comram import procon
producer = procon.Produce("share_name", data_type="/path_to_structure/test_structure.xml", ip="127.0.0.1", port=9980,
send_interval=0.01)
producer.start_produce()
消费数据结构:
from comram import procon
consumer = procon.Consume("share_name", "consumer_name", data_type="/path_to_structure/test_structure.xml",
ip="127.0.0.1", port=9980)
consumer.start_consume()
dmsg 用法:
生产:
from comram import dmsg
test_producer = dmsg.Produce("127.0.0.1", 9500, debug=True)
test_producer.send_message("test message")
test_producer.close()
消耗:
from comram import dmsg
test_consume = dmsg.Consume("test_consumer", "127.0.0.1", 9500)
test_msg = test_consume.get_msg()
test_consume.close()
已知的问题
不能低于 2 字节的标签长度
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
comram-0.0.12.tar.gz
(7.2 kB
查看哈希)
内置分布
comram-0.0.12-py3-none-any.whl
(8.4 kB
查看哈希)