Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


read digital input

  • Please log in to reply
1 reply to this topic

#1 gnasen

  • Members
  • 3 posts

Posted 30 October 2012 - 04:25 AM

Hey guys, I set up a timer and want to know at which time the timer is changing the output from high to low. Im using Linux and the u3Base class, however every try to read any output fails. Is there any example on how to read a digital output on lowlevel? I get weired errors and think I dont understand the manual about Feedbacks right. Can you show me an example on how to do it right (for example read digital output 7)?

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 30 October 2012 - 10:21 AM

We provide a Feedback example with the Exodriver that demonstrates usage:


It demonstrates multiple readings with one Feedback command/response. Here's an quick, easy example that only reads the state of FIO7:
unsigned char sendBuff[10];
	unsigned char readBuff[10];

	sendBuff[1] = (uint8)(0xF8);  //Command byte
	sendBuff[2] = 2;  //Number of data words (.5 word for echo, 1 word for IOType and 1 for padding byte)
	sendBuff[3] = (uint8)(0x00);  //Extended command number

	sendBuff[6] = 0;  //Echo

	sendBuff[7] = 10;  //IOType is BitStateRead.
	sendBuff[8] = 7;  //IONumber

	sendBuff[9] = 0;  //padding
	//calculate checksum and send 10 byte command
	//read 10 byte response (9 bytes for checksums, errorcode, etc and 1 for data), do error checking

	printf("FIO7 state is %d\n", readBuff[9]);

Feedback documentation can be found here along with the BitStateRead IOType:


Note that the padding byte is necessary when byte 2 of the command/response does not add up to a whole number. For example, if byte 2 adds up to 2 (0.5 + 1.5), then the padding byte is not necessary. If it adds to 1.5 (0.5 + 1) like in the above example, a padding byte needs to be added to the end of the command/response so the number of data words becomes 2 (0.5 + 1 + 0.5).

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users