Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace netapi_con
- {
- class Program
- {
- public enum hist_types
- {
- [Description("HST_1MIN")]
- HST_1MIN = 1,
- [Description("HST_6MIN")]
- HST_6MIN = 2,
- [Description("HST_1HOUR")]
- HST_1HOUR = 3,
- [Description("HST_8HOUR")]
- HST_8HOUR = 4,
- [Description("HST_24HOUR")]
- HST_24HOUR = 5,
- [Description("HST_5SECF")]
- HST_5SECF = 6,
- [Description("HST_1HOURE")]
- HST_1HOURE = 7,
- [Description("HST_8HOURE")]
- HST_8HOURE = 8,
- [Description("HST_24HOURE")]
- HST_24HOURE = 9
- }
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
- public struct GetPntData
- {
- [MarshalAs(UnmanagedType.LPStr)]
- public String Point_name;
- public UInt32 Point_type_num;
- public Int32 Getpnt_status;
- public GetPntData(String Point_name, UInt32 Point_type_num, Int32 Getpnt_status)
- {
- this.Point_name = Point_name;
- this.Point_type_num = Point_type_num;
- this.Getpnt_status = Getpnt_status;
- }
- }
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
- public struct GetArchData
- {
- public UInt16 hist_type;
- public UInt32 hist_start_date;
- public Single hist_start_time;
- public UInt16 num_hist;
- public UInt16 num_points;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
- public UInt16[] point_type_nums;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
- public UInt16[] point_params;
- [MarshalAs(UnmanagedType.LPStr)]
- public String archive_path;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)]
- public Single[] hist_values;
- public UInt16 gethst_status;
- public GetArchData(UInt16 hist_type, UInt32 hist_start_date, Single hist_start_time, UInt16 num_hist, UInt16 num_points, UInt32[] point_type_nums,
- UInt16[] point_params, String archive_path, Single[] hist_values, UInt16 gethst_status)
- {
- this.hist_type = hist_type;
- this.hist_start_date = hist_start_date;
- this.hist_start_time = hist_start_time;
- this.num_hist = num_hist;
- this.num_points = num_points;
- this.point_type_nums = point_type_nums;
- this.point_params = point_params;
- this.archive_path = archive_path;
- this.hist_values = hist_values;
- this.gethst_status = gethst_status;
- }
- }
- static void Main(string[] args)
- {
- string p_name = "71LBA10CF001";
- string server = "SRV7A";
- int num_points = 1;
- GetPntData[] rgetpnt_data_str_r = { new GetPntData(p_name, 0, 0) };
- int status = NativeMethods.rhsc_point_numbers_2(server, num_points, rgetpnt_data_str_r);
- UInt32[] point_type_nums = new UInt32[1];
- foreach (GetPntData element in rgetpnt_data_str_r)
- {
- Console.WriteLine(status.ToString("x4") + "\t" + element.Point_type_num.ToString() + "\t" + element.Getpnt_status.ToString());
- point_type_nums[0] = element.Point_type_num;
- }
- UInt16 hist_type = (UInt16)hist_types.HST_1HOUR;
- DateTime start_date = new DateTime(2017, 05, 29, 04, 00, 00);
- UInt32 hist_start_date = (UInt32)start_date.Subtract(new DateTime(1981, 1, 1, 0, 0, 0, DateTimeKind.Local)).Days;
- Single hist_start_time = (Single)(start_date.Hour * 60 * 60 + start_date.Minute * 60 + start_date.Second);
- UInt16[] point_params = new UInt16[1];
- point_params[0] = 32763;
- String archive_path = "";
- Single[] hist_values = new Single[25];
- UInt16 gethst_status = 0;
- GetArchData[] gethstpar_date_data = { new GetArchData(hist_type, hist_start_date, hist_start_time, 25, 1, point_type_nums, point_params, archive_path, hist_values, gethst_status) };
- status = NativeMethods.rgethstpar_date(server, 1, gethstpar_date_data);
- Console.WriteLine("status2 - " + status.ToString("x4"));
- foreach (GetArchData element in gethstpar_date_data)
- {
- Console.WriteLine("Date -" + "\t" + element.hist_start_date.ToString() + "\t" + element.hist_start_time.ToString("F") + "\t" + element.hist_values[0].ToString());
- }
- }
- internal class NativeMethods
- {
- [DllImportAttribute("hscnetapi.dll", CharSet = CharSet.Ansi, EntryPoint = "rhsc_point_numbers_2", CallingConvention = CallingConvention.StdCall)]
- public static extern int rhsc_point_numbers_2([MarshalAs(UnmanagedType.LPStr)] String server, int num_points, [In, Out] GetPntData[] rgetpnt_data_str);
- [DllImportAttribute("hscnetapi.dll", CharSet = CharSet.Ansi, EntryPoint = "rgethstpar_date", CallingConvention = CallingConvention.StdCall)]
- public static extern int rgethstpar_date([MarshalAs(UnmanagedType.LPStr)] String server, int num_gethsts, [In, Out] GetArchData[] gethstpar_date_data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement