Objectives
This article demonstrates detection of USB memory stick removal while logging data with the Data History component in the NB HMI.

Introduction
The NB HMI provides a powerful tool to log data to a mounted USB memory device. Abrupt or inadvertent removal of a USB memory device is not automatically detected and can be problematic. This article provides a simple solution to detect such a condition.
The NB-series HMI can log data read from the connected PLC(s) directly to a .CSV file on a USB stick inserted into the NB. By default, NB system bit LB9154 goes ON a few seconds after a USB stick is inserted, and this bit should be turned OFF (eg. via touch switch) prior to the USB stick being removed. But, if the stick is removed then LB9154 is not automatically switch OFF by the NB. This means that the NB cannot detect if a USB stick is removed inadvertently. However, by using a combination of a Data Transfer and 2 xTimer components, this functionality can be created in the user application.
- - NB3Q-TW01B
- - NB-Designer V1.45, project “NB Datalog with stick removal detection V1_01.nbp”
- - CP1L-M30xxx with CP1W-CIF41
- - CX-Programmer project “CP1L-M for NB datalogging demo V1_01.cxp”
Content
- A macro “macro_init” simply sets a value of 1 into LW0 on initialization of the NB.
- Screen/frame “1:Common Window” defines the following objects:
a. A Data History component to log 14 x REAL values from PLC address W0 – W27 and 2 x INT values from PLC address W28 & W29 to \trend\History Data\History Data.csv on a USB stick inserted into the NB every 5 seconds. These values are changed by the PLC program.
b. Data Transfer component DT0 that writes the value in LW0 to ERW0 when the NB has detected a USB stick (i.e. on the leading edge of LB9154, write 1 into ERW0 on the USB stick). Note that the Data Transfer component cannot write a constant value, only a variable hence the need of the initialization macro to set a variable LW0 to 1.
c. Timer component TM0 that triggers every second and copies ERW0 to LW9154 (if no USB stick is inserted, then no value is read and a value of 0 is written into LW9154)
d. Timer component TM1 that triggers every 2 seconds and copies bit 0 of LW9154 to LB9154 (hence, if no stick inserted then ERW0 cannot be read so LW9154 will be 0 so LB9154 will be forced OFF).
Summary