Signal Ports
Overview
Signal Ports are a core feature of the Electric Computer system in CC: Computer Energetics. They provide a way to interact with external hardware components by exposing physical input/output capabilities through software APIs.
Calling Conventions / Prefixes
Signal port handles or methods are accessed through the global cee namespace, where port represents the port number (1–8):
local signalValue = cee.signalPortRead(1)
cee.signalPortWrite(2, 1)
API Reference Table
| Method Signature | Arguments & Types | Description |
|---|---|---|
cee.signalPortRead(port) |
port (number, 1–8) |
Reads the current digital signal value from the specified port. Returns 0 for low signal, 1 for high signal. |
cee.signalPortWrite(port, value) |
port (number, 1–8), value (number, 0 or 1) |
Writes a digital signal value to the specified port. Sets the output to low (0) or high (1). |
cee.signalPortSetMode(port, mode) |
port (number, 1–8), mode (string, "input", "output", "bidirectional") |
Configures the operating mode of the specified port. |
cee.signalPortGetMode(port) |
port (number, 1–8) |
Returns the current operating mode of the specified port as a string. |
Lua Code Examples
Example 1: Basic Signal Reading and Writing
-- Read signal from port 1
local signalValue = cee.signalPortRead(1)
print("Signal value on port 1:", signalValue)
-- Write high signal to port 2
cee.signalPortWrite(2, 1)
print("Wrote high signal to port 2")
-- Write low signal to port 3
cee.signalPortWrite(3, 0)
print("Wrote low signal to port 3")
Example 2: Configuring Port Modes
-- Set port 4 as input mode
cee.signalPortSetMode(4, "input")
print("Port 4 set to input mode")
-- Set port 5 as output mode
cee.signalPortSetMode(5, "output")
print("Port 5 set to output mode")
-- Check current mode of port 4
local currentMode = cee.signalPortGetMode(4)
print("Current mode of port 4:", currentMode)
Example 3: Signal Monitoring Loop
-- Monitor signal changes on port 6
cee.signalPortSetMode(6, "input")
while true do
local signal = cee.signalPortRead(6)
print("Signal on port 6:", signal)
os.sleep(0.5) -- Wait half a second before next read
end
Example 4: Bidirectional Communication Setup
-- Configure port 7 as bidirectional
cee.signalPortSetMode(7, "bidirectional")
print("Port 7 configured for bidirectional communication")
-- Write to port 7
cee.signalPortWrite(7, 1)
print("Wrote high signal to port 7")
-- Read from port 7
local readValue = cee.signalPortRead(7)
print("Read value from port 7:", readValue)
Example 5: Error Handling
local function safeSignalRead(port)
local success, result = pcall(cee.signalPortRead, port)
if success then
return result
else
print("Error reading from port", port)
return nil
end
end
local value = safeSignalRead(1)
if value ~= nil then
print("Successfully read:", value)
end