Support Board
Date/Time: Sun, 24 Nov 2024 16:41:16 +0000
Working example code to read a cvs file.
View Count: 771
[2024-01-08 06:35:25] |
Ticks - Posts: 183 |
I have searched the sample code in the ACs_source folder and cannot find any examples of using sc.ReadFile sc.ReadFile() SC Support. Could you please provide the name of the ccp file that shows the working code on how to use sc.ReadFile or a link to example code in the support pages? Date Time Of Last Edit: 2024-01-09 01:45:17
|
[2024-01-08 19:50:39] |
Ticks - Posts: 183 |
46 views and also no response from SC techs.
|
[2024-01-08 23:38:27] |
User719512 - Posts: 263 |
This is a programming question, and I believe Sierra does not answer programming questions. You mention deleting the file as part of your workflow Ticks, how are you going to do that? Sierra does not have a sc.DeleteFile() function? That said...Sierra study code is c/c++ code and you can use Win32 API and std libraries/etc. So if you (or others) need to learn this, you can search or use ChatGPT to guide you. Assuming you will also want to control file locking and exclusive write access from Ninja in your c# code, and handle the same for Sierra to open and read with the file locked to prevent Ninja from overwriting your data while processing. Checking if the file exists is a poor pattern. A better pattern is to try to open the file with the access you need. If it succeeds, great. If not, that could fail for many reasons and the code should fail gracefully. I use many calls from these std libraries in Sierra #include <iostream> #include <sstream> #include <locale> #include <filesystem> namespace fs = std::filesystem; using namespace std; You might know these libraries already, or you (or others reading this) may not. This will be part of the journey to writing your studies and making them robust, reliable, and performant. |
[2024-01-09 01:35:22] |
Ticks - Posts: 183 |
I am just asking for the example code within an example study or support page with example code for their sc.ReadFile. Just like another customer asked for 3 years ago. I have removed my ideas or what I want to use the sc.ReadFile. Since it has caused confusion. I added the extra information of possible use to explain my need. Sometimes providing too much information is a bad thing. I have searched the sample code in the ACs_source folder and cannot find any examples of using sc.ReadFile
sc.ReadFile() SC Support. Could you please provide the name of the ccp file that shows the working code on how to use sc.ReadFile or a link to example code in the support pages? Date Time Of Last Edit: 2024-01-09 01:44:48
|
[2024-01-09 02:06:37] |
User719512 - Posts: 263 |
Are you more concerned with Sierra providing an example, which perhaps they should, or solving your problem? ChatGPT appears quite capable of answering this question. The first answer it gave me seemed to be using older header as the function prototypes did not match current headers. Once I told it the function prototypes, the code seemed pretty reasonable to me. NOTE: it will not work 100% as-is, and you'll need a little boilerplate for all the usual Sierra study variables, sc.Defaults, subgraph declarations/etc. It does however, show how to call sc.ReadFile. I am helping someone who has questions about Sierra chart ReadFile API and how to use it. I don't think they have tried to ask ChatGPT themselves how to use the ReadFile API, and I thought I would see your response and forward that on to them. Can you provide a minimal example of a Sierra chart study that uses sc.ReadFile API? For brevity in the code, let's assume the file is "c:\ninja2sierra.txt" and that file will contain a single line with a float that we will need to parse into a variable like "float data;". ...bad ChatGPT code omitted for brevity... You must have old headers. The prototype for Sierra file operations are: int32_t (SCDLLCALL* OpenFile)(const SCString& PathAndFileName, const int Mode, int& FileHandle); int32_t(SCDLLCALL* ReadFile)(const int FileHandle, char* Buffer, const int BytesToRead, unsigned int* p_BytesRead); int32_t(SCDLLCALL* WriteFile)(const int FileHandle, const char* Buffer, const int BytesToWrite, unsigned int* p_BytesWritten); int32_t(SCDLLCALL* CloseFile)(const int FileHandle); ChatGPT I apologize for the confusion. It looks like there has been a change in the Sierra Chart API since my last update. Below is the updated example using the correct prototypes for file operations: #include "sierrachart.h" SCDLLNAME_API int32_t SCDLLCALL OpenFile(const SCString& PathAndFileName, const int Mode, int& FileHandle); SCDLLNAME_API int32_t SCDLLCALL ReadFile(const int FileHandle, char* Buffer, const int BytesToRead, unsigned int* p_BytesRead); SCDLLNAME_API int32_t SCDLLCALL WriteFile(const int FileHandle, const char* Buffer, const int BytesToWrite, unsigned int* p_BytesWritten); SCDLLNAME_API int32_t SCDLLCALL CloseFile(const int FileHandle); SCSFExport scsf_ReadFileExample(SCStudyInterfaceRef sc) { // Define the file path const char* filePath = "c:\\ninja2sierra.txt"; // Declare variables float data = 0.0; // Open the file int fileHandle; if (sc.OpenFile(filePath, 0, fileHandle) == 1) { // Read the file contents char buffer[256]; // Adjust the buffer size as needed unsigned int bytesRead = 0; if (sc.ReadFile(fileHandle, buffer, sizeof(buffer) - 1, &bytesRead) == 1) { buffer[bytesRead] = '\0'; // Null-terminate the buffer // Parse the float value if (sscanf_s(buffer, "%f", &data) == 1) { // Successfully read and parsed the float value sc.AddMessageToLog("Read and parsed data from file.", 0); sc.AddMessageToLog(sc.FormatStudySubgraphName(0), 0); } else { // Failed to parse the float value sc.AddMessageToLog("Failed to parse data from file.", 1); } } else { // Error reading file sc.AddMessageToLog("Error reading file.", 1); } // Close the file sc.CloseFile(fileHandle); } else { // File does not exist or could not be opened sc.AddMessageToLog("File does not exist or could not be opened.", 1); } // Use the 'data' variable as needed // Output the result to a subgraph for visualization sc.Subgraph[0][sc.Index] = data; } ChatGPT This script uses the correct file operation prototypes for Sierra Chart. Please adjust the buffer size and handle errors as needed for your specific use case. |
[2024-05-11 19:00:32] |
reknirt - Posts: 8 |
I am just asking for the example code within an example study or support page with example code for their sc.ReadFile.
TICKS-- I requested to message you if you don't mind...follow up on your question. |
To post a message in this thread, you need to log in with your Sierra Chart account: