private void RaiseKeySwitchChange(ProcessorKeySwitch oldState, ProcessorKeySwitch newState) { if (KeySwitchChanged != null) { KeySwitchChanged(this, new LogixKeyChangedEventArgs(oldState, newState)); } }
/// <summary> /// Creates a new LogixKeyChangedEventArgs object /// </summary> /// <param name="oldPos">Old Key Position</param> /// <param name="newPos">New Key Position</param> internal LogixKeyChangedEventArgs(ProcessorKeySwitch oldPos, ProcessorKeySwitch newPos) { OldPosition = oldPos; NewPosition = newPos; }
private void DecodeAttributeReply(byte[] data) { //Ok, first is the number of attributes... ushort numAttrs = BitConverter.ToUInt16(data, 0); if (numAttrs != 0x07) { return; //Error, not enough attributes returned } int offset = 2; //The format of the reply seems to be: //[2:AttributeId][Variable Data] for (int i = 0; i < 7; i++) { //Read 2 bytes for the Attribute Id: ushort attribId = BitConverter.ToUInt16(data, offset); offset += 2; switch (attribId) { case 0x01: //VendorId //Returns 2 words for some reason, data is in the lower //word... offset += 2; _vendorId = BitConverter.ToUInt16(data, offset); offset += 2; break; case 0x02: //Device Type //Also 2 word reply... offset += 2; _deviceType = BitConverter.ToUInt16(data, offset); offset += 2; break; case 0x03: //Product Code //Again 2 words... offset += 2; _productCode = BitConverter.ToUInt16(data, offset); offset += 2; break; case 0x04: //Revision //Another 2 words offset += 2; _majorRevision = data[offset]; _minorRevision = data[offset + 1]; offset += 2; break; case 0x05: //Status //2 words offset += 2; //This gets a little complicated here... //State is stored in the upper nibble of the byte... ProcessorState oldState = _state; _state = (ProcessorState)(byte)((data[offset] & 0xF0) >> 4); offset += 1; //Fault state is in the lower nibble ProcessorFaultState oldFault = _faultState; _faultState = (ProcessorFaultState)(byte)((data[offset] & 0x0F)); //Keyswitch position is in the upper nibble ProcessorKeySwitch oldKey = _keySw; _keySw = (ProcessorKeySwitch)(byte)((data[offset] & 0xF0) >> 4); offset += 1; //Take care of events if (_stateEventsEnabled) { if (oldState != _state) { RaiseProcessorStateChange(oldState, _state); } if (oldFault != _faultState) { RaiseFaultStateChange(oldFault, _faultState); } if (oldKey != _keySw) { RaiseKeySwitchChange(oldKey, _keySw); } } break; case 0x06: //Serial Number //This returns 3 words, data is in the lower 2... offset += 2; _serialNumber = BitConverter.ToUInt32(data, offset); offset += 4; break; case 0x07: //Product Name //Skip one word offset += 2; //Get the size of the string... byte sSize = data[offset]; offset += 1; _productName = System.Text.ASCIIEncoding.ASCII.GetString(data, offset, sSize); offset += sSize; break; default: break; //This is an error } } }