Page 1 of 1

Send a single Byte to Serial Port

Posted: Mon Jan 09, 2017 10:36 pm
by europa81
after opening a serial port I would like to send a single byte over the port and reclose the port.
WriteSerialPortData only allows the use of @buffers. How do I manage a single byte with a defined value ?
Happy New Year

Re: Send a single Byte to Serial Port

Posted: Mon Jan 09, 2017 10:51 pm
by normeus
Poke the single byte to memory and send it:

Code: Select all

If OpenSerialPort(0, "COM1", 300, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
  *buffer=AllocateMemory(1)
   PokeB(*buffer,$20)              ; copying hex 20 to buffer 
   WriteSerialPortData(0, *Buffer, 1)
   CloseSerialPort(0)
   FreeMemory(*buffer)
   Debug "Success $20 to COM1"
  Else
    Debug "Failed"
  EndIf
Norm.

Re: Send a single Byte to Serial Port

Posted: Mon Jan 09, 2017 10:54 pm
by Wolfram
europa81 wrote:after opening a serial port I would like to send a single byte over the port and reclose the port.
WriteSerialPortData only allows the use of @buffers. How do I manage a single byte with a defined value ?
Happy New Year

Code: Select all

MyByte.a = $FF ;or what ever

WriteSerialPortData(MyPort, @MyByte, 1)