0
\$\begingroup\$

I am trying to send commands and image data to an NFC module connected to an e-paper display and keep getting TagLostException, probably meaning the command is wrong. I have asked this question on Stack Overflow but they told me this would probably be a better place to ask this. So basically I got a list of commands from the manufacturer but whatever I try to do I get the above mentioned exception. The module I am using is DENFC-M01 from Good Display.

var data_DB = "F0DB000069";//10    βÊýÊǺóÃæËùÓÐÊý¾ÝºÍµÄÒ»°ë¡£
var start = "A00603300190012C";//16   4.2´çµ¥É«400x300
var RST = "A4010C" + "A502000A" + "A40108" + "A502000A" + "A4010C" + "A502000A" + "A40108" + "A502000A" + "A4010C" + "A502000A" + "A40108" + "A502000A" + "A4010C" + "A502000A" + "A40103"; // 48 +56   ¸´Î»Èý´Î
var set_wf = "A102000F";//8  //0x00 0F
var set_power = "A10104" + "A40103";//12  //0x04  busy
var set_resolution = "A105610190012C";//14   //0x61 01 90 01 2C
var set_border = "A1025097";//8  //0x50 97
var write_BW = "A3021013"; //6    //0x10
var write_BWR = "A3021013"; //8   //0x13
var update = "A20112" + "A502000A" + "A40103";//20  //0x12 delay  busy
var sleep = "A20102" + "A40103" + "A20207A5"; //20 //0x02 busy 07 A5
val epd_init: Array<String> = arrayOf(
    data_DB + start + RST + set_wf + set_resolution + set_border + set_power + write_BWR + update + sleep, //16+104+8+12+14+8+8+20+20=152   210/2=0x69 //ÇÐÆÁ
    "F0DA000003F00330" //10    ÆÁÄ»²ÎÊý0000  Êý¾Ý³¤¶È03   ×Ô¶¨ÒåÆÁÄ»F0    ÆÁÄ»³ß´ç·Ö±æÂÊ12   ÆÁÄ»ÑÕÉ«20   £¨ÆÁÄ»·Ö±æÂʺÍÑÕÉ«ºÍA0ÃüÁîÒ»Ö£©
)

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    val p: Parcelable = intent?.getParcelableExtra(NfcAdapter.EXTRA_TAG) ?: return

    val tag = p as Tag
    val nfcA = NfcA.get(tag)
    if(nfcA != null) {
        try {
            Log.e("debug", "intent")

            nfcA.connect()
            var cmd: ByteArray
            var response: ByteArray
            nfcA.timeout = 60000
            
            cmd = hexStringToBytes(epd_init[0])
            response = nfcA.transceive(cmd)
            Log.e("epdinit_state", HexToString(response))

            cmd = hexStringToBytes(epd_init[1])
            response = nfcA.transceive(cmd)
            Log.e("epdinit_state", HexToString(response))

            //image_buffer is set to half white half black 400x300 image
            val datas = width0 * height0 / 8
            for (i in 0 until datas / 250) {
                cmd = byteArrayOf(0xF0.toByte(), 0xD2.toByte(), 0x00, i.toByte(), 0xFA.toByte())
                for (j in 0 until 250) {
                    cmd[j + 5] = image_buffer[j + 250 * i]
                }
                response = nfcA.transceive(cmd) // Send black and white data
                Log.e("${i + 1} sendData_state:", HexToString(response)) // Feedback data display, 9000 is Ok

                // Data mantissa sending
                if (i == datas / 250 - 1 && datas % 250 != 0) {
                    cmd = byteArrayOf(0xF0.toByte(), 0xD2.toByte(), 0x00, (i + 1).toByte(), 0xFA.toByte())
                    for (j in 0 until 250) {
                        cmd[j + 5] = image_buffer[j + 250 * (datas / 250)]
                    }
                    response = nfcA.transceive(cmd) // Send black and white data
                }
                Log.e("${i + 1} sendData_state:", HexToString(response)) // Feedback data display, 9000 is Ok
            }

            val refreshCmd = byteArrayOf(0xF0.toByte(), 0xD4.toByte(), 0x05, 0x80.toByte(), 0x00)
            response = nfcA.transceive(refreshCmd) // Send e-paper refresh command
            Log.e("RefreshData1_state:", HexToString(response)) // Feedback data display, 9000 is Ok
            if (response[0] != 0x90.toByte()) {
                response = nfcA.transceive(refreshCmd) // Send black and white refresh command
                Log.e("RefreshData2_state:", HexToString(response))
            }
        } catch (e: Exception) {
            e.printStackTrace()
            Log.e("debug", "Exception in onNewIntent: $e")
        } finally {
            nfcA.close()
        }
    }
}

I looked into the commands and the user manual for both the module and the display and the commands seem to be correct. Could there be any other reason they are not working? Do any of you have any experience with this module or generally sending images to be displayed on an e-paper. Also any advice on how to get this to work or any other information about this would be very appreciated.

Here is the link for the user manuals and everything I got from the manufacturers: https://www.dropbox.com/scl/fo/3186s7dey02t0ec8hqhd6/h?rlkey=tit9jvp95hvt4mys9byhi1rq8&dl=0

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I don't recognize the language your code is written in, but it looks to me as though you have a bug with your outer for i loop. You 're sending data in block of 250 bytes, but the way you've written that looks to me as though you won't send anything that's less than 250 bytes - so if the entire data package is less than 250 bytes you'll send nothing, and if it's more than 250 bytes then you'll send the 1st 250 bytes and then ignore the remainder. \$\endgroup\$ Commented Aug 14, 2023 at 12:11
  • \$\begingroup\$ @brhans The code is written in kotlin. If there is less then 250 bytes it should enter the if(), if there is more then 250 it should correctly assing the bytes here: image_buffer[j + 250 * i]. I am not sure though as the code hasn't gotten that far. It returns an exception in the first NfcA.receive(). \$\endgroup\$ Commented Aug 14, 2023 at 12:59
  • \$\begingroup\$ Do you have any way of confirming that the hexStringToBytes() function is producing the byte string/array/whatever you're expecting to get from your epd_init[] strings? Some kind of console print function which minimally processes "raw" bytes into printable ascii-hex? \$\endgroup\$ Commented Aug 14, 2023 at 19:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.