Windows Entertainment and Connected Home

How to organize, access and enjoy all of your media in and around your home

How to send Hex over a serial port using Powershell

  • rated by 0 users
  • This post has 1 Reply |
  • 1 Follower
Page 1 of 1 (2 items)
  •  

    I'm a self admitted software hack, so I'm sure this will sound dumb.   I need to send serial commands to my samsung display in hex.   When I use a hex com tool, it works.   When I use the following code, it doesn't.   What am I missing here?

    PS> $port= new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one
    PS> $port.open()
    PS> $port.WriteLine("0822000000012C")
    PS> $port.Close()

    The stuff in the WriteLine method is the hex string.

  •  

    Alright!    I got it!    (Just not with powershell, I had to use VB):

     

    Module Module1

    Sub Main()

    Dim xmtBuf() As Byte = {&H8, &H22, &H0, &H0, &H0, &H1, &HD5}

    Dim rcvBuf(1024) As Byte

    Dim Port1 As System.IO.Ports.SerialPort

    Port1 = New System.IO.Ports.SerialPort

    Port1.PortName = "COM1"

    Port1.BaudRate = 9600

    Port1.StopBits = IO.Ports.StopBits.One

    Port1.DataBits = 8

    Port1.Parity = IO.Ports.Parity.None

    Port1.Open()

    Port1.Write(xmtBuf, 0, xmtBuf.Length)

    Port1.Read(rcvBuf, 0, rcvBuf.Length)

    Port1.Close()

    End Sub

    End Module

     

Page 1 of 1 (2 items)