Server/Display.cs
author sl
Fri, 15 Aug 2014 10:20:01 +0200
changeset 30 c375286d1a1c
parent 12 f37c5ff8af18
child 39 083f4935aae4
permissions -rw-r--r--
Still trying to setup WCF for us to work nicely.
Now using multi threading and reliable session.
Implementing thread safe functions where needed.
Enforcing session mode.
Fixing bug in marquee label as we forgot to reset current position when text is changed.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 //
     7 using System.Runtime.InteropServices;
     8 
     9 namespace SharpDisplayManager
    10 {
    11     class Display
    12     {
    13 
    14         //Constructor
    15         public Display()
    16         {
    17             iDevice = IntPtr.Zero;
    18         }
    19 
    20         //
    21         public bool Open()
    22         {
    23             if (iDevice == IntPtr.Zero)
    24             {
    25                 iDevice = MiniDisplayOpen();
    26             }
    27             return iDevice != IntPtr.Zero;
    28         }
    29 
    30         public void Close()
    31         {
    32             MiniDisplayClose(iDevice);
    33             iDevice = IntPtr.Zero;
    34         }
    35 
    36         public bool IsOpen()
    37         {
    38             return iDevice != IntPtr.Zero;
    39         }
    40 
    41         public void Clear()
    42         {
    43             MiniDisplayClear(iDevice);
    44         }
    45 
    46         public void Fill()
    47         {
    48             MiniDisplayFill(iDevice);
    49         }
    50 
    51         public void SwapBuffers()
    52         {
    53             MiniDisplaySwapBuffers(iDevice);
    54         }
    55 
    56         public int MaxBrightness()
    57         {
    58             return MiniDisplayMaxBrightness(iDevice);
    59         }
    60 
    61         public int MinBrightness()
    62         {
    63             return MiniDisplayMinBrightness(iDevice);
    64         }
    65 
    66         public void SetBrightness(int aBrightness)
    67         {
    68             if (!IsOpen()) return;
    69 
    70             MiniDisplaySetBrightness(iDevice, aBrightness);
    71         }
    72 
    73         public int WidthInPixels()
    74         {
    75             return MiniDisplayWidthInPixels(iDevice);
    76         }
    77 
    78         public int HeightInPixels()
    79         {
    80             return MiniDisplayHeightInPixels(iDevice);
    81         }
    82 
    83         public void SetPixel(int aX, int aY, int aValue)
    84         {
    85             MiniDisplaySetPixel(iDevice,aX,aY,aValue);
    86         }
    87 
    88         public void RequestPowerSupplyStatus()
    89         {
    90             MiniDisplayRequestPowerSupplyStatus(iDevice);
    91         }
    92 
    93         public void RequestDeviceId()
    94         {
    95             MiniDisplayRequestDeviceId(iDevice);
    96         }
    97 
    98         public void RequestFirmwareRevision()
    99         {
   100             MiniDisplayRequestFirmwareRevision(iDevice);
   101         }
   102 
   103         public bool PowerSupplyStatus()
   104         {
   105             bool res = MiniDisplayPowerSupplyStatus(iDevice);
   106             return res;
   107         }
   108 
   109         public TMiniDisplayRequest AttemptRequestCompletion()
   110         {
   111             return MiniDisplayAttemptRequestCompletion(iDevice);
   112         }
   113 
   114         public TMiniDisplayRequest CurrentRequest()
   115         {
   116             return MiniDisplayCurrentRequest(iDevice);
   117         }
   118 
   119         public bool IsRequestPending()
   120         {
   121             return CurrentRequest() != TMiniDisplayRequest.EMiniDisplayRequestNone;
   122         }
   123 
   124 
   125         public string Vendor()
   126         {
   127             IntPtr ptr = MiniDisplayVendor(iDevice);
   128             string str = Marshal.PtrToStringUni(ptr);
   129             return str;
   130         }
   131 
   132         public string Product()
   133         {
   134             IntPtr ptr = MiniDisplayProduct(iDevice);
   135             string str = Marshal.PtrToStringUni(ptr);
   136             return str;
   137         }
   138 
   139         public string SerialNumber()
   140         {
   141             IntPtr ptr = MiniDisplaySerialNumber(iDevice);
   142             string str = Marshal.PtrToStringUni(ptr);
   143             return str;
   144         }
   145 
   146         public string DeviceId()
   147         {
   148             IntPtr ptr = MiniDisplayDeviceId(iDevice);
   149             string str = Marshal.PtrToStringAnsi(ptr);
   150             return str;
   151         }
   152 
   153         public string FirmwareRevision()
   154         {
   155             IntPtr ptr = MiniDisplayFirmwareRevision(iDevice);
   156             string str = Marshal.PtrToStringAnsi(ptr);
   157             return str;
   158         }
   159 
   160         //Our display device handle
   161         IntPtr iDevice;
   162 
   163         public enum TMiniDisplayRequest
   164         {
   165             EMiniDisplayRequestNone,
   166             EMiniDisplayRequestDeviceId,
   167             EMiniDisplayRequestFirmwareRevision,
   168             EMiniDisplayRequestPowerSupplyStatus
   169         }
   170 
   171         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   172         public static extern IntPtr MiniDisplayOpen();
   173 
   174         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   175         public static extern void MiniDisplayClose(IntPtr aDevice);
   176 
   177         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   178         public static extern void MiniDisplayClear(IntPtr aDevice);
   179 
   180         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   181         public static extern void MiniDisplayFill(IntPtr aDevice);
   182 
   183         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   184         public static extern void MiniDisplaySwapBuffers(IntPtr aDevice);
   185 
   186         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   187         public static extern void MiniDisplaySetBrightness(IntPtr aDevice, int aBrightness);
   188 
   189         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   190         public static extern int MiniDisplayMinBrightness(IntPtr aDevice);
   191 
   192         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   193         public static extern int MiniDisplayMaxBrightness(IntPtr aDevice);
   194 
   195         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   196         public static extern int MiniDisplayWidthInPixels(IntPtr aDevice);
   197 
   198         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   199         public static extern int MiniDisplayHeightInPixels(IntPtr aDevice);
   200 
   201         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   202         public static extern int MiniDisplaySetPixel(IntPtr aDevice, int aX, int aY, int aValue);
   203 
   204         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   205         public static extern IntPtr MiniDisplayVendor(IntPtr aDevice);
   206 
   207         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   208         public static extern IntPtr MiniDisplayProduct(IntPtr aDevice);
   209 
   210         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   211         public static extern IntPtr MiniDisplaySerialNumber(IntPtr aDevice);
   212 
   213         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   214         public static extern IntPtr MiniDisplayDeviceId(IntPtr aDevice);
   215 
   216         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   217         public static extern IntPtr MiniDisplayFirmwareRevision(IntPtr aDevice);
   218 
   219         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   220         [return: MarshalAs(UnmanagedType.I1)]
   221         public static extern bool MiniDisplayPowerSupplyStatus(IntPtr aDevice);
   222 
   223         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   224         public static extern void MiniDisplayRequestDeviceId(IntPtr aDevice);
   225 
   226         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   227         public static extern void MiniDisplayRequestFirmwareRevision(IntPtr aDevice);
   228 
   229         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   230         public static extern void MiniDisplayRequestPowerSupplyStatus(IntPtr aDevice);
   231 
   232         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   233         public static extern TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(IntPtr aDevice);
   234 
   235         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   236         public static extern TMiniDisplayRequest MiniDisplayCurrentRequest(IntPtr aDevice);
   237 
   238         [DllImport("MiniDisplay.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
   239         public static extern void MiniDisplayCancelRequest(IntPtr aDevice);
   240 
   241 
   242     }
   243 }