Tutorials |
This tutorials will give you straight-and-simple 1-2-3 style operations about the usage of SDK library.
This article don't involve too much details. If you need comprehensive understanding, please read the complete manual topic.
The port is the interface where device connects. Using GetPortNames methods of Host class to list all available ports in the local host (computer).
Below sample code lists all available ports.
private void MainForm_Load(object sender, EventArgs e) { _host = new Host(); _host.OnPortStateChanged += _host_OnPortStateChanged; foreach (string portName in _host.GetPortNames()) { Debug.WriteLine(portName); } _host.NetDeviceSearcherEnabled = true; _host.BleDeviceSearcherEnabled = true; } private void _host_OnPortStateChanged(object sender, string portName, Host.PortState portState) { Debug.WriteLine($"OnPortStateChanged: portName = {portName}, portState = {portState}"); }
Using Connect method to open the port where device connects for subsequent APIs calling.
You can get all available port name by using GetPortNames API. The port name contains the interface name (COM/USB/TCP/BLE) and relevant required parameter (port number,IP-address or MAC address).
For the USB interface, the port name will start with "USB" or "COM".
For the TCP interface, the port name will start with "TCP".
For the BLE interface, the port name will start with "BLE".
Below sample code shows using Connect method to connect to device. The second parameter baudrate is only used for COM port interface, for the other interface, the baudrate will be ignored.
_ts100.Connect("USB1");
_ts100.Connect("TCP:TS100A_4669BD:1001 [IP:192.168.100.150]");
_ts100.Connect("BLE3 (0c:d2:92:3e:1e:70-18:7a:93:4c:1c:3d)");
Adjust reader settings before inventory. For example, increase the RF output power may increase the inventory distance. Using SetAllSettings method to adjust the RF output power.
There are two places to store the settings: Register and EEPROM.
If temporary is set to true, settings are stored in Register.
Register represents reader's current settings and affects reader's behavior immediately.
Register settings are volatile.
If temporary is set to false, settings are stored in EEPROM and Register.
EEPROM settings are non-volatile and will take effect on next reboot.
EEPROM has a limited life for writing.
InventoryActiveMode is the exception that will stored in EEPROM only.
Call StartInventory to control current InventoryActiveMode instead.
Below sample code shows using SetAllSettings method to adjust the RF output stregth (19 dBm).
Settings settings = _ts100.GetAllSettings(false); settings.RfPower = 19; bool success = _ts100.SetAllSettings(false, settings); if (success) { MessageBox.Show("Set RF Power Successful."); }
Using StartInventory method to start the process of an inventory round.
Some devices (TS800) may need call SetTriggerType method to indicate the way of triggering the inventory round.
You can get the inventory tag data (EPC/TID) from the OnTagPresented (TS100, TS800) or OnTagPresentedEx (TS100) event.
If you want to get a tag's raw data when inventorying, call SetEventType(TagPresentedEvent) and choose which data (EPC, TID, User Bank, Tag removal event) should be outputted.
If you want to get a tag's decoded data when inventorying, call SetEventType(TagPresentedEventEx). Detailed output format is determined by other APIs.
Below sample code shows using StartInventory
_ts100.StartInventory();
Using StopInventory method to stop the process of inventory round.
Below sample code shows using StopInventory method.
_ts100.StopInventory();
Using ReadTag method to read the tag data.
Below sample code shows using ReadTag method to read your wanted memory bank data.
dataByteArray = _ts100.ReadTag("00000000", UHF.MemoryBank.EPC, 0, 0); if (dataByteArray != null) { // read OK } else { //read failed }
Using WriteTag method to write the data to tag memory.
Below sample code shows using WriteTag method to write binary data to the given memory bank.
result = _ts100.WriteTag("00000000", UHF.MemoryBank.EPC, 2, writeDataByteArray); if (result==true) { MessageBox.Show("Write Successful."); } else { MessageBox.Show("Write Failed."); }