Search code examples
powershellserial-portbarcode-scannerserial-communicationcom-port

How to send/write serial command to Honeywell 1300g scanner on virtual com port?


I've been trying to interface with a scanner connected via USB on a virtual com port in order to trigger it with a serial command. I am restricted to using Powershell due to the nature of the environment (work computer, no access to other applications or even allowed to run.ps1 scripts). I am able to create/open a port, set some parameters and receive data from the scanner however it seems like no matter what command I send via $port.Write(command), nothing ever happens. I do have the right COM port, the right matching baud rates. According to the user guide the command to trigger is SYNTCR or 0x16 0x54 0x0d, but I just cannot figure out how to correctly format it. So far this is what I type into the console:

$port = New-Object System.IO.Ports.SerialPort COM3, 38400, None, 8, one
$port.DTREnable = $True
$port.RTSEnable = $True

$port.Open()

$port.Write(command)

$port.ReadExisting()

$port.Close()

I've tried all the following combinations of commands to send to the port with no success:

  • port.WriteLine("\x16\T")
  • .WriteLine("\x16T")
  • .WriteLine("x16T")
  • .Write("\x16\x54\x0d")
  • .Write('\x16\x54\x0d')
  • .Write("x16 x54 x0d")
  • .Write("x16,x54,x0d")
  • .Write("\x16M\x0d\x16T\x0d")
  • .Write('\x16M\x0d\x16T\x0d')
  • .Write("\x16T\x0d")
  • .Write("\x16T\r\n")
  • .Write("\x16T\r")
  • .Write("\x16t\r")
  • .Write("53,59,4e,54,43,52")
  • .Write("0x53 0x59 0x4e 0x54 0x43 0x52")
  • .Write("53 59 4e 54 43 52")

Here's an image showing more information regarding the $port from Powershell: https://i.sstatic.net/3Aje4.png


Solution

  • To send the three bytes 0x16 0x54 0x0d try sending:

    [char]22+[char]84+[char]13