I have succeed transferred data from PC to NRF52840 dongle and managed to receive it back on the PC.
But i want to be available to manipulate the data in NRF52840 dongle before send it back.
My data types is float and i use Python.serial to send and receive data from PC.
Attached is my python code and SES main code snippet
static char m_cdc_data[512];
case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
{
ret_code_t ret;
static uint8_t index = 0;
index++;
NRF_LOG_INFO("Bytes waiting: %d", app_usbd_cdc_acm_bytes_stored(p_cdc_acm));
do
{
if ((m_cdc_data[index-1] == '\n') ||
(m_cdc_data[index-1] == '\r') ||
(index >= (255)))
{
if (index>1)
{
NRF_LOG_DEBUG("Ready to send data");
NRF_LOG_HEXDUMP_DEBUG(m_cdc_data, index);
uint16_t length = (uint16_t)index;
if (length + sizeof(ENDLINE_STRING)<255)
{
memcpy(m_cdc_data + length, ENDLINE_STRING, sizeof(ENDLINE_STRING));
length += sizeof(ENDLINE_STRING);
}
//m_cdc_data =
ret = app_usbd_cdc_acm_write(&m_app_cdc_acm,m_cdc_data, length);
}
index = 0;
}
/*Get amount of data transfered*/
size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);
NRF_LOG_INFO("RX: size: %lu char: %c", size, m_cdc_data[index-1]);
/* Fetch data until internal buffer is empty */
ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
&m_cdc_data[index],
READ_SIZE);
if (ret == NRF_SUCCESS)
{
index++;
}
/*for (int i = 0; i < size; i++)
{
m_cdc_data[i] = m_cdc_data[i] + 10;
}*/
}
while (ret == NRF_SUCCESS);
bsp_board_led_invert(LED_CDC_ACM_RX);
break;
}
i used USB CDC ACM example from NRF5SDK with some modifications.
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 17 03:18:43 2021
@author: owner
"""
import serial
import pandas as pd
import numpy as np
import scipy.io
import io
import struct
ser=serial.Serial("COM5",115200,timeout=1) # Open the port
fout = open("./OUTPUT.txt", "w")
a15 = scipy.io.loadmat("a17_s2_t3_inertial.mat")
data=a15['d_iner']
x1=data[:,0]
y1=data[:,1]
z1=data[:,2]
x2=data[:,3]
y2=data[:,4]
z2=data[:,5]
d = len(data)
x11 = struct.pack('39f', *x1)
ser.write(x11) # Send data to the port
k = ser.readlines() # Receive data from the port
fout.write(str(k)) # Write the received data to OUTPUT
fin.close()
fout.close()
ser.close()