### Main API Example Source: https://github.com/rapidscada/scada-v6/blob/master/ScadaWeb/OpenPlugins/PlgMain/wwwroot/custom/MainApiExample.html This example demonstrates how to use the Main API to fetch current and historical data. It includes functions to start cyclic updates of current data, request and display current data, and request and display hourly data. ```javascript const REFR_RATE = 1000; // the refresh rate of current data, ms const CNL_NUM = 101; // the channel number to read const ARCHIVE_BIT = 2; // specifies the hourly archive var mainApi = null; // the API instance // Starts cyclic update of current data. function startUpdatingCurData() { getCurData(function () { setTimeout(startUpdatingCurData, REFR_RATE); }); } // Requests and displays current data. function getCurData(callback) { mainApi.getCurData(CNL_NUM, function (dto) { if (dto.ok) { let cnlData = dto.data[0]; $("#divData1").html("Value = " + cnlData.val + "
Status = " + cnlData.stat); } else { $("#divData1").text("Error getting current data: " + dto.msg); } callback(); }); } // Requests and displays hourly data. function getHourData() { let myDate = new Date(); // current time myDate.setHours(0, 0, 0, 0); // today let startTime = myDate.toISOString(); myDate.setDate(myDate.getDate() + 1); // tomorrow let endTime = myDate.toISOString(); let timeRange = new TimeRange(startTime, endTime, false); mainApi.getHistData(ARCHIVE_BIT, timeRange, CNL_NUM, function (dto) { let outElem = $("#divData2"); if (dto.ok) { outElem.html(""); let timestamps = dto.data.timestamps; if (timestamps.length > 0) { let trend = dto.data.trends[0]; for (let i = 0; i < timestamps.length; i++) { let timestamp = timestamps[i]; let record = trend[i]; outElem.append( "Time = " + timestamp.ut + ", " + "Local time = " + timestamp.lt + ", " + "Value = " + record.d.val + ", " + "Status = " + record.d.stat + ", " + "Display value = " + record.df.dispVal + "
" ); } } else { outElem.text("No data"); } } else { outElem.text("Error getting hourly data: " + dto.msg); } }); } $(function () { // initialize the API mainApi = new MainApi({ rootPath: "../" }); // prepare a web page $("#divDescr1").text("Cyclically request the current data of channel " + CNL_NUM); $("#divDescr2").text("Request the hourly data of channel " + CNL_NUM + " for the current date"); // request data startUpdatingCurData(); getHourData(); }); ``` -------------------------------- ### Command API Example Source: https://github.com/rapidscada/scada-v6/blob/master/ScadaWeb/OpenPlugins/PlgMain/wwwroot/custom/CmdApiExample.html This JavaScript code demonstrates how to send a command using the MainApi class. It includes event handling for a button click, retrieving input values, and processing the API response. ```javascript $(function () { let mainApi = new MainApi({ rootPath: "../" }); $("#btnSend").on("click", function () { let cnlNum = parseInt($("#txtCnlNum").val()); let cmdVal = parseFloat($("#txtCmdVal").val()); let cmdData = $("#txtCmdData").val(); $("#txtResult").val("Sending..."); mainApi.sendCommand(cnlNum, cmdVal, false, cmdData, function (dto) { if (dto.ok) { $("#txtResult").val("Command sent successfully."); } else { $("#txtResult").val("Error sending command: " + dto.msg); } }); }); }); ``` -------------------------------- ### Build from Command Line Source: https://github.com/rapidscada/scada-v6/blob/master/HowToBuild.txt Commands to build Rapid SCADA solutions using the .NET SDK. ```bash dotnet build ScadaCommon/ScadaCommon.sln -c Release dotnet build ScadaAgent/ScadaAgent/ScadaAgent.sln -c Release dotnet build ScadaComm/ScadaComm/ScadaComm.sln -c Release dotnet build ScadaServer/ScadaServer/ScadaServer.sln -c Release dotnet build ScadaWeb/ScadaWeb/ScadaWeb.sln -c Release dotnet build ScadaAdmin/ScadaAdmin/ScadaAdmin.sln -c Release dotnet build ScadaReport/ScadaReport.sln -c Release dotnet build ScadaComm/OpenDrivers/OpenDrivers.sln -c Release dotnet build ScadaComm/OpenDrivers2/OpenDrivers2.sln -c Release dotnet build ScadaServer/OpenModules/OpenModules.sln -c Release dotnet build ScadaWeb/Mimics/Mimics.sln -c Release dotnet build ScadaWeb/OpenPlugins/OpenPlugins.sln -c Release dotnet build ScadaAdmin/OpenExtensions/OpenExtensions.sln -c Release ``` -------------------------------- ### Chart Initialization and Configuration Source: https://github.com/rapidscada/scada-v6/blob/master/ScadaWeb/OpenPlugins/PlgChart/wwwroot/test/ChartTest.html This JavaScript code snippet demonstrates how to initialize and configure a chart component. It sets up control options, defines a time range with custom hour mappings, prepares chart data including time points and trend data, and configures channel statuses. Finally, it builds and draws the chart, binds hint events, and sets up a resize handler. ```javascript $(document).ready(function () { let controlOptions = new scada.chart.ControlOptions(); controlOptions.chartTitle = "Chart Test"; controlOptions.chartStatus = "Status message"; controlOptions.hasError = false; controlOptions.locale = "en-US"; controlOptions.gapBetweenPoints = 6 * 3600 * 1000; // 6 hours // time range, UTC+3, Moscow time zone let timeRange = new scada.chart.TimeRange(); timeRange.startTime = Date.UTC(2022, 3, 30, 21, 0, 0); timeRange.endTime = Date.UTC(2022, 4, 2, 21, 0, 0); let hourMap = timeRange.hourMap; hourMap.set(Date.UTC(2022, 03, 30, 21, 0, 0), "2022-05-01T00:00:00"); hourMap.set(Date.UTC(2022, 04, 01, 03, 0, 0), "2022-05-01T06:00:00"); hourMap.set(Date.UTC(2022, 04, 01, 09, 0, 0), "2022-05-01T12:00:00"); hourMap.set(Date.UTC(2022, 04, 01, 15, 0, 0), "2022-05-01T18:00:00"); hourMap.set(Date.UTC(2022, 04, 01, 21, 0, 0), "2022-05-02T00:00:00"); hourMap.set(Date.UTC(2022, 04, 02, 03, 0, 0), "2022-05-02T06:00:00"); hourMap.set(Date.UTC(2022, 04, 02, 09, 0, 0), "2022-05-02T12:00:00"); hourMap.set(Date.UTC(2022, 04, 02, 15, 0, 0), "2022-05-02T18:00:00"); hourMap.set(Date.UTC(2022, 04, 02, 21, 0, 0), "2022-05-03T00:00:00"); // time points let chartData = new scada.chart.ChartData(); chartData.timePoints = [ [Date.UTC(2022, 03, 30, 21, 0, 0), "2022-05-01T00:00:00"], [Date.UTC(2022, 04, 01, 03, 0, 0), "2022-05-01T06:00:00"], [Date.UTC(2022, 04, 01, 09, 0, 0), "2022-05-01T12:00:00"], [Date.UTC(2022, 04, 01, 15, 0, 0), "2022-05-01T18:00:00"], [Date.UTC(2022, 04, 01, 21, 0, 0), "2022-05-02T00:00:00"], [Date.UTC(2022, 04, 02, 03, 0, 0), "2022-05-02T06:00:00"], [Date.UTC(2022, 04, 02, 09, 0, 0), "2022-05-02T12:00:00"], [Date.UTC(2022, 04, 02, 15, 0, 0), "2022-05-02T18:00:00"], [Date.UTC(2022, 04, 02, 21, 0, 0), "2022-05-03T00:00:00"] ]; // trends let trend1 = new scada.chart.Trend(); trend1.cnlNum = 1; trend1.cnlName = "Channel 1"; trend1.quantityID = 1; trend1.quantityName = "Voltage"; trend1.unitName = "V"; trend1.points = [ [0, 12, "0"], [1, 12, "1"], [5, 1, "5"], [2.5, 1, "2,5"], [2.5, 1, "2,5"], [7, 14, "7"], [7.5, 14, "7.5"], [6.7, 1, "6,7"], [8, 14, "8"] ]; let trend2 = new scada.chart.Trend(); trend2.cnlNum = 2; trend2.cnlName = "Channel 2"; trend2.points = [ [3, 1, "Three"], [0, 1, "Zero"], [0, 0, "---"], [1, 1, "One"], [2, 1, "Two"], [5, 1, "Five"], [4, 1, "Four"], [5, 1, "Five"], [3, 1, "Three"] ]; chartData.trends = [trend1, trend2]; // channel statuses chartData.cnlStatusMap.set(0, new scada.chart.CnlStatus(0, "Undefined", "Black")); chartData.cnlStatusMap.set(1, new scada.chart.CnlStatus(1, "Defined", "Black")); chartData.cnlStatusMap.set(12, new scada.chart.CnlStatus(12, "Low", "DeepSkyBlue")); chartData.cnlStatusMap.set(14, new scada.chart.CnlStatus(14, "High", "Orange")); let chart = new scada.chart.Chart("divChart"); chart.controlOptions = controlOptions; chart.timeRange = timeRange; chart.chartData = chartData; chart.buildDom(); chart.draw(); chart.bindHintEvents(); $(window).on("resize", function () { chart.draw(); }); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.