Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 18:30:41 +0000



Post From: Calling an External Input variable

[2023-11-17 09:44:14]
Gravity369 - Posts: 17
HI,

Thank you for your reply. I was thinking on similar lines.

I also tried CHATGPT and it came up with this answer, which I am unsure if ACSIL will Built correctly. Will try and let you know.

I was pleasantly surprised when I got to know ACSIL program is available on CHATGPT.

>>>>>>

write a program in Sierra Chart ACSIL to take an external input from another C++ program

ChatGPT
Certainly! To communicate between different programs, you can use inter-process communication (IPC) methods. One commonly used method for this purpose is using named pipes. Here's an example of how you might achieve this between a Sierra Chart ACSIL program and another C++ program using named pipes:

Sierra Chart ACSIL Code (Receiver):
cpp
Copy code
#include "scsf.h"
#include <iostream>
#include <fstream>

SCSFExport scsf_ReceiveExternalInput(SCStudyInterfaceRef sc) {
if (sc.SetDefaults) {
sc.GraphName = "Receive External Input";
return;
}

// Open a named pipe for reading
std::ifstream pipe;
pipe.open("/path/to/your/named_pipe", std::ios::in);

if (!pipe.is_open()) {
sc.AddMessageToLog("Failed to open named pipe for reading", 1);
return;
}

while (sc.UpdateStartIndex == 0) {
std::string input;
std::getline(pipe, input);

// Process the received input
if (!input.empty()) {
sc.AddMessageToLog(("Received: " + input).c_str(), 0);
// Process the received input here
// Example: Parse input and perform actions
}

sc.AddMessageToLog("Waiting for input...", 0);

// Sleep for a short time to avoid busy waiting
sc.Sleep(1000); // Sleep for 1 second
}

pipe.close(); // Close the named pipe
}
Replace "/path/to/your/named_pipe" with the actual path to your named pipe.

C++ Code (Sender):
Here's a simple example of how you might write to the named pipe from another C++ program:

cpp
Copy code
#include <iostream>
#include <fstream>

int main() {
std::ofstream pipe;
pipe.open("/path/to/your/named_pipe", std::ios::out);

if (!pipe.is_open()) {
std::cerr << "Failed to open named pipe for writing" << std::endl;
return 1;
}

// Send input to the named pipe
pipe << "Your message or data here\n";
pipe.close(); // Close the named pipe

return 0;
}
Make sure to replace "/path/to/your/named_pipe" with the actual path to the named pipe created by the Sierra Chart ACSIL code.

Remember, named pipes need to have the same name and location for both processes to communicate effectively. Also, error handling, synchronization, and proper message formatting should be considered for robust communication between programs.