Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6703271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:09:06+00:00 2026-05-26T07:09:06+00:00

I’m using pyserial to open two ports, and then write to each what I

  • 0

I’m using pyserial to open two ports, and then write to each what I read from the other. I then have a physical com port connected to one of these ports and a virtual com port connected to the other. The virtual com port is in turn connected to a second virtual com port to which my simulator connects:

Hardware device <> COM1 <> Python Script <> VCOM2 <> VCOM3 <> Simulator

I can see that the communication is correctly entering and exiting the com ports in my script but something isn’t right since the the hardware is failing to communicate correctly with the simulator.

I have an old c app that I can run in place of the Python Script and this works correctly. However, it is really badly written and I’ve no real interest in fixing all its bugs. So I’m hoping I can replace this app with a python script. I eventually wish to log the data passing through the ports with a timestamp.

I am using the correct baud rate in both cases, however I seem to be missing something. Should I be transferring signals between each port, DTR for example? pyserial has these functions:

sendBreak(duration=0.25)
setBreak(level=True)
setRTS(level=True)
setDTR(level=True)
getCTS()
getDSR()
getRI()
getCD()

What signals am I interested in?

EDIT:

When I poll these values for each port:

getCTS(), getDSR(), getRI(), getCD()

I Get:
True, False, False, True COM1
False, False, False, False VCOM2

However, I see that CD becomes false sometimes. How do I transfer this out through VCOM2 or do I need to do this?

EDIT:

Here’s my code. Once communication starts the script locks up and I need to restart my computer to release the port. I can’t kill the associated python process on Windows 7…

import serial

class NewMonitor():
    def __init__(self, com_port_1, com_port_2):
        self.read_time_in_seconds = 0.1
        self.serialPort1 = serial.Serial(com_port_1, 9600, timeout=self.read_time_in_seconds, rtscts=True, dsrdtr=True)
        self.serialPort2 = serial.Serial(com_port_2, 9600, timeout=self.read_time_in_seconds, rtscts=True, dsrdtr=True)

        try:
            while True:
                item = self.serialPort1.read()
                self.serialPort2.write(item)
                self.serialPort2.setRTS(self.serialPort1.getCTS())
                self.serialPort2.setDTR(self.serialPort1.getDSR())


                item = self.serialPort2.read()
                self.serialPort1.write(item)
                self.serialPort1.setRTS(self.serialPort2.getCTS())
                self.serialPort1.setDTR(self.serialPort2.getDSR())
        finally:
                self.serialPort1.close()
                self.serialPort2.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:09:06+00:00Added an answer on May 26, 2026 at 7:09 am

    you cannot ignore the signals, especially if you use HW based flow-control. I assume that you at least have to link the following signals between both ports besides RX(read) and TX(write)

    CTS -> RTS
    DSR -> DTR
    

    Comments about your code:

    1. You defined a timeout, this means the IO function will block (even if it is only for a short amount of time). Consider setting it to 0

    2. You call read without parameter. This will only read a single byte. Any reason why you do not want to read more at once? Would reduce the overhead.

    3. Consider adding a condition to exit the while loop. At the moment the code will run until pyserial throws an exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.