Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
Dim ByteToSend As Byte

       ByteToSend(0) = 49
       ByteToSend(1) = 48
       ByteToSend(3) = 48
and send this with a:
VB
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!
Posted

Maybe I'm missing something, but it looks like trivial.
VB
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.
 
Share this answer
 
Comments
glennPattonWork3 17-Feb-14 5:53am    
Thanks!, Griff beat you to it!
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:
VB
Dim ByteToSend(3) As Byte
So it is an array, rather than a single byte.
 
Share this answer
 
Comments
glennPattonWork3 17-Feb-14 5:54am    
Face + Palm, I was going by the book Serial Port Complete 2nd Ed by Jan Axelson on page 164 WriteByte is down as a command...
OriginalGriff 17-Feb-14 6:08am    
What? You believed a *book* over the internet? :laugh:
glennPattonWork3 17-Feb-14 6:11am    
Couldn't use the Net PC booting, however have got around issue I think!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900