jefffhaynes / XBee

A .NET library for XBee wireless controllers
MIT License
41 stars 17 forks source link

Is DigitalSampleState really the Digital Channel Mask? #14

Closed PaulNoto closed 8 years ago

PaulNoto commented 8 years ago

When looking at the information returned by DigitalSampleState, I came to the conclusion that it is the Digital Channel Mask. Is this correct? If so, I need the to access the Digital Sample to know which pins are High or Low. I could not find a way to do this. If I'm on the wrong track please ignore the rest of this.

I looked at the XBee manual. Here goes...

Frame Type: 0x92 ZigBee IO Data Sample Rx Indicator

Offset 16,17 Digital Channel Mask This is what I'm seeing returned by DigitalSampleState. I believe this, because it is a list of every pin on my node that is configured for digital input or output. This is not much use to me, because I already know which pin does what and it does not tell me which pin is an input or output, just that it is digital. I have never seen how to ask an XBee which pin is an input or output (maybe there is a way) and I have never had a reason to. I'm guessing this mask is a good way to test if a coding error is trying to read or write a non digital pin. I wonder how this would be useful to stop code from writing to an input pin?

Offset 19,20 Digital Samples This is what I need to get at. The state of all configured digital pins. I'm thinking this, about (SampleReceivedEventArgs sample)

Change: SampleReceivedEventArgs.DigitalSampleState

To: SampleReceivedEventArgs.DigitalSampleMask

Add: SampleReceivedEventArgs.DigitalSampleData

Be able to code things like: if ( sample.DigitalSampleData.DIO7 == false ) Actually: if ( !sample.DigitalSampleData.DIO7 )

What do you think?

Back Story: The fact that the sample contains not just the state of input pins but also output pins turned out to be really useful to me. Here is why: By convention, I setup all my nodes with DIO7 high and to transmit a sample to the controller every 10 seconds. When a node shows up for the first time or if it has been Power Cycled, DIO7 will be High and my software knows that this node is out of sync with what my software thinks it is currently doing and can reconfigure it. Part of reconfiguration, is to set DIO7 Low and automatic sampling to every 60 seconds. I do not commit these changes. Every incoming sample my software sets a flag that the node has Phoned Home. Every 3 minutes I check the flags and reset them. If a flag isn't set, I know that the node has a problem requiring manual intervention. I also had a Solar Powered Motion Detector stolen and within 3 minutes it showed up as MIA. Never got it back. The other thing that my use of DIO7 is great for, is something like my Flood Light with Motion Detector. If DIO7 is High it acts like a regular motion detector light. When I set DIO7 Low the motion detector sends signals to my software and my software controls the light. I can make it flash from motion. I can turn it on when I need light at night and I don't want to keep moving to trigger the motion detector, etc... Anyway, I have found that getting Input and output state in the sample is very useful.

jefffhaynes commented 8 years ago

Ugh. Did I really do that?  Sorry, let me look again. 

On Tue, Apr 26, 2016 at 8:22 AM -0700, "PaulNoto" notifications@github.com wrote:

When looking at the information returned by DigitalSampleState, I came to the conclusion that it is the Digital Channel Mask. Is this correct? If so, I need the to access the Digital Sample to know which pins are High or Low. I could not find a way to do this. If I'm on the wrong track please ignore the rest of this.

I looked at the XBee manual. Here goes...

Frame Type: 0x92 ZigBee IO Data Sample Rx Indicator

Offset 16,17 Digital Channel Mask

This is what I'm seeing returned by DigitalSampleState. I believe this, because it is a list of every pin on my node that is configured for digital input or output. This is not much use to me, because I already know which pin does what and it does not tell me which pin is an input or output, just that it is digital. I have never seen how to ask an XBee which pin is an input or output (maybe there is a way) and I have never had a reason to. I'm guessing this mask is a good way to test if a coding error is trying to read or write a non digital pin. I wonder how this would be useful to stop code from writing to an input pin?

Offset 19,20 Digital Samples

This is what I need to get at. The state of all configured digital pins.

I'm thinking this, about (SampleReceivedEventArgs sample)

Change: SampleReceivedEventArgs.DigitalSampleState

To: SampleReceivedEventArgs.DigitalSampleMask

Add: SampleReceivedEventArgs.DigitalSampleData

Be able to code things like: if ( sample.DigitalSampleData.DIO7 == false )

Actually: if ( !sample.DigitalSampleData.DIO7 )

What do you think?

Back Story:

The fact that the sample contains not just the state of input pins but also output pins turned out to be really useful to me. Here is why: By convention, I setup all my nodes with DIO7 high and to transmit a sample to the controller every 10 seconds. When a node shows up for the first time or if it has been Power Cycled, DIO7 will be High and my software knows that this node is out of sync with what my software thinks it is currently doing and can reconfigure it. Part of reconfiguration, is to set DIO7 Low and automatic sampling to every 60 seconds. I do not commit these changes. Every incoming sample my software sets a flag that the node has Phoned Home. Every 3 minutes I check the flags and reset them. If a flag isn't set, I know that the node has a problem requiring manual intervention. I also had a Solar Powered Motion Detector stolen and within 3 minutes it showed up as MIA. Never got it back. The other thing that my use of DIO7 is great for, is something like my Flood Light wi th Motion Detector. If DIO7 is High it acts like a regular motion detector light. When I set DIO7 Low the motion detector sends signals to my software and my software controls the light. I can make it flash from motion. I can turn it on when I need light at night and I don't want to keep moving to trigger the motion detector, etc...

Anyway, I have found that getting Input and output state in the sample is very useful.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

jefffhaynes commented 8 years ago

Ok, granted I might be missing something but I think what you're seeing is the sample state. The sample state lines up with the sample channel mask exactly so they might look similar.

As an example, if you have DIO3 configured for DI (Digital IN) and everything else default/disabled then SampleChannels will be Digital3 and DigitalSampleState (what actually gets returned by the event) will be Input3 if the input is high, or None if the input is low. Is that what you're seeing?

I do like your idea of including the SampleChannels info in the sample so I'll add that.

Thanks

PaulNoto commented 8 years ago

I'm so embarrassed. It is the digital channel data. I apologize for wasting your time.

jefffhaynes commented 8 years ago

No problem! I'm just glad I only screwed up 4 rather than 5 times this week ;)

I just pushed 2.2.3, which also includes the channel info.

Cheers

On Tue, Apr 26, 2016 at 9:43 PM, PaulNoto notifications@github.com wrote:

I'm so embarrassed. It is the digital channel data. I apologize for wasting your time.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/jefffhaynes/XBee/issues/14#issuecomment-214940125

If you want to build a ship, don't drum up people together to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea.

Antoine de Saint-Exupery

PaulNoto commented 8 years ago

Great. Thanks once again.