Data Wires LEGO MINDSTORMS NXT

資料線
Data Wire

資料線負責在程式指令之間傳送資料. 很多指令的功能是需要資料線來連結,例如隨機指令的輸出只能依賴資料線來傳遞.
Data wires carry information between programming blocks. Many blocks require that a data wire be attached if the blocks are to function at all. For example, the output from a Random block can only be sent out via a data wire.

開啟資料集線器與連接資料線
Opening data hubs and creating data wires

你可以從資料集線器上拉出一條資料線. 幾乎所有的程式指令都有資料集線器跟使用資料線.
You create a data wire by “drawing it out” of a block’s data hub. Nearly all of the programming blocks have data hubs and can support data wires.

當指令被放到工作區上時就可以按下指令圖示的左下角,來打開該指令的資料集線器.
Open a block’s data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area.

Image showing two blocks side-by-side: one with an unopened data hub (with the tab surrounded with a colored rectangle), the other block with an open data hub (with a mouse pointer shown drawing out a data wire)

注意: 有時資料集線器沒有完全打開而導致有些連接埠被隱藏起來.此時可以再次按下圖示的左下角區域(如上面左圖所示).也可以藉由點選該區域而關閉資料集線(或是隱藏起沒有連結的資料線的連接埠). 這會有助於整理工作區域.
Note:Sometimes data hubs will not open completely, leaving some plugs hidden. Reveal all of a data hub’s plugs by clicking again on the tab area (as shown in the left image above). You can also close a data hub (or hide any unused plugs not connected to data wires) by clicking the tab area. This will help clean up your work area.

資料線連結
Drawing out a data wire

當滑鼠靠近連接埠或在其上方時,滑鼠的圖示將會改變.接著如果按下滑鼠按鍵並向右方拖曳,一條資料線就會像是從捲線器拉出來似的,可用來連結到其他資料集線器上的連接埠.
The cursor will change shape when it hovers over or is near a data plug. If you then press the mouse button and drag to the right, a data wire will “unroll” that can be connected to a plug on another block’s data hub.

資料線刪除
Deleting a data wire

如果要刪除一條從左方連接埠連到右方連接埠的資料線時,只須點選右方連接埠即可
.To delete a data wire that stretches from left to right between two data plugs, click on the right plug.

輸入與輸出
Input and output

連接到集線器左邊連接埠的資料線是屬於負責傳遞資料進入指令中(也就是輸入資料), 而要從指令送出資料時(也就是輸出資料),則須從集線器的右邊連接埠連接資料線.
Data wires carrying information to a block (i.e., carrying input) are connected to the plugs on the left side of its data hub. Data wires carrying information away from a block to another block (i.e., carrying output) are connected to the plugs on the right side.

Image of data wires

[A]輸入連接埠 [A] Input plug
[B]輸出連結埠 [B] Output plug
[C]數字資料線(黃) [C] Number data wire (yellow)
[D]邏輯資料線(綠) [D]Logic data wire (green)
[E]文字資料線(橘) [E]Text data wire (orange)
[F]無效資料線(灰) [F]Broken data wire (gray)

特定的資料型態
Data wires carry specific types of data

每條資料線都負責傳送特定資料.例如,一條從邏輯連接埠拉出的資料線則只能連結到另一個同屬邏輯連接埠的集線器上.
Each data wire carries a specific type of data between blocks. For example, if a data wire is dragged from a logic plug on a block’s data hub, it can only be connected to a logic plug on another block’s data hub.

資料線顏色
Data wire colors

資料線依照特定的顏色作識別:
Data wires are identified with specific colors:

無效的資料線
Broken data wires

如果資料線連結到錯誤資料型態的連接埠時,則該資料線會呈現斷線無效狀態並以灰色表示.而有無效的資料線存在就無法下載程式.If you try to connect a data wire to a plug of the wrong data type, the data wire will be “broken” and colored gray. You will not be able to download your program if it contains broken data wires.

點選無效的資料線時,在工作區右下方的幫助視窗中會看到無效的原因.
If you click on a broken wire you can read why it is broken in the small help window at the lower right corner of the work area.

Image of the little help window.

資料必須在連接埠的限制範圍內
Data must be within the possible range of the plug

如果資料線傳輸該連接埠資料範圍之外的資料時,該指令不是忽略資料就是轉成合理範圍內的資料.對那些只能接收少量輸入值的連接埠來說(例如,0,1,或2),該連結埠就會忽略超出範圍的數值.
If an input data wire transmits a value outside the possible range of the plug it is connected to, the block will either ignore the value or change it to a value within its range. For plugs that allow just a few input values (example: just 0, 1, or 2), the plug will ignore the input if a value arrives outside its range.

而對那些可以接收大量範圍輸入值(例如: 0~100)的連接埠來說,該連接埠就會將數值轉成可接受的範圍. 例如, 移動指令的動力連接埠接收到150的輸入值時,那麼移動指令就會轉成100(也就是動力連接埠的範圍內).
For plugs that accept larger input ranges (example: 0 – 100), the plug will force any input outside its range to fit. For example, if a Move block’s Power plug receives an input value of 150, the block will change the input value to 100 (i.e., a number within the Power plug’s range).

資料由輸入端傳至傳出端
Passing data from the input plug to the output plug

Image of two input/output pairs of plugs – show the first with both logic input and output wires; show the second with only a gray output wire; show some indication that the first example is okay and the second if is not

如果輸入連接埠有對應的輸出連接埠時,那麼輸入的資料就會原封不動地傳遞到輸出連接埠.在這樣的情況下, 如果輸入連接埠連著資料線,那麼就只能使用輸出連結埠來做連結. 也就是說,當連結輸出連接線到這樣的輸出連接埠,而不透過相對應的輸入資料線時,就會讓該輸出連接線呈現無效的狀態.
If an input plug has a corresponding output plug, the input data will pass through from the input plug to the output plug without being changed. In this case, you can only use the output plug if the input plug is connected to an input data wire; connecting an output data wire to such an output plug without a connected input data wire will cause the output data wire to be “broken” and colored gray.

資料集線器說明
Data Hub chart

每一個程式指令都有圖表來說明該資料集線器中各連接埠的特性.例如,喚醒指令的圖表就會像下圖所示:
The Help file for each programming block contains a chart that shows the different characteristics of the plugs on the block’s data hub. For example, the chart for the Keep Alive block looks like this:

  連接埠
Plug
資料型態
Data Type
資料範圍
Possible Range
資料意義
What the Values Mean
連接埠例外說明
This Plug is Ignored When...
Port 到睡著前的時間 Time until sleep 數字 Number 0 - 4294967296 以毫秒來表示到NXT睡著前的執行時間Time in milliseconds until the NXT goes to sleep