LineReadState

Top  Previous  Next

Message

 

LineReadState <linenumber>|<alias>

 

Originator

 

Client

 

Response

 

Info: State: <linenumber> (<alias>) on|off

SyntaxError: invalid parameters to LineReadState

SyntaxError: insufficient parameters to LineReadState

Error: no such line or alias

Error: LineReadState cannot read line <linenumber>

 

Response (immediate socket)

 

on

off

error

 

Details

 

Asks the server what the current status of the line is (on or off). Applies to input and output lines.

 

From WhiskerServer v2.11, hardware is supported that can only detect ON transitions, not OFF transitions (e.g. the Lafayette/ABET hardware); consequently, Whisker can only respond to ON events on such lines, and if you attempt to read the actual state of the line (which Whisker has not been informed of by the external hardware and cannot be aware of), an error is generated.

 

Advanced point: if a group alias is given on the main socket, the server will respond with a State message for each applicable line. If a group alias is given on the immediate socket, the server will only return the state of one line, chosen (effectively) at random. This situation will generate a Warning: message. I would discourage you from using group aliases with LineReadState.        

 

SDK Control

 

       Function LineReadState(MyLine As String) As wsLineState

       Property LineState(MyLine As String) As wsLineState

 

Read the state of digital I/O line MyLine. Returns wsOn (1) if the line is On, wsOff (0) if it is Off, or wsUnknown (2) if the line cannot be read (e.g. if the control is not connected to a WhiskerServer)

 

Example VB syntax:

 

       'To check if it succeeds

       Dim CurrentState As wsLineState

       CurrentState = Whisker.LineReadState(MyLine)

       'Using alternative syntax:

       If(Whisker.LineState(MyLine) = wsOn) Then

               'line is on

               Call MySub

       End If

               

Remarks

 

The VB values True (-1) and False (0) can be used as synonyms for wsOn and wsOff when turning lines on with LineSetState, but the values returned by LineReadState cannot simply be treated as if they were Boolean values (True or False) .

 

For example, in VisualBasic the operator Not can be used to turn True into False, and vice versa. This cannot be used in the same way with wsLineState values:

 

       'Example

       'We wish to make sure 'Light2' is off if 'Light1' is on, and vice versa

               

       'The following code WILL WORK in the intended way

       Whisker.LineState(Light2) = Not (Whisker.LineState(Light1) = wsOn)

       'This DOES NOT work and will cause an error if Light1 is wsOn (=1)

       Whisker.LineState(Light2) = Not Whisker.LineState(Light1)

 

ClientLib

 

bool LineReadState(const CString& strLine, bool& bState);        

 

Sets bState to true if strLine is currently on, false if it is off.  Returns true for success, false for failure.

 

Revision history

 

Implemented in WhiskerServer version 1 as ReadState.

Renamed in WhiskerServer version 2.3.

 

See also

 

LineSetState
Digital I/O devices