如何让VB.Net使用WriteByte() [英] How do I get VB.Net to use WriteByte()

查看:84
本文介绍了如何让VB.Net使用WriteByte()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

周一早上再次混乱!在VB.Net(VS 2008)中是否支持WriteByte? MSDN说是的,

Jan Axelson的Serial Port-to-book Serial Port Complete 2nd Ed说是,但是IDE报告WriteByte不是'System.IO.Ports.SerialPort'的成员。我可以这样做的一种方法是

将Ascii字符转换为等效小数,然后通过Com端口发送它们,如下所示



  Dim  ByteToSend  As  字节 

ByteToSend( 0 )= 49
ByteToSend( 1 )= 48
ByteToSend( 3 )= 48

并发送以下内容:

 myComPort.Write(ByteToSend, 0  3 



然而,这会产生以下错误

表达式不是数组或方法,也不能有参数列表。


嗯?我想要做的是将100发送到串口上的设备,该设备似乎不会响应Write / WriteLine。 Aggah!

解决方案

不,它没有!

SerialPort类中没有WriteByte方法: http://msdn.microsoft.com/en-us/library/System .IO.Ports.SerialPort_methods(v = vs.110).aspx [ ^ ]

有一个Write方法接受一个字节数组,但是没有发送单字节值的具体方法。



你需要做的是修改ByteToSend的声明:

  Dim  ByteToSend( 3  As  字节 

所以它是一个数组,而不是一个字节。


也许我是遗失了什么,但看起来喜欢琐碎。

  Dim  ByteToSend  As       字节   3   
ByteToSend( 0 )= 49
ByteToSend( 1 )= 48
ByteToSend( 2 )= 48
myComPort.Write(ByteToSend, 0 3



或者这些只是打字错误而且我完全偏离了主题。

无论如何,希望这会有所帮助。


Hi There,
Monday morning confusion again! In VB.Net (VS 2008) is WriteByte supported? MSDN says Yes,
The Serial Port go-to book Serial Port Complete 2nd Ed by Jan Axelson says Yes, but the IDE reports WriteByte is not a member of 'System.IO.Ports.SerialPort'. One way I can do it is
to convert the Ascii chars to there equivalent decimal and send them via a Com port write like the following

Dim ByteToSend As Byte

       ByteToSend(0) = 49
       ByteToSend(1) = 48
       ByteToSend(3) = 48

and send this with a:

myComPort.Write(ByteToSend, 0, 3) 


This however generates the following error

Expression is not an array or a method, and cannot have an argument list.


Huh? What I am trying to do is send "100" to a device on a serial port that wont seem to respond to a Write/WriteLine. Aggah!

解决方案

No, it doesn't!
There is no WriteByte method in the SerialPort class: http://msdn.microsoft.com/en-us/library/System.IO.Ports.SerialPort_methods(v=vs.110).aspx[^]
There is a Write method that accepts an array of bytes, but there is no specific method to send a single byte value.

What you need to do is modify the declaration of ByteToSend:

Dim ByteToSend(3) As Byte

So it is an array, rather than a single byte.


Maybe I'm missing something, but it looks like trivial.

Dim ByteToSend As New Byte(3)
ByteToSend(0) = 49
ByteToSend(1) = 48
ByteToSend(2) = 48
myComPort.Write(ByteToSend, 0, 3)


Or these were just typos and I'm completely off-subject.
Anyway, hope this helps.


这篇关于如何让VB.Net使用WriteByte()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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