Writing multichannels to a file

Supporting 2.7 and 3.2+
Post Reply
mirvine
Phidgetsian
Posts: 6
Joined: Tue Jan 23, 2018 7:44 am
Contact:

Writing multichannels to a file

Post by mirvine »

Hi All

I am probablement thinking in a complicated way but if I use a 1046 with 4 analog input channels, what is the simple way of logging all 4 channels into one file ? Give that each channel has its own event this seems complicated to me. Any help would be appreciated.

Thanks
Mark
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Writing multichannels to a file

Post by mparadis »

You can register all four channels to the same event, like this:

Code: Select all

ch0.setChannel(0)
ch1.setChannel(1)
ch2.setChannel(2)
ch3.setChannel(3)
ch0.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
ch1.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
ch2.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
ch3.setOnVoltageRatioChangeHandler(VoltageRatioChangeHandler)
The change handler can tell the difference between which channel triggered the event by looking at the first parameter:

Code: Select all

def VoltageRatioChangeHandler(e, voltageRatio):
    print("CH%d: VoltageRatio: %f" % (e.getChannel(), voltageRatio))
In this case, the first parameter "e" contains all of the information about who triggered the event (in future examples we might rename "e" to "self" to make this more intuitive). As you can see, e.getChannel() tells you which number the triggering channel is set to.
mirvine
Phidgetsian
Posts: 6
Joined: Tue Jan 23, 2018 7:44 am
Contact:

Re: Writing multichannels to a file

Post by mirvine »

Ok great thanks for this and your quick response !

Best wishes
Mark
mirvine
Phidgetsian
Posts: 6
Joined: Tue Jan 23, 2018 7:44 am
Contact:

Re: Writing multichannels to a file

Post by mirvine »

Sorry but with this solution it is necessary that each ch object has the file handler as a propriety no ? Again am I missing something ? Are there no multi channel examples which write to a file ?

Thanks
Mark
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Writing multichannels to a file

Post by mparadis »

Yes, you'd have to pass the file pointer in by adding to to each of the channel objects, as mentioned in the other topic you posted in. We don't currently have a code sample that shows how to log multiple channels to a file using the same event, but I've added it to our list of potential articles for the future.
mirvine
Phidgetsian
Posts: 6
Joined: Tue Jan 23, 2018 7:44 am
Contact:

Re: Writing multichannels to a file

Post by mirvine »

Hi

Thanks again for your answer which clears things up. I must admit that this is not very efficient for me (compared to how I used to code in phidgets). I have to use globals as I change the file every hour. I could update every object also but I am not sure that this will happen in time so I am going for the global solution.

Best wishes
Mark
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests