Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace netapi_con
  9. {
  10.     class Program
  11.     {
  12.         public enum hist_types
  13.         {
  14.             [Description("HST_1MIN")]
  15.             HST_1MIN = 1,
  16.             [Description("HST_6MIN")]
  17.             HST_6MIN = 2,
  18.             [Description("HST_1HOUR")]
  19.             HST_1HOUR = 3,
  20.             [Description("HST_8HOUR")]
  21.             HST_8HOUR = 4,
  22.             [Description("HST_24HOUR")]
  23.             HST_24HOUR = 5,
  24.             [Description("HST_5SECF")]
  25.             HST_5SECF = 6,
  26.             [Description("HST_1HOURE")]
  27.             HST_1HOURE = 7,
  28.             [Description("HST_8HOURE")]
  29.             HST_8HOURE = 8,
  30.             [Description("HST_24HOURE")]
  31.             HST_24HOURE = 9
  32.         }
  33.  
  34.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  35.         public struct GetPntData
  36.         {
  37.             [MarshalAs(UnmanagedType.LPStr)]
  38.             public String Point_name;
  39.             public UInt32 Point_type_num;
  40.             public Int32 Getpnt_status;
  41.  
  42.             public GetPntData(String Point_name, UInt32 Point_type_num, Int32 Getpnt_status)
  43.             {
  44.                 this.Point_name = Point_name;
  45.                 this.Point_type_num = Point_type_num;
  46.                 this.Getpnt_status = Getpnt_status;
  47.             }
  48.         }
  49.  
  50.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  51.         public struct GetArchData
  52.         {
  53.             public UInt16 hist_type;            
  54.             public UInt32 hist_start_date;          
  55.             public Single hist_start_time;
  56.             public UInt16 num_hist;
  57.             public UInt16 num_points;
  58.            
  59.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]            
  60.             public UInt16[] point_type_nums;
  61.            
  62.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]            
  63.             public UInt16[] point_params;
  64.  
  65.             [MarshalAs(UnmanagedType.LPStr)]
  66.             public String archive_path;          
  67.            
  68.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)]          
  69.             public Single[] hist_values;
  70.  
  71.             public UInt16 gethst_status;
  72.  
  73.             public GetArchData(UInt16 hist_type, UInt32 hist_start_date, Single hist_start_time, UInt16 num_hist, UInt16 num_points, UInt32[] point_type_nums,
  74.                                UInt16[] point_params, String archive_path, Single[] hist_values, UInt16 gethst_status)
  75.             {
  76.                 this.hist_type = hist_type;
  77.                 this.hist_start_date = hist_start_date;
  78.                 this.hist_start_time = hist_start_time;
  79.                 this.num_hist = num_hist;
  80.                 this.num_points = num_points;
  81.                 this.point_type_nums = point_type_nums;
  82.                 this.point_params = point_params;
  83.                 this.archive_path = archive_path;
  84.                 this.hist_values = hist_values;
  85.                 this.gethst_status = gethst_status;
  86.             }
  87.         }
  88.  
  89.         static void Main(string[] args)
  90.         {
  91.             string p_name = "71LBA10CF001";
  92.  
  93.             string server = "SRV7A";
  94.             int num_points = 1;    
  95.  
  96.             GetPntData[] rgetpnt_data_str_r = { new GetPntData(p_name, 0, 0) };        
  97.  
  98.  
  99.             int status = NativeMethods.rhsc_point_numbers_2(server, num_points, rgetpnt_data_str_r);
  100.  
  101.             UInt32[] point_type_nums = new UInt32[1];
  102.  
  103.             foreach (GetPntData element in rgetpnt_data_str_r)
  104.             {
  105.                 Console.WriteLine(status.ToString("x4") + "\t" + element.Point_type_num.ToString() + "\t" + element.Getpnt_status.ToString());
  106.                 point_type_nums[0] = element.Point_type_num;
  107.             }
  108.  
  109.             UInt16 hist_type = (UInt16)hist_types.HST_1HOUR;
  110.             DateTime start_date = new DateTime(2017, 05, 29, 04, 00, 00);
  111.             UInt32 hist_start_date = (UInt32)start_date.Subtract(new DateTime(1981, 1, 1, 0, 0, 0, DateTimeKind.Local)).Days;
  112.             Single hist_start_time = (Single)(start_date.Hour * 60  * 60 + start_date.Minute * 60 + start_date.Second);
  113.             UInt16[] point_params = new UInt16[1];
  114.             point_params[0] = 32763;
  115.             String archive_path = "";
  116.            
  117.             Single[] hist_values = new Single[25];
  118.             UInt16 gethst_status = 0;
  119.            
  120.             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) };            
  121.  
  122.             status = NativeMethods.rgethstpar_date(server, 1, gethstpar_date_data);
  123.  
  124.             Console.WriteLine("status2 - " + status.ToString("x4"));
  125.  
  126.             foreach (GetArchData element in gethstpar_date_data)
  127.             {
  128.                 Console.WriteLine("Date -" + "\t" + element.hist_start_date.ToString() + "\t" + element.hist_start_time.ToString("F") + "\t" + element.hist_values[0].ToString());
  129.             }            
  130.         }
  131.  
  132.         internal class NativeMethods
  133.         {
  134.             [DllImportAttribute("hscnetapi.dll", CharSet = CharSet.Ansi, EntryPoint = "rhsc_point_numbers_2", CallingConvention = CallingConvention.StdCall)]
  135.             public static extern int rhsc_point_numbers_2([MarshalAs(UnmanagedType.LPStr)] String server, int num_points, [In, Out] GetPntData[] rgetpnt_data_str);
  136.  
  137.             [DllImportAttribute("hscnetapi.dll", CharSet = CharSet.Ansi, EntryPoint = "rgethstpar_date", CallingConvention = CallingConvention.StdCall)]
  138.             public static extern int rgethstpar_date([MarshalAs(UnmanagedType.LPStr)] String server, int num_gethsts, [In, Out] GetArchData[] gethstpar_date_data);
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement