Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Phidget Input Parameter List

NameDescriptionHow Used?

DeviceType

Specify the type of device that requires interaction. Supported values are:

PhidgetRFID, PhidgetTextLCD, PhidgetGPS, PhidgetInterfaceKit, PhidgetAdvancedServo

DeviceType is passed as a modifier to Invoke.

<Invoke Method="Get" DeviceType="PhidgetInterfaceKit"/>

SerialNumberThis represents the interface port number to which the sensor or motor is connected.SerialNumber is passed as a modifier to Invoke
ServoAngleAngle to be applied to a Advanced Servo Motor.

ServoAngle is passed as a payload to Invoke wrapped within

Message/Value container.

<Invoke Method="Post" DeviceType="PhidgetTextLCD">

<Message><Value><ServoAngle>110.0</ServoAngle></Value></Message>

</Invoke>

SimulatedSimulates Sensor Behavior by sending random integer values between 1 and 100 
-

Some time if you need to pass a String value to the handler as input - usually in case of RFID Writer

or LCD Text Display, you can pass it as part of <Message><Value>Hello</Value></Message> as payload to Invoke.

Payload of <Invoke>.

<Invoke Method="Post" DeviceType="PhidgetTextLCD">

<Message><Value>Hello</Value></Message>

 </Invoke>

 

Phidget Output Format

Output from the Phidget Handler is simply a text value.

...

Running Phidget Handler in Simulated Mode.

Code Block
languagexml
titlePhidget Handler Thing Facet in Simulated mode
linenumberstrue
<ThingFacet Name="PhidgetSimulatedFacet">
  <Integer Name="SimulatedValue" Update="auto" KnownBy="PhidgetSimAction"/>
  <String Name="DeviceType"/>
  <String Name="SerialNumber"/>
  <Action Name="PhidgetSimAction" Documentation="Returns integer values from 1 - 100 in Random order">
    <Workflow Limit="1" Live="1" Timeout="-1">
      <Task Name="Main" While="True">
        <Event Name="Argument" As="ActionArgument"/>
        <Invoke Name="ReadValue" waitFor="Argument" Get="phid://" SerialNumber="[%:Event.Argument.SerialNumber.Value:%]" DeviceType="[%:Event.Argument.DeviceType.Value:%]" Simulated="true"/>
        <Output Name="Result" As="ActionResult">
          <Value>
            <SimulatedValue>[%:[%:@Output:%]Invoke.ReadValue.Message.Value:%]</SimulatedValue>
          </Value>
        </Output>
      </Task>
    </Workflow>
  </Action>
</ThingFacet>

Reading Data from Sensors Connected to Phidget Interface Kit

There are few important points to be noted here:

  • Note that PhidgetInterfaceKit is usually a multi port device (2/2/2 or 8/8/8) i.e it has 8 USB, and 8 GPI and 8 8 GPO pins.
  • When there are multiple sensors attached to the InterfaceKit, there will be multiple instances created in ThingModel to which PhidgetSensorFacet is attached.
  • Even though there is one single USB connection, the Protocol handler supports multiplexing of data to different Channel.
  • Therefore when we do a Invoke with Get="phid://[%:Event.Argument.SerialNumber.Value:%]" we attach the serial number to make the invocation unique.
  • Internally there will be multiple listeners attached to the USB serial port each receiving data and saving to SensorValue.

Code Block
languagexml
titlePhidget Handler Thing Facet to Read Sensors
linenumberstrue
<ThingFacet Name="PhidgetSensorFacet">
  <Integer Name="SensorValue" Update="auto" KnownBy="PhidgetSensorAction"/>
  <String Name="DeviceType"/>
  <String Name="SerialNumber"/>
  <String Name="SensorName"/>
  <Action Name="PhidgetSensorAction" Documentation="Returns integer values from 1 - 100 in Random order">
    <Workflow Limit="1" Live="1" Timeout="-1">
      <Task Name="Main" While="True">
        <Event Name="Argument" As="ActionArgument"/>
        <Invoke Name="ReadValue" waitFor="Argument" Get="phid://[%:Event.Argument.SerialNumber.Value:%]" SerialNumber="[%:Event.Argument.SerialNumber.Value:%]" DeviceType="[%:Event.Argument.DeviceType.Value:%]" Simulated="false"/>
        <Output Name="Result" As="ActionResult">
          <Value>
            <SensorValue>[%:[%:@Output:%]Invoke.ReadValue.Message.Value:%]</SensorValue>
          </Value>
        </Output>
      </Task>
    </Workflow>
  </Action>
</ThingFacet>
<!-- Combine with Model -->
<ThingModel Name="PhidgetSensors" Combines="PhidgetSensorFacet">
   <Sid Name="SensorID"/>
</ThingModel>
<!-- Activate Sensor -->
<Query>
  <Save format="version,current">
    <PhidgetSensors>
      <SensorName>Rotation</SensorName>
      <DeviceType>PhidgetInterfaceKit</DeviceType>
      <SerialNumber>0</SerialNumber>
      <SensorValue value="$Null()"/>
    </PhidgetSensors>
  </Save>
</Query>

 

Reading Data from a GPS Sensor

  • Note that GPS sensor is directly attached to the USB of controller i.e (Raspberry Pi or Laptop or VM)
  • If there are multiple GPS sensors you plan to attach you can use SerialNumber create a unique protocol string i.e. phid://1 etc
Code Block
languagexml
titlePhidget Handler Thing Facet to Read GPS Sensor
linenumberstrue
<ThingFacet Name="GPSPhidgetSensorFacet">
	<String Name="GPSOutput" update="auto" KnownBy="GPSPhidgetSensorAction" />
    <String Name="SerialNumber" />
	<String Name="DeviceType" />
	<Action Name="GPSPhidgetSensorAction" Documentation="Connect to GPS sensor">
	<Workflow Limit="1" Live="1" Timeout="-1">
		<Task name="Main" while="true">
				<Event name="Argument" as="ActionArgument" />
				<Invoke name="ReadValue" waitFor="Argument"
                       Post="phid://[%:Event.Argument.SerialNumber.Value:%]" SerialNumber="[%:Event.Argument.SerialNumber.Value:%]"
						DeviceType="[%:Event.Argument.DeviceType.Value:%]"/>
                <!-- Optionally parse the string if desired -->
				<Output name="Result" as="ActionResult">
					<Value>
						<GPSOutput>[%:[%:@Output:%]Invoke.ReadValue.Message.Value:%]</GPSOutput>
					</Value>
				</Output>
			</Task>
		</Workflow>
	</Action>
</ThingFacet>

Display Text on LCD Screen.

Code Block
languagexml
titlePhidget Handler Thing Facet display text on LCD Screen
linenumberstrue
<ThingFacet Name="PhidgetTextLCDFacet">
	<String Name="DisplayString" KnownBy="LCDDisplayAction" Documentation="This is a runtime parameter" />
	<String Name="DeviceType" />
	<Action Name="LCDDisplayAction"
		Documentation="Display the string to Phidget Text LCD">
		<Workflow Limit="1" Live="1" Timeout="-1">
			<Task name="Main" while="true">
				<Event name="ActionArgument" as="ActionArgument" />
				<Log Message="******Invoking Phidget Text LCD"/>
				<Invoke name="WriteToLCD" waitFor="ActionArgument"
					Post="[%:Event.Argument.SensorURL.Value:%]" 
					DeviceType="[%:Event.Argument.DeviceType.Value:%]">
				 <Message Type="text" Value="[%:Event.Argument.DisplayString.Value:%]" />
				 </Invoke>
				<Log Message="Invoked Phidget Text LCD"/>
				<Output name="Result" as="ActionResult">
					<Value>
						<DisplayString>[%:[%:@Output:%]Invoke.WriteToLCD.Message.Value:%]</DisplayString>
					</Value>
				</Output>
			</Task>
		</Workflow>
	</Action>
</ThingFacet>
<!-- Combine with Model -->
<ThingModel Name="PhidgetLCDScreenModel" Combines="PhidgetTextLCDFacet">
   <Sid Name="LCDScreenID"/>
</ThingModel>
<!-- Write Text for first time -->
<Query>
  <Save format="version,current">
    <PhidgetLCDScreenModel>
      <SensorName>Rotation</SensorName>
      <DeviceType>PhidgetTextLCD</DeviceType>
      <DisplayString>Hello TQL!</DisplayString>
    </PhidgetLCDScreenModel>
  </Save>
</Query>
<!-- Subsequent Writes can happen via Update Query -->
<Query>
 <Find format="version"> 
		<PhidgetLCDScreenModel>
			<LCDScreenID ne=""/>
		</PhidgetLCDScreenModel>
	</Find>
	<SetResponseData> 
		<key>Message.Value.Find.Result.PhidgetLCDScreenModel.DisplayString.Value</key>
		<value>Hello Again!!</value>
	</SetResponseData>
	<Update> 
		<from>Result</from>
		<Include>$Response.Message.Value.Find</Include>
	</Update>
</Query>
 

Driver Installation Steps

Installing Phidget Driver

Linux: - To install Phidget libraries on your Linux system, the following steps must be performed.

  • Install libusb-1.0 development libraries (libusb-1.0-0-dev). This libraries can be installed from the source (http://www.libusb.org/) or if you are running a debian based  system you can simply run the command shown below    
Code Block
languagetext
themeEclipse
titleCommand to install USB Lib
linenumberstrue
sudo apt-get install libusb-1.0-0-dev

Note: - For additional information and troubleshooting visit the following website (http://www.phidgets.com/docs/OS_-_Linux)