Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Component's label is not unique on copy and paste

2 posters

Go down  Message [Page 1 of 1]

n3645



Component's label should be unique in the project to identify the component?
For instance, DS18B20-X, where X is the unique number in the project?

I have notice that when copy and paste one component (particularly noticed with DS18B20), the component's label stay the same, This makes a bit of confusion in debug console if used - exact device cannot be identified, thus have to be manually changed.



Last edited by arcachofo on Tue May 10, 2022 4:18 pm; edited 1 time in total (Reason for editing : Mark as solved (green color))

arcachofo

arcachofo

Solved at Rev 1169.

n3645



New ROM ID should be generated on copy and paste as well, for DS18B20...

arcachofo

arcachofo

I see... the ROM generated in constructor is overwritten with the ROM of the copied.

But when you do a copy it's a copy.
I think that if you need a new ROM better getting a new component instead of copy paste.

n3645



I understand, however that is not practical. Should be a way to override this special case... . ROM ID is unique for each 1-wire device.

I have tried to test 63 devices on the same bus, but 60 during copy and paste retained the same ROM ID.

Well, if not possible, it is not possible...

arcachofo

arcachofo

Wait... there is a very simple way:
I didn't remember, but the component can know if the circuit is doing a paste operation and avoid the overwrite.
I think it should work and you can do it easily:
Code:
void Ds18b20::setROM( QString ROMstr )
{
    if( Circuit::self()->pasting() ) return; /// ADD THIS LINE
    
    bool ok;
    QStringList lstROM = ROMstr.split(" ");
    lstROM.removeAll("");
    for( int i=0; i<8; ++i ) m_ROM[i] = lstROM.at( i ).toInt( &ok, 16 );
    qDebug() << idLabel() <<"Ds18b20::setROM"<<arrayToHex( m_ROM, 8 );
}

Also Ds18b20 should have an static list of ROMs already in the circuit.
And Ds18b20::generateROM should  check if the new ROM generated is already in use, if not generate a new one.
Then add the new ROM to the list.

n3645



What do it now is paste one component with new ROM ID, however, the rest is clean copy of that with the same, newly created ROM ID.

I.e. If there is 6 devices, copy and paste all 6 gives only 7 unique ROM ID devices, instead all 12...

arcachofo

arcachofo

I.e. If there is 6 devices, copy and paste all 6 gives only 7 unique ROM ID devices, instead all 12...
It gives unique new ROMs for me.
The original 6 devices had the same ROM?

n3645



arcachofo wrote: The original 6 devices had the same ROM?

No, they are all unique...

But I have involved srand(time(0)) to get more unique ID, but whole paste procedure is too fast to get unique seed... Just remove it and it works fine now. Sorry.

arcachofo likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum