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

Whats causes the event APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE?

I can't go into too many details, but the scenario we have is:

We have an NRF52840 device connected to a PC through serial (for both power and communication)
The NRF device needs to send some data to the referred PC, but it only does that if the serial connection is active. We check the state of the connection by reading the app_usbd_cdc_acm_user_event_t events
If we receive the APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN event, we know that the connection is opened, if we receive the APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE we know the connection is closed, and then the data will be buffered and not be sent to the PC
The problematic scenario is: the PC is being shut off but it still supplies power to the NRF device, and it looks like that the device doesn't receive the CLOSE event, so the device still thinks that the connection is ready, and then the data is being sent and getting lost since no one is on the RX side to read it

So, that's why I want to know what causes the CLOSE event. Does the side that's closing the connection need to send some kind of EVENT_CLOSE data to the other device?
Therefore, in a scenario where the software on the PC crashes (or it is suddenly turned off) this information will never be sent and the connection will never really close?

I know that can happen in a TCP/IP connection scenario, but I don't know how that works for serial communication

Any input will be greatly appreciated!

Related