半导体设备通信标准—secsgem v0.3.0版本使用说明文档(3)之SECS(SEMI E4,SEMI E5)

news2025/4/18 21:31:53

文章目录

  • 1、变量
    • 1.1、数组类型
    • 1.2、获取数据
    • 1.3、设置数据
    • 1.4、编码/解码
    • 1.5、Array
    • 1.6、List
    • 1.7、动态变量
  • 2、Items
    • 2.1、 Item types
    • 2.2、 Creating items
      • 2.1.1、 From value
      • 2.1.2、From SML text
      • 2.1.3、 From protocol text
    • 2.3、 Getting data
      • 2.3.1、 Python value
      • 2.3.2、 SML text
      • 2.1.3、 Protocol text
  • 3、Functions
  • 4、Handler

1、变量

SECS 定义了几种用于传输数据的类型。

Data TypeClassCode
List{py:class}secsgem.secs.variables.ArrayL
List{py:class}secsgem.secs.variables.ListL
Binary{py:class}secsgem.secs.variables.BinaryB
Boolean{py:class}secsgem.secs.variables.BooleanTF
ASCII{py:class}secsgem.secs.variables.StringA
8-Byte integer{py:class}secsgem.secs.variables.I8I8
1-Byte integer{py:class}secsgem.secs.variables.I1I1
2-Byte integer{py:class}secsgem.secs.variables.I2I2
4-Byte integer{py:class}secsgem.secs.variables.I4I4
8-Byte float{py:class}secsgem.secs.variables.F8F8
4-Byte float{py:class}secsgem.secs.variables.F4F8
8-Byte unsigned integer{py:class}secsgem.secs.variables.U8U8
1-Byte unsigned integer{py:class}secsgem.secs.variables.U1U1
2-Byte unsigned integer{py:class}secsgem.secs.variables.U2U2
4-Byte unsigned integer{py:class}secsgem.secs.variables.U4U4

Example:

>>> import secsgem.secs
>>> secsgem.secs.variables.String("TESTString")
<A "TESTString">
>>> secsgem.secs.variables.Boolean(True)
<BOOLEAN True >
>>> secsgem.secs.variables.U4(1337)
<U4 1337 >

1.1、数组类型

numeric 类型也可以是该类型的数组:

>>> secsgem.secs.variables.U1([1, 2, 3, 4])
<U1 1 2 3 4 >
>>> secsgem.secs.variables.Boolean([True, False, False, True])
<BOOLEAN True False False True >

这个数组的长度可以用 length 参数来固定:

>>> secsgem.secs.variables.U1([1, 2, 3], count=3)
<U1 1 2 3 >
>>> secsgem.secs.variables.U1([1, 2, 3, 4], count=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ext005207/Development/secsgem/secsgem/secs/variables.py", line 1439, in __init__
    self.set(value)
  File "/home/ext005207/Development/secsgem/secsgem/secs/variables.py", line 1537, in set
    raise ValueError("Value longer than {} chars".format(self.count))
ValueError: Value longer than 3 chars

>>> secsgem.secs.variables.String("Hello", count=3).get()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ext005207/Development/secsgem/secsgem/secs/variables.py", line 1220, in __init__
    self.set(value)
  File "/home/ext005207/Development/secsgem/secsgem/secs/variables.py", line 1337, in set
    raise ValueError("Value longer than {} chars ({} chars)".format(self.count, len(value)))
ValueError: Value longer than 3 chars (5 chars)

1.2、获取数据

该数据可通过 {py:func}secsgem.secs.variables.U1.get` 方法进行访问,数组则可通过索引运算符进行访问:

>>> secsgem.secs.variables.U1(1).get()
1
>>> secsgem.secs.variables.U1([1, 2, 3], count=3).get()
[1, 2, 3]
>>> secsgem.secs.variables.U1(1)[0]
1
>>> secsgem.secs.variables.U1([1, 2, 3])[1]
2

1.3、设置数据

数据可以通过 {py:func}secsgem.secs.variables.String.set 方法进行设置,数组可以通过索引运算符进行更新:

>>> v=secsgem.secs.variables.U1([1, 2, 3], count=3)
>>> v.set([3, 2, 1])
>>> v
<U1 3 2 1 >
>>> v[0] = 1
>>> v
<U1 1 2 1 >

1.4、编码/解码

这些变量类型本身可以使用 {py:func}secsgem.secs.variables.Array.encode 和 {py:func}secsgem.secs.variables.String.decode 方法将数据转换为可与 HSMS 协议进行传输的 ASCII 数据:

>>> v=secsgem.secs.variables.String("Hello")
>>> d=v.encode()
>>> d
'A\x05Hello'
>>> secsgem.common.format_hex(d)
'41:05:48:65:6c:6c:6f'
>>> v.set("NewText")
>>> v
<A "NewText">
>>> v.decode(d)
7
>>> v
<A "Hello">

1.5、Array

{py:class}secsgem.secs.variables.Array 是一种用于表示同类型列表的特殊类型。数组中的各项可以通过索引运算符进行访问。

>>> v=secsgem.secs.variables.Array(secsgem.secs.variables.U4)
>>> v.set([1, 2, 3])
>>> v
<L [3]
<U4 1 >
<U4 2 >
<U4 3 >

>
>>> v.get()
[1, 2, 3]
>>> v[1]
<U4 2 >

可以使用 {py:func}secsgem.secs.variables.Array.append 方法向数组添加新元素。

1.6、List

{py:func}secsgem.secs.variables.List 是一种用于不同类型列表的特殊类型。
列表中的各项可以通过像访问对象属性那样进行访问。

创建有序字典是必需的,因为 Python 的默认字典是随机排序的。排序是必不可少的,因为双方都需要数据保持相同的顺序。

>>> v=secsgem.secs.variables.List([secsgem.secs.data_items.OBJACK, secsgem.secs.data_items.SOFTREV])
>>> v.OBJACK=3
>>> v.SOFTREV="Hallo"
>>> v
<L [2]
<U1 3 >
<A "Hallo">

>
>>> v.SOFTREV
<A "Hallo">
>>> secsgem.common.format_hex(v.encode())
'01:02:a5:01:03:41:05:48:61:6c:6c:6f'

1.7、动态变量

{py:class}secsgem.secs.variables.Dynamic 类型可变,若指定为特定的一组类型,则可取不同的类型。

>>> v=secsgem.secs.variables.Dynamic([secsgem.secs.variables.String, secsgem.secs.variables.U1])
>>> v.set(secsgem.secs.variables.String("Hello"))
>>> v
<A "Hello">
>>> v.set(secsgem.secs.variables.U1(10))
>>> v
<U1 10 >
>>> v.set(secsgem.secs.variables.U4(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ext005207/Development/secsgem/secsgem/secs/variables.py", line 255, in set
    raise ValueError("Unsupported type {} for this instance of Dynamic, allowed {}".format(value.__class__.__name__, self.types))
ValueError: Unsupported type U4 for this instance of Dynamic, allowed [<class 'secsgem.secs.variables.String'>, <class 'secsgem.secs.variables.U1'>]

2、Items

项目是构成 SECS 消息结构的实体。
就本包而言,列表也被假定为项目。

2.1、 Item types

TypeClassCode
List{py:class}secsgem.secs.items.ItemLL
Binary{py:class}secsgem.secs.items.ItemBB
Boolean{py:class}secsgem.secs.items.ItemBOOLEANTF
ASCII{py:class}secsgem.secs.items.ItemAA
JIS-8{py:class}secsgem.secs.items.ItemJJ
8-Byte integer{py:class}secsgem.secs.items.ItemI8I8
1-Byte integer{py:class}secsgem.secs.items.ItemI1I1
2-Byte integer{py:class}secsgem.secs.items.ItemI2I2
4-Byte integer{py:class}secsgem.secs.items.ItemI4I4
8-Byte float{py:class}secsgem.secs.items.ItemF8F8
4-Byte float{py:class}secsgem.secs.items.ItemF4F8
8-Byte unsigned integer{py:class}secsgem.secs.items.ItemU8U8
1-Byte unsigned integer{py:class}secsgem.secs.items.ItemU1U1
2-Byte unsigned integer{py:class}secsgem.secs.items.ItemU2U2
4-Byte unsigned integer{py:class}secsgem.secs.items.ItemU4U4

2.2、 Creating items

2.1.1、 From value

可以通过 Item 类的 from_value 方法来创建项目对象。

>>> import secsgem.secs.items
>>> 
>>> secsgem.secs.items.Item.from_value(10)
< U1 10 >
>>>
>>> secsgem.secs.items.Item.from_value([["Hallo", b"Welt"], 10, 2.5])
< L [3]
    < L [2]
        < A "Hallo">
        < B 0x57 0x65 0x6c 0x74 >
    >
    < U1 10 >
    < F4 2.5 >
>

这将自动为传递的 Python 值选择相应的项类型。
但可以通过传入一个项对象而非 Python 值来对其进行覆盖。

>>> secsgem.secs.items.Item.from_value([secsgem.secs.items.ItemU4(10)])
< L [1]
    < U4 10 >
>

特定的项类型可以通过在构造函数中使用 Python 值来进行初始化。

>>> secsgem.secs.items.ItemI4(10)
< I4 10 >
>>>
>>> secsgem.secs.items.ItemI4([10, 20])
< I4 10 20 >
>>>
>>> secsgem.secs.items.ItemL([10, 20])
< L [2]
    < U1 10 >
    < U1 20 >
>
>>>
>>> secsgem.secs.items.ItemI4("text")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/secsgem/secs/item.py", line 132, in __init__
    self._value = self.validate_value(value)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/secsgem/secs/item_number.py", line 77, in validate_value
    raise self._invalid_type_exception(value)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/secsgem/secs/item.py", line 508, in _invalid_type_exception
    raise TypeError(f"Invalid value '{data}' of '{data.__class__.__name__}' for '{cls.__name__}'")
TypeError: Invalid value 'text' of 'str' for 'ItemI4'

2.1.2、From SML text

还可以通过 SML 字符串创建一个项目。

>>> secsgem.secs.items.Item.from_sml("< U4 10 >")
< U4 10 >
>>> 
>>> type(secsgem.secs.items.Item.from_sml("< U4 10 >"))
<class 'secsgem.secs.item_number.ItemU4'>
>>> 
>>> secsgem.secs.items.Item.from_sml("""
< L [3]
    < L [2]
        < A "Hallo">
        < B 0x57 0x65 0x6c 0x74 >
    >
    < U4 10 >
    < F4 2.5 >
>
""")
< L [3]
    < L [2]
        < A "Hallo">
        < B 0x57 0x65 0x6c 0x74 >
    >
    < U4 10 >
    < F4 2.5 >
>

2.1.3、 From protocol text

通过 SECS-I/HSMS 接收的二进制数据可以使用 decode 方法进行解码。

>>> secsgem.secs.items.Item.decode(b'\x01\x03\x01\x02A\x05Hallo!\x04Welt\xa5\x01\n\x91\x04@ \x00\x00')
< L [3]
    < L [2]
        < A "Hallo">
        < B 0x57 0x65 0x6c 0x74 >
    >
    < U1 10 >
    < F4 2.5 >
>

2.3、 Getting data

2.3.1、 Python value

通过使用 value 属性,可以获取一个项目的 Python 值。

>>> item = secsgem.secs.items.Item.from_value([["Hallo", b"Welt"], 10, 2.5])
>>> item.value
[['Hallo', b'Welt'], 10, 2.5]

2.3.2、 SML text

通过使用 sml 属性可以生成一个 SML 字符串。

>>> item = secsgem.secs.items.Item.from_value([["Hallo", b"Welt"], 10, 2.5])
>>> item.sml
'< L [3]\n    < L [2]\n        < A "Hallo">\n        < B 0x57 0x65 0x6c 0x74 >\n    >\n    < U1 10 >\n    < F4 2.5 >\n>'

该条目对象的 Python 输出还会打印出 SML 文本。

>>> item = secsgem.secs.items.Item.from_value([["Hallo", b"Welt"], 10, 2.5])
>>> item
< L [3]
    < L [2]
        < A "Hallo">
        < B 0x57 0x65 0x6c 0x74 >
    >
    < U1 10 >
    < F4 2.5 >
>

2.1.3、 Protocol text

SECS-I/HSMS 协议文本可以通过 encode 方法生成。

>>> item = secsgem.secs.items.Item.from_value([["Hallo", b"Welt"], 10, 2.5])
>>> item.encode()
b'\x01\x03\x01\x02A\x05Hallo!\x04Welt\xa5\x01\n\x91\x04@ \x00\x00'

3、Functions

该函数是从 {py:class}secsgem.secs.functionbase.SecsStreamFunction 继承而来的。

示例:

class SecsS02F33(SecsStreamFunction):
    _stream = 2
    _function = 33

    _data_format = [
        DATAID,
        [
            [
                RPTID,
                [VID]
            ]
        ]
    ]

    _to_host = False
    _to_equipment = True

    _has_reply = True
    _is_reply_required = True

    _is_multi_block = True

函数的数据可以通过与变量相同的功能进行读取和操作。
{py:func}secsgem.secs.functionbase.SecsStreamFunction.set、{py:func}secsgem.secs.functionbase.SecsStreamFunction.get、{py:func}secsgem.secs.functionbase.SecsStreamFunction.append、索引运算符以及对象属性。
这些对象还可以自行编码和解码。

Usage:

>>> f=secsgem.secs.functions.SecsS02F33()
>>> f.DATAID=10
>>> f.DATA.append({"RPTID": 5, "VID": ["Hello", "Hallo"]})
>>> f.DATA.append({"RPTID": 6, "VID": ["1", "2"]})
>>> f
S2F33 W
<L [2]
<U1 10 >
<L [2]
<L [2]
    <U1 5 >
    <L [2]
    <A "Hello">
    <A "Hallo">
    >
>
<L [2]
    <U1 6 >
    <L [2]
    <A "1">
    <A "2">
    >
>
>
> .
>>> f.DATA[1].VID[0]="Goodbye"
>>> f.DATA[1].VID[1]="Auf Wiedersehen"
>>> f
S2F33 W
<L [2]
<U1 10 >
<L [2]
<L [2]
    <U1 5 >
    <L [2]
    <A "Hello">
    <A "Hallo">
    >
>
<L [2]
    <U1 6 >
    <L [2]
    <A "Goodbye">
    <A "Auf Wiedersehen">
    >
>
>
> .
>>> secsgem.common.format_hex(f.encode())
'01:02:a5:01:0a:01:02:01:02:a5:01:05:01:02:41:05:48:65:6c:6c:6f:41:05:48:61:6c:6c:6f:01:02:a5:01:06:01:02:41:07:47:6f:6f:64:62:79:65:41:0f:41:75:66:20:57:69:65:64:65:72:73:65:68:65:6e'

编码后的数据可作为数据字符串与 {py:class}secsgem.hsms.HsmsMessage 中的 {py:class}secsgem.hsms.HsmsStreamFunctionHeader 一同使用。
请参阅 {doc}/hsms/messages

4、Handler

SecsHandler 具有为特定流和函数添加回调的功能。

>>> def s01f13_handler(connection, packet):
...     print "S1F13 received"
...
>>> def on_connect(event, data):
...     print "Connected"
...
>>> settings = secsgem.hsms.Settings(address="127.0.0.1", port=5000, connect_mode=secsgem.hsms.HsmsConnectMode.PASSIVE, device_type=secsgem.common.DeviceType.HOST)
>>> client = secsgem.secs.SecsHandler(settings)
>>> client.events.connected += on_connect
>>> client.register_stream_function(1, 13, s01f13_handler)
>>>
>>> client.enable()
Connected
S1F13 received
>>> client.disable()

此外,还涉及有关收集事件、服务变量和设备常量的其他功能。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2337551.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据中台(大数据平台)之数据资源目录

数据资源目录是数据管理的账本&#xff0c;是数据应用的基础&#xff0c;更是是数据治理成果的体现&#xff0c;因此数据中台产品应提供数据资源目录编制、发布、资源挂载、下架的管理能力。 1.数据资源目录分类 资源目录能够支持基于业务特点创建和维护基础目录分类和特色目…

【随身WiFi】随身WiFi Debian系统优化教程

0.操作前必看 本教程基于Debian系统进行优化&#xff0c;有些操作对随身WiFi来说可能会带来负优化&#xff0c;根据需要选择。 所有操作需要在root用户环境下运行&#xff0c;否则都要加sudo 随身wifi Debian系统&#xff0c;可以去某安的随声WiFi模块自行搜索刷机 点赞&am…

JAVA Web_定义Servlet2_学生登录验证Servlet

题目 页面StudentLogin.html中有一HTML的表单代码如下&#xff1a; <form action"studentLogin" method"post">学生姓名&#xff1a;<input type"text" name"stuName" value""><br>登录密码&#xff1a;…

Unity入门笔记(缘更)

内容来源SiKi学院的Luna’s Fantasy 文章目录 一、基础知识1.准备2.基础知识1.层级(Layer)2.轴心点3.预制体(Prefab)4.刚体组件(Rigidbody)5.碰撞器组件(BoxCollider) 二、代码1.移动 一、基础知识 1.准备 Unity安装&#xff1a; https://unity.cn 2.基础知识 1.层级(Layer…

【Python】用Python写一个俄罗斯方块玩玩

【Python】用Python写一个俄罗斯方块玩玩 一、引言1.成品效果展示 二、思考准备1.思考设计2.代码设计2.1 游戏页面2.2 控件设计2.2.1 方块生成2.2.2 方块碰撞2.2.3 方块消融2.2.4 游戏主循环2.2.5 游戏窗口 三、游戏完整版 一、引言 今日看到侄子在玩游戏&#xff0c;凑近一看…

记录一次生产中mysql主备延迟问题处理

登录库&#xff1a; mysql -uXXXX -pXXXX -P3306 -hXXXXXX -A 备库上执行&#xff1a;show slave status\G 查看 seconds_Behind_Master&#xff0c;延迟 2705s&#xff0c;而且还一直在增加。 SHOW CREATE TABLE proc_i_income_temp; -- 查看表的结构 show index from proc…

ffmpeg无损转格式的命令行

将ffmpeg.exe拖入命令行窗口 c:\users\zhangsan>D:\ffmpeg-2025-03-11\bin\ffmpeg.exe -i happy.mp4 -c:v copy -c:a copy 格式转换后.mkv -c:v copy 仅做拷贝视频,不重新编码 -c:a copy 仅做拷贝音频 ,不重新编码

强化学习算法系列(五):最主流的算法框架——Actor-Critic算法框架

强化学习算法 &#xff08;一&#xff09;动态规划方法——策略迭代算法(PI)和值迭代算法(VI) &#xff08;二&#xff09;Model-Free类方法——蒙特卡洛算法(MC)和时序差分算法(TD) &#xff08;三&#xff09;基于动作值的算法——Sarsa算法与Q-Learning算法 &#xff08;四…

设计模式(结构型)-桥接模式

目录 摘要 定义 类图 角色 具体实现 优缺点 优点 缺点 使用场景 使用案例 JDBC 和桥接模式 总结 摘要 在软件开发领域&#xff0c;随着系统规模和复杂性的不断攀升&#xff0c;如何设计出具有良好扩展性、灵活性以及可维护性的软件架构成为关键挑战。桥接模式作为一…

【MySQL】MySQL数据库 —— 简单认识

目录 1. 数据库的介绍 1.1 什么是数据库 1.2 数据库和数据结构之间关系 2. 数据库分类 2.1 关系型数据库&#xff08;RDBMS&#xff09; 2.2 非关系型数据库 2.3 区别 一些行内名词简单解释&#xff1a; 3. 关于mysql 主要学什么 4. MySQL中重要的概念 4.1 概念 4…

RNN - 语言模型

语言模型 给定文本序列 x 1 , … , x T x_1, \ldots, x_T x1​,…,xT​&#xff0c;语言模型的目标是估计联合概率 p ( x 1 , … , x T ) p(x_1, \ldots, x_T) p(x1​,…,xT​)它的应用包括 做预训练模型&#xff08;eg BERT&#xff0c;GPT-3&#xff09;生成本文&#xff…

过拟合、归一化、正则化、鞍点

过拟合 过拟合的本质原因往往是因为模型具备方差很大的权重参数。 定义一个有4个特征的输入&#xff0c;特征向量为,定义一个模型&#xff0c;其只有4个参数&#xff0c;表示为。当模型过拟合时&#xff0c;这四个权重参数的方差会很大&#xff0c;可以假设为。当经过这个模型后…

【python画图】:从入门到精通绘制完美柱状图

目录 Python数据可视化&#xff1a;从入门到精通绘制完美柱状图一、基础篇&#xff1a;快速绘制柱状图1.1 使用Matplotlib基础绘制1.2 使用Pandas快速绘图 二、进阶篇&#xff1a;专业级柱状图定制2.1 多系列柱状图2.2 堆叠柱状图2.3 水平柱状图 三、专业参数速查表Matplotlib …

基础知识:离线安装docker、docker compose

(1)离线安装docker 确认版本:Ubuntu 18.04 LTS - bionic 确认架构:X86_64 lsb_release -a uname -a 官方指南:https://docs.docker.com/engine/install/ 选择Ubuntu,发现页面上最低是Ubuntu20.04, 不要紧

畅游Diffusion数字人(27):解读字节跳动提出主题定制视频生成技术Phantom

畅游Diffusion数字人(0):专栏文章导航 前言:主题定制视频生成,特别是zero-shot主题定制视频生成,一直是当前领域的一个难点,之前的方法效果很差。字节跳动提出了一个技术主题定制视频生成技术Phantom,效果相比于之前的技术进步非常显著。这篇博客详细解读一下这一工作。 …

《Adaptive Layer-skipping in Pre-trained LLMs》- 论文笔记

作者&#xff1a;Xuan Luo, Weizhi Wang, Xifeng Yan Department of Computer Science, UC Santa Barbara xuan_luoucsb.edu, weizhiwangucsb.edu, xyancs.ucsb.edu 1. 引言与动机 1.1 背景 LLM 的成功与挑战: 大型语言模型 (LLMs) 在翻译、代码生成、推理等任务上取得巨大成…

微信小程序实现table样式,自带合并行合并列

微信小程序在代码编写过程好像不支持原生table的使用&#xff0c;在开发过程中偶尔又得需要拿table来展示。 1.table效果展示 1.wxml <view class"table-container"><view class"table"><view class"table-row"><view cla…

电脑的品牌和配置

我的笔记本是2020年买的&#xff0c;之前的订单找不到了&#xff0c;就知道是联想&#xff0c;不清楚具体的配置。 本文来源&#xff1a;腾讯元宝 检查系统信息&#xff08;Windows&#xff09; 这通常是 ​​联想&#xff08;Lenovo&#xff09;​​ 的型号代码。 81XV 是联想…

Redis面试——常用命令

一、String &#xff08;1&#xff09;设置值相关命令 1.1.1 SET 功能&#xff1a;设置一个键值对&#xff0c;如果键已存在则覆盖旧值语法&#xff1a; SET key value [EX seconds] [PX milliseconds] [NX|XX]EX seconds&#xff1a;设置键的过期时间为 seconds 秒 PX milli…

Swin-Transformer-UNet改进:融合Global-Local Spatial Attention (GLSA) 模块详解

目录 1.模块概述 2.swinUNet网络 3. 完整代码 1.模块概述 Global-Local Spatial Attention (GLSA) 是一种先进的注意力机制模块,专为计算机视觉任务设计,能够同时捕捉全局上下文信息和局部细节特征。 该模块通过创新的双分支结构和自适应融合机制,显著提升了特征表示能…