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 Reply Children
  • 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

Related