How to implement serial programming in PB

zhaozj2021-02-16  47

You can use MSComm32.ocx controls

The script is as follows:

String ls_data

// Use the COM1 port.

OLE_1.Object.commport = 1

// Set the rate of 9600, no parity, 8-bit data, a stop bit.

OLE_1.Object.Settings = "9600, N, 8, 1"

// Read the data of the entire buffer.

OLE_1.Object.inputlen = 0

Open port

OLE_1.Object.Portopen = TRUE

// Send an attention command

OLE_1.Object.Output = "ATV1Q0" char (13)

// Wait for data.

DO

Yield ()

/ / Data from the COM port

LS_DATA = OLE_1.Object.input

LOOP Until (POS (LS_Data, "OK" char (13) char (10))> 0)

/ / Send data to the COM port to use Output method

OLE_1.Object.output = ls_data

// Turn off the port.

OLE_1.Object.Portopen = FALSE

转载请注明原文地址:https://www.9cbs.com/read-26074.html

New Post(0)