Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

SC115 + FileRename() not working

Jean-Baptiste LILY Apr 23, 2021 12:49 AM


I'm trying to use the FileRename() instruction to rename files saved on SC115 modules, and it does not seem to work. I use the Resident mode to store ICOS files only on the SC115.

When I use NL115 or NL116, my program works great.

On old OS 27.04 (tested on CR1000 and CR3000), files names are modified but they are writtend with special characters. On OS 32.05, nothing appends (both CR1000 and CR3000).

Here is the programme that we used with my collegue (for debug):

'program author:Bartosz ZAWILSKI
'CR1000 Series Datalogger

Public PTemp, batt_volt

Public rTime(9) As Float
Public OutStat As Float
Public LastFileName As String * 46
Public DataFile As String * 46
Public uniquefilename As String * 25
Public Icostimestamps As String * 25

Public SW_IN
Public SW_IN_IU

DataTable (MB,1,-1)
DataInterval (0,1,Min,10)
TableFile("USB:FR-Hes_BM_",15,-1,0,2,Min,OutStat,LastFileName) 'Creation table de donnes dans la memoire
Sample (1,Icostimestamps,String)
Sample (1,SW_IN,IEEE4)
Sample (1,SW_IN_IU,IEEE4)

Sub Nommage
RealTime(rTime()) 'Appel a l'horloge temps reel centrale
Sprintf (uniquefilename,"%04.0f%02.0f%02.0f_L05_F01.csv",rTime(1),rTime(2),rTime(3))

'Main Program
SerialOpen (Com2,9600,16,0,100)
RealTime(rTime()) 'Appel a l'horloge temps reel centrale
Sprintf (uniquefilename,"%04.0f%02.0f%02.0f_L05_F01.csv",rTime(1),rTime(2),rTime(3))

Scan (20,Sec,0,0)

Sprintf (Icostimestamps,"%04.0f%02.0f%02.0f%02.0f%02.0f%02.0f",rTime(1),rTime(2),rTime(3),rTime(4),rTime(5),rTime(6)) 'timestampicos
PanelTemp (PTemp,250)
Battery (batt_volt)

SW_IN_IU = -9999
SW_IN = -9999

CallTable MB

If(OutStat = -1) Then
DataFile="USB:FR-Hes_BM_" + uniquefilename 'Concatenation des donnees pour former le nom du fichier icos
FileRename(LastFileName,DataFile) 'Renommage du fichier dans la memoire

Call Nommage 'Appel sous programme de creation de noms formalises

If you have a solution, I'm interested.



Nico May 1, 2021 09:06 PM

Have you tried to use SerialClose() or FileClose() before you try to rename it?

See the command reference for FileRename():

The FileHandle for the file must be closed (FileClose) before the file can be renamed.

Actually.. when you write your files that you want to rename.. why don't you use the FileOpen() command family?!

The FileOpen function is used to open an ASCII text file or a binary file for writing or reading.




= FileOpen ( "FileName", "Mode", SeekPoint )


The FileOpen function returns a FileHandle, which can then be used by subsequent file read/write functions (FileWrite, FileRead, FileReadLine, FileClose). The FileHandle variable must be declared as a Long variable type. The file to be read from or written to can be either an ASCII text file or a binary file. If FileOpen fails, 0 will be returned.

With files opened for writing in ASCII text, every line feed character will be replaced with a carriage return. When reading ASCII text files, all carriage return characters (CHR(13)) are discarded and line feed characters (CHR(10)) are converted to end of line

The FileName parameter is used to specify the Device and FileName for the file written to or read from. FileName must be enclosed in quotes. It is entered in the format of "Device:FileName" where Device is CPU, CRD (memory card), USB (SC115), or USR. The USR device is an area of memory that can be set up by the user by assigning a value to the datalogger's UsrDriveSize setting in the Status table. This drive must be set to at least 8192 bytes, in 512-byte increments (if the value entered is not a multiple of 512 bytes, the size will be rounded up). The USR drive is the recommended device if a card is not being used and a file is being written, since frequent writes to datalogger CPU memory could quickly surpass the number of write cycles for the flash memory.

Log in or register to post/reply in the forum.