Sorry, my description of the problem was incorrect. The error is generated by the call to DAQmxBaseCreateDIChan, not the call to DAQmxBaseCreateTask. lsdaq reports the following:
--------------------------------
Detecting National Instruments DAQ Devices
Found the following DAQ Devices:
NI USB-6501: "Dev1" (USB0::0x3923::0x718A::01187C83::RAW)
--------------------------------
I've tried modifying the value of 'chan' from the value in the example's code ("Dev1/port0") to "Dev1/port1", "Dev1/port2", "Dev1/port0/line1", etc., but the same error, -200170, is always generated.