コード例 #1
0
        public virtual bool Initialize()
        {
            bool opened = this.OpenDevice();

            if (!opened)
            {
                return(false);
            }

            this.StartHochVolt();

            this.DoBeforeInitialization();

            byte[] data = new byte[8];
            data[0] = 0x01;
            // equalize sensor results
            //0xc0 alle Refsoll Werte werden gleich initialisiert. Bei Ref = Messkapazität wird 75% Messbereich ausgegeben
            //0x80 alle Refsoll Werte werden gleich initialisiert. Bei Ref = Messkapazität wird 50% Messbereich ausgegeben
            //0xFF individueller Abgleich. Alle Module werden gemessen und dann wird versucht jedes einzelne auf 50% Messbereich
            // einzustellen
            data[2] = 0xFF;

            ModifyInitData(data);

            bool initResult = BrailleDisNet.BrdCommand(
                this.DeviceNumber, // device-number
                data);             // flags

            return(initResult);
        }
コード例 #2
0
        public static Device CreateDeviceObject(DeviceInformation_T di, BrailleDisNet parent)
        {
            var types = Assembly.GetExecutingAssembly().GetTypes();

            foreach (var type in types)
            {
                var attribs = type.GetCustomAttributes(typeof(DeviceTypeAttribute), false);
                if (attribs.Length <= 0)
                {
                    continue;
                }
                foreach (DeviceTypeAttribute att in attribs)
                {
                    if (att.DeviceType == di.DeviceType)
                    {
                        var constructor = type.GetConstructor(new Type[] { });
                        var newDevice   = constructor.Invoke(new object[] { }) as Device;
                        newDevice.DeviceInformation     = di;
                        newDevice.Parent                = parent;
                        newDevice.DeviceTypeInformation = Device.DeviceTypes[att.DeviceType];
                        return(newDevice);
                    }
                }
            }

            return(new DeviceBrailleDis());
        }
コード例 #3
0
        public virtual bool StartHochVolt()
        {
            byte[] dataHV = new byte[8];
            dataHV[0] = 0x02;
            dataHV[1] = 0x01;
            bool initResultHV = BrailleDisNet.BrdCommand(
                this.DeviceNumber, // device-number
                dataHV);           // flags

            return(initResultHV);
        }
コード例 #4
0
 public override void DoBeforeInitialization()
 {
     Thread.Sleep(400);
     {
         byte[] dataHV = new byte[8];
         dataHV[0] = 0x04;
         dataHV[1] = 0x00;
         dataHV[2] = 0x08;
         bool cmessResult = BrailleDisNet.BrdCommand(
             this.DeviceNumber, // device-number
             dataHV);           // flags
         Thread.Sleep(100);
     }
 }
コード例 #5
0
 public virtual bool OpenDevice()
 {
     try
     {
         var criteria = new byte[2];
         criteria[0] = 32;
         criteria[1] = 0;
         int devType = 0;
         this.DeviceNumber = BrailleDisNet.BrdInitDevice(criteria, ref devType);
         if (this.DeviceNumber == -1)
         {
             return(false);
         }
     }
     catch (Exception)
     {
         this.DeviceNumber = -1;
         return(false);
     }
     return(true);
 }
コード例 #6
0
        public override void Recalibrate(BrailleDisNet brailleDis)
        {
            Thread.Sleep(500);
            brailleDis.ReleaseAllPins();

            /*bool[,] matrix = new bool[brailleDis.NumberOfPinRows, brailleDis.NumberOfPinColumns];
             * for (int c = 0; c < brailleDis.NumberOfPinColumns; c++)
             * {
             *  for (int r = 0; r < brailleDis.NumberOfPinRows; r++)
             *  {
             *      matrix[r, c] =
             *          (r + 1) % brailleDis.NumberOfModuleRows == 0;
             *  }
             * }
             * brailleDis.SetCompleteMatrix(matrix);*/

            Thread.Sleep(500);

            base.Recalibrate(brailleDis);
            Thread.Sleep(300);
        }
コード例 #7
0
        public virtual void Recalibrate(BrailleDisNet brailleDis)
        {
            brailleDis.m_touch_input           = new int[BrailleDisConsts.NUMBER_OF_SENSOR_ROWS, BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS];
            brailleDis.m_reference_touch_input = new int[BrailleDisConsts.NUMBER_OF_SENSOR_ROWS,
                                                         BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS];
            brailleDis.m_reference_touch_input.Initialize();

            byte[] readBuffer = new byte[BrailleDisConsts.TOTAL_INPUT_LENGTH];
            int    readResult = 0;

            try
            {
                //System.Threading.Thread.BeginCriticalRegion();
                readResult = BrailleDisNet.BrdReadData(DeviceNumber, readBuffer.Length, readBuffer);

                if (readResult < BrailleDisConsts.TOTAL_INPUT_LENGTH)
                {
                    return;
                }
            }
            finally
            {
                //System.Threading.Thread.EndCriticalRegion();
            }

            if (readBuffer[BrailleDisConsts.INPUT_TYPE] == BrailleDisConsts.OLD_BRAILLEDIS)
            { // first generation of BrailleDis with 720 sensors
                // todo: if you wish to treat the old BrailleDis withh 1440 sensors
                // then set m_deviceGeneration to 2 instead of 1
                brailleDis.m_deviceGeneration = 1;
                foreach (var damagedTouches in brailleDis.m_damagedTouches)
                { // duplicate because of duplication of sensors
                    int pos = damagedTouches.X + damagedTouches.Y * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS * 2;
                    if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                    {
                        continue;
                    }
                    readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                    pos += 60; // second occurence of sensor
                    if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                    {
                        continue;
                    }
                    readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                }
            }
            else
            {
                // todo: if you wish to treat the new BrailleDis withh 720 sensors
                // then set m_deviceGeneration to 1 instead of 2
                brailleDis.m_deviceGeneration = 2;
                foreach (var damagedTouches in brailleDis.m_damagedTouches)
                {
                    int pos = damagedTouches.X + damagedTouches.Y * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                    if (pos >= BrailleDisConsts.TOUCH_ARRAY_SIZE)
                    {
                        continue;
                    }
                    readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + pos] = 0;
                }
            }

            for (int i = 0; i < BrailleDisConsts.TOUCH_ARRAY_SIZE; i++)
            {
                int row    = i / BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                int column = i - row * BrailleDisConsts.NUMBER_OF_MODULE_COLUMNS;
                // for the old BrailleDis you should only treat 720 sensors
                if (brailleDis.m_deviceGeneration == 1)
                {
                    if ((row & 1) == 1) // second sensor on a module
                    {
                        i += 59;        // do not process this sensor line
                        continue;
                    }
                    row /= 2; // correct number
                }
                brailleDis.m_reference_touch_input[row, column] = readBuffer[BrailleDisConsts.FIRST_TOCH_BYTE + i];
            }
        }