Ejemplo n.º 1
0
        private void rw1990_Read_Button_Click(object sender, EventArgs e)
        {
            this.FormClosing += OneWireDumpForm_FormClosing;
            if (_programmer.IsBusy || (_programmer == null))
            {
                return;
            }
            byte[] commands = new byte[65];

            commands[1] = Constants.DS1990_READ;//READ_DS1990

            Action <ProgrammingCompleteInfo, MemoryRegion> completed =
                delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region)
            {
                if (pcInfo.error != null)
                {
                    infoPanel.SetErrorState(pcInfo.error.Message);
                }
                else
                {
                    if (region.Data[1] == 0)
                    {
                        infoPanel.SetOkState("Read serial code complete");
                        byte[] ds_sn = new byte[8];
                        for (int i = 0; i < 8; i++)
                        {
                            ds_sn[i] = region.Data[2 + i];
                        }

                        List <byte> seq = new List <byte>();
                        for (int i = 0; i < 7; i++)
                        {
                            seq.Add(ds_sn[i]);
                        }
                        byte crc = CRC.CRC8_Calc(seq);
                        //byte crc2 = CRC.CRC8_Calc2(seq);
                        if (crc == ds_sn[7])
                        {
                            infoPanel.SetOkState("Read serial code complete");
                        }
                        else
                        {
                            infoPanel.SetErrorState("OW_ERROR : CRC ERROR");
                        }

                        rw1990_HexBox.ByteProvider          = new DynamicByteProvider(ds_sn);
                        rw1990_HexBox.ByteProvider.Changed += rw1990_EditorChanged;
                    }
                    else
                    {
                        infoPanel.SetErrorState("OW_ERROR : " + region.Data[1].ToString("X2"));
                    }
                }
                this.FormClosing -= OneWireDumpForm_FormClosing;
            };


            infoPanel.SetProgressState("Reading serial code");

            _programmer.ExecuteCommandSet(commands, completed, infoPanel.GetProgressDelegate());
        }
Ejemplo n.º 2
0
        private void gen_READ_SC_Button_Click(object sender, EventArgs e)
        {
            this.FormClosing += OneWireDumpForm_FormClosing;
            if (_programmer.IsBusy || (_programmer == null))
            {
                return;
            }
            byte[] commands = new byte[65];

            commands[1] = Constants.ONEWIRE_COMMAND; //QUERY_DEVICE
            commands[2] = 1;                         //1 command set

            commands[3] = 0x33;                      //RomCommand READ ROM
            commands[4] = 0x08;                      //RomCommandDataSize
            commands[5] = 0x00;                      //FuncCommand READ SCRATCHPAD
            commands[6] = 0x00;                      //FuncCommandDataSize

            Action <ProgrammingCompleteInfo, MemoryRegion> completed =
                delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region)
            {
                if (pcInfo.error != null)
                {
                    infoPanel.SetErrorState(pcInfo.error.Message);
                }
                else
                {
                    if (region.Data[5] == 0)
                    {
                        infoPanel.SetOkState("Read serial code complete");
                        byte[] ds_sn = new byte[8];
                        for (int i = 0; i < 8; i++)
                        {
                            ds_sn[i] = region.Data[6 + i];
                        }

                        List <byte> seq = new List <byte>();
                        for (int i = 0; i < 7; i++)
                        {
                            seq.Add(ds_sn[i]);
                        }
                        byte crc = CRC.CRC8_Calc(seq);

                        if (crc == ds_sn[7])
                        {
                            infoPanel.SetOkState("Read serial code complete");
                        }
                        else
                        {
                            infoPanel.SetErrorState("OW_ERROR : CRC ERROR");
                        }

                        gen_SC_HexBox.ByteProvider = new DynamicByteProvider(ds_sn);
                    }
                    else
                    {
                        infoPanel.SetErrorState("OW_ERROR : " + region.Data[5].ToString("X2"));
                    }
                }
                this.FormClosing -= OneWireDumpForm_FormClosing;
            };


            infoPanel.SetProgressState("Reading serial code");

            _programmer.ExecuteCommandSet(commands, completed, infoPanel.GetProgressDelegate());
        }