techElder
Well-known member
I was a little surprised not to find any hits by using Google here to find "serial number".
Anyway, my need was to create a way to get a sensor transceiver to create its own serial number that is relatively unique. In other words it would be easier to reprogram one or two units with duplicate numbers rather than create unique serial numbers for every unit as it is programmed (not to mention keeping track as I do that.)
There will certainly be less than 100 sensors, and there are no real security issues involved.
So, I came up with the following code, but since I am moving, I don't have a way to put it on hardware at the moment. Was wondering what you thought about it.
PS. I do understand all the ramifications around generating RANDOM numbers etc. ad nauseum.
Anyway, my need was to create a way to get a sensor transceiver to create its own serial number that is relatively unique. In other words it would be easier to reprogram one or two units with duplicate numbers rather than create unique serial numbers for every unit as it is programmed (not to mention keeping track as I do that.)
There will certainly be less than 100 sensors, and there are no real security issues involved.
So, I came up with the following code, but since I am moving, I don't have a way to put it on hardware at the moment. Was wondering what you thought about it.
PS. I do understand all the ramifications around generating RANDOM numbers etc. ad nauseum.
Code:
[color=Blue]symbol [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Purple]w13[/color]
[color=Blue]data [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Navy]0[/color][color=Black], [/color][color=Navy]0[/color][color=Blue]) [/color][color=Green]' preload zero[/color]
[color=Blue]read [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]if [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then [/color][color=Green]' create a serial number
[/color][color=Blue]readinternaltemp IT_RAW_L[/color][color=Black], [/color][color=Navy]0[/color][color=Black], [/color][color=Purple]w0
[/color][color=Blue]random [/color][color=Purple]w0
[/color][color=Green]'pause w0 ' random delay
[/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Purple]w0
[/color][color=Blue]random [/color][color=Black]serialNumber
[/color][color=Blue]write [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]endif[/color]