PDA

View Full Version : How do I convert PI:setOutputState (9,true) to comserver message?



Mastiff
February 3rd, 2008, 09:11 AM
I will try to run the Phidgets on a virtual machine on my server to increase stability and reliability of Girder (one to many close calls). I have tried, and I can access and do all the Phidgets stuff on the VM. Then I'll use Comserver to send messages between the Server and the VM. But the problem is that I have a ton of code on my main server GML to access different outputs, and they all look like this:

PI:setOutputState (9,true)
That activates Phidgets output 9.

PI:setOutputState (9,false)
And that will deactivate output 9.

I have functions for the comserver as well, to get easy access to commands. The function of the IP for the VM is like this:

function Kom.C11(msg,pld1,pld2,pld3,pld4)
g2g.ClientSendEvent("192.168.0.11",msg,200,1,pld1,pld2,pld3,pld4)
end


So how do I get that Phidgets command converted to a comserver command that gets sent like this, so I won't have to change any of the old code:

Kom.C11("Phidget",9,true)
Then I need one single command at the Phidgets VM end to receive this and turn it back into this:


PI:setOutputState (9,true)

But that should be possible with something like this, I think:

PI:setOutputState (pld1,pld2) Or am I barking up the wrong forrest as usual?

Rob H
February 5th, 2008, 01:10 AM
Something like this should do it

Main server (instead of the code that opens the phidgets interface)



PI = {}
function PI:setOutputState(output, state)
Kom.C11("Phidget",9,true)
end

At the VM end you'd just have a simple scripting action in the GML that does


PI:setOutputState(pld1, pld2) and you'd drag and drop the Phidget event from the logger to that

Mastiff
February 5th, 2008, 01:49 AM
Thank you very much, Rob! And bad Mastiff, because I didn't even explain it correctly! :( This would only work to activate output 9. But I managed to make it do them all:


PI = {}
function PI:setOutputState(output, state)
state = tostring(state)
Kom.C11("Phidget",output, state)
end

Then this:

PI:setOutputState (12,false)
sends "Phidget" to the VM with 12 and false as the payloads.

I had to use tostring because the state came as true and false, and comserver didn't accept a boolean as a payload. But that of course creates a problem in the other end. I haven't found a function called "toboolean", so I had to do this to the receiver end:

output = pld2
state = pld3
if state == "false"
then state = false
end
if state == "true"
then state = true
output = tonumber(output)
print(output, state)
PI:setOutputState(output, state)
end


And that seems to work! Thanks again, tonight I'm gonna try this out!

Edit: Changed a bit of the receiving end, updated to show the changes. But for some strange reason the Phidgets script prints the wrong output number. When I toggle output 9 it insists that I'm toggling output 14 (but the actual output toggled is correct), and when I toggle output 11, it mysteriously says that I'm working on output 12. I have no idea why, but as long as I'm getting the correct end result it doesn't bother me that much. Gotta see what happens with the inputs, though.