Esempio n. 1
0
        private void SPI_Write()
        {
            int counts = (int)this.numericUpDownBytes.Value;

            ushort[] writeData = new ushort[counts];
            if (writeData.Length == 0)
            {
                return;
            }

            try
            {
                for (int i = 0; i < writeData.Length; i++)
                {
                    object ob = this.dataGridView4.Rows[i / 16].Cells[i % 16].Value;
                    if (ob == null)
                    {
                        return;
                    }
                    writeData[i] = ushort.Parse((string)ob, System.Globalization.NumberStyles.HexNumber);
                }
            }
            catch
            {
                MessageBox.Show("Unfomart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int regAdress = 0;

            try
            {
                byte[] buf_regAdress = Algorithm.HexStringToBytes(this.txtRegAdress.Text);

                for (int i = 0; i < buf_regAdress.Length; i++)
                {
                    regAdress += buf_regAdress[i] << 8 * i;
                }
            }
            catch
            {
                MessageBox.Show("Unfomart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (macom_006409 == null)
            {
                macom_006409 = new MACOM_006409();
            }

            for (ushort i = 0; i < counts; i++)
            {
                if (macom_006409.WriteReg((ushort)(regAdress + i), writeData[i]) == false)
                {
                    MessageBox.Show("macom_006409 write ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            return;
        }
Esempio n. 2
0
        private void SPI_Read()
        {
            //clear cells
            for (int i = 0; i < maxCells; i++)
            {
                this.dataGridView4.Rows[i / 16].Cells[i % 16].Value = null;
            }
            this.dataGridView4.Refresh();
            int counts = (int)this.numericUpDownBytes.Value;

            short[] buff = new short[counts];

            if ((int)this.numericUpDownBytes.Value > 0)
            {
                int regAdress = 0;
                try
                {
                    byte[] buf_regAdress = Algorithm.HexStringToBytes(this.txtRegAdress.Text);

                    for (int i = 0; i < buf_regAdress.Length; i++)
                    {
                        regAdress += buf_regAdress[i] << 8 * i;
                    }
                }
                catch
                {
                    MessageBox.Show("Unfomart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (macom_006409 == null)
                {
                    macom_006409 = new MACOM_006409();
                }

                for (ushort i = 0; i < counts; i++)
                {
                    buff[i] = macom_006409.ReadReg((ushort)(regAdress + i));
                    if (buff[i] == -1)
                    {
                        MessageBox.Show("macom_006409 write ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }

            int length = Math.Min(maxCells, buff.Length);

            for (int i = 0; i < length; i++)
            {
                this.dataGridView4.Rows[i / 16].Cells[i % 16].Value = Convert.ToString(buff[i], 16).ToUpper();
            }
        }
Esempio n. 3
0
 private void btnVendorRead_Click(object sender, EventArgs e)
 {
     try
     {
         this.txtVendorID.Text = "";
         this.txtVendorID.Refresh();
         Thread.Sleep(100);
         if (macom_006409 == null)
         {
             macom_006409 = new MACOM_006409();
         }
         ushort vendorid = macom_006409.GetVendorID();
         this.txtVendorID.Text = "0x" + Convert.ToString(vendorid, 16).ToUpper();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "No link.", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 4
0
        private void btnLoad_Batch_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtBatch_FilePath.Text == "")
                {
                    return;
                }

                this.btnLoad_Batch.Enabled   = false;
                this.btnLoad_Batch.BackColor = Color.Yellow;
                this.btnLoad_Batch.Refresh();

                DirectoryInfo directoryInfo = Directory.GetParent(this.txtBatch_FilePath.Text);
                if (!directoryInfo.Exists)
                {
                    MessageBox.Show("File is no exist", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.btnLoad_Batch.Enabled   = true;
                    this.btnLoad_Batch.BackColor = SystemColors.Control;
                    return;
                }

                DataTable setting_table = this.GetExcelTable(this.txtBatch_FilePath.Text);

                for (int row = 0; row < setting_table.Rows.Count; row++)
                {
                    int regAddress = 0;
                    int writeData  = 0;
                    try
                    {
                        byte[] buf_regAdress = Algorithm.HexStringToBytes(setting_table.Rows[row][1].ToString());
                        for (int i = 0; i < buf_regAdress.Length; i++)
                        {
                            regAddress += buf_regAdress[i] << 8 * i;
                        }

                        byte[] buf_writeData = Algorithm.HexStringToBytes(setting_table.Rows[row][2].ToString());
                        for (int i = 0; i < buf_writeData.Length; i++)
                        {
                            writeData += buf_writeData[i] << 8 * i;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Unfomart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.btnLoad_Batch.Enabled   = true;
                        this.btnLoad_Batch.BackColor = SystemColors.Control;
                        return;
                    }

                    if (macom_006409 == null)
                    {
                        macom_006409 = new MACOM_006409();
                    }

                    if (macom_006409.WriteReg((ushort)regAddress, (ushort)writeData) == false)
                    {
                        MessageBox.Show("No link. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.btnLoad_Batch.Enabled   = true;
                        this.btnLoad_Batch.BackColor = SystemColors.Control;
                        return;
                    }
                }

                this.btnLoad_Batch.Enabled   = true;
                this.btnLoad_Batch.BackColor = SystemColors.Control;
                MessageBox.Show("Done", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "No link.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }