Connect to serial on OSX or com port on Windows?

Just starting out? Need help? Post your questions and find answers here.
stmdbe2019
User
User
Posts: 89
Joined: Mon Aug 31, 2009 2:11 pm

Connect to serial on OSX or com port on Windows?

Post by stmdbe2019 »

How to write it in PureBasic?

Python_serial.py:

Code: Select all

import serial
ser = serial.Serial('/dev/tty.usbserial', serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)

# 6 byte at a time
ser.write(b'\xA0h\xC1h\x01\x00h\x00h\xAFh')

# 1 byte at a time

for command in [b'0xA0h', b'0xC1h', b'0x01', b'0x00h', b'0x00h', b'0xAFh']:
    ser.write(command)

ser.close()
-----
Registered PureBasic Coder.
infratec
Always Here
Always Here
Posts: 6867
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Connect to serial on OSX or com port on Windows?

Post by infratec »

You really should read the help :!:

Code: Select all

ser = OpenSerialPort(#PB_Any, "/dev/tty.usbserial", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 128, 128)
If ser
  ; 6 byte at a time
  WriteSerialPortData(ser, ?CM1Start, ?CM1End - ?CM1Start)
  
  ;1 byte at a time
  For command = 0 To ?CM1End - ?CM1Start - 1
    WriteSerialPortData(ser, ?CM1Start + command, 1)
  Next command
  
  CloseSerialPort(ser)
EndIf

DataSection
  CM1Start:
  Data.a $A0, $C1, $01, $00, $00, $AF
  CM1End:
EndDataSection
stmdbe2019
User
User
Posts: 89
Joined: Mon Aug 31, 2009 2:11 pm

Re: Connect to serial on OSX or com port on Windows?

Post by stmdbe2019 »

Thanks a lot. You are Genius. PureBasic is like God power.
-----
Registered PureBasic Coder.
Post Reply