$canonicalOutput = false
[line 230]
Public. Whether to drop the first zero from hex output.
If true, the methods which query the device's status do not prepend a zero for values lower than 0F, if the result is hexadecimal. If false, a two-character string is returned unconditionally. If $decimalOutput is set, the result of all query methods is a PHP integer regardless of this property.
Tags:
$decimalOutput = false
[line 241]
Public. Whether to return output as decimal or hexadecimal.
If true, the methods which query the device's status return results in base 10 (the default is base 16).
Tags:
$dev = NULL
[line 73]
Private. The current serial device (e.g. "/dev/ttyS0").
You should set this using setDev().
Tags:
$errors = array()
[line 92]
Private. An array storing this object's error messages.
Tags:
$forceOutEOL = ""
[line 173]
Public. Force the End Of Line character(s) used by the class.
Used by getErrors(). If not set, $outEOL is used.
Tags:
$healthy = true
[line 84]
Private. This object's health status.
True if this object is healthy (see isHealthy() for what "healthy" means in this context), or false if not healthy.
For all intents and purposes, this is overridden by $neverWork.
$kitEOL = "\r\n"
[line 141]
Public. The End Of Line character(s) used by the device.
Typically "\r\n" (CR/LF), set as such by default. Used by rawWrite(). Its value should be changed if the device's behavior changes in the future.
Tags:
$kitPrompt = "#"
[line 152]
Public. The prompter provided by the device.
Typically "#", this is used to validate the device's output. Its value should be changed if the device's behavior changes in the future. The EOL before the prompt MUST NOT be included.
Tags:
$lastOrder = ''
[line 185]
Private. The previous known order.
This is where the previous order sent through this object is stored in order to validate or clean up the device output.
Tags:
$lastOrderType = NULL
[line 215]
Private. The previous known order's type.
This property remembers whether the last order was a command or a query -- used by sendOrder() to clean up the output.
Legitimate values:
- NULL: no previous (known) order
- "command": the previous order was a command ('N','F','T','R')
- "query": the previous order was a query ('S','I','?')
$neverWork = false
[line 200]
Private. Whether this class can possibly work in this system's context.
This is set true when there's no chance this class will ever possibly work.
For all intents and purposes, this overrides $healthy.
Tags:
$outEOL = "\n"
[line 163]
Private. The End Of Line character(s) used by the class.
Used by getErrors(), identified by _setOutEOL() and overridden by $forceOutEOL.
Tags:
$serial = NULL
[line 129]
Private. The actual serial object.
Tags:
$serialClassName = 'phpSerial'
[line 122]
Public. The name of the serial class.
See initSerial() for more details.
Tags:
$serialIncludeFull = ''
[line 102]
Public. The file which contains the serial class.
See initSerial() for more details.
Tags:
$serialIncludePath = ''
[line 112]
Public. The path to the serial class file.
See initSerial() for more details.
Tags:
$_virgin = true
[line 252]
Private. Whether this object has ever been initialised.
This is set by setDev() the first time it's called.
Tags:
constructor Kit108 [line 293]
boolean Kit108(
[string
$dev = NULL])
|
|
Class constructor.
If $dev is set, it calls setDev(); otherwise it does nothing. You might want it to do nothing if you want to set properties used by setDev() and other downstream methods before really initialising the object.
Tags:
Parameters:
method addError [line 693]
void addError(
string
$error)
|
|
Public. Add an error message to this object's queue.
Retrieve errors stored this way using getErrors().
You typically shouldn't need to call this method unless you decide to use this object's error management system to store your own errors related to this device.
Parameters:
method closeDev [line 380]
Public. Close the serial port.
The opposite of setDev(), this method closes the connection to the current serial device.
Tags:
method getDev [line 402]
Public. Returns the current serial port.
You can set the current serial port using setDev().
Tags:
method getErrors [line 267]
Public. Retrieve the current errors.
This method returns this object's current errors, in a format ready for output in the current context.
Tags:
method getInput [line 1023]
integer|boolean getInput(
integer
$input)
|
|
Public. Get the status of the specified input.
The inputs are counted from zero -- that is, the first input is 0 and the last one is 3.
Tags:
Parameters:
method getInputs [line 1044]
string|integer|boolean getInputs(
)
|
|
Public. Get the status of all inputs at once.
Returns a value between 0 and 15 representing the status of all device inputs (each bit represents an input; 1 means the input is set, 0 means it's not set), or boolean false on error.
The result of this method is affected by $canonicalOutput and decimalOutput.
Tags:
method getKitPrompt [line 277]
Private. The prompt used by the device.
Tags:
method getRelay [line 907]
integer|boolean getRelay(
integer
$relay)
|
|
Public. Returns the current state of the specified relay.
The relays are counted starting from zero (i.e. in order to get the status for the first relay you pass 0, and for the last one you pass 7).
Tags:
Parameters:
method getRelays [line 892]
integer|string|boolean getRelays(
)
|
|
Public. Get the status for all relays at once.
Returns the status for all relays at once as a byte.
This method's result is affected by $decimalOutput and $canonicalOutput.
Each bit in the result represents a relay (the least significant bit represents the first relay, the most significant bit represents the last relay). A bit set to 1 means the relay is activated, a bit set to 0 means that it isn't.
Tags:
method getSoftwareVersion [line 487]
string|boolean getSoftwareVersion(
)
|
|
Public. Returns the Kit108 device's firmware version.
The value it returns is the version alone (e.g. "2.1"). If you want the full reply from the device, call sendOrder("?") instead.
The result is boolean false on error.
Tags:
method initDev [line 422]
boolean initDev(
[string
$dev = NULL])
|
|
Private. Initializes the current serial port for use with a Kit108 device.
This method initializes the serial devices and verifies if it can properly handshake with a Kit108 device.
If the optional $dev parameter is passed, a call to setDev() is made before actually initializing the device.
You can close the connection initialized by this method using closeDev().
Tags:
Parameters:
method initSerial [line 638]
Private. Initialises the serial port.
This is called automatically by initDev(), you really shouldn't ever need to call it directly.
This class uses the phpSerial class to connect to the serial port in order to communicate with the device. Depending on your setup, you might want to tell this class where phpSerial resides (see $serialIncludePath and $serialIncludeFull), and what it's called (maybe you needed to rename the phpSerial class for some reason -- see $serialClassName).
Tags:
method isHealthy [line 716]
Public. Checks whether this object is healthy.
Use this method at any point to find whether this object is ready to receive commands for the device -- it takes care of all implications.
This method is also used internally to determine whether to try communicating with the device -- if the object is not healthy, no communication with the device is ever attempted.
Tags:
method loadDependencies [line 779]
boolean loadDependencies(
)
|
|
Private. Loads dependencies required for this class to operate.
This method behaves as follows:
Tags:
method makeCanonical [line 862]
method mapInput [line 1060]
integer|boolean mapInput(
integer
$input)
|
|
Private. Map incoming input-related queries over the device native inputs.
Used by getInput(), this method shifts the input parameter by one unit and checks whether the result is valid in the device's input space.
Tags:
Parameters:
method mapRelay [line 1078]
method rawRead [line 604]
string|boolean rawRead(
)
|
|
Public. This is the lowest-level method for reading from the device within the context of this class.
See rawWrite() for more context on this method.
Please note that legitimate output can be an empty string (e.g. if you call the method twice in a row) -- make sure to use the identity operator (===) to check for errors.
Tags:
method rawWrite [line 576]
boolean rawWrite(
string
$order)
|
|
Public. This is the lowest-level method for writing to the device within the context of this class.
In most circumstances you probably want to use sendOrder() instead of this method. Another alternative is the read()/write() combination.
Use this method in tandem with rawRead() if you want to handle all input and output from the device manually. The only pieces of logic these methods implement are the following:
- The class sanity is verified before any attempt to communicate
with the device (i.e. the methods will not blindly attempt to
communicate if the serial device hasn't been defined or successfully
initialised);
- Method rawWrite() appends $kitEOL at the end of the command
so you don't have to append it every time.
Apart from those, you're on your own -- you have to process device echo, prompts, the whole deal.
Tags:
Parameters:
method read [line 532]
Public. Read data from the device.
See write() for more context on this method.
Tags:
method relayOff [line 958]
boolean relayOff(
integer
$relay)
|
|
Public. Deactivate the specified relay.
The relays are counted starting from zero (see getRelay()).
Tags:
Parameters:
method relayOn [line 941]
boolean relayOn(
integer
$relay)
|
|
Public. Activate the specified relay.
The relays are counted starting from zero (see getRelay()).
Tags:
Parameters:
method sendOrder [line 1108]
string|boolean sendOrder(
string
$order)
|
|
Public. Send an order to the device and retrieve the output.
This is the highest-level method in the context of this class except the truly dedicated methods like setRelays(), getRelays(), etc.
This method uses write() and rawRead() to handle all I/O strings related to a Kit108 unit -- it processes the EOLs, the device prompt, echo and so on; it interprets the type of command it has been issued in the context of a Kit108 unit (it decides whether it was given a command or it was asked to provide the result of a query) and acts accordingly.
Tags:
Parameters:
method setAllRelays [line 996]
Public. Activate all relays.
Identical to setRelays(255).
Tags:
method setDev [line 349]
boolean setDev(
string
$dev)
|
|
Public. Sets the current object's serial device and initializes it.
This method is also called by the class constructor, if the device parameter is passed to the constructor.
The first time this method is called, it calls _setOutEOL() and _everWork() (and sets $_virgin in order to register that is has been called once).
This method always sets $healthy by calling initDev().
You can retrieve the current device with getDev().
Tags:
Parameters:
method setHexRelays [line 832]
boolean setHexRelays(
$relays
$relays)
|
|
Public. Sets all relays to the hexadecimal value passed in $relays.
Identical in every way to setRelays(), except this method takes the input in hexadecimal.
Tags:
Parameters:
method setRelay [line 973]
boolean setRelay(
integer
$relay)
|
|
Public. Alias for
relayOn().
Tags:
Parameters:
method setRelays [line 811]
boolean setRelays(
integer
$relays)
|
|
Public. Sets all relays to the values passed in $relays.
The device has eight relays, and there are eight bits in a byte. This method takes a value between 0 and 255 and sets all eight relays according to on and off depending on whether the bits in the input value are set (relay ON) or not set (relay OFF).
Passing values below 0 or above 255 will result in an error.
Tags:
Parameters:
method testDev [line 470]
Public. Test the current device.
Assumes the current device is set up already and tests whether it works properly. This is automatically called by initDev(), it doesn't need to be called by your code at the beginning of the session.
Tags:
method toggleRelay [line 924]
boolean toggleRelay(
integer
$relay)
|
|
Public. Toggle the status of the specified relay.
The relays are counted starting from zero (see getRelay()).
Tags:
Parameters:
method unsetAllRelays [line 1008]
boolean unsetAllRelays(
)
|
|
Public. Deactivate all relays.
Identical to setRelays(0).
Tags:
method unsetRelay [line 984]
boolean unsetRelay(
integer
$relay)
|
|
Public. Alias for
relayOff().
Tags:
Parameters:
method write [line 515]
boolean write(
string
$order)
|
|
Public. Write data to the device.
Both read() and write() are relatively low-level methods within the context of this class, you typically don't need to call them directly. In most contexts, you probably want to call sendOrder() instead.
On the other hand, these methods still perform some logic of their own within the context of this class, and read() attempts to clean up the output. If you want to go down and dirty and process all I/O manually, use rawRead() and rawWrite() instead.
As opposed to sendOrder(), this method only writes the order to the serial device, without waiting for or processing the output -- you will need to call read() afterwards to retrieve the output.
Tags:
Parameters:
method _everWork [line 740]
Private. Decides whether this class will ever work on this system.
This is where $neverWork is set (or not). The decision is based on the operating system you're using. Currently only Linux is fully supported. You can override the default behavior by setting constant KIT108_OVERRIDE_OS to boolean true (strict). For more details, see this page.
Tags:
method _setOutEOL [line 315]
Private. Decides a default EOL for output depending on the context.
This method sets $outEOL depending on the following factors:
- If the code is being executed in the context of an HTTP request,
the EOL is unconditionally "
\n". - If the code is being executed under Linux, the default "\n" is
retained.
- Otherwise, "\r\n" (CR/LF) is used.
The defaults can be overridden by
$forceOutEOL.
Tags: