npComp plugin

About this plugin

This plugin is intented to use for basic Serial Communications. The plugin allows to create various Comp objects in order to work separatelly with various COM ports. You can open, close, read, write and set several options and flags of the COM ports.

You can use this plugin to communicate your NeoBook applications with hardware like Arduino boards, barcode scanners and other similar hardware connected to the COM ports. The plugin count dozens of actions and allow you to use several options, events and subroutines.

Thirparty

This plugin are imposible without the aid of this people:

Thanks a lot!

Plugin actions index

npCompCreate

Create a new instance of an Comp object. The result variable store the instance ID (a numeric value) of the created object, which you can use later on other plugin actions.

↑↑

npCompDestroy

Destroy a previously created instanace of an Comp object. Specify the instance ID of the object that you what to destroy. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompDestroyAll

Destroy all previously created instances of Comp objects.

↑↑

npCompEnumPorts

Enumerate the system COM ports in the specified variables. The list variable store the available COM identifiers in an Array form. The list count variable store the number of available COM ports, or, in other words, the maximum index for the Array stored in the list variable. If the system have no COM ports available then the list count variable store "0". Below you can view an example of how enumerate the system COM ports and used it to fill a NeoBook ListBox object.

npCompEnumPorts "[CompPorts]" "[CompPortsCount]"

If "[CompPortsCount]" "=" "0"
  Alertbox "Warning" "Sorry, no COM ports found. The program cannot continue."
  Exit "" ""
EndIf

Loop "1" "[CompPortsCount]" "[I]"
  ListBoxAddItem "CompPortsList" "0" "[CompPorts[I]]"
EndLoop
SetVar "[CompPortsList]" "[CompPorts1]"

You must use one of the COM ports identifiers in the npCompOpenPort action in order to open such port.

↑↑

npCompOpenPort

Open the specified port name using the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompClosePort

Close the specified port name using the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompIsPortOpen

Check if the specified Comp object have previously opened certain COM port. The result variable store "True" if the specified COM port is open or "False" when not. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompReadString

Read the specified count of string chars from the specified Comp object open COM port. The action does not return until count bytes are read or timeout elapses (You can specify read timeouts using the npCompSetOptions action). Even when this action can be executed in whatever place, the most common use is into the subroutine specified in the npOnCompRxChar action. The result variable store the input readed string. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompWriteString

Write the specified string chars to the specified Comp object open COM port. The action does not return until the whole string is written or timeout elapses (You can specify write timeouts using the npCompSetOptions action). The result variable store the number of bytes that are actually written. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompSetOptions

Specify general options of a Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error. The available actions are described below:

* Read and write timeout options defines detailed timeout settings for read and write operations. When timeout for specific operation elapses, operation is aborted, however, no errors are reported.

Two types of time-outs are enabled by the time-out parameters. An interval time-out occurs when the time between the receipt of any two characters exceeds a specified number of milliseconds. Timing starts when the first character is received and is restarted when each new character is received. A total time-out occurs when the total amount of time consumed by a read operation exceeds a calculated number of milliseconds. Timing starts immediately when the I/O operation begins. Write operations support only total time-outs. Read operations support both interval and total time-outs, which can be used separately or combined.

The time, in milliseconds, of the total time-out period for a read or write operation is calculated by using the multiplier and constant:

Timeout = (MULTIPLIER * number_of_bytes) + CONSTANT

↑↑

npCompGetOptions

Retrieve general options from a Comp object instance. The available options and possible values are described in the npCompSetOptions action. The result variable store the value of the specified option. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompInputCount

Retrieve the number of bytes in input buffer in the specified Comp object instance. The result variable store the input buffer size in bytes. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompOuptutCount

Retrieve the number of bytes in output buffer in the specified Comp object instance. The result variable store the output buffer size in bytes. The result variable can also store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompClearInput

Clear the input buffer of the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompClearOutput

Clear the output buffer of the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompSetDTR

Enable or disable DTR (data-terminal-ready) signal in the specified Comp object instance. If the ControlDTR option is set to dtrHandshake, it is an error for the application to execute this action and an error is raised. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompSetRTS

Enable or disable RTS (request-to-send) signal in the specified Comp object instance. If the ControlRTS option is set to rtsHandshake, it is an error for the application to execute this action and an error is raised. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompSetBreak

Set break or non-break transmission state in the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompSetXonXoff

Simulate Xon/Xoff character arrival in the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npCompSignals

Determine the state of signals in the specified Comp object instance. To determine the change of signals use the appropiate event action. This action can determine the state of the following signals: CTS: Clear-to-send, DSR: Data-set-ready, Ring: Ring indicator, RLSD: Receive-line-signal-detected.

The result variable is conformed by the specified variable followed by the appropiate signal name: [ResultVar.CTS], [ResultVar.DSR], [ResultVar.Ring] and [ResultVar.RLSD]. This variables can be "True" or "False", depending on the signal high state. The result variable also can store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompStateFlags

Retrieve information about serial communication device in the specified Comp object instance. The result variable is conformed by the specified variable followed by the appropiate flag name, as you can in the below list.

The result variable also can store "False" if an error occur. In this last case the [LastError] variable store information about the error.

↑↑

npCompTransmitChar

Transmit a character ahead of any pending data in output buffer in the specified Comp object instance. The action is useful for sending an interrupt character (such as a CTRL+C) to a host system. Character transmission is subject to normal flow control and handshaking. If the device is not transmitting, this action cannot be called repeatedly. Once tgus actuib places a character in the output buffer, the character must be transmitted before the function can be called again. If the previous character has not yet been sent, this action raises an error. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompRxChar

Set a subroutine to be executed when arrived characters arrive to the input buffer in the specified Comp object instance. The count variable store the number of bytes in input buffer waiting to be read. This event is usually used for reading characters from input buffer using read actions. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompError

Set a subroutine to be executed when a line status error occurs in the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompBreak

Set a subroutine to be executed when hardware detects a break on input in the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompRing

Set a subroutine to be executed when Ring indicator is detected in the specified Comp object instance. This event is mainly used when programming modem application. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompRxFlag

Set a subroutine to be executed when event character arrives in the specified Comp object instance. Set the EventChar option to set event charachter ASCII code. An event character is also placed in input buffer. The only difference between event and non-event character is that event character triggers npOnCompRxChar and npOnCompRxFlag events, while non-event characters triggers only npOnCompRxChar event. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompTxEmpty

Set a subroutine to be executed when output buffer becomes empty, that is, all characters in output buffer have been transmitted in the specified Comp object instance. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompCTSChange

Set a subroutine to be executed when CTS (clear-to-send) signal has changed state in the specified Comp object instance. If the OnOff variable is "True", CTS has changed from low to high state. If the "OnOff" variable is "False", CTS has changed from high to low state. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompDSRChange

Set a subroutine to be executed when DSR (data-set-ready) signal has changed state in the specified Comp object instance. If the "OnOff" argument is "True", DSR has changed from low to high state. If the "OnOff" variable is "False", DSR has changed from high to low state. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

npOnCompRLSDChange

Set a subroutine to be executed when RLSD (receive-line-signal-detected) signal has changed state in the specified Comp object instance. If the "OnOff" variable is "True", RLSD has changed from low to high state. If the "OnOff" variable is "False", RLSD has changed from high to low state. The result variable store "True" if everything is OK, or "False" if not. In this last case the [LastError] variable store information about the error.

↑↑

Action errors subroutine

All the NeoPlugins deal with errors in the same way that NeoBook does: when the plugin found an action error the [LastError] variable store information about the error, so you can take care about this variable when execute an action.

But all the NeoPlugins also incorporate an advanced way to deal with possible action errors. You can define a subroutine named OnNeoPluginActionError in order to be executed when some action error are found and you can use this variables inside:

Note that this error handling subroutine are shared for all the NeoPlugins, so you no need to specify a subroutine for every plugin you use in your publication because the same subroutine are recognized and automagically used by every NeoPlugin. Below you can view a sample of this subroutine code:

:OnNeoPluginActionError
  AlertBox "NeoPlugin Error" "Error [LastError] in plugin: [PluginName]"
Return

Also note that the use of this NeoPlugins error handling subroutine is completelly optional. You can continue using the [LastError] variable as usual and even use the both methods at the same time.

↑↑