hLink Documentation

Copyright Notice and Disclaimer
All rights reserved. No parts of this manual or script may be reproduced in any form without the express written permission of Sparrow Design.

Sparrow Design makes no representations or warranties with respect to the contents hereof. In addition, information contained herein are subject to change without notice. Sparrow Design assumes no responsibility for errors or omissions or any damages resulting from the use of the information contained in this publication.

Overview

So what is hLink.Js?

It is a javascript text file that will allow you to interface with Triangle Research's Super PLCs through web browsers or Hybrid Phone apps!

This manual will help you with the second half of step #2 on using the hLink.js file.

For more help working with Triangle Research's PLC's, refer to tri-plc.com as well as there documentation.

Note: Sparrow Design is not officially associated with or endorsed by Triangle Research. Consider this as a third party tool to aid with your product development.

1
2
3
4
// Add these variables to appName_custom.js
var hLinkIpAddress = "192.168.1.5:9080"
var hLinkUsername = ""
var hLinkPassword = ""

Download hLink.js and add it to your "Javascript Libraries".

This guide will help you format your call for the functions and be able to handle the response.
Let's begin by looking trying an example. We want to read the status of digital input #1. To do this we will call the readDI( ) function.
First write:

readDI();

Next we need to tell it to read input #1. We write it as follows:

readDI(1);

This function will initiate the transmission but how do we return the data after it is received? For this we will receive the data from a callback function. We make this happen by inserting a function where a second variable will go:

readDI(1, function(data, status){alert(data+status)});

After transmission is received and the callback function is executed, "data" will contain the state of input #1 in string format of either "On" or "Off". Also if the the transmission was successful, "status" will contain the string "success".

If, in our example the input #1 were ON, the data variable would equal "On" otherwise the data variable would equal "Off".
Example Explained Further:


The below image shows the functions flow and how the data is returned:


16.1 Device ID Read

1
2
// Section 16.1 Device ID Read 
readID(function(data, status){alert(data+status)});     // data returns ID of Device

16.3 Read Digital Inputs

// Section 16.3 Read Digital Input
readDI(inputNumber, function(data, status){alert(data+status)});     //  inputNumber = Input Number (Accepted Values = 1 - 256).  Data returns state of the selected input.  Results as a string (On or Off)

16.4 Read Digital Outputs

// Section 16.4 Read Digital Output
readDO(outputNumber, function(data, status){alert(data+status)});     //  inputNumber = Input Number (Accepted Values = 1 - 256).  Data returns state of the selected output.  Results as a string (On or Off)

16.5 Read Internal Relays

// Section 16.5 Read Internal Relay
readRelay(relayNumber, function(data, status){alert(data+status)});     //  relayNumber = Relay Number (Accepted Values = 1 - 512).  Data returns state of the selected relay.  Results as a string (On or Off)

16.6 Read Timer Contacts

// Section 16.6 Read Timer Contacts
readTimerContacts(timerNumber, function(data, status){alert(data+status)});     //  timerNumber = Timer Number (Accepted Values = 1 - 64).  

16.7 Read Counter Contacts

// Section16.7 Read Counter Contacts
readCounterContacts(counterNumber, function(data, status){alert(data+status)});    //   counterNumber = Counter Number (Accepted Values = 1 - 64).   

16.8 Read Timer Present Value (P.V.)

// Section 16.8 Read Timer Present Value (P.V.)
readTimerPV(timerNumber, function(data, status){alert(data+status)});     //  timerNumber = Timer Number  (Accepted Values = 1 - 64).  A data response of "NaN" (Not a Number), means the timer is not active.

16.9 Read Timer Set Value (S.V.)

// Section16.9 Read Timer Set Value (S.V.)
readTimerSV(timerNumber, function(data, status){alert(data+status)});     //  timerNumber = Timer Number  (Accepted Values = 1 - 64).  Note: If you read a timer where the SV has not been defined , it may return an erroneous number.

16.10 Read Counter Present Value (P.V.)

// Section 16.10 Read Counter Present Value (P.V.)
readCounterPV(counterNumber, function(data, status){alert(data+status)});    //  counterNumber = Counter Number (Accepted Values = 1 - 64).  A data response of "NaN" (Not a Number), means the counter is not active.

16.11 Read Counter Present Value (S.V.)

// Section 16.11 Read Counter Set Value (S.V.)
readCounterSV(counterNumber, function(data, status){alert(data+status)});     //  counterNumber = Counter Number (Accepted Values = 1 - 64).  A data response of "NaN" (Not a Number), means the counter SV is not set yet.

16.12 Read Variable - Integers (A to Z)

// Section 16.12 Read Variable - Integers (A to Z)
readIntegers(variableInteger, function(data, status){alert(data+status)});     //  variableInteger = Variable Integer (Accepted Values "A" - "Z")

16.13 Read Variable - Strings (A$ to Z$)

1
2
// Section 16.13 Read Variable - Strings (A$ to Z$)
readStrings(variableString, function(data, status){alert(data+status)});     //  variableString = Variable String (Accepted Values "A" - "Z")  Note: Do not add "$"

16.14 Read Variable - Data Memory (DM[1] to DM[4000])

1
2
// Section 16.14 Read Variable - Data Memory (DM[1] to DM[4000])
readDM(dmNum, function(data, status){alert(data+status)});      //  dmNum = Data Memory,  DM[1] = 1   (Accepted Values 1 - 4000) 

16.15 Read Variable - System Variables

// Section 16.15 Read Variable - System Variables
readSystemVariables(type, index, function(data, status){alert(data+status)});     //  type = System Variable Type (Accepted Values = 1 - 13)  - See chart for reference.  index = index into the array (See Section 16.15 of  Tri-PLC user manual for more info)

16.16 Read Variable - High Speed Counter HSCPV[ ]

1
2
// Section 16.16 Read Variable - High Speed Counter HSCPV[ ]
readHSCPV(channel, function(data, status){alert(data+status)});     //  channel = High Speed Counter channer #1 or #2 (Accepted Values = 1 - 2)

16.33 Read Analog Input

1
2
// Section 16.33 Read Analog Input
readAI(channel, function(data, status){alert(data+status)});     //  channel = The Analog input number, AI #1 = 1  (Accepted Values: 1-8, Depends on how many inputs your model of PLC has)

16.34 Read EEPROM Integer Data

1
2
// Section 16.34 Read EEPROM Integer Data
readEEPROMInteger(startAddress, wordCnt, function(data, status){alert(data+status)});     //  startAddress = Starting Address of EEPROM data, wordCnt = How many words should be returned, must be less than 32.

16.35 Read EEPROM String Data (r47 Firmware Only)

1
2
// Section 16.35 Read EEPROM String Data (r47 Firmware Only)
readEEPROMString(stringAddress, function(data, status){alert(data+status)});      //  stringAddress = Address of EEPROM String, (String must be 40 characters or less)


16.2 Device ID Write

1
2
// Section 16.2 Device ID Write
writeID(ID, function(data, status){alert(data+status)});     // ID = New Device ID (Accepted values: 0 - 255)

Section 16.17 Write Inputs

I recommend not using this Write Inputs command. When using this command, you must set all the bits in a channel to be either ON or OFF. It does not allow you to control only one Input bit at a time. Instead use Section 16.39 Force Set/Clear Single I/O Bit

Section 16.18 Write Outputs

I recommend not using this Write Outputs command. When using this command, you must set all the bits in a channel to be either ON or OFF. It does not allow you to control only one Outpit bit at a time. Instead use Section 16.39 Force Set/Clear Single I/O Bit

Section 16.19 Write Relays

I recommend not using this Write Relays command. When using this command, you must set all the bits in a channel to be either ON or OFF. It does not allow you to control only one Relay bit at a time. Instead use Section 16.39 Force Set/Clear Single I/O Bit

Section 16.20 Write Timer-contacts

I recommend not using this Write Timer-Contacts command. When using this command, you must set all the bits in a channel to be either ON or OFF. It does not allow you to control only one Timer-Contact bit at a time. Instead use Section 16.39 Force Set/Clear Single I/O Bit

Section 16.21 Write Counter-contacts

I recommend not using this Write Counter-Contacts command. When using this command, you must set all the bits in a channel to be either ON or OFF. It does not allow you to control only one Timer-Contact bit at a time. Instead use Section 16.39 Force Set/Clear Single I/O Bit

Section 16.22 Write Timer Present Value (P.V.)

// Section 16.22 Write Timer Present Value (P.V.)
writeTimerPV(timerNumber, value, function(data, status){alert(data+status)});     //  timerNumber = Timer Number (Accepted Values = 1 - 64),  value = New Present Value  (Accepted Values = 0 - 9999).

Section 16.23 Write Timer Set Value (S.V.)

// Section 16.23 Write Timer Set Value (S.V.)
writeTimerSV(timerNumber, value, function(data, status){alert(data+status)});      //  timerNumber = Timer Number (Accepted Values = 1 - 64),  value = New Set Value  (Accepted Values = 0 - 9999).

Section 16.24 Write Counter Present Value (P.V.)

// Section 16.24 Write Counter Present Value (P.V.)
writeCounterPV(counterNumber, value, function(data, status){alert(data+status)});     //  counterNumber = Counter Number (Accepted Values = 1 - 64),  value = New Present Value  (Accepted Values = 0 - 9999).

Section 16.25 Write Counter Set Value (S.V.)

// Section  16.25 Write Counter Set Value (S.V.)
writeCounterSV(counterNumber, value, function(data, status){alert(data+status)});     //  counterNumber = Counter Number (1 = Counter #1),  value = New Set Value  (Accepted Values = 0 - 9999).

Section 16.26 Write Variable - Integers (A to Z)

// Section 16.26 Write Variable - Integers (A to Z)
writeIntegers(variableInteger, value, function(data, status){alert(data+status)});     // variableInteger = Integer (Accepted Values "A"-"Z"),  value = Integer Value  

Section 16.27 Write Variable - Strings (A$ to Z$)

Note: Spaces in strings can not be sent using this method. However, you can specify a replacement character and then remove it inside of the PLC Program if you want. By default spaces will be replaced with the "+" sign.

// Section 16.27 Write Variable - Strings (A$ to Z$)
writeStrings(variableString, value, "+", function(data, status){alert(data+status)});    // variableString = Variable String (Accepted Values "A"-"Z" ,  No need to include "$"),  value = String  Value, "+" = Space replacement value.

Section 16.28 Write Variable - Data Memory (DM[1] to DM[4000])

// Section 16.28 Write Variable - Data Memory (DM[1] to DM[4000])
writeDM(dmNum, value, function(data, status){alert(data+status)});     // dmNum = DM[Number] (Accepted Values 1-4000),  value = New Number

Section 16.29 Write Variable - System Variables

1
2
// Section 16.29 Write Variable - System Variables
writeSystemVariables(type, index, value, function(data, status){alert(data+status)});     // type = System variable type, index = Index Number, Value = New Number

Section 16.30 Write Variable - High Speed Counter HSCPV[ ]

1
2
// Section 16.30 Write Variable - High Speed Counter HSCPV[ ]
writeHSCPV(channel, value, function(data, status){alert(data+status)});     //  channel = High Speed Counter channel.  value = High Speed Counter Present Value

Section 16.36 Write Analog Output

1
2
// Section 16.36 Write Analog Output
writeAO(channel, value, function(data, status){alert(data+status)});     // channel = Analog channel address.  value = 0-4095 (0-100%)

Section 16.37 Write EEPROM Integer Data

1
2
 // Section 16.37 Write EEPROM Integer Data
writeEEPROMInteger(address, value, function(data, status){alert(data+status)});     //  address = EEPROM address.  value = integer value

Section 16.38 WRITE EEPROM String Data

1
2
// Section 16.39 Force Set/Clear Single I/O Bit
forceSetClearBit(type, address, state, function(data, status){alert(data+status)});     //  type = "Input", "Output", "Timer", "Counter", "Relay".  address = (Accepted values = 1-256).  state = "off" or "on"

Section 16.39 Force Set/Clear Single I/O Bit

Examples:
To turn Output #8 ON, use command:
forceSetClearBit("Output", 8, "on", function(data, status){alert(data+status)});

To turn Relay #23 ON, use command:
forceSetClearBit("Relay", 23, "on", function(data, status){alert(data+status)});

To turn Timer Contact #5 OFF, use command:
forceSetClearBit("Timer", 5, "off", function(data, status){alert(data+status)});

Note: If you write to an output, timer, counter or relay that is being driven either on or off in the ladder logic, the ladder logic will override your command as soon as the next scan is executed (Usually every few milliseconds depending on program size). If you want to control an output through both ladder logic and by using hLink, you will have to set up a unique way of controlling it. This can be done by using a relay contact that is controlled bu hLink and another input or relay contact for normal ladder logic functions. They can be configured in series, in parallel or latching to make any scenario you would like.

Also, if writing to an input, it will always return to it's prior condition, whether "on" or "off". It will toggle momentarily, thus it could be used to energize a latching relay to keep something on or to de-energize a latching relay to turn something off.

1
2
// Section 16.39 Force Set/Clear Single I/O Bit
forceSetClearBit(type, address, state, function(data, status){alert(data+status)});     //  type = "Input", "Output", "Timer", "Counter", "Relay".  address = (Accepted values = 1-256).  state = "off" or "on"


Section 16.31 Halting the PLC

1
2
// Section 16.31 Halting the PLC
haltPLC (function(data, status){alert(data+status)});     // Simply call this function to halt the operation of the PLC

Section 16.32 Resume PLC Operation

1
2
// Section 16.32 Resume PLC Operation
resumePLC (function(data, status){alert(data+status)});    // Simply call this function to resume the operation of the PLC

hLink Documentation | Version 1.0
© 2017 BY SPARROW DESIGN