英文:
I am trying to read data from RFID. But the class RFIDEventListener is not getting called. Can someone help me out here?
问题
以下是我用于从RFID获取数据的代码。但是它无法正常工作。运行这段代码后,我得到了一些输出,但并不是我想要的全部内容。
RFIDEventListener 应该捕获事件并获取数据。有人可以告诉我在这段代码中做错了什么吗?
import com.mot.rfid.api3.*;
public class TestConnect {
RFIDReader reader = null;
TestConnect testconnection = null;
public TestConnect() throws InvalidUsageException, OperationFailureException {
String hostname = "192.168.1.110";
reader = new RFIDReader(hostname, 0, 0);
reader.connect();
}
public static void main(String args[]) throws InvalidUsageException, OperationFailureException, InterruptedException {
TestConnect tc = new TestConnect();
tc.getdata();
}
public void getdata() throws InvalidUsageException, OperationFailureException, InterruptedException {
// ... (代码的其余部分,请参考原始内容)
}
public class EventsHandler implements RfidEventsListener {
// ... (代码的其余部分,请参考原始内容)
}
}
请注意,由于您要求只返回翻译好的代码部分,我在这里只提供了代码的框架,以及您在原始内容中提供的部分代码。如果您需要更详细的解释或其他信息,请随时提问。
英文:
The below code is what i am using to fetch data from RFID. But it's not working. By running this code, i am getting some output, but not everything i want.
RFIDEventListener is supposed to capture events and get data. Can someone tell me what i did wrong in this code?
import com.mot.rfid.api3.*;
public class TestConnect {
RFIDReader reader = null;
TestConnect testconnection = null;
public TestConnect() throws InvalidUsageException, OperationFailureException {
String hostname = "192.168.1.110";
reader = new RFIDReader(hostname, 0, 0);
reader.connect();
}
public static void main(String args[]) throws InvalidUsageException, OperationFailureException, InterruptedException {
TestConnect tc = new TestConnect();
tc.getdata();
}
public void getdata() throws InvalidUsageException, OperationFailureException, InterruptedException {
//Get power State
System.out.println("Get power State: " + reader.Config.getRadioPowerState());
reader.Config.setRadioPowerState(RADIO_POWER_STATE.ON);
System.out.println("Get power State: " + reader.Config.getRadioPowerState());
// Get Reader capabilities
System.out.println("Reader ID: " + reader.ReaderCapabilities.ReaderID.getID());
System.out.println("ModelName: " + reader.ReaderCapabilities.getModelName());
System.out.println("Communication Standard: " + reader.ReaderCapabilities.getCommunicationStandard().toString());
System.out.println("Country Code: " + reader.ReaderCapabilities.getCountryCode());
System.out.println("FirwareVersion: " + reader.ReaderCapabilities.getFirwareVersion());
System.out.println("RSSI Filter: " + reader.ReaderCapabilities.isRSSIFilterSupported());
System.out.println("Tag Event Reporting: " + reader.ReaderCapabilities.isTagEventReportingSupported());
System.out.println("Tag Locating Reporting: " + reader.ReaderCapabilities.isTagLocationingSupported());
System.out.println("NXP Command Support: " + reader.ReaderCapabilities.isNXPCommandSupported());
System.out.println("BlockEraseSupport: " + reader.ReaderCapabilities.isBlockEraseSupported());
System.out.println("BlockWriteSupport: " + reader.ReaderCapabilities.isBlockWriteSupported());
System.out.println("BlockPermalockSupport: " + reader.ReaderCapabilities.isBlockPermalockSupported());
System.out.println("RecommisionSupport: " + reader.ReaderCapabilities.isRecommisionSupported());
System.out.println("WriteWMISupport: " + reader.ReaderCapabilities.isWriteUMISupported());
System.out.println("RadioPowerControlSupport: " + reader.ReaderCapabilities.isRadioPowerControlSupported());
System.out.println("HoppingEnabled: " + reader.ReaderCapabilities.isHoppingEnabled());
System.out.println("StateAwareSingulationCapable: " + reader.ReaderCapabilities.isTagInventoryStateAwareSingulationSupported());
System.out.println("UTCClockCapable: " + reader.ReaderCapabilities.isUTCClockSupported());
System.out.println("NumOperationsInAccessSequence: " + reader.ReaderCapabilities.getMaxNumOperationsInAccessSequence());
System.out.println("NumPreFilters: " + reader.ReaderCapabilities.getMaxNumPreFilters());
System.out.println("NumAntennaSupported: " + reader.ReaderCapabilities.getNumAntennaSupported());
System.out.println("NumGPIPorts: " + reader.ReaderCapabilities.getNumGPIPorts());
System.out.println("NumGPOPorts: " + reader.ReaderCapabilities.getNumGPOPorts());
//GPI read config
System.out.println("IS GPI port 1 Enabled? " + reader.Config.GPI.isPortEnabled(1));
System.out.println("IS GPI port 2 Enabled? " + reader.Config.GPI.isPortEnabled(2));
System.out.println("GPI Port 1 State: " + reader.Config.GPI.getPortState(1));
System.out.println("GPI Port 2 State: " + reader.Config.GPI.getPortState(2));
//GPI read config
System.out.println("IS GPI port 1 Enabled? " + reader.Config.GPI.isPortEnabled(1));
System.out.println("IS GPI port 2 Enabled? " + reader.Config.GPI.isPortEnabled(2));
System.out.println("GPI Port 1 State: " + reader.Config.GPI.getPortState(1));
System.out.println("GPI Port 2 State: " + reader.Config.GPI.getPortState(2));
//GPO read config
System.out.println("GPO Port 1 State: " + reader.Config.GPO.getPortState(1));
System.out.println("GPO Port 2 State: " + reader.Config.GPO.getPortState(2));
System.out.println("GPO Port 3 State: " + reader.Config.GPO.getPortState(3));
// Gets the Duty cycle index
short dutyCycleIndex = (short)(reader.ReaderCapabilities.getDutyCycleValues().length - 1);
System.out.println("Duty Cycle Index: "+ dutyCycleIndex);
EventsHandler eventHandler = new EventsHandler();
reader.Events.addEventsListener(eventHandler);
// Subscribe required status notification
reader.Events.setInventoryStartEvent(true);
reader.Events.setInventoryStopEvent(true);
reader.Events.setAccessStartEvent(true);
reader.Events.setAccessStopEvent(true);
// enables tag read notification. if this is set to false, no tag read notification will be send
reader.Events.setTagReadEvent(true);
reader.Events.setAntennaEvent(true);
reader.Events.setBufferFullEvent(true);
reader.Events.setBufferFullWarningEvent(true);
reader.Events.setGPIEvent(true);
reader.Events.setReaderDisconnectEvent(true);
TagStorageSettings tagStorageSettings = reader.Config.getTagStorageSettings();
tagStorageSettings.enableAccessReports(true);
reader.Config.setTagStorageSettings(tagStorageSettings);
reader.Actions.Inventory.perform();
Thread.sleep(1000);
reader.Actions.Inventory.stop();
reader.disconnect();
}
public class EventsHandler implements RfidEventsListener {
// Read Event Notification
public void eventReadNotify(RfidReadEvents e){
System.out.println("Read Event Signalled");
// Recommended to use new method getReadTagsEx for better performance in case of large tag population
TagData[] myTags = reader.Actions.getReadTags(1000000);
if (myTags != null)
{
for (int index = 0; index < myTags.length; index++)
{
System.out.println("Tag ID " + myTags[index].getTagID());
System.out.println("Antenna ID " + myTags[index].getAntennaID());
System.out.println("CRC " + myTags[index].getCRC());
System.out.println("Memory Bank " + myTags[index].getMemoryBank());
System.out.println("OpCode " + myTags[index].getOpCode());
System.out.println("Get OpStatus " + myTags[index].getOpStatus());
System.out.println("PeakRSSI " + myTags[index].getPeakRSSI());
System.out.println("Phase " + myTags[index].getPhase());
System.out.println("TagEvent " + myTags[index]. getTagEvent());
System.out.println("Tag Seen Count " + myTags[index].getTagSeenCount());
System.out.println("Tag Event TimeStamp " + myTags[index].getTagEventTimeStamp());
System.out.println("getXPC_W1 " + myTags[index].getXPC_W1());
System.out.println("getXPC_W2 " + myTags[index].getXPC_W2());
System.out.println();
System.out.println();
if (myTags[index].getOpCode() == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ &&
myTags[index].getOpStatus() == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS)
{
if (myTags[index].getMemoryBankData().length() > 0) {
System.out.println(" Mem Bank Data " + myTags[index].getMemoryBankData());
}
}
}
}
}
// Status Event Notification
public void eventStatusNotify(RfidStatusEvents e) {
System.out.println("Status Notification: " + e.StatusEventData.getStatusEventType());
}
}
}
答案1
得分: 0
Change EventsHandler to EventHandler.
EventHandler 被 RFIDApi3 使用。
英文:
Change EventsHandler to EventHandler.
EventHandler Is used by RFIDApi3
答案2
得分: 0
你需要添加:
reader.Events.setAttachTagDataWithReadEvent(false);
在调用 reader.Actions.Inventory.perform()
之前,以获取标签数据:
TagData[] myTags = reader.Actions.getReadTags(1000000);
你可能还希望将一次读取的最大标签数量设置为较低的值。通常情况下,设置为 100 就足够了。
英文:
You'll need to add:
reader.Events.setAttachTagDataWithReadEvent(false);
Before calling reader.Actions.Inventory.perform()
to get the tag data:
TagData[] myTags = reader.Actions.getReadTags(1000000);
You probably also want to set the maximum amount of tags read at once to something lower. Like a 100 is usually fine.
专注分享java语言的经验与见解,让所有开发者获益!
评论