http://solarstrike.net/wiki/index.php?title=Serial_Port_Class&feed=atom&action=historySerial Port Class - Revision history2024-03-29T14:05:58ZRevision history for this page on the wikiMediaWiki 1.30.0http://solarstrike.net/wiki/index.php?title=Serial_Port_Class&diff=1283&oldid=prevElverion: Created page with "== isConnected == '''boolean serialPort:isConnected''' Returns a boolean describing whether or not the serial port is connected. Unless you've closed the port, this should pr..."2018-02-27T00:42:42Z<p>Created page with "== isConnected == '''boolean serialPort:isConnected''' Returns a boolean describing whether or not the serial port is connected. Unless you've closed the port, this should pr..."</p>
<p><b>New page</b></p><div>== isConnected ==<br />
'''boolean serialPort:isConnected'''<br />
<br />
Returns a boolean describing whether or not the serial port is connected. Unless you've closed the port, this should probably be true.<br />
<br />
<br />
'''Example:'''<br />
<source lang="lua"><br />
if( not port:isConnected() ) then<br />
print("The port has been closed.");<br />
end<br />
</source><br />
<br />
<br />
<br />
== read ==<br />
'''string,boolean serialPort:read()'''<br />
'''string,boolean serialPort:read(number length)'''<br />
<br />
Reads queued data out of a serial port. If 'length' is supplied, this function will only read up to that many bytes. If 'length' is not supplied, it will read up to the maximum buffer size (10240) in bytes.<br />
<br />
This function returns two variables: a string containing the data read and a boolean describing whether or not there is more data left in the queue. If this function fails, it should return nil.<br />
<br />
<br />
'''Example:'''<br />
<source lang="lua"><br />
local data,more = myPort:read(); -- Read as much as our buffer can hold (10240)<br />
<br />
-- or --<br />
<br />
repeat -- Keep reading until there's no more left in the queue<br />
data,more = myPort:read(4); -- Read 4 bytes at a time<br />
until not more<br />
</source><br />
<br />
<br />
== write ==<br />
'''boolean serialPort:write(string data)'''<br />
<br />
Writes data to a serial port. Returns true if the function succeeds, otherwise it returns false.<br />
<br />
<br />
'''Example:'''<br />
<source lang="lua"><br />
if( not port:write("Hello World") ) then<br />
print("Failed to write data");<br />
end<br />
</source><br />
<br />
<br />
== close ==<br />
'''serialPort:close()'''<br />
<br />
Closes a serial port. Does not accept any parameters nor does it return anything. A serial port becomes useless after being closed and you must re-call [[Serial_Module#open|serial.open]]() if you wish to re-open it.<br />
<br />
<br />
'''Example:'''<br />
<source lang="lua"><br />
port:close();<br />
port = nil; -- Set it to nil to delete the object so that it can be removed from memory<br />
</source></div>Elverion