Eln Computer Probe

From Electrical Age
Jump to: navigation, search

The Eln Computer Probe is a block which allows a computer to read and manipulate signals passing through it, as well as wireless signals within range.

Functions

The functions it provides do not contain an internal API, so they will be defined here:

  • signalSetDir("side","in" or "out") - Sets the direction a signal flows on the specified side. Both arguments must be strings, and are case-sensitive. Always returns nil. This can be used to set a value before actually applying it to your ELN network, or to deactivate it without losing its value. This also means one cannot read and write a voltage value at the same time. Switch the modes on each port as needed or dedicate different ports for reading and writing.
  • signalGetDir("side") - Used to determine if the specified side is in "in" or "out" mode.
  • signalGetIn("side") - Gets the signal strength as a percentage. Multiply by 50 to get exact voltage value.
  • signalSetOut() - If the side is set to "out" use this function to set the signal's strength as a percentage. If the side is set to "in" the voltage won't change until it is set to "out". Divide by 50 to use the exact voltage value.
  • wirelessGet("channel name") - Gets the wireless signal strength as a percentage, uses channel name rather than side.
  • wirelessSet("channel name",number) - Sets the signal strength of the specified channel name. Uses the same percentage value. Divide by 50 to use exact voltage value.
  • wirelessRemove("channel name") - Removes a wireless channel from the block by name.
  • wirelessRemoveAll() - Clears the wireless channels within the block. This is used to disable all wireless interactions in a single command.

Directions

When a probe is placed, 6 sides will appear printed on the sides of the block. These always face the same way, no matter which direction you place the block in. These are used to control the previous functions, usually to specify which side to operate the function on. Its naming structure is a reference to transistors, where P-type is considered positive and N-type is considered negative. The x and y refers to the co-ordinate value.

  • XN - Faces West
  • XP - Faces East
  • YN - Faces Ground
  • YP - Faces Skyward
  • ZN - Faces North
  • ZP - Faces South

Sample Code

These are some ideas for how you can use these functions. At the bottom of this section there is a listing that combines all of this content into one file.

Configuring I/O

This configures a side of the Computer Probe (there are 6 independently configurable sides) for input or output

probe.signalSetDir("ZP","out") --The South end is now emitting voltage
probe.signalSetDir("ZN","in") --The North end is now reading voltage

Reading voltages

This reads a probe side set for input.

The signalGetIn() method takes the side and returns a floating point number between 0 and 1, which correlates the range 0 to 50 volts.

local voltage = probe.signalGetIn("ZN") * 50 -- Reads the North end as a voltage value
local output = voltage / 2 --The output is now half the value of the input

Writing voltages

This writes a probe side output voltage.

The signalSetOut() method takes the side and the output (a number between 0 and 1 inclusive is accepted) and returns (probably) nothing.

Said number between 0 and 1 correlates to a voltage between 0 and 50 volts.

probe.signalSetOut("ZP",output/50) --Now the South end is emitting half the value of the North end

Final Listing

You can type this code into a .lua file (use the edit command to write files) and it will run once and work as expected. If you wanted to halve the voltage constantly, you would need a loop of some kind.

local component = require("component")
local probe = component.ElnProbe
probe.signalSetDir("ZP","out") --The South end is now emitting voltage
probe.signalSetDir("ZN","in") --The North end is now reading voltage
local voltage = probe.signalGetIn("ZN") * 50 -- Reads the North end as a voltage value
local output = voltage / 2 --The output is now half the value of the input
probe.signalSetOut("ZP",output/50) --Now the South end is emitting half the value of the North end

ComputerCraft

The above code works in ComputerCraft, you just need to change how you create the probe proxy:

local probe = peripheral.find("ElnProbe")

So, you would get this:

local probe = peripheral.find("ElnProbe")
probe.signalSetDir("ZP","out") --The South end is now emitting voltage
probe.signalSetDir("ZN","in") --The North end is now reading voltage
local voltage = probe.signalGetIn("ZN") * 50 -- Reads the North end as a voltage value
local output = voltage / 2 --The output is now half the value of the input
probe.signalSetOut("ZP",output/50) --Now the South end is emitting half the value of the North end