Как узнать, что нажат спусковой крючок RFID-пистолета на RFD40 + TC21Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как узнать, что нажат спусковой крючок RFID-пистолета на RFD40 + TC21

Сообщение Anonymous »

Как я могу узнать, когда спусковой крючок пистолета нажат программно, с помощью Zebra DataWedge 11.3.28, используя транслятор намерений на RFD40 + TC21?
Я использую один из примеров от Zebra

Код: Выделить всё

object DataWedgeUtility {
private const val PROFILE_NAME = "DW_my_app"
private const val ACTION_DATAWEDGE = "com.symbol.datawedge.api.ACTION"
private const val EXTRA_CREATE_PROFILE = "com.symbol.datawedge.api.CREATE_PROFILE"
private const val EXTRA_SET_CONFIG = "com.symbol.datawedge.api.SET_CONFIG"

fun createDWProfile(context: Context) {
sendDataWedgeIntentWithExtra(
context,
ACTION_DATAWEDGE,
EXTRA_CREATE_PROFILE,
PROFILE_NAME
)

val profileConfig = Bundle()
profileConfig.putString("PROFILE_NAME", PROFILE_NAME)
profileConfig.putString("PROFILE_ENABLED", "true") //  Seems these are all strings
profileConfig.putString("CONFIG_MODE", "UPDATE")
val rfidConfig = Bundle()
rfidConfig.putString("PLUGIN_NAME", "RFID")
rfidConfig.putString("RESET_CONFIG", "true")

val rfidProps = Bundle()
/* values true o false as string */
rfidProps.putString("rfid_input_enabled", "true")
/* values true o false as string */
rfidProps.putString("rfid_beeper_enable", "true")
/* Integer from 5 to 30 */
rfidProps.putString("rfid_antenna_transmit_power", "25")

rfidProps.putString("rfid_memory_bank", "0")

rfidProps.putString("rfid_session", "1")
rfidProps.putString("rfid_filter_duplicate_tags", "true")
rfidProps.putString("rfid_hardware_trigger_enabled", "true")

rfidProps.putString("rfid_trigger_mode", "1")
rfidProps.putString("rfid_tag_read_duration", "100")

rfidConfig.putBundle("PARAM_LIST", rfidProps)
profileConfig.putBundle("PLUGIN_CONFIG", rfidConfig)
val appConfig = Bundle()
appConfig.putString(
"PACKAGE_NAME",
context.packageName
) //  Associate the profile with this app
appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*"))
profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig))
sendDataWedgeIntentWithExtra(context, ACTION_DATAWEDGE, EXTRA_SET_CONFIG, profileConfig)

//  You can only configure one plugin at a time, we have done the RFID input, now do the intent output
profileConfig.remove("PLUGIN_CONFIG")
val intentConfig = Bundle()
intentConfig.putString("PLUGIN_NAME", "INTENT")
intentConfig.putString("RESET_CONFIG", "true")
val intentProps = Bundle()
intentProps.putString("intent_output_enabled", "true")
intentProps.putString(
"intent_action",
context.resources.getString(R.string.activity_intent_filter_action)
)

intentProps.putString("intent_delivery", "0")
intentConfig.putBundle("PARAM_LIST", intentProps)
profileConfig.putBundle("PLUGIN_CONFIG", intentConfig)
sendDataWedgeIntentWithExtra(context, ACTION_DATAWEDGE, EXTRA_SET_CONFIG, profileConfig)

//  Disable keyboard output
profileConfig.remove("PLUGIN_CONFIG")
val keystrokeConfig = Bundle()
keystrokeConfig.putString("PLUGIN_NAME", "KEYSTROKE")
keystrokeConfig.putString("RESET_CONFIG", "true")
val keystrokeProps = Bundle()
keystrokeProps.putString("keystroke_output_enabled", "false")
keystrokeConfig.putBundle("PARAM_LIST", keystrokeProps)
profileConfig.putBundle("PLUGIN_CONFIG", keystrokeConfig)
sendDataWedgeIntentWithExtra(context, ACTION_DATAWEDGE, EXTRA_SET_CONFIG, profileConfig)
}

private fun sendDataWedgeIntentWithExtra(
context: Context,
action: String,
extraKey: String,
extraValue:  String
) {
val dwIntent = Intent()
dwIntent.action = action
dwIntent.putExtra(extraKey, extraValue)
context.sendBroadcast(dwIntent)
}

private fun sendDataWedgeIntentWithExtra(
context: Context,
action: String,
extraKey: String,
extras: Bundle
) {
val dwIntent = Intent()
dwIntent.action = action
dwIntent.putExtra(extraKey, extras)
context.sendBroadcast(dwIntent)
}
}
А в действии у меня есть следующий код

Код: Выделить всё

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DataWedgeUtility.createDWProfile(this)
...
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val action = intent.action

if (action == resources.getString(R.string.activity_intent_filter_action)) {
//  Received a RFID scan
try {
val epc = intent.getStringExtra(
resources.getString(R.string.datawedge_intent_key_data)
)
if (epc?.isNotBlank() == true){
val tagList = epc.split("\n")
tagList.forEach {
EventBus.getDefault().post(TagReadEvent(epc = it))
}
}
} catch (e: Exception) {
//  Catch if the UI does not exist when we receive the broadcast
}
}
}

fun softRfidTrigger(): Boolean{
val dwIntent = Intent()
dwIntent.action = "com.symbol.datawedge.api.ACTION"
//  Button released, end scan
when  {
!readingFlag -> {
readingFlag = true
dwIntent.putExtra(
"com.symbol.datawedge.api.SOFT_RFID_TRIGGER",
"START_SCANNING"
)
}
else -> {
readingFlag = false
dwIntent.putExtra(
"com.symbol.datawedge.api.SOFT_RFID_TRIGGER",
"STOP_SCANNING"
)
}
}
sendBroadcast(dwIntent)
return readingFlag
}
..
}
Я использую в приложении подход с одним действием, и весь обмен данными между действием и фрагментами осуществляется с помощью событий EventBus.

Подробнее здесь: https://stackoverflow.com/questions/773 ... rfd40-tc21
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»