1) how do I open and print all the channels at once
In order to open all four encoder channels, you need to create four separate encoder handles:
Code: Select all
ch0 = Encoder()
ch1 = Encoder()
ch2 = Encoder()
ch3 = Encoder()
Then you need to set parameters for each channel. If the 1047 is the only encoder Phidget connected to your computer or network, you can just set channel:
Code: Select all
ch0.setChannel(0)
ch1.setChannel(1)
ch2.setChannel(2)
ch3.setChannel(3)
Then set position change handlers for each one:
Code: Select all
ch0.setOnPositionChangeHandler(onPositionChangeHandler)
ch1.setOnPositionChangeHandler(onPositionChangeHandler)
ch2.setOnPositionChangeHandler(onPositionChangeHandler)
ch3.setOnPositionChangeHandler(onPositionChangeHandler)
Then you open each channel:
Code: Select all
ch0.openWaitForAttachment(5000)
ch1.openWaitForAttachment(5000)
ch2.openWaitForAttachment(5000)
ch3.openWaitForAttachment(5000)
If you're using the digital input channels, you can do the same process but with DigitalInput and setOnStateChangeHandler.
In order to print position data from all four channels, you need to create the "onPositionChangeHandler" function, which will trigger any time one of the encoders moves. Take a look at this function in our python encoder example to see what to put in it. Since all four channels trigger the same event function, you'll want to use the line
inside the event to determine which of the four channels this data belongs do. Then you can print the channel at the same time as the data. If this output looks too messy, you can instead store the data in one of four variables (one for each channel) and then use loop in your main program that prints these variables perodically.
2) how do I get the position (not the change that the code example has but like the phidgets interface that I downloaded and used to make sure the board was good) so it reads 100 then 101,102 etc it stead of 5,0,9,0 etc (change of state since last check)
The best you can do is keep track of the positions using variables that start at zero, and then add the position change to the appropriate variable each time an event comes in.
3) reset to zero once homed... no clue.
If you keep track of the total position using variables as I just described, then zeroing is as simple as setting that variable equal to zero.
EDIT: Oops, I forgot that there's a variable for total position already in the API. See James' response below.