• Resolved

DLPNIRNANOEVM: Communication over UART

Prodigy 90 points

Replies: 13

Views: 434

Part Number: DLPNIRNANOEVM

Hi 

I'm trying to communicate with the NIRscan nano over the UART expansion connector. 

I've written a python script which can open, close, write and write over the COM port to which i attached the NIRscan. 

But I'm struggling with defining the bytes I have to send over to get a useful response. 

Right now I'm just trying to get any response such that I can confirm that my setup is working. 

According tot he documentation i need to send the following: 

- Start bytes 65 66 67 68

- Checksum bytes ?? ?? ?? ??

- Flag bytes 11????0

- Sequence ??

- Length ??

- Command ?? ??

- Data 42 (I want to perform a 'Read file list')

- End bytes 68 67 66 65

import serial
import time

ser = serial.Serial(
    port='COM6',
    baudrate=115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)

ser.flushInput()
ser.flushOutput()

if ser.is_open == 1:
    print("Port is open")
    
    start_bytes = bytearray([65, 66, 67, 68])
    ser.write(start_bytes)
    
    checksum_bytes = bytearray([0, 0, 0, 0])
    ser.write(checksum_bytes)

    flag_byte = 112
    ser.write(flag_byte)

    sequency_byte = 0
    ser.write(sequency_byte)

    length_bytes = bytearray([0, 0])
    ser.write(length_bytes)

    command_bytes = bytearray([42, 0])
    ser.write(command_bytes)

    data_bytes = bytearray([0, 0, 0, 0])
    ser.write(data_bytes)

    end_bytes = bytearray([68, 67, 66, 65])
    ser.write(end_bytes)
    
    print("Data sent")

    print(ser.read())
 
ser.close()
if ser.is_open == 0:
    print("Port is closed")

  • UPDATE: 

    I'm already getting back the error message from the Microcontroller: b'ABCD\x10\x00\x00\x00\x10\x00\x00\x00DCBA'

    So I guess that my program is sending and receiving well, but what I'm sending is probably wrong. 

    To perform the 'Read file data' command I came up with the following values to send over: 

    values = [65, 66 ,67, 68, 10, 0, 0, 0, 0, 0, 1, 0, 45, 2, 68, 67, 66, 65]

    Can someone check if this sequence is correct for this command?

  • In reply to Nick Verlooy:

    Nick, 

    Kindly note the correct UART Byte sequence for the command you are trying to send:

    0x41, 0x42, 0x43, 0x44 – (start id)

    0xF0, 0x00, 0x00, 0x00 – (checksum)

    0xC0 - ( Flags: Read (1), Reply Requested(1). Rest 0)

    0x00 - (sequence byte)

    0x02, 0x00 – (length of command + data)

    0x2E, 0x00 (command byte, group byte)

    0x44, 0x43, 0x42, 0x41 (end id)

    Can you kindly try with this sequence and see if you are able to get a proper reply?

    Thanks & Regards,

    Hirak.

  • In reply to Hirak Biswas:

    Hirak,

    Thank you for the information. 

    I'm able now to send commands to put the lamp on and off, get the device status, ...

    So I'm able to send en receive commands.

    The next thing to do is to receive the files which are stored on the SD card. 

    But I'm struggling with sending the proper 'data' in the command. 

    First, I wan't to perform the 'Read file list size' command over UART. 

    The user guide says that it needs 1 byte for the Data Payload Input, but it is unclear for me what it should be. 

    It just says 'NNO_FILE_SCAN_LIST'

    Can you help me with this?

    Regards

    Nick 

  • In reply to Nick Verlooy:

    Nick,

    NNO_FILE_SCAN_LIST and other similar capitalized values in the User's Guide are defined in either the Tiva source code or the Spectrum Library source code.

    This particular one is in the Tiva and GUI source code, under Common/include/NNOCommandDefs.h

  • In reply to Eric Pruett:

    I looked in the code, thanks for pointing out where it is! 

    I tried to send '6' as input byte since this is the number  'NNO_FILE_SCAN_LIST' has in the 'NNO_FILE_TYPE' enum. 

    Unfortunately, I'm not getting the response I think I should get. 

    The msg is send is: 

    byte readFileListSizeCMD[] = {65, 66 , 67, 68,
                                  244, 0, 0, 0,
                                  192, 0, 3, 0,
                                  43, 0, 6,
                                  68, 67, 66, 65
                                 };

    Device response: 65 66 67 68 237 0 0 0 192 0 2 0 43 0 68 67 66 65 

    So it is not responding with any data, while there is an SD card inserted with scan data on it. 

  • In reply to Nick Verlooy:

    Hi Nick, 

    Is this the same question you asked in another thread? If yes, I'll close one of them due to duplication. 

    Thanks & Regards,

    Hirak.

  • In reply to Hirak Biswas:

    Hi Hirak

    Yes it is. Sorry for the duplicate.

    Looking forward to receive the solution. 

  • In reply to Nick Verlooy:

    Hi Nick, 

    You need to follow the following procedure to read the scan data from SDCard. 

    1. Send the command "NNO_CMD_FILE_GET_READSIZE" with parameter as "NNO_FILE_SCAN_DATA_FROM_SD" (found in the file "NNOCommandDefs.h"). This command will return the read size for the Scan data stored in SDCard.

    2. Send the command "NNO_CMD_FILE_GET_DATA" to get the response containing the scan data from SDCard in serialized format. 


    Kindly try the following steps in given order and see if you are able to get correct response. 


    Thanks & Regards

    Hirak.

  • In reply to Hirak Biswas:

    Hi Hirak, 

    I already tried this. I made the following command to send: 

    byte readFileSizeCMD[] = {65, 66 , 67, 68,
                              247, 0, 0, 0,
                              192, 0, 3, 0,
                              45, 0, 7,
                              68, 67, 66, 65
                             };

    The 7 is the parameter stating the 'NNO_FILE_SCAN_DATA_FROM_SD' . I think my checksum and other bytes are correct. Please check this. 

    The response I get is always the same. Even when I perform a scan which is stored on the SD. I would expect the data size response to be different then? I get this response:  65 66 67 68 239 1 0 0 192 0 6 0 45 0 238 14 0 0 68 67 66 65 22.

    The 'NNO_CMD_FILE_GET_DATA' is the following in byte format:

    byte readFileDataCMD[] = {65, 66 , 67, 68,
                              240, 0, 0, 0,
                              192, 0, 2, 0,
                              46, 0,
                              68, 67, 66, 65
                             };

    The response on this command is the following: 

    65 66 67 68 198 96 0 0 192 0 0 2 46 0 116 112 108 0 117 14 0 0 83 40 117 99 35 99 99 99 99 99 99 99 106 106 118 118 117 36 40 102 35 102 35 41 99 35 118 99 99 99 99 118 99 35 99 35 118 118 99 118 118 105 35 41 0 20 0 0 0 3 0 0 0 3 0 0 0 8 0 0 0 8 0 0 0 40 0 0 0 96 3 0 0 1 0 0 0 67 111 108 117 109 110 32 49 0 0 0 0 0 0 0 0 0 0 0 0 15 3 31 2 7 5 55 210 48 227 10 0 0 182 14 1 0 75 0 0 173 141 45 12 216 23 192 159 53 144 76 108 243 168 63 61 254 133 235 115 25 26 191 243 216 145 173 220 209 155 64 239 118 36 247 142 128 236 191 155 124 200 22 145 2 49 191 54 49 48 48 49 53 50 0 237 0 24 25 64 0 17 0 54 49 48 48 49 53 50 0 67 111 108 117 109 110 32 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 132 3 164 6 6 228 0 6 0 4 1 0 0 193 0 0 0 87 2 0 0 182 1 0 0 7 1 0 0 214 1 0 0 206 3 0 0 27 3 0 0 2 2 0 0 159 2 0 0 59 1 0 0 174 1 0 0 254 1 0 0 72 2 0 0 202 2 0 0 31 2 0 0 158 2 0 0 2 2 0 0 130 3 0 0 241 2 0 0 255 2 0 0 61 2 0 0 48 3 0 0 238 2 0 0 132 0 0 0 99 2 0 0 215 3 0 0 78 2 0 0 43 3 0 0 211 2 0 0 129 3 0 0 103 4 0 0 172 2 0 0 173 3 0 0 220 1 0 0 239 3 0 0 14 1 0 0 218 2 0 0 160 2 0 0 121 3 0 0 205 3 0 0 96 4 0 0 152 3 0 0 13 5 0 0 240 2 0 0 17 2 0 0 251 2 0 0 54 2 0 0 93 3 0 0 232 255 255 255 203 3 0 0 168 2 0 0 22 3 0 0 46 3 0 0 241 1 0 0 211 3 0 0 7 0 0 0 94 3 0 0 101 4 0 0 119 2 0 0 156 3 0 0 125 3 0 0 47 3 0 0 168 1 0 0 78 2 0 0 163 1 0 0 123 68 67 66 65 

    It sends back 528 bytes and I see the terminator (68 67 66 65) bytes so I assume that the communication is working.

    Converting this response into ASCII gives me some pieces which I can recognize in the .dat files but it is far from the complete SD files. 

    I think there is still something wrong in the commands, the parameters which I send, the checksum, the LSB, MSB, ...

    Maybe I'm reading out a different file instead of the SD card. 

    Nick

  • In reply to Nick Verlooy:

    Hi Hirak

    Do you have an idea when I can expect some answer? 

    Regards

    Nick