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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:56:20+00:00 2026-06-14T11:56:20+00:00

I have a usb device that is supposed to send a number when queried.

  • 0

I have a usb device that is supposed to send a number when queried.

The instructions I have are:

  1. Connect the USB port to a PC and then open the virtual serial port at 9600 baud, 8 data bits, no parity, 1 stop bit.
  2. Send ESC (I think it’s char 27)
  3. You’ll get “>” as an acknowledgement
  4. Send “c” and you will get the count followed by “<“

I have looked everywhere and must not be understanding what I am reading because I cannot figure out how to get a response from the unit.

  1. Am I sending the “ESC” key properly?
  2. Am I querying a response properly?
  3. Am I displaying an assumed response properly?
  4. Is libusb something I need to research? I assumed it was a library for earlier versions of .NET.

Thanks in advance.

Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace SerialPortTest
{
public partial class Form1 : Form
{
    System.IO.Ports.SerialPort counter = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
    public Form1()
    {
        InitializeComponent();
    }

    private void btnWrite_Click_1(object sender, EventArgs e)
    {
        // Get a list of serial port names. 
        string[] ports = System.IO.Ports.SerialPort.GetPortNames();

        lblOut.Text = ("The following serial ports were found:");

        // Display each port name to the console. 
        txtOut.Clear();
        foreach (string port in ports)
        {
            txtOut.Text = (port);
        }
    }

    private void Form1_KeyDown_1(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.A)
        {
            //configuring the serial port
            //serialPort1.PortName = "COM5";
            //serialPort1.BaudRate = 9600;
            //serialPort1.DataBits = 8;
            //serialPort1.Parity = Parity.None;
            //serialPort1.StopBits = StopBits.One;

            //Open the serial port
            serialPort1.Open();

            //Write data to serial port
            serialPort1.Write(Keys.Escape.ToString());

            //Read data from serial port
            //string[] number;
            //counter.DataReceived += counter.ReadExisting();
            //counter.ReadLine();
            //new SerialDataReceivedEventHandler(counter_DataReceived);
            txtOut.Text = counter.ReadLine();

            //Close the serial port
            serialPort1.Close();
        }
    }

    //private static SerialDataReceivedEventHandler counter_DataReceived(object sender, SerialDataReceivedEventArgs e)
    //{
    //    //throw new NotImplementedException();
    //    SerialPort sp = (SerialPort)sender;
    //    string indata = sp.ReadExisting();
    //    return (sp.ReadExisting());
    //}
}

}

  • 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-14T11:56:21+00:00Added an answer on June 14, 2026 at 11:56 am

    counter.ReadLine() will only return when a newline character is read, which according to the specifications given by you will never happen.

    After the first input, you expect one byte of output back, so you should read one byte. Then you need to send a c, after which you’ll have to read until you encounter an <.

    So something like this should work:

    SerialPort serialPort = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
    
    var esc = new byte { 27 };
    var c = new byte { 99 };
    
    serialPort.Write(esc, 0, 1);
    
    serialPort.ReadTo(">"); // Or ReadByte() and check if the byte read has a value of 62
    
    serialPort.Write(c, 0, 1);
    
    string data = serialPort.ReadTo("<");
    

    Then you can parse the data string to whatever format you expect it to be.

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

Sidebar

Related Questions

I have a USB device I'm trying to communicate with over a virtual serial
Background information: I presently have a hardware device that connects to the USB port.
I have a .sh script that automounts any usb device that is plugged in.
Is it possible to use a USB device peripheral that I have created directly
I have an exceedingly simple USB device. There is no driver provided and instructions
I have a USB device that I need to be able to talk to
I have a device that connects to pc via USB, which gets mapped to
I have developed a USB device that communicates with linux over a simple but
I have device that is a USB HID Human Interface that sends keycodes to
I have a USB device that can move along a linear axis, stop at

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.