如何从USB端口检索数据? [英] How can I retrieve data from usb port?

查看:64
本文介绍了如何从USB端口检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从我的硬​​币接收器接收任何数据。该程序可以识别我的外围设备的COM端口。我检查了奇偶校验,数据位等,但它仍然无法正常工作。请帮帮我。



我的尝试:



进口系统

导入System.IO.Ports'访问SerialPort对象



模块SerialCommRead

Sub Main()

Dim MyCOMPort As SerialPort

Dim PortName As String

Dim BaudRate As Integer

Dim DataReceived As String

Dim AvailablePorts()As String = SerialPort.GetPortNames()

Console.WriteLine(Available Ports ::)

Dim Port As String

每个端口在AvailablePorts

Console.WriteLine(端口)

下一个端口

Console.WriteLine()

Console.WriteLine(输入您的端口 - >)

PortName = Console.ReadLine()

Console.WriteLine(输入波特率 - >)

BaudRate = Convert.ToInt32(Console.ReadLine())

MyCOMPort =新的SerialPort()

MyCOMPort.PortName = PortName

MyCOMPort.BaudRate = BaudRate

MyCOMPort。奇偶校验= Parity.None

MyCOMPort.DataBits = 8

MyCOMPort.StopBits = StopBits.One

MyCOMPort.Open()

Console.WriteLine(等待接收数据)

DataReceived = MyCOMPort.ReadLine()

MyCOMPort.Close()

Console.WriteLine()

Console.WriteLine(收到数据 - > {0},DataReceived)

Console.WriteLine(+ ----------------------------- ---------------- +)

Console.ReadLine()

结束子



结束模块

i can't receive any data from my coin acceptor. this program can identify the com port of my peripheral device. i checked the parity, data bits, etc but it cannot still work. please help me.

What I have tried:

Imports System
Imports System.IO.Ports 'To Access the SerialPort Object

Module SerialCommRead
Sub Main()
Dim MyCOMPort As SerialPort
Dim PortName As String
Dim BaudRate As Integer
Dim DataReceived As String
Dim AvailablePorts() As String = SerialPort.GetPortNames()
Console.WriteLine("Available Ports ::")
Dim Port As String
For Each Port In AvailablePorts
Console.WriteLine(Port)
Next Port
Console.WriteLine()
Console.WriteLine("Enter Your Port ->")
PortName = Console.ReadLine()
Console.WriteLine("Enter Baudrate ->")
BaudRate = Convert.ToInt32(Console.ReadLine())
MyCOMPort = New SerialPort()
MyCOMPort.PortName = PortName
MyCOMPort.BaudRate = BaudRate
MyCOMPort.Parity = Parity.None
MyCOMPort.DataBits = 8
MyCOMPort.StopBits = StopBits.One
MyCOMPort.Open()
Console.WriteLine("Waiting for Data to be Received")
DataReceived = MyCOMPort.ReadLine()
MyCOMPort.Close()
Console.WriteLine()
Console.WriteLine("Data received -> {0}", DataReceived)
Console.WriteLine("+---------------------------------------------+")
Console.ReadLine()
End Sub

End Module

推荐答案

Quote:

i无法从我的硬​​币接收器接收任何数据。

i can't receive any data from my coin acceptor.



串口很慢,你必须等待接收数据。

串口通讯是一种特殊的域,最好是找到一个教程来了解它是如何工作的。

你没有收到数据的另一个原因是你可能需要向请求数据的设备发送一个命令。阅读设备文档,可能会在制造商网站上获取一些代码示例。


Serial port is slow, you have to wait to receive data.
Serial port communication is a special domain, the best is to find a tutorial to learn how it works.
Another reason you don't receive data is that it is possible that you need to send a command to the device requesting the data. Read device documentation and may be get some code sample at maker site.


这篇关于如何从USB端口检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆