03、SECS-I协议介绍

博客 动态
0 147
羽尘
羽尘 2023-05-24 19:55:50
悬赏:0 积分 收藏

03、SECS-I 协议介绍

03、SECS-I 协议介绍

上一篇我们学习了 SECS-II 协议,对 SECS-II 协议有了初略的了解,现在我们再来一起学习 SECS-I 协议。

文章的内容基本上来自参考资料和自己看的文档,若有侵权,请联系删除,谢谢。

SECS-I属于传输协议标准,主要定义了电气规格、传输速度、交握码等物理信息。

1、SECS-I 基础介绍

注意,1、SECS-I 基础介绍 这一段内容主要是参考 SECS半导体设备通讯-1 SECS的基本概念 文章,但是内容加上了自己的理解以及看到的其他资料,所以与原文对比是有出入的。这段内容对 SECS-I 有一个初略的介绍,后面的内容来源自己查找的资料,对 SECS-I 有一个更加深入的介绍。因为本小节的内容主要参考 SECS半导体设备通讯-1 SECS的基本概念 ,特在此说明。

1.1 物理传输单位 bit

SECS-I 定义了使用RS-232作为传输媒质时点到点的数据通信。实际的传输由8位Bit连续发送,有一个开始位和一个停止位。

通信是 双向和异步的,但是同一时间只能有一个方向的数据进行传输方向由特殊字符和握手建立,然后发送数据本身。

注意这里 1 上面的是 lsb 。

1.2 逻辑传输单位 Block

数据被分块进行传输,每个数据块最大为 254 字节。一个消息是一个方向完整的通信单元,由1到32,767个块组成。每个块标头都包含用于标识该块作为特定消息的一部分的信息。

1.3 Block的组成

一个Block包括一个Length Byte、N Data Bytes 和 CheckSum

  • LengthByte:表示随后有多少个字节的数据(即 N bytes),不包括最后 2个字节的校验和
  • CheckSum:计算N Data Bytes的校验和;
  • N Data Bytes:Block中的数据,长度范围是 10 至 254 字节,它由十个字节的头和消息数据组成。

Data Bytes 由 10 byte Header 和 Message Data 组成:

  • MessageData:表示Data Bytes中的数据部分,由编码后的 SECS-II 消息构成
  • 10 byte Header:描述Data Bytes中的数据内容。

10 byte Header 由 4个内容组成,其中:

  • Device ID:Header的第一和第二字节,其第一个比特为 R-bit,其作用是指出消息传输的方向。
  • Message ID:Header的第三和第四字节,其第一个比特为 Wait-bit,用于指示消息的发送者是否需要回复。
  • Block No.:Header的第五和第六字节,其第一个比特为 End-bit,用于指示这个是否是消息的最后一个块。
  • System Bytes:Header的最后四个字节,第七和第八字节表示 source ID,用于表示消息的发送者,第九和第十字节表示 transaction ID,用于唯一标示每个发送的消息

我们一起看看 Block 的组成:

我们一起看看 Header 的组成:

这里的 Upper Device ID 是指:

1.4 Block的传输

块的传输过程,先传输块的长度,再传输块,最后发送校验码。

标准建议每次可传输的Date Bytes字节最多为254,如果一个消息的大小<245个字节,则以一个块的形式进行传输。如果一个消息的大小> 245个字节,则以分块的形式进行传输。

2、SECS-I Block Transfer Protocol

从上图中,我们可以得知,SECS-I 使用的是块传输协议。

块传输协议用于建立通信的方向,并为传递消息块提供环境。主消息或回复消息可能需要多个块传输(多块消息)。

2.1 Handshake Sequence(握手顺序)

看到这个,是不是想起来 TCP 建立连接时的三次握手。这里的作用是 TCP 的三次握手差不多,用于确认通信双方已经准备就绪。那接下来我们一起看看 Block Transfer Protocol 的握手顺序是怎么做的。

Block Transfer Protocol 中的握手顺序是主机和设备之间的字节交换

那既然是字节交换,交换的是哪些字节的呢?

Handshake Codes(握手码):

有四种 握手码。它们用于控制块传输协议中的数据流。下表展示了这四种握手码

Handshake Codes Hex Value 描述
ENQ 05 Ready to Send
EOT 04 Ready to Receive
ACK 06 Correct Reception
NAK 15 Incorrect Reception

SECS-I Parameters

用于在实现块传输协议时定义一些边界。下表显示了SECS-I参数:

SECS-I Parameters 描述
T1 Inter-Character Timeout
T12 Protocol Timeout
RTY Retry Limit (最大重试次数)
Master/Slave Resolve contention (解决争论)
  • T1: 在接受 BLOCK DATA时,接收到每个字符的时间间隔(从接收到第一个字符后开始计算)

Is the time between receiving each character (after receiving the first character) in the BLOCK DATA

  • T2: 发送 ENQ 和接收到 EOT 之间的时间间隔

Is the time between sending the ENQ and receiving the EOT

  • RTY: 这里说说我的理解,这里就是当使用 ENQ 开始发送后,接收到了 NAK 或者其他的错误(比如超时等),就会重新发送 ENQ,重新发送的最大次数是 RTY。

This defines the number of times to initiate the block transfer (start sending with the ENQ.) Upon the receipt of a NAK (or other protocol error), the RTY value is adjusted and the block transfer is again attempted.

  • Master/Slave: 用于解决争议。主机是 slave ,设备是 master。争论是指主机和设备同时尝试进行通信。下面显示了如何解决争论

Is used to resolve contention. The host is slave and the equipment is the master. Contention is when both the host and the equipment attempt to communicate at the same time. The following shows how contention is resolved

2.2 Block Data

2.2.1、块数据简介

块数据是单块或多块消息的数据部分。它包含一个Length Byte(长度字节), N Data Bytes(N个数据字节)和a two byte Checksum(一个两个字节校验和)

下面这张图很重要,一定要看懂,不然不知道 Block Data 是怎么组成的,自己写代码的时候,也会一脸懵逼。

接下来,我们对上面的图进行逐一的讲解:

  • Length Byte:是在块数据中发送的第一个字节。它是N个DAta Bytes(10 Byte Header + Data Structure)中的字节数。两个字节校验和不包括在这个计数中,值范围为10到254字节。这里要注意的是,Length Byte 占用一个字节

Is the first byte sent in the Block Data. It is the number of bytes in the N Date Bytes (10 Byte Header + Data Structure). The two byte Checksum is not included in this count The value ranges from 10 to 254 bytes.

  • N Data Bytes: 是消息块的数据部分。它包含一个10字节的报头和消息数据。大小范围从10字节到254字节。N个数据字节的最小为10(只包含10字节的字节头),最大为254。

– Is the data portion of the message block. It contains a 10 Byte Header, and the Message Data. The size ranges from 10 bytes to 254 bytes. The minimum size of N Data Bytes is 10 (contains only the 10 Byte Header), and the maximum is 254.

  • Message Data: 是消息的数据部分。它包含已编码的SECS-II的全部或部分(如果是多块消息)。这里需要注意的是,发送的是多块消息时, Message Data 只包含了已编码的 SECS-II 的部分。

Is the data portion of the message. It contains all or a portion (if a multiblock message) of the encoded SECS-II.

2.2.2、10 字节的Header

每个消息都包含一个报头。标头用于描述包含在块数据中的数据。它包含 Device ID, Message ID, Block Number, and System Bytes(设备ID、消息ID、块号和系统字节)。其他重要指标也包括在内。

接下来,我们一起来看看 Header 的 4 个组成部分:

  • Device ID: 报头的第1个和第2个字节是设备ID。左字节是上设备ID,右字节是下设备ID。左字节中最左边的位是反向位(R位)。R-位决定了消息的方向。

Bytes 1 and 2 of the header are the device ID. The left byte is the upper device ID, and the right byte is the lower device ID. The left most bit of the left byte is the reverse bit (R-bit). The R-bit determines the direction of the message.

  • Message ID: 报头的第3个字节和第4个字节是消息ID。左字节是上消息ID,右字节是下消息ID。左字节中最左边的位是等待位(W位)。w位用于表示主消息的发送方是否期望得到回复。

Bytes 3 and 4 of the header is the message ID. The left byte is the upper message ID, and the right byte is the lower message ID. The left most bit of the left byte is the Wait bit (W-bit). The W-Bit is used to indicate that the sender of the primary message is expecting a reply.

The message ID indicates the SECS-II stream and function. The upper message ID is the stream, and the lower message ID is the function.

如果还记得上一篇文章中,描述 Streams and Functions 取值范围, Stream 的取值范围是 0 ~ 127。因为 strem 的MSB 是 W-bit,用于表示是否期望得到回复。 Function 的范围是 0 ~ 255。

  • Block Number:
报头的第5个字节和第6个字节表示块号。左字节是 upper block number,右字节是  lower block number。左字节中最左边的位是结束位(E位)。E位表示这是否是消息的最后一个块。

当发送的消息需要多个块时,将使用多块消息。每个块都是数字并且是有序的(这里的数字应该指的是块的序号)。由于消息的接收者不知道一共发送了多少个块,所以使用 e位 指示当前块是不是最后一个块,不会最后一个块的话,后面还会有块发送过来。多块消息中的最大块数为32,767个。

Bytes 5 and 6 of the header is the block number. The left byte is the upper block number, and the right byte is the lower block number. The left most bit of the left byte is the end bit (E-bit). The E-bit indicates this is the last block of a message.

A multi-block message is used when the sent message requires more than one block. Each block is number and sent in order. Since the receiver of the message does not know how may blocks to expect, the E-bit indicates which block is the last, or if there are more bocks to follow. The maximum number of blocks in a multi-block message is 32,767.

  • System Bytes: 报头的最后四个字节system bytes(系统字节)。左边的两个字节是 source ID(源ID),右边的两个字节是 transaction ID(事务ID)。源ID标识消息的发送方,并用于消息路由。事务ID标识该消息,并且对于所发送的每个消息都是唯一的。在其关联应答处的主消息具有相同的(匹配的)系统字节。最后一句话如何理解呢?它的意思是,回复的消息的 System Bytes 和 发送的消息的 System Bytes 是相等的。

The last four bytes of the header are the system bytes. The left two bytes are the source ID, and the right two bytes are the transaction ID. The source ID identifies the sender of the message and is used for message routing. The transaction ID identifies the message and is unique for each message sent. A primary message at its associated reply have the same (matching) system bytes.

上面我们对 SECS-I 使用到的 Block Transfer Protocol 有了初略的了解。接下来,一起看看 如何发送 S1F1 指令,以及对应的回复指令 S1F2。

3、Example of S1F1 / S1F2

下面显示了在发送primary message和接收secondary reply message时传输的字节。这不是一个多块的消息。主机发送S1F1,设备发送S1F2应答。

这张图及其重要,对理解 block transfer protocol 特别重要,理解了这张图,对 SECS-II 和 SECS-I 算是有一个入门的了解了。

4、Typical SECS Protocol Parameters

这一节内容我们将一起看看Typical SECS Protocol Parameters(典型的SECS协议参数)

下面是 SECS-I / SECS-II 协议参数的摘要集,以及一些典型的值。

Parameter Function Typical value
Baud (波特率) Rate Serial line speed 9600
Device ID Identifier assigned to equipment (分配给设备的标识符) 0
T1 Inter-Character Timeout 1 (second)
T2 ENT / EOT Timeout 10 (seconds)
T3 Reply Timeout 45 (seconds)
T4 Inter-Block Timeout 45 (seconds)
RTY Retry Limit 3
M / S Master / Slave Host-Slave
Equip - Master

参考资料:

SECS半导体设备通讯-1 SECS的基本概念

posted @ 2023-05-24 19:21  画个一样的我  阅读(0)  评论(0编辑  收藏  举报
回帖
    羽尘

    羽尘 (王者 段位)

    2233 积分 (2)粉丝 (11)源码

     

    温馨提示

    亦奇源码

    最新会员