PDA

View Full Version : working w/byte array and MAC


korda
06-28-2008, 03:38 PM
Kevin,
In our script for remote (not portal) we would like to process node's MAC and retrieve least significant byte from the mac and make it int type.
We understood that localAddr() and loadNvParam(2) return the same result.
MAC = localAddr()
LSB = MAC[2] //unfortunately is not working.
Any other ideas?

kbanks
06-30-2008, 09:27 AM
In the earliest (BETA) versions of SNAPpy, you could get the numeric value of a single character from within a string by doing something like:


# This is an example that no longer works!
a = "ABC"
b = a[0] # b is now an integer with the value 0x41


This was non-standard (this was not what "desktop" Python would do), and we later upgraded SNAPpy to match Python. Still, depending on how long you have been using SNAPpy, you may remember this different(non-standard) technique.

Now you should use the ord() function, doing something like:


a = "ABC"
c = a[0] # this gives you a STRING of "A", not a number
b = ord( a[0] ) # b is now an integer with the value 0x41


An example of this technique (substituting a string for a byte array) was shown in the post "Lookup table for thermistor temperature conversion" (do a search).

I'm attaching a script that demonstrates reading/accessing the full MAC address.

Keep in mind that you must "intercept STDOUT" to see those print statements within Portal.