Phidget Interface never Attaching

Comments & issues
eliddell
Fresh meat
Posts: 4
Joined: Tue Aug 20, 2013 9:21 am
Contact:

Phidget Interface never Attaching

Postby eliddell » Tue Aug 20, 2013 9:25 am

I have to admit i have never worked with phidgets and i am trying to debug someone else's code. We have a Phidget interface kit 8/8/8 wired to a windows 7 machine and the Phidget Control panel seems to be communicating with the board just fine.. even fires my relays and everything.. but When debugging our AIR (AS3 application) i notice that the phidget actually never attaches.. I can't for the life of me figure out why? I call open(localhost,5001) and set a listener for ATTACH but, the onAttach Handler never gets fired..

any help would be super appreciated:

here is my code:

Code: Select all

public class PhidgetsController extends EventDispatcher {

        private var address:String = 'localhost';
        private var port:Number = 5001;

        [Bindable][Inject]
        public var applicationController:ApplicationController;

        private var phidIK:PhidgetInterfaceKit;

        private var phidSC:PhidgetsSonarController;

        public var clientActivated:Boolean = false;

        public function PhidgetsController() {
        }


        /**
         *      INITIALIZE
         **/
        [EventHandler(event="PhidgetsControllerEvent.PHIDGET_INITIALIZE")]
        public function init():void {
            trace("-----phidIK init----");
            if (phidIK) {
                // close any current
                trace("----------------------phidget was already init terminating----------------------");
                terminate();
            }
            phidIK = new PhidgetInterfaceKit();

            phidIK.open(address, port);
            phidIK.addEventListener(PhidgetEvent.ATTACH, onAttach);
            trace("phidget attached:"+phidIK.isAttached+" is connected:"+phidIK.isConnected);

        }

        private function onAttach(e:PhidgetEvent):void {
            dispatchEvent(new PhidgetsControllerEvent(PhidgetsControllerEvent.PHIDGETS_READY));
            trace("----------------------phidget attached----------------------");
        }

        /**
         *      TERMINATE
         **/
        public function terminate():void {
            trace("----------------------phidget terminated----------------------");
            if (phidIK) {
                phidIK.close();
            }
            // dispatch event phidgetInterfaceKit closed
        }

        /**
         *      SONAR
         **/
        public function proximityScan():void {
            if (!phidIK) {
                init();
            }
            if (!phidSC) {
                phidSC = new PhidgetsSonarController();
            }
            var tmpXMLList:XMLList;
            for (var i:int = 0; i < applicationController.productConfigXML.children().length(); i++) {
                trace(applicationController.productConfigXML.children()[i].@id);
                if (applicationController.productConfigXML.children()[i].@id == 'sonar') {
                    tmpXMLList = applicationController.productConfigXML.children()[i].children();
                }
            }
            phidSC.initSonar(phidIK, tmpXMLList[0], tmpXMLList[1], tmpXMLList[2]);
            phidSC.addEventListener(PhidgetsSonarController.ACTIVATE_CLIENT, onActivateClient);
            phidSC.addEventListener(PhidgetsSonarController.DEACTIVATE_CLIENT, onDeactivateClient);
        }
        public function onActivateClient(e:Event):void {
            trace("----------------------client activated----------------------");
            if (!clientActivated) {
                dispatchEvent(new PhidgetsControllerEvent(PhidgetsControllerEvent.PHIDGET_ACTIVATE_CLIENT));
                clientActivated = true;
            }
        }
        public function onDeactivateClient(e:Event):void {
            trace("----------------------phidget deactivated----------------------");
            if (clientActivated) {
                dispatchEvent(new PhidgetsControllerEvent(PhidgetsControllerEvent.PHIDGET_DEACTIVATE_CLIENT));
                clientActivated = false;
            }
        }


        /**
         *      RELAY
         **/
        public function toggleRelay(dir:String):void {

            if(!phidIK.isAttached){
                phidIK.open("localhost",5001);
            }
            trace("toggle relay: "+dir);
            trace("NOW IS THE MOTHER ATTACHED?:::"+phidIK.isAttached);
            switch (dir) {
                case 'on':
                    trace("SWitching on");
                try{

                phidIK.setOutputState(0, true);
                phidIK.setOutputState(1, true);
                }catch(error:Error){
                    trace("ERROR IN TOGGLE RELAY::::::"+error);
                    var file:File = File.desktopDirectory.resolvePath("phidget error log.txt");
                    var stream:FileStream = new FileStream();
                    stream.open(file, FileMode.APPEND);
                    stream.writeUTFBytes("\n Error from toggle:"+error);
                    stream.close();

                }
                trace('switch on');
                    break;
                case 'off':
                    trace("SWitching off");
                    try{
                phidIK.setOutputState(0, false);
                phidIK.setOutputState(1, false);
                    }catch(error:Error){
                        trace("ERROR IN TOGGLE RELAY::::::"+error);
                        var file:File = File.desktopDirectory.resolvePath("phidget error log.txt");
                        var stream:FileStream = new FileStream();
                        stream.open(file, FileMode.APPEND);
                        stream.writeUTFBytes("\n Error from toggle:"+error);
                        stream.close();
                    }
                trace('switch off');
                    break;
            }
        }


        private function getOutputValue():Boolean {
            return phidIK.getOutputState(0);
        }

    }
}

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: Phidget Interface never Attaching

Postby frodegill » Tue Aug 20, 2013 11:16 am

eliddell wrote:

Code: Select all

            phidIK = new PhidgetInterfaceKit();
            phidIK.open(address, port);
            phidIK.addEventListener(PhidgetEvent.ATTACH, onAttach);

I guess your problem is here. To quote the documentation (which for some mysterious reason uses "start" instead of "open"):
"If attach and detach listeners are to be used, they should be registered before start is called so that no events are missed."

eliddell
Fresh meat
Posts: 4
Joined: Tue Aug 20, 2013 9:21 am
Contact:

Re: Phidget Interface never Attaching

Postby eliddell » Tue Aug 20, 2013 11:58 am

yeah i changed that actually to bethe right order.. still not working.. though i noticed the log coming in the phidget control panel output spits out the folloing error when flash tries to connect

78] - ERR: Recieved unexpected data in authenticate: 904 authenticate, version=2.1.8
[79] - WARN: Authentication failed or bad version - closing connection
[80] - INFO: done - session closed

that seems to happen here in my code:

Code: Select all

private function onSocketConnect(evt:Event):void{         
         trace("on socket connect fired::::conection ="+_socket.connected);
         if(!_socket.connected)
         {
            _errorCallback(new PhidgetError(com.phidgets.Constants.EPHIDGET_NETWORK_NOTCONNECTED));
            return;
         }
         
         _connected = true;
         
         //AS3.0 wants line to be null terminated
         socketSend("need nulls");
         //start authentication proccess
         socketSend("904 authenticate, version="+protocol_ver);// was 995 changed to 904 eliddell
      }


this not being my code orginally i noticed that they had 995 instead of 904 (i changed it to 904 because that is the version number on the back of the board. they have the protocol_ver set to "1.0.4"

i believe this is nowmy problem but i don't know what it should say..

Erik

eliddell
Fresh meat
Posts: 4
Joined: Tue Aug 20, 2013 9:21 am
Contact:

Re: Phidget Interface never Attaching

Postby eliddell » Tue Aug 20, 2013 12:53 pm

i changed the 904 back to 995 and the error says my webservice is 1.0.10 and the phidget service protocol is 1.0.4 and prompts me to update both to the latest version.. how do i update this supposed webservice?

if i just set my protocol_ver to match 1.0.10 it seems to work but I would like to make sure everything is actually up to date

User avatar
Patrick
Lead Developer
Posts: 3052
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Phidget Interface never Attaching

Postby Patrick » Tue Aug 20, 2013 12:54 pm

995 is not a version, it's control code - part of the webservice protocol.

You should never have to modify any of the Phidgets provided library code. You will however need to make sure that both the AS3 library code and the installed phidget21 libraries are of the same version.

Just download the latest AS3 code from the website and overwrite the older version that you have.

-Patrick

eliddell
Fresh meat
Posts: 4
Joined: Tue Aug 20, 2013 9:21 am
Contact:

Re: Phidget Interface never Attaching

Postby eliddell » Tue Aug 20, 2013 1:10 pm

i was unable to find the latest code can you share the links?

User avatar
Patrick
Lead Developer
Posts: 3052
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Phidget Interface never Attaching

Postby Patrick » Tue Aug 20, 2013 2:13 pm



Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests