Open DanielSSilva opened 6 years ago
Thanks for this Daniel! Did you mean Set-I2CRegister
?
Oh yes... I wrote it from my memory ๐
This is the case of really bad documentation but this is already supported!
Device
, Register
and Data
are ValueFromPipelineByPropertyName
๐
So if you have a custom object array and pass that into Set-I2CRegister it should work:
$device = Get-I2CDevice -Id 0x44 -FriendlyName Foo
$arr = @(
[pscustomobject]@{
Register = 0x12
Data = @(1,2,3)
Device = $device
},
[pscustomobject]@{
Register = 0x77
Data = @(2,3,4)
Device = $device
})
$arr | Set-I2CRegister
Note: haven't tested that code ^ but I'm pretty sure it works.
Oh I see... although it's only valid to set an array of values into a register, not a 1 to 1 relation, aka, 1 register 1 value. But this might only be useful in my case, i don't know...
You want to do 1 value to many registers?
No. I want an array of 5 registers and an array of 5 values and use register[i] value[i]. But then again, I don't have much experience to say that this would be a common situation on I2C protocol... Might only be useful in my case
Wait I just realized that you said "not a 1 to 1 relation" to my example above.
My example above IS a 1 to 1 example.
You have an array of custom objects that contain a register and a value property. When you pipe the array into Set-I2CRegister
it handles each item in the array one by one and each item in the array has a register and a value sรณ that's a 1 register to 1 value operation.
I think it would be good to have an overload that would accept an array of registers and an array of values to be set on those registers, 'freeing' the developer to have the necessity to create a loop to iterate each array and set each value