Advertisement
Guest User

Digole.vb

a guest
Jun 20th, 2015
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 20.80 KB | None | 0 0
  1. Public Class Digole
  2.     Implements IDisposable
  3.  
  4.     Private Shared ReadOnly Enc As Text.Encoding = Text.Encoding.GetEncoding("ISO-8859-1")
  5.     Private Port As IO.Ports.SerialPort
  6.     Private PortName As String
  7.  
  8.     ''' <summary>Creates a new instance of this class and opens the com port with the default settings</summary>
  9.     ''' <param name="PortName">The name of the com port to open, eg. "COM2"</param>
  10.     Public Sub New(ByVal PortName As String)
  11.  
  12.         Me.New(PortName, 9600)
  13.  
  14.     End Sub
  15.  
  16.     ''' <summary>Creates a new instance of this class and opens the com port with the default settings</summary>
  17.     ''' <param name="PortName">The name of the com port to open, eg. "COM2"</param>
  18.     ''' <param name="Baud">The baud rate to use. Normally 9600</param>
  19.     Public Sub New(ByVal PortName As String, ByVal Baud As Integer)
  20.  
  21.         Me.PortName = PortName
  22.  
  23.         Port = New IO.Ports.SerialPort(PortName, Baud, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
  24.         Port.Encoding = Enc
  25.         Port.Open()
  26.  
  27.     End Sub
  28.  
  29.     ''' <summary>Releases all used resources by this class and closes the com port</summary>
  30.     Public Sub Dispose() Implements IDisposable.Dispose
  31.  
  32.         If Port IsNot Nothing Then
  33.             If Port.IsOpen Then Port.Close()
  34.             Port.Dispose()
  35.             Port = Nothing
  36.         End If
  37.         GC.SuppressFinalize(Me)
  38.         GC.Collect()
  39.  
  40.     End Sub
  41.  
  42.  
  43.  
  44.     ''' <summary>Writes raw data to the com port</summary>
  45.     ''' <param name="Data">The data to write</param>
  46.     Public Sub WriteRaw(ByVal Data As Byte())
  47.  
  48.         Port.Write(Data, 0, Data.Length)
  49.  
  50.     End Sub
  51.  
  52.     ''' <summary>Writes raw data to the com port</summary>
  53.     ''' <param name="Data">The data to write</param>
  54.     Public Sub WriteRaw(ByVal Data As String)
  55.  
  56.         Port.Write(Data)
  57.  
  58.     End Sub
  59.  
  60.     ''' <summary>Clears the screen</summary>
  61.     Public Sub ClearScreen()
  62.  
  63.         Port.Write("CL")
  64.  
  65.     End Sub
  66.  
  67.     ''' <summary>Enables the text cursor</summary>
  68.     Public Sub EnableCorsor()
  69.  
  70.         Port.Write("CS1")
  71.  
  72.     End Sub
  73.  
  74.     ''' <summary>Disables the text cursor</summary>
  75.     Public Sub DisableCursor()
  76.  
  77.         Port.Write("CS0")
  78.  
  79.     End Sub
  80.  
  81.     ''' <summary>Enables the backlight</summary>
  82.     Public Sub BacklightOn()
  83.  
  84.         Port.Write("BL1")
  85.  
  86.     End Sub
  87.  
  88.     ''' <summary>Disables the backlight</summary>
  89.     Public Sub BacklightOff()
  90.  
  91.         Port.Write("BL0")
  92.  
  93.     End Sub
  94.  
  95.     ''' <summary>Sets the backlight (0..100%)</summary>
  96.     Public Sub SetBacklight(ByVal Percent As Byte)
  97.  
  98.         If Percent > 100 Then Throw New ArgumentException("Value must be in range of 0..100.", "Percent")
  99.  
  100.         Dim Data As Byte() = Enc.GetBytes("BL ")
  101.         Data(2) = Percent
  102.  
  103.         Port.Write(Data, 0, Data.Length)
  104.  
  105.     End Sub
  106.  
  107.     ''' <summary>Sets the screen on (True) or off (False)</summary>
  108.     ''' <param name="OnOff">True for turn on the screen, False for turn off</param>
  109.     Public Sub ScreenPower(ByVal OnOff As Boolean)
  110.  
  111.         If OnOff Then
  112.             Port.Write("SOO1")
  113.         Else
  114.             Port.Write("SOO0")
  115.         End If
  116.  
  117.     End Sub
  118.  
  119.     ''' <summary>Sets if the configuration is displayed (True) or not (False)</summary>
  120.     ''' <param name="OnOff">True to display the information, False for not</param>
  121.     Public Sub DisplayConfig(ByVal OnOff As Boolean)
  122.  
  123.         If OnOff Then
  124.             Port.Write("DC1")
  125.         Else
  126.             Port.Write("DC0")
  127.         End If
  128.  
  129.     End Sub
  130.  
  131.     ''' <summary>Sets the baud rate for the device.</summary>
  132.     ''' <param name="Rate">The new baud rate. Must be one of the following: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200</param>
  133.     ''' <remarks>Device always starts up with 9600 baud</remarks>
  134.     Public Sub SetBaudrate(ByVal Rate As Integer)
  135.  
  136.         Select Case Rate
  137.             Case 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200 ' anything ok
  138.             Case Else : Throw New ArgumentException("Rate invalid.", "Rate")
  139.         End Select
  140.  
  141.         Port.Write("SB" & Rate.ToString)
  142.         Port.Write(New Byte() {0}, 0, 1)
  143.  
  144.         Do While Port.BytesToWrite > 0
  145.             Threading.Thread.Sleep(100)
  146.         Loop
  147.         Port.Close()
  148.         Port = Nothing
  149.         GC.Collect()
  150.         Port = New IO.Ports.SerialPort(PortName, Rate, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
  151.         Port.Encoding = Enc
  152.         Port.Open()
  153.  
  154.     End Sub
  155.  
  156.     ''' <summary>Sets the I2C address</summary>
  157.     Public Sub SetI2CAddress(ByVal Address As Byte)
  158.  
  159.         Dim Data As Byte() = Enc.GetBytes("SI2CA ")
  160.         Data(5) = Address
  161.  
  162.         Port.Write(Data, 0, Data.Length)
  163.  
  164.     End Sub
  165.  
  166.     ''' <summary>Sets the displays columns and rows</summary>
  167.     Public Sub SetLCDColRow(ByVal Columns As Byte, ByVal Rows As Byte)
  168.  
  169.         Dim Data As Byte() = Enc.GetBytes("STCR      ")
  170.         Data(4) = Columns
  171.         Data(5) = Rows
  172.         Data(6) = &H80
  173.         Data(7) = &HC0
  174.         Data(8) = &H94
  175.         Data(9) = &HD4
  176.  
  177.         Port.Write(Data, 0, Data.Length)
  178.  
  179.     End Sub
  180.  
  181.     ''' <summary>Sets the position of the text cursor</summary>
  182.     ''' <param name="x">The vertical position</param>
  183.     ''' <param name="y">The horizontal position</param>
  184.     Public Sub SetPrintPos(ByVal x As Byte, ByVal y As Byte)
  185.  
  186.         Dim Data As Byte() = Enc.GetBytes("TP  ")
  187.         Data(2) = x
  188.         Data(3) = y
  189.  
  190.         Port.Write(Data, 0, Data.Length)
  191.  
  192.     End Sub
  193.  
  194.     ''' <summary>Writes a text on the display</summary>
  195.     ''' <param name="Text">The text to write</param>
  196.     Public Sub Print(ByVal Text As String)
  197.  
  198.         Dim Data As Byte() = Enc.GetBytes("TT" & Text & " ")
  199.         Data(Data.Length - 1) = 0
  200.  
  201.         Port.Write(Data, 0, Data.Length)
  202.  
  203.     End Sub
  204.  
  205.     ''' <summary>Writes a number on the display</summary>
  206.     ''' <param name="Value">The number to write</param>
  207.     Public Sub Print(ByVal Value As Double)
  208.  
  209.         Dim Data As Byte() = Enc.GetBytes("TT" & Value.ToString & " ")
  210.         Data(Data.Length - 1) = 0
  211.  
  212.         Port.Write(Data, 0, Data.Length)
  213.  
  214.     End Sub
  215.  
  216.     ''' <summary>Sends a raw command to the display, bypassing the controller</summary>
  217.     ''' <param name="Command">The command to write</param>
  218.     Public Sub DirectCommand(ByVal Command As Byte)
  219.  
  220.         Dim Data As Byte() = Enc.GetBytes("MCD ")
  221.         Data(3) = Command
  222.  
  223.         Port.Write(Data, 0, Data.Length)
  224.  
  225.     End Sub
  226.  
  227.     ''' <summary>Sends a raw command to the display, bypassing the controller</summary>
  228.     ''' <param name="Command">The command to write</param>
  229.     Public Sub DirectData(ByVal Command As Byte)
  230.  
  231.         Dim Data As Byte() = Enc.GetBytes("MDT ")
  232.         Data(3) = Command
  233.  
  234.         Port.Write(Data, 0, Data.Length)
  235.  
  236.     End Sub
  237.  
  238.     ''' <summary>Sets the graplic position</summary>
  239.     ''' <param name="x">The horizontal position</param>
  240.     ''' <param name="y">The vertical position</param>
  241.     Public Sub SetPointPos(ByVal x As Byte, ByVal y As Byte)
  242.  
  243.         Dim Data As Byte() = Enc.GetBytes("GP  ")
  244.         Data(2) = x
  245.         Data(3) = y
  246.  
  247.         Port.Write(Data, 0, Data.Length)
  248.  
  249.     End Sub
  250.  
  251.     ''' <summary>Sets the drawing mode</summary>
  252.     ''' <param name="Mode">C = Copy, ! or ~ = NOT, | = OR, ^ = XOR, &amp; = AND</param>
  253.     Public Sub SetMode(ByVal Mode As Char)
  254.  
  255.         Select Case Mode
  256.             Case "C"c, "!"c, "~"c, "|"c, "^"c, "&"c ' all ok
  257.             Case Else : Throw New ArgumentException("Invalid mode.", "Mode")
  258.         End Select
  259.  
  260.         Port.Write("DM" & Mode)
  261.  
  262.     End Sub
  263.  
  264.     ''' <summary>Draws a monochrome image on the display</summary>
  265.     ''' <param name="x">The horizontal position</param>
  266.     ''' <param name="y">The vertical position</param>
  267.     ''' <param name="Width">The width of the image</param>
  268.     ''' <param name="Height">The height of the image</param>
  269.     ''' <param name="Image">The raw image data</param>
  270.     Public Sub DrawBitmap(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte, ByVal Image As Byte())
  271.  
  272.         Dim Data(Image.Length + 6) As Byte
  273.         Array.Copy(Enc.GetBytes("DIM"), Data, 3)
  274.         Data(3) = x
  275.         Data(4) = y
  276.         Data(5) = Width
  277.         Data(6) = Height
  278.         Array.Copy(Image, 0, Data, 7, Image.Length)
  279.  
  280.         Port.Write(Data, 0, Data.Length)
  281.  
  282.     End Sub
  283.  
  284.     ''' <summary>Sets the graphic rotation</summary>
  285.     ''' <param name="Value">0 for 0°, 1 for 90°, 2 for 180°, 3 for 270°</param>
  286.     Public Sub SetRotation(ByVal Value As Byte)
  287.  
  288.         If Value > 3 Then Throw New ArgumentException("Value must be in range of 0..3", "Value")
  289.  
  290.         Port.Write("SD" & Value.ToString)
  291.  
  292.     End Sub
  293.  
  294.     ''' <summary>Same as SetRotation(0)</summary>
  295.     Public Sub UndoRotation()
  296.         Call SetRotation(0)
  297.     End Sub
  298.  
  299.     ''' <summary>Same as SetRotation(1)</summary>
  300.     Public Sub SetRot90()
  301.         Call SetRotation(1)
  302.     End Sub
  303.  
  304.     ''' <summary>Same as SetRotation(2)</summary>
  305.     Public Sub SetRot180()
  306.         Call SetRotation(2)
  307.     End Sub
  308.  
  309.     ''' <summary>Same as SetRotation(3)</summary>
  310.     Public Sub SetRot270()
  311.         Call SetRotation(3)
  312.     End Sub
  313.  
  314.     ''' <summary>Sets the display contrast</summary>
  315.     ''' <param name="Value">The contrast value</param>
  316.     Public Sub SetContrast(ByVal Value As Byte)
  317.  
  318.         Dim Data As Byte() = Enc.GetBytes("CT ")
  319.         Data(2) = Value
  320.  
  321.         Port.Write(Data, 0, Data.Length)
  322.  
  323.     End Sub
  324.  
  325.     ''' <summary>Draws a filled rectangle</summary>
  326.     ''' <param name="x">Horizontal position</param>
  327.     ''' <param name="y">Vertical position</param>
  328.     ''' <param name="Width">The width</param>
  329.     ''' <param name="Height">The height</param>
  330.     Public Sub DrawBox(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte)
  331.  
  332.         Dim Data As Byte() = Enc.GetBytes("FR    ")
  333.         Data(2) = x
  334.         Data(3) = y
  335.         Data(4) = x + Width
  336.         Data(5) = y + Height
  337.  
  338.         Port.Write(Data, 0, Data.Length)
  339.  
  340.     End Sub
  341.  
  342.     ''' <summary>Draws a rectangle</summary>
  343.     ''' <param name="x">Horizontal position</param>
  344.     ''' <param name="y">Vertical position</param>
  345.     ''' <param name="Width">The width</param>
  346.     ''' <param name="Height">The height</param>
  347.     Public Sub DrawFrame(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte)
  348.  
  349.         Dim Data As Byte() = Enc.GetBytes("DR    ")
  350.         Data(2) = x
  351.         Data(3) = y
  352.         Data(4) = x + Width
  353.         Data(5) = y + Height
  354.  
  355.         Port.Write(Data, 0, Data.Length)
  356.  
  357.     End Sub
  358.  
  359.     ''' <summary>Draws a circle</summary>
  360.     ''' <param name="x">Horizontal position</param>
  361.     ''' <param name="y">Vertical position</param>
  362.     ''' <param name="Radius">The radius</param>
  363.     ''' <param name="Filled">True to fill it, False to not fill</param>
  364.     Public Sub DrawCircle(ByVal x As Byte, ByVal y As Byte, ByVal Radius As Byte, ByVal Filled As Boolean)
  365.  
  366.         Dim Data As Byte() = Enc.GetBytes("CC    ")
  367.         Data(2) = x
  368.         Data(3) = y
  369.         Data(4) = Radius
  370.         Data(5) = CByte(If(Filled, Asc("1"c), Asc("0"c)))
  371.  
  372.         Port.Write(Data, 0, Data.Length)
  373.  
  374.     End Sub
  375.  
  376.     ''' <summary>Draws a filled circle</summary>
  377.     ''' <param name="x">Horizontal position</param>
  378.     ''' <param name="y">Vertical position</param>
  379.     ''' <param name="Radius">The radius</param>
  380.     Public Sub DrawDisc(ByVal x As Byte, ByVal y As Byte, ByVal Radius As Byte)
  381.         Call DrawCircle(x, y, Radius, True)
  382.     End Sub
  383.  
  384.     ''' <summary>Draws a single pixel</summary>
  385.     ''' <param name="x">Horizontal position</param>
  386.     ''' <param name="y">Vertical position</param>
  387.     Public Sub DrawPixel(ByVal x As Byte, ByVal y As Byte)
  388.  
  389.         Dim Data As Byte() = Enc.GetBytes("DP  ")
  390.         Data(2) = x
  391.         Data(3) = y
  392.  
  393.         Port.Write(Data, 0, Data.Length)
  394.  
  395.     End Sub
  396.  
  397.     ''' <summary>Draws a line on the screen</summary>
  398.     ''' <param name="x1">The horizontal start position</param>
  399.     ''' <param name="y1">The vertical start position</param>
  400.     ''' <param name="x2">The horizontal end position</param>
  401.     ''' <param name="y2">The vertical end position</param>
  402.     Public Sub DrawLine(ByVal x1 As Byte, ByVal y1 As Byte, ByVal x2 As Byte, ByVal y2 As Byte)
  403.  
  404.         Dim Data As Byte() = Enc.GetBytes("LN    ")
  405.         Data(2) = x1
  406.         Data(3) = y1
  407.         Data(4) = x2
  408.         Data(5) = y2
  409.  
  410.         Port.Write(Data, 0, Data.Length)
  411.  
  412.     End Sub
  413.  
  414.     ''' <summary>Draws a horizontal line on the screen</summary>
  415.     ''' <param name="x">The horizontal start position</param>
  416.     ''' <param name="y">The vertical start position</param>
  417.     ''' <param name="Width">The width for the line</param>
  418.     Public Sub DrawHLine(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte)
  419.         Call DrawLine(x, y, x + Width, y)
  420.     End Sub
  421.  
  422.     ''' <summary>Draws a vertical line on the screen</summary>
  423.     ''' <param name="x">The horizontal start position</param>
  424.     ''' <param name="y">The vertical start position</param>
  425.     ''' <param name="Height">The height for the line</param>
  426.     Public Sub DrawVLine(ByVal x As Byte, ByVal y As Byte, ByVal Height As Byte)
  427.         Call DrawLine(x, y, x, y + Height)
  428.     End Sub
  429.  
  430.     ''' <summary>Draws a line from the last position to the new position</summary>
  431.     ''' <param name="x">The new horizontal position</param>
  432.     ''' <param name="y">The new vertical position</param>
  433.     Public Sub DrawLineTo(ByVal x As Byte, ByVal y As Byte)
  434.  
  435.         Dim Data As Byte() = Enc.GetBytes("LT  ")
  436.         Data(2) = x
  437.         Data(3) = y
  438.  
  439.         Port.Write(Data, 0, Data.Length)
  440.  
  441.     End Sub
  442.  
  443.     ''' <summary>Moves the text cursor to the next line</summary>
  444.     Public Sub NextTextLine()
  445.  
  446.         Port.Write("TRT")
  447.  
  448.     End Sub
  449.  
  450.     ''' <summary>Sets the font which will be used</summary>
  451.     ''' <param name="Font">The font to use. Valid: 0, 6, 10, 18, 51, 120, 123, 200, 201, 202, 203</param>
  452.     Public Sub SetFont(ByVal Font As Byte)
  453.  
  454.         Select Case Font
  455.             Case 0, 6, 10, 18, 51, 120, 123, 200, 201, 202, 203 ' Anything ok
  456.             Case Else : Throw New ArgumentException("Invalid font.", "Font")
  457.         End Select
  458.  
  459.         Dim Data As Byte() = Enc.GetBytes("SF ")
  460.         Data(2) = Font
  461.  
  462.         Port.Write(Data, 0, Data.Length)
  463.  
  464.     End Sub
  465.  
  466.     ''' <summary>Sets the color which will be used</summary>
  467.     ''' <param name="Color">The color to use. Valid: 0..255 for color displays, 0..1 for monochrome</param>
  468.     Public Sub SetColor(ByVal Color As Byte)
  469.  
  470.         Dim Data As Byte() = Enc.GetBytes("SC ")
  471.         Data(2) = Color
  472.  
  473.         Port.Write(Data, 0, Data.Length)
  474.  
  475.     End Sub
  476.  
  477.     ''' <summary>Moves an area to another location</summary>
  478.     ''' <param name="x">The horizontal position of the rectangle to move</param>
  479.     ''' <param name="y">The vertical position of the rectangle to move</param>
  480.     ''' <param name="Width">The width of the rectangle to move</param>
  481.     ''' <param name="Height">The height of the rectangle to move</param>
  482.     ''' <param name="XOffset">The horizontal offset to move to</param>
  483.     ''' <param name="YOffset">The vertical offset to move to</param>
  484.     Public Sub MoveArea(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte, ByVal XOffset As Byte, ByVal YOffset As Byte)
  485.  
  486.         Dim Data As Byte() = Enc.GetBytes("MA      ")
  487.         Data(2) = x
  488.         Data(3) = y
  489.         Data(4) = Width
  490.         Data(5) = Height
  491.         Data(6) = XOffset
  492.         Data(7) = YOffset
  493.  
  494.         Port.Write(Data, 0, Data.Length)
  495.  
  496.     End Sub
  497.  
  498.     ''' <summary>Moves the text cursor back to the last position</summary>
  499.     Public Sub SetTextPosBack()
  500.  
  501.         Port.Write("ETB")
  502.  
  503.     End Sub
  504.  
  505.     ''' <summary>Moves the text cursor to another relative position (in pixel)</summary>
  506.     ''' <param name="XOffset">The horizontal offset to move to</param>
  507.     ''' <param name="YOffset">The vertical offset to move to</param>
  508.     Public Sub SetTextPosOffset(ByVal XOffset As Byte, ByVal YOffset As Byte)
  509.  
  510.         Dim Data As Byte() = Enc.GetBytes("ETO  ")
  511.         Data(3) = XOffset
  512.         Data(4) = YOffset
  513.  
  514.         Port.Write(Data, 0, Data.Length)
  515.  
  516.     End Sub
  517.  
  518.     ''' <summary>Moves the text cursor to another absolute position (in pixel)</summary>
  519.     ''' <param name="x">The horizontal position to move to</param>
  520.     ''' <param name="y">The vertical position to move to</param>
  521.     Public Sub SetTextPosAbs(ByVal x As Byte, ByVal y As Byte)
  522.  
  523.         Dim Data As Byte() = Enc.GetBytes("ETP  ")
  524.         Data(3) = x
  525.         Data(4) = y
  526.  
  527.         Port.Write(Data, 0, Data.Length)
  528.  
  529.     End Sub
  530.  
  531.     ''' <summary>Uploads the splash screen data</summary>
  532.     ''' <param name="Image">The splash screen data</param>
  533.     Public Sub UploadStartScreen(ByVal Image As Byte())
  534.  
  535.         Dim Data(4 + Image.Length) As Byte
  536.         Array.Copy(Enc.GetBytes("SSS"), Data, 3)
  537.         Data(3) = CByte(Image.Length And &HFF)
  538.         Data(4) = CByte(Image.Length >> 8)
  539.         Array.Copy(Image, 0, Data, 5, Data.Length)
  540.  
  541.         Port.Write(Data, 0, Data.Length)
  542.  
  543.     End Sub
  544.  
  545.     ''' <summary>Uploads a user font data</summary>
  546.     ''' <param name="Index">The section for the data</param>
  547.     ''' <param name="Font">The font data</param>
  548.     Public Sub UploadUserFont(ByVal Index As Byte, ByVal Font As Byte())
  549.  
  550.         Dim Data(5 + Font.Length) As Byte
  551.         Array.Copy(Enc.GetBytes("SUF"), Data, 3)
  552.         Data(3) = Index
  553.         Data(4) = CByte(Font.Length And &HFF)
  554.         Data(5) = CByte(Font.Length >> 8)
  555.         Array.Copy(Font, 0, Data, 5, Data.Length)
  556.  
  557.         Port.Write(Data, 0, Data.Length)
  558.  
  559.     End Sub
  560.  
  561.     ''' <summary>Sets if the start screen should be displayed or not</summary>
  562.     ''' <param name="Value">True will show the splash screen on startup, False disables it</param>
  563.     Public Sub DisplayStartScreen(ByVal Value As Boolean)
  564.  
  565.         Port.Write("DSS" & If(Value, "1", "0"))
  566.  
  567.     End Sub
  568.  
  569.     ''' <summary>Sends a byte to the output head of the display</summary>
  570.     ''' <param name="Value">The byte to send</param>
  571.     Public Sub DigitalOutput(ByVal Value As Byte)
  572.  
  573.         Dim Data As Byte() = Enc.GetBytes("DOUT ")
  574.         Data(4) = Value
  575.  
  576.         Port.Write(Data, 0, Data.Length)
  577.  
  578.     End Sub
  579.  
  580.     ''' <summary>Sets the line pattern when drawing a line</summary>
  581.     ''' <param name="Value">The pattern to use. eg.: 0xAA = dotted, 0xFA = dash</param>
  582.     Public Sub SetLinePattern(ByVal Value As Byte)
  583.  
  584.         Dim Data As Byte() = Enc.GetBytes("SLP ")
  585.         Data(3) = Value
  586.  
  587.         Port.Write(Data, 0, Data.Length)
  588.  
  589.     End Sub
  590.  
  591.     ''' <summary>Draws an image on the device which has up to 256 colors.</summary>
  592.     ''' <param name="x">The horizontal position for the image</param>
  593.     ''' <param name="y">The vertical position of the image</param>
  594.     ''' <param name="Width">The width of the image</param>
  595.     ''' <param name="Height">The height of the image</param>
  596.     ''' <param name="Image">The raw image data</param>
  597.     ''' <remarks>Color format: RRRGGGBB</remarks>
  598.     Public Sub DrawBitmap256(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte, ByVal Image As Byte())
  599.  
  600.         Dim Data(9 + Image.Length) As Byte
  601.         Array.Copy(Enc.GetBytes("EDIM1"), Data, 5)
  602.         Data(5) = x
  603.         Data(6) = y
  604.         Data(7) = Width
  605.         Data(8) = Height
  606.         Array.Copy(Image, 0, Data, 9, Image.Length)
  607.  
  608.         Port.Write(Data, 0, Data.Length)
  609.  
  610.     End Sub
  611.  
  612.     ''' <summary>Draws an image on the device which has up to 65k colors.</summary>
  613.     ''' <param name="x">The horizontal position for the image</param>
  614.     ''' <param name="y">The vertical position of the image</param>
  615.     ''' <param name="Width">The width of the image</param>
  616.     ''' <param name="Height">The height of the image</param>
  617.     ''' <param name="Image">The raw image data</param>
  618.     ''' <remarks>Color format: RRRRRGGG GGGBBBBB</remarks>
  619.     Public Sub DrawBitmap64K(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte, ByVal Image As Byte())
  620.  
  621.         Dim Data(9 + Image.Length) As Byte
  622.         Array.Copy(Enc.GetBytes("EDIM2"), Data, 5)
  623.         Data(5) = x
  624.         Data(6) = y
  625.         Data(7) = Width
  626.         Data(8) = Height
  627.         Array.Copy(Image, 0, Data, 9, Image.Length)
  628.  
  629.         Port.Write(Data, 0, Data.Length)
  630.  
  631.     End Sub
  632.  
  633.     ''' <summary>Draws an image on the device which has up to 262k colors.</summary>
  634.     ''' <param name="x">The horizontal position for the image</param>
  635.     ''' <param name="y">The vertical position of the image</param>
  636.     ''' <param name="Width">The width of the image</param>
  637.     ''' <param name="Height">The height of the image</param>
  638.     ''' <param name="Image">The raw image data</param>
  639.     ''' <remarks>Color format: 00RRRRRR 00GGGGGG 00BBBBBB</remarks>
  640.     Public Sub DrawBitmap262K(ByVal x As Byte, ByVal y As Byte, ByVal Width As Byte, ByVal Height As Byte, ByVal Image As Byte())
  641.  
  642.         Dim Data(9 + Image.Length) As Byte
  643.         Array.Copy(Enc.GetBytes("EDIM3"), Data, 5)
  644.         Data(5) = x
  645.         Data(6) = y
  646.         Data(7) = Width
  647.         Data(8) = Height
  648.         Array.Copy(Image, 0, Data, 9, Image.Length)
  649.  
  650.         Port.Write(Data, 0, Data.Length)
  651.  
  652.     End Sub
  653.  
  654.     ''' <summary>Sets the color for ongoing graphic operations.</summary>
  655.     ''' <param name="Red">The intensity for red color</param>
  656.     ''' <param name="Green">The intensity for green color</param>
  657.     ''' <param name="Blue">The intensity for blue color</param>
  658.     Public Sub SetTrueColor(ByVal Red As Byte, ByVal Green As Byte, ByVal Blue As Byte)
  659.  
  660.         Dim Data As Byte() = Enc.GetBytes("ESC   ")
  661.         Data(3) = Red
  662.         Data(4) = Green
  663.         Data(5) = Blue
  664.  
  665.         Port.Write(Data, 0, Data.Length)
  666.  
  667.     End Sub
  668.  
  669.     ''' <summary>Sets the color for ongoing graphic operations.</summary>
  670.     ''' <param name="Color">The .Net Framework color</param>
  671.     Public Sub SetTrueColor(ByVal Color As Drawing.Color)
  672.  
  673.         Call SetTrueColor(Color.R >> 2, Color.G >> 2, Color.B >> 2)
  674.  
  675.     End Sub
  676.  
  677.     ''' <summary>Sets the LCD chip used. See user manual for details.</summary>
  678.     ''' <param name="Chip">The chip to use.</param>
  679.     Public Sub SetLCDChip(ByVal Chip As Byte)
  680.  
  681.         Dim Data As Byte() = Enc.GetBytes("SLCD ")
  682.         Data(4) = Chip
  683.  
  684.         Port.Write(Data, 0, Data.Length)
  685.  
  686.     End Sub
  687.  
  688.     ''' <summary>Shuts down the MCU to save energy. Send a dummy byte (0x00) for wake up and wait a few msec.</summary>
  689.     Public Sub ShutdownMCU()
  690.  
  691.         Port.Write("DNMCU")
  692.  
  693.     End Sub
  694.  
  695.     ''' <summary>Shuts down the MCU and the display to save energy. Send a dummy byte (0x00) for wake up and wait a few msec.</summary>
  696.     Public Sub ShutdownDevice()
  697.  
  698.         Port.Write("DNALL")
  699.  
  700.     End Sub
  701.  
  702.     ''' <summary>Dummy function to wakeup the device after shutdown command</summary>
  703.     Public Sub WakeupDevice()
  704.  
  705.         Dim Data(0) As Byte
  706.         Data(0) = 0
  707.         Port.Write(Data, 0, Data.Length)
  708.  
  709.     End Sub
  710.  
  711.  
  712.  
  713. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement