示例#1
0
        private void ReadButton_Click(object sender, EventArgs e)
        {
            IntPtr BufferToRead = Marshal.AllocHGlobal(UserDataSize);

            if (BufferToRead == IntPtr.Zero)
            {
                MessageBox.Show("Error in Buffer allocation", "ReadButton_Click");
                return;
            }

            Byte[] DataToBeWrittenArray = new Byte[UserDataSize];

            int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_ReadUserData(
                (uint)0, (uint)DataToBeWrittenArray.Length, DataToBeWrittenArray
                );

            if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
            {
                GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(
                    RetVal, "PermanentDataStorageForm,GBMSAPI_NET_ReadUserData");
            }

            SaveFileDialog SFDlg = new SaveFileDialog();

            SFDlg.Title = "Open file for saving data";
            if (SFDlg.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Error in Opening File");
                return;
            }
            String fname = SFDlg.FileName;

            File.WriteAllBytes(fname, DataToBeWrittenArray);
        }
示例#2
0
        private void CalibrateDeviceButton_Click(object sender, EventArgs e)
        {
            ////////////////////////////
            // OPEN IMAGE FILE
            ////////////////////////////
            OpenFileDialog OFDlg = new OpenFileDialog();

            OFDlg.Title = "Open Calibration Image";
            if (OFDlg.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Error in Opening File");
                return;
            }
            String fname = OFDlg.FileName;

            Byte [] CalImageBytes = System.IO.File.ReadAllBytes(fname);

            if (CalImageBytes.Length != (CalibrationImageSX) * (CalibrationImageSY))
            {
                MessageBox.Show("Error: file size not correct");
                return;
            }

            ///////////////////////////////
            // CALIBRATE DEVICE
            ///////////////////////////////
            // ver 2.10.0.0: use "2" functions
            //int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_SetCalibrationImage(
            //    this.FlatScanArea, CalImageBytes);
            int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_SetCalibrationImage2(
                this.ScanArea, CalImageBytes);

            // end ver 2.10.0.0: use "2" functions
            if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
            {
                GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(
                    RetVal, "CalibrateDeviceButton_Click,GBMSAPI_NET_SetCalibrationImage2");
            }
            else
            {
                MessageBox.Show("Device Calibrated", "Calibration results");
            }

            return;
        }
示例#3
0
        private void WriteButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog OFDlg = new OpenFileDialog();

            OFDlg.Title = "Open file containing data";
            if (OFDlg.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Error in Opening File");
                return;
            }
            String fname = OFDlg.FileName;

            Byte[] DataToBeWrittenArray = File.ReadAllBytes(fname);

            if (DataToBeWrittenArray.Length > (UserDataSize - 1))             // I need at least a byte at the end of the buffer for CRC calculation
            {
                MessageBox.Show("Warning: Data To be written too much long; they will be truncated to the " + UserDataSize + "-th byte");
            }

            int BytesToBeWritten;

            if (DataToBeWrittenArray.Length > (UserDataSize - 1))
            {
                BytesToBeWritten = (UserDataSize - 1);
            }
            else
            {
                BytesToBeWritten = DataToBeWrittenArray.Length;
            }

            int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_WriteUserData(
                (uint)0, (uint)BytesToBeWritten, DataToBeWrittenArray
                );

            if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
            {
                GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(
                    RetVal, "PermanentDataStorageForm,GBMSAPI_WriteUserData");
            }
            else
            {
                MessageBox.Show("Written " + BytesToBeWritten + "bytes");
            }
        }
示例#4
0
        private void SetFactoryCalibrationButton_Click(object sender, EventArgs e)
        {
            ///////////////////////////////
            // CALIBRATE DEVICE
            ///////////////////////////////
            // ver 2.10.0.0: use "2" functions
            //int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_SetCalibrationImage(this.FlatScanArea, null);
            int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_SetCalibrationImage2(
                GBMSAPI_NET_ScanAreas.GBMSAPI_NET_SA_FULL_FRAME, null);

            // end ver 2.10.0.0: use "2" functions
            if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
            {
                GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(
                    RetVal, "SetFactoryCalibrationButton_Click,GBMSAPI_GetImageSize");
                return;
            }

            MessageBox.Show("Device Calibrated", "Calibration results");
        }
示例#5
0
        public PermanentDataStorageForm()
        {
            InitializeComponent();

            int RetVal, Appoggio;

            RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_GetUserDataSize(out Appoggio);

            if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
            {
                GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(RetVal, "GBMSAPI_NET_GetUserDataSize");

                this.Close();
            }
            else
            {
                UserDataSize = Appoggio;
                this.StorageSizeLabel.Text = "Available bytes = " + UserDataSize;
            }
        }
示例#6
0
        // end ver 2.10.0.0: use "2" functions
        private void GetNewCalibrationImageButton_Click(object sender, EventArgs e)
        {
            try
            {
                uint    CalibrationDiagnostic;
                Byte [] CalImageArray;

                // ver 2.10.0.0: use "2" functions
                //int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_GetCalibrationImage(
                //    FlatScanArea,out CalImageArray,out CalibrationDiagnostic);
                int RetVal = GBMSAPI_NET_AuxiliaryRoutines.GBMSAPI_NET_GetCalibrationImage2(
                    this.ScanArea, out CalImageArray, out CalibrationDiagnostic);
                // end ver 2.10.0.0: use "2" functions

                if (RetVal != GBMSAPI_NET_ErrorCodes.GBMSAPI_NET_ERROR_CODE_NO_ERROR)
                {
                    GBMSAPI_Example_Util.GBMSAPI_Example_ManageErrors(
                        RetVal, "GetNewCalibrationImageButton_Click,GBMSAPI_GetImageSize");
                    return;
                }

                Marshal.Copy(CalImageArray, 0, this.CalibrationImage, CalImageArray.Length);

                // show diagnostic
                this.Diagnostic = CalibrationDiagnostic;
                this.DiagnosticListBox.Items.Clear();
                if (CalibrationDiagnostic != 0)
                {
                    List <String> DiagList = GBMSAPI_Example_Util.GetDiagStringsFromDiagMask(CalibrationDiagnostic);
                    if ((DiagList != null) && (DiagList.Count > 0))
                    {
                        for (int i = 0; i < DiagList.Count; i++)
                        {
                            this.DiagnosticListBox.Items.Add(DiagList[i]);
                        }
                    }
                }

                // be aware of stride
                int    stride;
                IntPtr BmpBuffer;
                if ((CalibrationImageSX % 4) != 0)
                {
                    stride = CalibrationImageSX - (CalibrationImageSX % 4);

                    Byte [] Dest; Byte [] Src;
                    Dest = new Byte[stride * CalibrationImageSY];
                    Src  = new Byte[CalibrationImageSX * CalibrationImageSY];

                    if (Dest == null || Src == null)
                    {
                        MessageBox.Show("Error in memory allocation in GetNewCalibrationImageButton_Click");
                    }

                    Marshal.Copy(GBMSAPI_Example_Globals.CalibrationBuffer, Src, 0, Src.Length);
                    Marshal.Copy(GBMSAPI_Example_Globals.DummyCalibrationBuffer, Dest, 0, Dest.Length);

                    int DestOffset = 0, SrcOffset = 0;
                    for (int i = 0; i < CalibrationImageSY;
                         i++, DestOffset += stride, SrcOffset += CalibrationImageSX)
                    {
                        Buffer.BlockCopy(Src, SrcOffset, Dest, DestOffset, stride);
                    }

                    Marshal.Copy(Dest, 0, GBMSAPI_Example_Globals.DummyCalibrationBuffer, Dest.Length);

                    BmpBuffer = GBMSAPI_Example_Globals.DummyCalibrationBuffer;
                }
                else
                {
                    stride    = CalibrationImageSX;
                    BmpBuffer = GBMSAPI_Example_Globals.CalibrationBuffer;
                }

                // draw image
                this.CalibrationImagePictureBox.Image = new Bitmap(
                    CalibrationImageSX, CalibrationImageSY,
                    stride,
                    System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
                    BmpBuffer
                    );

                System.Drawing.Imaging.ColorPalette pal = this.CalibrationImagePictureBox.Image.Palette;
                for (int i = 0; i < pal.Entries.Length; i++)
                {
                    pal.Entries[i] = Color.FromArgb(255, i, i, i);
                }
                this.CalibrationImagePictureBox.Image.Palette = pal;
                this.CalibrationImagePictureBox.SizeMode      = PictureBoxSizeMode.StretchImage;

                this.SaveButton.Enabled = true;

                this.Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception in GetNewCalibrationImageButton_Click: " + ex.Message);
            }
        }