# 消息

消息在链接的[节点](https://docs.luxonis.com/software/depthai-components/nodes.md)之间发送。节点之间相互通信的唯一方式是发送消息。在目录中（页面左侧）所有 DepthAI 消息类型都列在
Messages 条目下。您可以点击它们以了解更多信息。

## 在 Script 节点中创建消息

DepthAI 消息可以在设备上自动创建，也可以由节点自动创建，或者手动在 Script 节点内部创建。在下面的示例中，代码取自 Script Camera Control 示例，其中每隔一秒在 Script 节点内部创建 Camera Control
消息，并发送到 ColorCamera 的输入（cam.inputControl）。

```python
script = pipeline.create(dai.node.Script)
script.setScript("""
  # 创建一条消息
  ctrl = CameraControl(1)
  # 配置消息
  ctrl.setCaptureStill(True)
  # 从 Script 节点发送消息
  node.io['out'].send(ctrl)
""")
```

## 在主机上创建消息

也可以在主机上创建并通过 XLinkIn 节点发送到设备。RGB Camera Control、Video & MobilenetSSD 和 Stereo Depth from host
代码示例完美展示了这一功能。在下面的示例中，我们移除了所有不相关的代码，以展示如何在主机上创建消息并通过 XLink 发送到设备。

```python
# 创建 XLinkIn 节点并配置它
xin = pipeline.create(dai.node.XLinkIn)
xin.setStreamName("frameIn")
xin.out.link(nn.input) # 将其连接到 NeuralNetwork 的输入

with dai.Device(pipeline) as device:
  # 创建输入队列，允许您向设备发送消息
  qIn = device.getInputQueue("frameIn")
  # 创建 ImgFrame 消息
  img = dai.ImgFrame()
  img.setData(frame)
  img.setWidth(300)
  img.setHeight(300)
  qIn.send(img) # 将消息发送到设备
```
