# 消息

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

## 在 Script 节点中创建消息

DepthAI 消息可以在设备上由节点自动创建，也可以在 [Script](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/script.md)
节点中手动创建。以下示例代码摘自 [Script 摄像头控制](https://docs.luxonis.com/software-v3/depthai/examples/script_camera_control.md) 示例，其中
[摄像头控制](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/camera_control.md) 消息在 Script 节点内每秒创建一次，并发送至
[摄像头](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/camera.md) 的输入（cam.inputControl）。

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

## 在主机上创建消息

消息也可以在主机计算机上创建，并通过输入队列发送至设备。以下示例中，我们移除了所有不相关的代码，仅展示如何在主机上创建消息并发送至设备。

```python
imgFrame = dai.ImgFrame()
frame = np.ones((300, 300, 3), np.uint8) * 255
imgFrame.setData(frame)
imgFrame.setWidth(frame.shape[1])
imgFrame.setHeight(frame.shape[0])
imgFrame.setType(dai.ImgFrame.Type.BGR888i)

with dai.Pipeline() as pipeline:
    # 定义源和输出
    script = pipeline.create(dai.node.Script)
    cam_input_q = script.inputs["frame"].createInputQueue()
    script.setScript("""
    import time
    while True:
        frame = node.io["frame"].get()
        if frame:
          node.warn("Received frame")
        time.sleep(0.1)
    """)

    pipeline.start()
    while pipeline.isRunning():

        cam_input_q.send(imgFrame)
        time.sleep(1)
```
