public void FetchAll()
        {
            //this.OnFetchData(this.simulateJTokenInstance("123", "add", 123));

            Matcher matcher = new Matcher();
            FetchId id;

            _peer.Fetch(out id, matcher, OnFetchData, null, 500); // Onfetch = null (given by 'JetBusConnection'), timeoutms=500;

            bool success = true;

            this.ConvertJTokenToStringArray();

            if (this.behavior != Behavior.ReadFail_DataReceived)
            {
                RaiseDataEvent?.Invoke(this, new DataEvent(DataUshortArray, DataStrArray));
            }

            BusActivityDetection?.Invoke(this, new LogEvent("Fetch-All success: " + success + " - buffersize is " + _dataBuffer.Count));
        }
Example #2
0
        public void ReadRegisterPublishing(DataEvent e)
        {
            // Behavoir : Kann in Standard oder Filler Mode sein, kann unterschiedliche "NumInputs" haben. Dementsprechend abhängig
            // ist die Anzahl der eingelesenen Werte. Erstmal vom einfachen Fall ausgehen!

            switch (this.behavior)
            {
            case Behavior.WriteHandshakeTestSuccess:

                if (_dataWTX[4] == 0x0000)
                {
                    _dataWTX[4] = 0x4000;
                }
                else
                if (_dataWTX[4] == 0x4000)
                {
                    _dataWTX[4] = 0x0000;
                }
                break;

            case Behavior.InFillerMode:

                //data word for a application mode being in filler mode: Bit .0-1 = 1 || 2 (2 is the given value for filler mode according to the manual, but actually it is 1.)
                _dataWTX[5] = 0x1;
                break;

            case Behavior.InStandardMode:

                //data word for a application mode being in standard mode, not in filler mode: Bit .0-1 = 0
                _dataWTX[5] = 0x00;

                break;

            case Behavior.CalibrationFail:

                //Handshake bit:

                if (_dataWTX[5] >> 14 == 0)
                {
                    _dataWTX[5] = 0x4000;
                }
                else if (_dataWTX[5] >> 14 == 1)
                {
                    _dataWTX[5] = 0x0000;
                }

                break;

            case Behavior.CalibrationSuccess:

                //Handshake bit:

                if (_dataWTX[5] >> 14 == 0)
                {
                    _dataWTX[5] = 0x4000;
                }
                else if (_dataWTX[5] >> 14 == 1)
                {
                    _dataWTX[5] = 0x0000;
                }

                break;

            case Behavior.MeasureZeroFail:

                // Net value in hexadecimal:
                _dataWTX[0] = 0x00;
                _dataWTX[1] = 0x2710;

                // Gross value in hexadecimal:
                _dataWTX[2] = 0x00;
                _dataWTX[3] = 0x2710;

                //Handshake bit:
                if (_dataWTX[5] >> 14 == 0)
                {
                    _dataWTX[5] = 0x4000;
                }

                else if (_dataWTX[5] >> 14 == 1)
                {
                    _dataWTX[5] = 0x0000;
                }

                break;

            case Behavior.MeasureZeroSuccess:

                // Net value in hexadecimal:
                _dataWTX[0] = 0x00;
                _dataWTX[1] = 0x00;

                // Gross value in hexadecimal:
                _dataWTX[2] = 0x00;
                _dataWTX[3] = 0x00;

                //Handshake bit:
                if (_dataWTX[5] >> 14 == 0)
                {
                    _dataWTX[5] = 0x4000;
                }
                else if (_dataWTX[5] >> 14 == 1)
                {
                    _dataWTX[5] = 0x0000;
                }

                break;

            case Behavior.ReadFail:

                // If there is a connection fail, all data attributes get 0 as value.

                for (int index = 0; index < _dataWTX.Length; index++)
                {
                    _dataWTX[index] = 0x0000;
                }

                _logObj = new LogEvent("Read failed : Registers have not been read");

                BusActivityDetection?.Invoke(this, _logObj);

                break;

            case Behavior.ReadSuccess:

                // The most important data attributes from the WTX120 device:

                _dataWTX[0] = 0x0000;
                _dataWTX[1] = 0x4040;
                _dataWTX[2] = 0x0000;
                _dataWTX[3] = 0x4040;
                _dataWTX[4] = 0x0000;
                _dataWTX[5] = 0x0000;

                _logObj = new LogEvent("Read successful: Registers have been read");
                BusActivityDetection?.Invoke(this, _logObj);
                break;


            case Behavior.t_UnitValue_Success:
                _dataWTX[5] = 0x100;
                break;

            case Behavior.t_UnitValue_Fail:
                _dataWTX[5] = 0x0000;
                break;

            case Behavior.kg_UnitValue_Success:
                _dataWTX[5] = 0x0000;
                break;

            case Behavior.kg_UnitValue_Fail:
                _dataWTX[5] = 0xFFFF;
                break;

            case Behavior.g_UnitValue_Success:
                _dataWTX[5] = 0x80;
                break;

            case Behavior.g_UnitValue_Fail:
                _dataWTX[5] = 0x0000;
                break;

            case Behavior.lb_UnitValue_Success:
                _dataWTX[5] = 0x180;
                break;


            case Behavior.lb_UnitValue_Fail:
                _dataWTX[5] = 0x0000;
                break;

            case Behavior.NetGrossValueStringComment_0D_Success:
                _dataWTX[5] = 0x0000;
                break;

            case Behavior.NetGrossValueStringComment_1D_Success:
                _dataWTX[5] = 0x10;
                break;

            case Behavior.NetGrossValueStringComment_2D_Success:
                _dataWTX[5] = 0x20;
                break;

            case Behavior.NetGrossValueStringComment_3D_Success:
                _dataWTX[5] = 0x30;
                break;

            case Behavior.NetGrossValueStringComment_4D_Success:
                _dataWTX[5] = 0x40;
                break;

            case Behavior.NetGrossValueStringComment_5D_Success:
                _dataWTX[5] = 0x50;
                break;

            case Behavior.NetGrossValueStringComment_6D_Success:
                _dataWTX[5] = 0x60;
                break;

            // Simulate for testing 'Scale range':

            case Behavior.ScaleRangeStringComment_Range1_Fail:
                _dataWTX[4] = 0x200;
                break;

            case Behavior.ScaleRangeStringComment_Range2_Fail:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.ScaleRangeStringComment_Range3_Fail:
                _dataWTX[4] = 0x100;
                break;

            case Behavior.ScaleRangeStringComment_Range1_Success:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.ScaleRangeStringComment_Range2_Success:
                _dataWTX[4] = 0x100;
                break;

            case Behavior.ScaleRangeStringComment_Range3_Success:
                _dataWTX[4] = 0x200;
                break;

            // Simulate for testing 'Limit status':

            case Behavior.LimitStatusStringComment_Case0_Fail:
                _dataWTX[4] = 0xC;
                break;

            case Behavior.LimitStatusStringComment_Case1_Fail:
                _dataWTX[4] = 0x8;
                break;

            case Behavior.LimitStatusStringComment_Case2_Fail:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.LimitStatusStringComment_Case3_Fail:
                _dataWTX[4] = 0x4;
                break;

            case Behavior.LimitStatusStringComment_Case0_Success:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.LimitStatusStringComment_Case1_Success:
                _dataWTX[4] = 0x4;
                break;

            case Behavior.LimitStatusStringComment_Case2_Success:
                _dataWTX[4] = 0x8;
                break;

            case Behavior.LimitStatusStringComment_Case3_Success:
                _dataWTX[4] = 0xC;
                break;

            // Simulate for testing 'Weight moving':
            case Behavior.WeightMovingStringComment_Case0_Fail:
                _dataWTX[4] = 0x0010;
                break;

            case Behavior.WeightMovingStringComment_Case1_Fail:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.WeightMovingStringComment_Case0_Success:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.WeightMovingStringComment_Case1_Success:
                _dataWTX[4] = 0x0010;
                break;

            // Simulate for testing 'Weight type':
            case Behavior.WeightTypeStringComment_Case0_Fail:
                _dataWTX[4] = 0x0080;
                break;

            case Behavior.WeightTypeStringComment_Case1_Fail:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.WeightTypeStringComment_Case0_Success:
                _dataWTX[4] = 0x0000;
                break;

            case Behavior.WeightTypeStringComment_Case1_Success:
                _dataWTX[4] = 0x0080;
                break;

            case Behavior.LogEvent_Fail:

                _logObj = new LogEvent("Read failed : Registers have not been read");
                BusActivityDetection?.Invoke(this, _logObj);

                break;

            case Behavior.LogEvent_Success:

                _logObj = new LogEvent("Read successful: Registers have been read");
                BusActivityDetection?.Invoke(this, _logObj);

                break;

            default:
                /*
                 * for (int index = 0; index < _dataWTX.Length; index++)
                 * {
                 *  _dataWTX[index] = 0;
                 * }
                 * _logObj = new LogEvent("Read failed : Registers have not been read");
                 * BusActivityDetection?.Invoke(this, _logObj);
                 */
                break;
            }

            RaiseDataEvent?.Invoke(this, new DataEvent(this._dataWTX, new string[0]));

            /*
             * var handler = RaiseDataEvent;
             *
             * //If a subscriber exists:
             * if (handler != null) handler(this, new DataEvent(_dataWTX));
             */
        }