Herunterladen Diese Seite drucken

Optelec ClearNote HD Bedienungsanleitung Seite 179

Vorschau ausblenden Andere Handbücher für ClearNote HD:

Werbung

for i, v in ipairs(Value) do
printf("%02X ", v)
if i % 16 == 0 then
printf("\n")
end
end
end
--Write EEPROM
CountBytes = #aSendData
for Address = 0, CountBytes * 10, CountBytes do
nRC = LS_I2CWriteEEProm(nHandle, 1, Address, aSendData, CountBytes, 16)
end
LS_I2CWriteDigital(nHandle, 0)
LS_I2CCloseDevice(nHandle)
end
Beispiel 16.3. I2C-Lua Scriptbeispiel EEPROM-Funktionen
2. Beispiel
• 2 Bytes an einen I2C-Partner zum schreiben senden
• 1024 Bytes aus einem I2C-Partner lesen
--**************************************************
local function printf(...)
io.write(string.format(...))
io.flush()
end
--**************************************************
function main()
local aSendData = {}
for i = 1, 128, 1 do
table.insert(aSendData, i-1)
end
local nRC, nHandle = LS_I2COpenDevice(1000000, "10.1.2.162", 5000)
if nRC ~= 0 then
print(LS_I2CErrorMessage(nRC))
os.exit()
end
--Write
local aData = {0x00, 0x05} -- ab Adresse 5 lesen
local Value
nRC, Value = LS_I2CWrite(nHandle, 0xa2, aData, #aData)
--Read
nRC, Value = LS_I2CRead(nHandle, 0xa2, 1024)
for i, v in ipairs(Value) do
printf("%02X ", v)
if i % 16 == 0 then
printf("\n")
end
end
printf("\n")
Lua-Programmier-Beispiele
170
© 2007-2015 Analytica GmbH

Werbung

loading