|
-
Apr 10th, 2007, 09:35 PM
#1
Thread Starter
New Member
send HEX to serial port
I am using 2005 and try to send commands (in HEX) to the serial port which is connected to my equipment.
I have tried several methods using e.g. ChrW(&HD1) and it won't work. It only works when it the command is placed inside an byte array. Any help will be much appreciated, thanks!
Private Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim chBuf(0), trans_curr As Byte
chBuf(0) = &HD1
trans_curr = &HD1
Try
serialPort.Write(chBuf, 0, 1) ' this works'
serialPort.Write(trans_curr) 'this does not works'
With txtDataReceived
.SelectionColor = Color.Black
.ScrollToCaret()
End With
txtDataToSend.Text = String.Empty
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
-
Apr 11th, 2007, 03:44 PM
#2
Re: send HEX to serial port
In the example, what is it you want to send? "D1" (which in serial bits would be 2 bytes - 0100 1000 and 0011 0001) or the value 209 (which, in serial bits would be 1101 0001)? Where, in the real program, are you getting the value(s) to send? How are you defining the variable that holds them (byte, string, some type of array)?
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 11th, 2007, 08:25 PM
#3
Thread Starter
New Member
Re: send HEX to serial port
Hi
I need to send a Byte to the hardware, it would be in HEX D1 i.e binary 11000001.
Both are defined as Byte. The command can be defined explicitly inside the program
Thanks!
-
Apr 13th, 2007, 02:53 PM
#4
Re: send HEX to serial port
You could send Chr$(209).
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|