Difference between revisions of "Peripheral (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Link to Category:Peripherals)
(Apparently the __TOC__ and arrangement of this page got spaghettified.)
Line 1: Line 1:
The Peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the [[Disk Drive]], the [[Advanced Monitor]] and [[Monitor]]. (More peripherals can be found under [[:Category:Peripherals|here]])<br />
+
__TOC__
[[Computer|Computers]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''.
+
The Peripheral API is for interacting with external [http://en.wikipedia.org/wiki/Peripheral peripherals], such as the [[Disk Drive]], the [[Advanced Monitor]] and [[Monitor]]. (More peripherals can be found under [[:Category:Peripherals|here]]). [[Computer|Computers]] and [[Turtle|Turtles]] are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to [[Rednet (API)|rednet]]. Both Computers and Turtles provide the same methods: ''turnOn'', ''shutdown'', ''reboot'', ''getID''.
  
 
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
 
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
 
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
 
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
+
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;Peripheral (API)</td></tr>
Peripheral (API)
+
</td></tr>
+
  
 
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
 
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
Line 26: Line 24:
  
 
</table>
 
</table>
 
 
[[Category:APIs]]
 
  
 
==Remote Peripherals using Networking Cables==
 
==Remote Peripherals using Networking Cables==

Revision as of 11:44, 11 April 2013

The Peripheral API is for interacting with external peripherals, such as the Disk Drive, the Advanced Monitor and Monitor. (More peripherals can be found under here). Computers and Turtles are also considered peripherals and you can interface two adjacent computers, although in a more limited fashion compared to rednet. Both Computers and Turtles provide the same methods: turnOn, shutdown, reboot, getID.

Grid disk.png  Peripheral (API)
Method NameDescription
peripheral.isPresent(side) Returns true if a peripheral is present on side.
peripheral.getType(side) Returns the type or peripheral present on side, nothing returned if side is empty.
peripheral.getMethods(side) Returns a table containing all methods for peripheral on side.
peripheral.call(side, methodName, param1, param2, ...) Sends a function call to peripheral located on side. Return values match those of called method.
Note: methodName is a string.
peripheral.wrap(side) Returns a handle to the peripheral located on side. If assigned to a variable, it can be used to call all methods available from that peripheral, as if calling peripheral.call(), e.g.:
m = peripheral.wrap("left")
m.someMethod()
- is the same as -
peripheral.call("left","someMethod")

Remote Peripherals using Networking Cables

Using Networking Cables, you can attach and use peripherals without having them directly touching the computer. To connect a peripheral in this way, place a Wired Modem on any side of your computer, as you would a Wireless Modem, as well as all the peripherals you wish to connect, connecting all of them with Networking Cables. Then right click each of the wired modems. You should receive messages in your chat bar informing you of a successful connection. Don't forget to connect the computer too!

Finally, you need to wrap the wired modem on your computer using the methods above. As well as those outlined on the Modem API page, the following additional functions will then become available to you, where p is the variable the modem is wrapped to:

Method NameDescription
p.getNamesRemote() Returns the names of all connected peripherals. Peripheral names are the type of peripheral followed by an underscore and a unique number, e.g. "disk_0".
p.isPresentRemote(peripheral name) Returns true if the specified peripheral is connected; false otherwise.
p.getTypeRemote(peripheral name) Returns the type of the specified peripheral.
p.getMethodsRemote(peripheral name) Returns a table of all the methods for the specified peripheral.
p.callRemote(peripheral name, peripheral method) Calls the specified method for the specified peripheral.

Monitor

Monitor Peripheral functions have been moved to the Monitor page. In addition, the Advanced Monitor Peripheral functions have been moved to the Advanced Monitor page.

Printer

Printer Peripheral functions have been moved to the Printer page.

Computers

Computer Peripheral functions have been moved to the Computer page. In addition, the Advanced Computer Peripheral functions have been moved to the Advanced Computer page.