From 12cf1472f159b5aaf26d871d88f684f1f46cf856 Mon Sep 17 00:00:00 2001 From: cbdev Date: Thu, 24 Aug 2023 20:13:51 +0200 Subject: Implement single-tag select --- twn3_test.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'twn3_test.c') diff --git a/twn3_test.c b/twn3_test.c index ca10574..734201e 100644 --- a/twn3_test.c +++ b/twn3_test.c @@ -12,8 +12,8 @@ int main(int argc, char** argv){ char data[1024]; unsigned u; - int device = twn3_open("/dev/ttyACM0"); - + int device = twn3_open("/dev/ttyACM3"); + printf("Device is at fd %d\n", device); if(device < 0){ printf("%s\n", strerror(errno)); @@ -33,7 +33,7 @@ int main(int argc, char** argv){ } //write some userdata - twn3_sync_write_eeprom(device, 0, 19, 0xAA); + //twn3_sync_write_eeprom(device, 0, 19, 0xAA); //set ExtendID bit //twn3_sync_write_eeprom(device, 0, 5, 0x05); @@ -42,8 +42,23 @@ int main(int argc, char** argv){ //twn3_sync_restart(device, 0); //store a key - uint8_t key[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - twn3_sync_storekey(device, 0, 12, key); + //uint8_t key[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + //twn3_sync_storekey(device, 0, 12, key); + + //wait for a single tag + int status; + uint8_t type = tag_none; + uint8_t serial[20]; + size_t serial_length = sizeof(serial); + for(status = twn3_sync_select_first(device, 0, &type, serial, &serial_length); + status == 0; + status = twn3_sync_select_first(device, 0, &type, serial, &serial_length)){ + if(type != tag_none){ + printf("Tag with UID length %lu found, type %02X\n", serial_length, type); + break; + } + serial_length = sizeof(serial); + } close(device); return EXIT_SUCCESS; -- cgit v1.2.3