Purebasic Serial Port Example

  • 1 Comments!

PureBasic - SerialPort. The Serial port (also know as the RS-232 port) was first created in 1969, and despite its age, it is still widely used in the industry.

OpenSerialPort OpenSerialPort() Syntax Result = OpenSerialPort(#SerialPort, SerialPortName$, Bauds, Parity, Data, Stop.f, HandshakeMode, InputBufferSize, OutputBufferSize) Description Opens a serial port for use. Parameters #SerialPort A number to identify the new serial port. Can be used to auto-generate this number. SerialPortName$ Text identifier for the serial port, for example 'COM1' on Windows or '/dev/ttyS0' on Linux. Bauds Defines the speed of the serial connection and can be one of the following values: 50, 75, 110, 150, 300, 600, 1200, 1800, 2400 4800, 9600, 19200, 38400, 57600 or 115200 Parity Defines how the parity will be handled on the connection. It can be one of the following values: #PB_SerialPort_NoParity: No parity #PB_SerialPort_EvenParity: Even parity #PB_SerialPort_MarkParity: Mark parity #PB_SerialPort_OddParity: Odd parity #PB_SerialPort_SpaceParity: Space parity Data Defines the data length, in byte (usually 7 or 8).

Stop Sets the number of stop bits (1, 1.5 or 2). HandshakeMode The handshake mode.

It can be one of the following values: #PB_SerialPort_NoHandshake: No handshaking #PB_SerialPort_RtsHandshake: No handshaking but RTS is set to 1 #PB_SerialPort_RtsCtsHandshake: RTS/CTS #PB_SerialPort_XonXoffHandshake: Xon/Xoff InputBufferSize Defines the size of the input buffer, in bytes. OutputBufferSize Defines the size of the output buffer, in bytes.

Return value Nonzero if the serial port was successfully opened, zero otherwise (it may be already in use, or the parameters are wrong). If #PB_Any was used for the #SerialPort parameter then the generated number is returned on success. Example If OpenSerialPort(0, 'COM1', 300, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024) Debug 'Success' Else Debug 'Failed' EndIf See Also Supported OS All.

Define Com.i, Int1.l, Int2.l, Recv.l, Ptr.i Com = OpenSerialPort(#PB_Any, 'COM7', 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 256, 256) If Com Int1 = 123 Int2 = 456 WriteSerialPortData(Com, @Int1, SizeOf(Long)) WriteSerialPortData(Com, @Int2, SizeOf(Long)) Repeat While AvailableSerialPortInput(Com) ReadSerialPortData(Com, @Recv + Ptr, 1) Ptr + 1 Wend Until Ptr = 4 Debug Recv CloseSerialPort(Com) EndIf Maybe a byte swap is needed. I don't know the endianess of the Arduino.

Download your desired books • 3. Register for FREE 1st month. Easy to cancel your membership. Electronics 2nd edition hambley pdf files download. Joint with more than 80.000 Happy Readers. Recommended Books• • • • • • • • • • Note: We cannot guarantee that every book is in the library.