This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Transfer data (in file) between PC and nrf52840-mdk-usb-dongle over USB CDC

Hi,

   I am working on an USB CDC program with nrf52840-mdk-usb-dongle. The PC needs to use a terminal emulator like putty to connect to the dongle. Now I send and recieve data through the putty terminal.

   I want to send and recieve data through files, not through putty terminal. I mean, setting an INPUT file and an OUTPUT file on PC. The dongle reads data from the INPUT file, and writes data to the OUTPUT file. Is it possible to implement this?

Thanks

Parents
  • Hi

    Yes, I think this should be possible. You can check out the nRF52 BLE image transfer demo to see an example where the nRF52 handles and transfers files. You should be able to modify this to handle your desired file type and to transfer over USB instead of BLE. I am not sure what type of files you have in mind though, and this has not been tested as far as I know, so I can't guarantee that it will work.

    Best regards,

    Simon

  • Hi Simonr,

    Thanks for your help! I have solved this problem in another way. I replace the putty with pyserial, a python serial port library.

    Here are the steps:

    1. Load an USB CDC program to the dongle, e.g., <SDK>/examples/peripheral/cli. The program can be adapted to dongle by following this excellent tutorial.

    2. Install pyserial on PC.

    3. Create a file named INPUT on PC, and write some words to the file. 

    4. Run the following python program:

    import serial
    
    ser=serial.Serial("/dev/ttyS8",115200,timeout=0.1)  # Open the port
    
    fin = open("./INPUT", "r")
    fout = open("./OUTPUT", "w")
    
    s = fin.read()										# Read data from INPUT
    
    ser.write("print all "+"\'"+s+"\'"+"\r\n")			# Send data to the port
    s = ser.readlines()									# Receive data from the port
    
    fout.write(str(s))									# Write the received data to OUTPUT
    
    fin.close()
    fout.close()
    
    ser.close()											# Close the port

Reply
  • Hi Simonr,

    Thanks for your help! I have solved this problem in another way. I replace the putty with pyserial, a python serial port library.

    Here are the steps:

    1. Load an USB CDC program to the dongle, e.g., <SDK>/examples/peripheral/cli. The program can be adapted to dongle by following this excellent tutorial.

    2. Install pyserial on PC.

    3. Create a file named INPUT on PC, and write some words to the file. 

    4. Run the following python program:

    import serial
    
    ser=serial.Serial("/dev/ttyS8",115200,timeout=0.1)  # Open the port
    
    fin = open("./INPUT", "r")
    fout = open("./OUTPUT", "w")
    
    s = fin.read()										# Read data from INPUT
    
    ser.write("print all "+"\'"+s+"\'"+"\r\n")			# Send data to the port
    s = ser.readlines()									# Receive data from the port
    
    fout.write(str(s))									# Write the received data to OUTPUT
    
    fin.close()
    fout.close()
    
    ser.close()											# Close the port

Children
No Data
Related