Codecore Logo
Quick Search
»
Advanced Search »

Generic Serial Driver

RSS
The generic serial driver allows interfacing with devices connected to a serial port where no driver yet exists. Incoming data is expected to be delimited by a string of characters to distinguish packets.

Manufacturer: N/A

Primary Communications Port: Serial


Configuration Settings

  • Serial Port Name : The name of the serial port to connect to. Ex. COM1
  • Delimiter : (optional) Defaults to carriage-return linefeed ( \r\n ). This is the string that delimits incoming data packets.
  • New Line String : (optional) Defaults to carriage-return linefeed ( \r\n ). This is what the SendLine() method uses.
  • Baud : (optional) The baud rate to use. Defaults to 9600.
  • Parity : (optional) Can be Even, Odd, Space, Mark, None. Defaults to None.
  • DataBits : (optional) Defaults to 8. Usually 7 or 8.
  • StopBits : (optional) Defaults to 1. Can be 0, 1, 1.5, or 2.

Delimiter and NewLine special characters:

  • \r : Carriage-return (ASCII character 13)
  • \n : Linefeed (ASCII character 10)
  • \t : Tab (ASCII character 9)

Events

Ready State Changed

The device's running and ready state changed.

Whenever Filter:

none

EventArgs:

  • Number NewValue : The new property value.
  • Number PreviousValue : The previous property value.

Received Data

Occurs when the serial port receives incoming data.

Whenever Filter:

none

EventArgs:

  • String Data : The received data.

Example Script:

// Do something here. Normally you would parse the data string
// using the String datatype methods to determine what was received.
// Data formats:
// "STOPPED:%%" where %% is a number of how open the drapes are
// "OPENING"
// "CLOSING"
command = EventArgs.Data.Substring(0, 7);
if ( command == "STOPPED" )
    Log( "Drapes are open " + EventArgs.Data.Substring(8, 2) + "%" );
else if ( command == "OPENING" )
    Log( "Drapes are opening." );
else if ( command == "CLOSING" )
    Log( "Drapes are closing." );

Here is sample script that was used by a user before the Nuvo Concerto Driver was made available. Now that the Nuvo Concerto Driver, there is no reason to use this script, but it provides a good example.

IncomingCommand = EventArgs.Data;
ThisSource = IncomingCommand.SubString(1,2); //source number
ThisCommand = IncomingCommand.SubString(6); //the command
//system.Log( ThisSource );
//system.Log( ThisCommand );
if (ThisSource == "S3" || ThisSource == S4) // if ThisSource equals S3 or S4...
{
if (ThisCommand == "PLAY")
    itunes.Play(); // make itunes play
else if (ThisCommand == "STOP")
    itunes.Stop(); // make itunes stop playing
else if (ThisCommand == "FWD")
    itunes.PlayNextTrack(); // make itunes play next track
else if (ThisCommand == "RWD")
    itunes.PlayPreviousTrack(); // make itunes play previous track
else if (ThisCommand == "PAUSE")
    itunes.TogglePause(); // make itunes toggle pausing
}

Instance Properties

DeviceDisplayName

The display name for this device.

Accessibility : Read Only

Type: String

DeviceStartTime

The date and time when this device was started.

Accessibility : Read Only

Type: DateTime

DeviceLifecycleStage

The current lifecycle stage of the device. The stages in order are: Pending Start, Starting, Running, Stopping

Accessibility : Read Only

Type: Number

DeviceIsRunningAndReady

Indicates if the device is ready for use, ie it is in the Running lifecycle stage and all properties are valid and all methods are ready to be used.

Accessibility : Read Only

Type: Boolean

Instance Methods

Send ( String )

Sends the specified ASCII to the serial port. No character escaping is allowed.

Syntax

void Send( String data )

Parameters

data : The ASCII characters to send. No character escaping is allowed.

SendLine ( String )

Sends the specified ASCII to the serial port followed by the characters in the New Line String device setting. No character escaping is allowed.

Syntax

void SendLine( String data )

Parameters

data : The ASCII characters to send. No character escaping is allowed.

SendBinary ( String )

Sends binary data to the serial port.

Syntax

void SendBinary( String hexData )

Parameters

hexData : The binary data represented as a contiguous string of hexidecimal. Example: "00FF0900"

SetPropertyForDuration ( String, TimeSpan, Object, Object )

Sets a property for a duration of time and then sets the property to a subequent value asynchronously. This action returns after setting the first value and the timer and subsequent property set run in the background. Subsequent sets of the same property will reset the timer if the subsequent value has not yet been set. This is an advanced feature, be sure to set the property name correctly.

Syntax

void SetPropertyForDuration( String propertyName, unknown duration, Object initialValue, Object finalValue )

Parameters

propertyName : The name of the property to set.
duration : The amount of time to wait after setting the initial value to set the subsequent value.
initialValue : The value to set the property to initially.
finalValue : The value to set the property to after the duration of time has passed.

SetPropertyForDuration ( String, Number, TimeSpan, Object, Object )

Sets a property for a duration of time and then sets the property to a subequent value asynchronously. This action returns after setting the first value and the timer and subsequent property set run in the background. Subsequent sets of the same property will reset the timer if the subsequent value has not yet been set. This is an advanced feature, be sure to set the property name correctly.

Syntax

void SetPropertyForDuration( String propertyName, Number arrayIndex, unknown duration, Object initialValue, Object finalValue )

Parameters

propertyName : The name of the property to set.
arrayIndex : The property's array index to set.
duration : The amount of time to wait after setting the initial value to set the subsequent value.
initialValue : The value to set the property to initially.
finalValue : The value to set the property to after the duration of time has passed.

Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.