Ollie Sharratt
Ollie Sharratt

Reputation: 95

Usage of Pyserial and Pexpect in Windows

I have a script which functions perfectly in Ubuntu, however my desire is to get this working on a Windows machine for use in a Production environment. The general purpose of this script is to program a PCB.

I am having issues both researching and adapting this section of the code:

try: 
  fd = serial.Serial(Port, Baud) #Opens the specified port
  child = pexpect.fdpexpect.fdspawn(fd, timeout=180)
except:
  input('There has been an error making the connection, check your connections and try again\nPress enter to exit')
  sys.exit()
input('Press enter to continue, then apply 24V power to the unit')

The issue being with:

child = pexpect.fdpexpect.fdspawn(fd, timeout=180)

Any advice or modifications are much appreciated!

Upvotes: 2

Views: 1901

Answers (1)

Pedro Borges
Pedro Borges

Reputation: 1270

There seems to be some differences for Windows. PySerial does not have fileno on it.

Based on this github issue you could try using something like this:

import os
import pexpect.fdpexpect
port = "COM5"
reader = pexpect.fdpexpect.fdspawn(os.open(port, os.O_RDWR))

Upvotes: 2

Related Questions