I am trying to use dbf module for read and write of the DBF database file.
I got the needed functions prepared and tested in VSCode, but when testing them in Ignition Script console, I can read but cannot write value to the db.
The following script has been tested in VSCode.
When testing it in Ignition, the table can be created but no values are added to the table.
before running the script.
- copy dbf and aenum module to ignition module folder.
C:\Program Files\Inductive Automation\Ignition\user-lib\pylib
## code to work with dbf module aenum-2.1.2 dbf-0.97.11
import dbf
table = dbf.Table('C:\\Users\\xxxx\\Documents\\DBF\\newRecipe.DBF', 'name C(30); age N(3,0); birth D')
print('db definition created with field names:', table.field_names)
table.open(mode=dbf.READ_WRITE)
for datum in (('John Doe', 31, dbf.Date(1979, 9,13)),
('Ethan Furman', 102, dbf.Date(1909, 4, 1)),
('Jane Smith', 57, dbf.Date(1954, 7, 2)),
('John Adams', 44, dbf.Date(1967, 1, 9)),):
table.append(datum)
print ('records added:')
for record in table:
print (record)
print ('-----')
table.close()
table.open(mode=dbf.READ_WRITE)
table.add_fields('telephone C(10)')
telephones = {'John Doe': '1234',
'Ethan Furman': '2345',
'Jane Smith': '3456',
'John Adams': '4567'}
for record in table:
with record as r:
r.telephone = telephones[r.name.strip()]
print ('updated records')
for record in table:
print (record)
print ('-----')
Maybe issue is at the following new data list, but I cannot figure out why it behaves different in ignition.
for datum in (('John Doe', 31, dbf.Date(1979, 9,13)),
('Ethan Furman', 102, dbf.Date(1909, 4, 1)),
('Jane Smith', 57, dbf.Date(1954, 7, 2)),
('John Adams', 44, dbf.Date(1967, 1, 9)),):
Appreciate if anyone can help with troubleshooting.