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 9134511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:40:28+00:00 2026-06-17T08:40:28+00:00

I am trying to get a python script to write to a serial port

  • 0

I am trying to get a python script to write to a serial port with pyserial, to node.js using serialport2.

I am very confused about bytes() in python, wonder can anyone give me a hand?

python:

ser.write(bytes(chr(160))
ser.write(bytes(chr(157))

so how do I do this in node.js?

serialport2 used in node.js is located here.

  • 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-06-17T08:40:29+00:00Added an answer on June 17, 2026 at 8:40 am

    From the node-serialport2 readme:

    write(buffer, [callback])

    Writes data to the serial port.

    Arguments

    • buffer – This can be a node Buffer object or a string.
    • callback(err, byteWritten) – Callback called after writing bytes.

    So, you can give a string object or Buffer object as the argument. A Buffer object will probably do what you want (send integer values):

    var buffer = new Buffer([ 8, 6, 7, 5, 3, 0, 9]);

    This initializes the buffer to the contents of this array. Keep in mind that the contents
    of the array are integers representing bytes.

    For your data, it would be:

    var buffer = new Buffer([160, 157]);
    

    By the way, you don’t need to do any special casting in Python with PySerial. From the PySerial API documentation:

    write(data)

    • Parameters: data – Data to send.
    • Returns: Number of bytes written.
    • Raises SerialTimeoutException: In case a write timeout is configured for the port and the time is exceeded.

    Write the string data to the port.

    Changed in version 2.5: Accepts instances of bytes and bytearray when
    available (Python 2.6 and newer) and str otherwise.

    Note the “changed in version 2.5” note.

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

Sidebar

Related Questions

I'm trying to write a notification script using python-dbus. How can I get properties
Im trying to write a python script using the pexpect library. What im trying
I am trying to write a VERY simple UI in Python using Tkinter. I
I'm trying to write a small Python script that will get query results from
I'm trying to write a Python script that will get the md5sum of all
Hey brilliant minds out there, I'm trying to get this Python script that I
I am just trying to get into python, but I've found it very difficult
I'm trying to write a simple Python script that inserts .odt documents into an
I'm trying to write a Python script to test the output of some various
I'm trying to write a Python script which takes a special type of file

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.