Send a single Byte to Serial Port

Just starting out? Need help? Post your questions and find answers here.
europa81
User
User
Posts: 24
Joined: Tue Oct 20, 2015 11:42 pm
Location: Southern Germany

Send a single Byte to Serial Port

Post 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
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Send a single Byte to Serial Port

Post 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.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: Send a single Byte to Serial Port

Post 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)
macOS Catalina 10.15.7
Post Reply