Having an issue reading and writing to a USB Memory stick tied to the EPIC via PACControl.
Unless I missed something this should work.
Groov Manage:
USB Setup
Enable USB set
Automount set
Permission unsecured (originally had this as secured and thought this was the solution - it wasn’t unless we need to reboot the EPIC).
In PACControl setup a communication channel as follows:
“file:r,/run/media/sdb1/TUNE_F.BIN” to READ
“file:w,/run/media/sdb1/TUNE_F.BIN” to WRITE
For comparison read/write to unsecured disk of EPIC worked fine:
“file:r,/home/dev/unsecured/TUNE_F.BIN”
“file:w,/home/dev/unsecured/TUNE_F.BIN”
Get error as follows:
On usb file read get -408 (error during file access) when Opening Outgoing Communication
On usb file write get -408 (error during file access) when Opening Outgoing Communication
Also got -52 invalid connection on Write Command (but port wasn’t open).
Same logic setup but accessing unsecured files - no problem works fine.
Please check your system info and tell me what firmware version you are running… There was a bug on this that got fixed, and I need to know what version your running.
Thanks.
I happen to work on some Epic USB datalogging this week. I had to update my firmware to 2.0.2 for it to work. Also I had a little trouble at first and wonder if a reboot of the Epic fixed it. Not sure about that.
It is datalogging to a csv file, but it does both opens for reads and writes. To the Unsecured area.
The example has commented-out lines for a few different paths. One to the root of the USB stick, another to a folder on the USB Stick. Then an example for the Epic internal drive - showing a shorthand ~ path or full path to the unsecured file area.
Hope this helps!
Here is the script:
// Basic code for data logging to USB memory stick on Epic
// Dave Engsberg
// SETTINGS ON THE EPIC - groovManage
// System / USB : Set Enable USB, Set Automount, Set Permissions to Unsecured
// With the USB Stick inserted go the USB Files and verify the device name path
// mine is /run/media/sdb1
// Filename
dlog_Basename = "testing.csv";
// USB DRIVE
dlog_Filename = "/run/media/sdb1/" + dlog_Basename; // write to root folder on usb drive
// dlog_Filename = "/run/media/sdb1/datalog/" + dlog_Basename; // write to datalog folder on usb drive
// LOCAL EPIC DRIVE
// These 2 paths are identical on the epic local drive
// dlog_Filename = "~/unsecured/" + dlog_Basename;
// dlog_Filename = "/home/dev/unsecured/" + dlog_Basename;
dlog_CRLF = Chr(13) + Chr(10); // define a cr / lf string
// WRITE HEADER
// Open the file read-only. If it cant open it, assume it doesn't exist then create it
dlog_Header = "DATE ,TIME ,VAR1 ,VAR2" + dlog_CRLF;
dlog_Filespec = "file:r," + dlog_Filename; // open the file to see if it is there
SetCommunicationHandleValue(dlog_Filespec, dlog_filehandle); // read only
dlog_Result = OpenOutgoingCommunication( dlog_filehandle ); // open the handle
if (dlog_Result==0) then
CloseCommunication(dlog_filehandle); // close the read-only file handle then check status
endif
if (dlog_Result <> 0) then
// write the header if there is no file yet
dlog_Filespec = "file:w," + dlog_Filename; // open for append or create
SetCommunicationHandleValue(dlog_Filespec, dlog_filehandle);
dlog_Result = OpenOutgoingCommunication(dlog_filehandle);
if (dlog_Result <> 0) then
// write header open error
NumberToString(dlog_Result, dlog_NumberAsString);
dlog_StatusMsg = "File Error Open Write Header. Error #" + dlog_NumberAsString + " Filename:" + dlog_Filename;
else
dlog_Result = TransmitString(dlog_Header, dlog_filehandle); // write the header line
CloseCommunication(dlog_filehandle); // close the header file handle
if (dlog_Result <> 0) then
// write header write error
NumberToString(dlog_Result, dlog_NumberAsString);
dlog_StatusMsg = "File Error Open Write Header. Error #" + dlog_NumberAsString + " Filename:" + dlog_Filename;
endif
endif
endif
// WRITE A CSV LINE
// ** build and write the data line if there is no error
if (dlog_Result==0) then
// build the write record string
// date and time
DateToStringMMDDYYYY(dlog_DateAsString); // get a date string
TimeToString(dlog_TimeAsString); // get a time string
dlog_CsvLineString = dlog_DateAsString + "," + dlog_TimeAsString + ",";
// variables
// Var1
dlog_ScratchFloat = var1;
if (IsFloatValid(dlog_ScratchFloat)) then
// valid
else
dlog_ScratchFloat = 0.0; // set to 0 if variable bad
endif
FloatToString(dlog_ScratchFloat, 7, 2, dlog_FloatAsString);
dlog_CsvLineString = dlog_CsvLineString + dlog_FloatAsString + ", ";
// Var2
dlog_ScratchFloat = var2;
if (IsFloatValid(dlog_ScratchFloat)) then
// valid
else
dlog_ScratchFloat = 0.0; // set to 0 if variable bad
endif
FloatToString(dlog_ScratchFloat, 7, 2, dlog_FloatAsString);
dlog_CsvLineString = dlog_CsvLineString + dlog_FloatAsString;
// CR LF
dlog_CsvLineString = dlog_CsvLineString + dlog_CRLF;
// ** Write the line to the file
dlog_Filespec = "file:a," + dlog_Filename; // open for append or create
SetCommunicationHandleValue(dlog_Filespec, dlog_filehandle);
dlog_Result = OpenOutgoingCommunication(dlog_filehandle);
if (dlog_Result <> 0) then
// write csv line open error
NumberToString(dlog_Result, dlog_NumberAsString);
dlog_StatusMsg = "File Error Open Write Line Error #" + dlog_NumberAsString + " Filename:" + dlog_Filename;
else
dlog_Result = TransmitString(dlog_CsvLineString, dlog_filehandle);// write it
if (dlog_Result <> 0) then
// write csv line write error
NumberToString(dlog_Result, dlog_NumberAsString);
dlog_StatusMsg = "File Error Write Line Error #" + dlog_NumberAsString + " Filename:" + dlog_Filename;
endif
CloseCommunication(dlog_filehandle); // close the header file handle
endif
endif
Dave,
Thanks for the feedback and script - its appreciated.
Your comment regarding an EPIC reboot was something I was also wondering about. I did reboot the system yesterday but it may have been before I set the USB permission to unsecured.
Rebooted the EPIC (this morning) and I now can read / write to the USB.
When I rebooted I had the memory stick still in the system. Not sure if this makes it work or its something else (USB permission setting is only thing I had to change).
Something Strange - the Time / Date on the USB memory files (I deleted the files and re-saved) the dates are wrong. Checked EPIC Time (Groov Manage) and it was good but the Time in PACControl (Control Engine Inspect) was different. Synced time to PC (in PACControl) and retried and the time / date stamp on the files match.
Question - is PACControl time different from EPIC time ?
Hi Guys,
We have not had time to write up a KB articule on this yet, but we do have a known issue where the USB state change does not ‘take’ until either the EPIC is restarted, or the PAC Control (or CodeSys) engine is restarted.
The guts of it goes like this…
In groov Manage -> System -> USB, the Permissions setting "Secured" or "Unsecured" only takes effect after restarting the controller. The UI should make this clear to the user or offer to restart the running controller after changing this setting.
The fix is coming in a future firmware update.
Regarding the time. I have not seen that happen before, will need to dig into it a bit.
The PAC Controller should be in lock step with the system time.