Products for USB Sensing and Control
It is currently Thu May 23, 2013 9:14 pm

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Tue Feb 24, 2009 6:39 am 
Offline
Phidgetsian

Joined: Tue Feb 24, 2009 6:32 am
Posts: 7
I would like to have a simple webservice-programm in C#. So no direct usage of the Phidget-Kit.

Has anyone done this before? Any sources (i looked through the website and didn't found something).

Or is there a description of the used webservices-Commands? A Documentation about the Webservice?

Thanks for any help

René

(Background: I use C#/Mono in a GameEngine and there it is not so easy to import Libraries)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 10:17 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
I don't quite understand your meaning. Are you wanting to control a Phidget via the webservice from C#, but without importing the phidget21.NET.dll library? I would not recommend this, the webservice protocol is not documented and can change at any time. You should be able to import libraries - we have used our .NET library in mono without any troubles.

-Patrick


Top
 Profile Send private message  
 
 Post subject: direct access
PostPosted: Wed Feb 25, 2009 10:17 am 
Offline
Phidgetsian

Joined: Tue Feb 24, 2009 6:32 am
Posts: 7
yes i want do exactly this. i am just interested in the 8/8/8 and the interface-kit. i just wanna read out and send the values nothing more.

out of an engine this is the easiest way, you don't have to implement a library or some external things. i had the same problem a while ago with a serial thing and ardunio. easy thing read out the serial data in mono. but the hell if you have a good gameengine without the possiblity or a not good implementation of C#. therefore i search for the easiest way. the other way would be to make a plugin, this would be easy in fact but the problem is there you need the big version 2000$ dollar for it and therefore i need a cheaper variant at the moment.

but you say the webservice is not documentated (so it's correct that there is no documentation) and i guess it is not a classic xml-webservice or?

but is there still someone out there which did this? a simple implementation for read out and send data for the 8/8/8 ?

thanks for reply

t00cg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 1:06 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
You can look at the AS3.0 code for a client implementation - AS3.0 is fairly similar to C# so it shouldn't be too hard to read. What sort of system are you running this on where C# would be giving you such issues? Could you not use the C library instead?

-Patrick


Top
 Profile Send private message  
 
 Post subject: thanks for reply
PostPosted: Sat Feb 28, 2009 11:33 am 
Offline
Phidgetsian

Joined: Tue Feb 24, 2009 6:32 am
Posts: 7
will look at as library and try to reimplement it.


Top
 Profile  
 
PostPosted: Tue Mar 10, 2009 5:03 pm 
Offline
Phidgetsian

Joined: Tue Feb 24, 2009 6:32 am
Posts: 7
thanks again for the as3 hint. i implemented it raw for the game engine unity3d (coming soon also for windows).

# C# in Unity3d (http://www.unity3d.com)
PhidgetInterfaceKit Raw Implementation for 1 attached PhidgetInterfaceKit. Find Source-Code for Unity3d here:
http://www.gametheory.ch/index.jsp?positionId=113660

# C#-Standalone
If you want to have a implementation just C#/Mono just copy and paste together the things:
1. Rename: "Start()" > "PhidgetInterfaceKitClient()"
2. Add "Update();" in the method: "WaitForDataReceive()" before "WaitForData();" - this should work.
(3. There will be a Problem with stopping the AsyncCallback)

The Protocoll for connecting, i get out of the AS3 code, here the Modification for interested people (perhaps there is someone like me out there :-)

And dont blame me about the code. It is not sexy at all just simple. But perhaps helps someone in going straight forwards.

/*
// ---------------------------------------------------------
// debugging and research with Flash
// ---------------------------------------------------------
// send data
1. com/phidgets/PhidgetSocket.as > Search for method "socketSend" enable trace()
// receive data
2. com/phidgets/PhidgetSocket.as > Search for method "onSocketData" add trace("Receive Data: "+realData);


// ---------------------------------------------------------
// filestructure
// ---------------------------------------------------------
// manager
// socket
// constants
// com/phidgets/Constants.as


// ---------------------------------------------------------
// transcript
// ---------------------------------------------------------
[out] need nulls
[out] 995 authenticate, version=1.0.1
[in] 200 appending NULLs to lines
[in] 996 No need to authenticate, version=1.0.1
[out] report 8 report
[out] set /PCK/Client/0.0.0.0/90819/PhidgetInterfaceKit="Open" for session
[out] listen /PSK/PhidgetInterfaceKit lid0
[in] 200 inter-report period adjusted to 8ms
[in] 200 set successful
[in] 200 listening, id lid0
[in] report 200-periodic report follows:
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/0 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/0 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/1 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/2 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/3 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/4 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/5 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/6 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Input/7 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Label latest value "das erste" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Name latest value "Phidget InterfaceKit 8/8/8" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/NumberOfInputs latest value "8" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/NumberOfOutputs latest value "8" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/NumberOfSensors latest value "8" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/0 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/1 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/2 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/3 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/4 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/5 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/6 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Output/7 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/0 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/1 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/2 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/3 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/4 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/5 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/6 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/7 latest value "0" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Status latest value "Attached" (added)
[in] report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Version latest value "826" (added)

// serial number: 85030
// sending a command (output)
[out] set /PCK/PhidgetInterfaceKit/85030/Output/3="1"

// ---------------------------------------------------------
// testing with shell netcat (nc)
// ---------------------------------------------------------
nc localhost 5001

need nulls
995 authenticate, version=1.0.1
report 8 report
listen /PSK/PhidgetInterfaceKit lid0

// now updates automatically

// read out
// /PSK/PhidgetInterfaceKit/[SERIALNUMBER]/Input/1 latest value "0" (current)
// /PSK/PhidgetInterfaceKit/85030/Input/1 latest value "0" (current)
// /PSK/PhidgetInterfaceKit/85030/Output/0 latest value "1" (current)
// /PSK/PhidgetInterfaceKit/85030/Status latest value "Attached" (current)
// /PSK/PhidgetInterfaceKit/85030/Label latest value "Label" (current)
// /PSK/PhidgetInterfaceKit/85030/Version latest value "826" (current)


// manually read out serial number /PSK/PhidgetInterfaceKit/SERIALXYZ/
// set /PCK/PhidgetInterfaceKit/SERIALXYZ/Output/3="1"
set /PCK/PhidgetInterfaceKit/85030/Output/3="1"


# shell
nc localhost 5001

need nulls
995 authenticate, version=1.0.1
report 8 report
set /PCK/Client/0.0.0.0/32556/PhidgetInterfaceKit="Open" for session
listen /PSK/PhidgetInterfaceKit lid0

// ...
/PSK/PhidgetInterfaceKit/85030/NumberOfInputs value 8

# receive data
200-periodic report follows:report 200-lid0 is pending, key /PSK/PhidgetInterfaceKit/85030/Sensor/3 latest value "407" (changed)

// setzen eines outputs ..
set /PCK/PhidgetInterfaceKit/85030/Output/3="1"

# protocoll
need nulls
// append nulls
995 authenticate, version=1.0.1
// authenti. else 996 error ! else auth.
/*
case "999": //Authentication required
var ticket :String = realData+_password;
_password = null;
var hash :String = MD5.hex_md5(ticket);
request = "997 " + hash;
socketSend(request);
break;
case "998": //Authentication failed
_errorCallback(new PhidgetError(com.phidgets.Constants.EPHIDGET_BADPASSWORD));
break;
case "996": //Authenitcated, or no authentication
//check version
if(realData.indexOf("version=",0)<=0)
{
_errorCallback(new PhidgetError(com.phidgets.Constants.EPHIDGET_BADVERSION));
break;
}
onAuthenticated();
break;
case "994": //Authentication failed
_errorCallback(new PhidgetError(com.phidgets.Constants.EPHIDGET_BADVERSION));
break;



//Commands
public static const NULL_CMD:String = "need nulls";
public static const LISTEN_CMD:String = "listen";
public static const IGNORE_CMD:String = "ignore";
public static const REPORT_CMD:String = "report";
public static const WAIT_CMD:String = "wait";
public static const FLUSH_CMD:String = "flush";
public static const WALK_CMD:String = "walk";
public static const QUIT_CMD:String = "quit";
public static const GET_CMD:String = "get";
public static const SET_CMD:String = "set";
//responses
public static const SUCCESS_200_RESP:String = "2";
public static const FAILURE_300_RESP:String = "3";
public static const FAILURE_400_RESP:String = "4";
public static const FAILURE_500_RESP:String = "5";
public static const AUTHENTICATE_900_RESP:String = "9";

public static const OK_PENDING_RESP:String = "200-";
public static const OK_RESP:String = "200 ";

//Listen key change reasons
public static const VALUE_CHANGED:int = 1;
public static const ENTRY_ADDED:int = 2;
public static const ENTRY_REMOVING:int = 3;

*/


Attachments:
PhidgetInterfaceKitClient.zip [5.39 KiB]
Downloaded 103 times
Top
 Profile  
 
PostPosted: Wed Mar 11, 2009 9:48 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Looks pretty good, I'm glad you were able to implement it.

Two things to note:
-you probably don't need to bother sending the 'need nulls' command - this was implemented because AS3 needs NULL to be appended to each line, without it, we append a newline to each line - and for the terminal, and .NET certainly, that's enough.
-You might want to keep a copy of the phidget webservice that you're programming against because we can and do change the webservice protocol from time to time. This at least is being version controlled now, so for example the released version right now is 1.0.2, and your code should check for this discrepancy - the changes are commented in the AS3 code, and pretty minor from your perspective I think.

-Patrick


Top
 Profile Send private message  
 
PostPosted: Wed Mar 11, 2009 6:07 pm 
Offline
Phidgetsian

Joined: Tue Feb 24, 2009 6:32 am
Posts: 7
# needs nulls
will disable this.

# version
you are of course right. i will always update the code when i use it again with a new version. and it should also not to be very complicated to rebuild or adapt it if you can use the AS3 code for reverse doing it.

thanks anyway.

tomorrow the students will build games with the phidgets in unity .-) will be nice.

good time to canada from europe

t00cg/rené


Top
 Profile  
 
PostPosted: Thu Mar 12, 2009 10:21 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Sounds like a really cool project. Sorry for the runaround, we don't like to encourage users doing undocumented things because we can't maintain the support, but of course sometimes it's just the way to go.

-Patrick


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group