borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (Run Embeded exe) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Sending Hex on serial port
Poster Message
ajayzone
Level: Trainee

Registered: 16-06-2007
Posts: 3

icon Sending Hex on serial port

I want to send Hex code over the serial port how can i go about doing that  

i want to send a string which looks like 02-03-64-60-28-03 in hex.

i have used characters to give output on comport but i don`t know how to put these hex values.

thanks
ajay  

____________________________
new guy

16-06-2007 at 07:05 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151
icon Re: Sending Hex on serial port

hi thhere

Tho i haven't tried this, but i think this shud work:

Mscomm1.output = HEX(02) & HEX(03) & HEX(64) ...

Assuming that the digits u mentioned are in decimal...
Pls tell me if it works, i might have a use of this thing in the future...

Regards

____________________________
lOsT...

11-07-2007 at 05:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
TheGoat
Level: Trainee

Registered: 13-12-2007
Posts: 1
icon Re: Sending Hex on serial port

I know this thread is a bit old but just to avoid any misunderstanding.....

Hexadecimal (Hex) is a notation, not a data type.
ie Hex is a representation of an 8 bit binary value in Base 16.

For example, suppose you've got one of those TVs that you can connect to your serial port and control it from your computer. Let's also assume that in the Manual, it states that to turn it on you have to send it the following (Hexadecimal) codes: 02 03 64 60 28 03

In other words you have to send the following binary data:

0000 0010 (02)
0000 0011 (03)
0110 0100 (64)
0110 0000 (60)
0010 1000 (28)
0000 0011 (03)

There are 2 ways you can do this, either by using the Character representation of the binary value:

Dim strCommand As String
strCommand = Chr$(&H2) & Chr$(&H3) & Chr$(&H64) & Chr$(&H60) & Chr$(&H28) & Chr$(&H3)
MSComm1.Output = strCommand


or you could use a Byte Array:


Dim bytCommand(5) As Byte
bytCommand(0) = &H02
bytCommand(1) = &H03
bytCommand(2) = &H64
bytCommand(3) = &H60
bytCommand(4) = &H28
bytCommand(5) = &H03
MSComm1.Output = bytCommand

Note the difference between Hex() and &H.
Hex(255) will return the characters "FF" ie 2 bytes which will be:

0100 0110 0100 0110 (hex 46 46)

&H(FF) will return one byte, which will be:

1111 1111 (hex FF)

So, if you want to send Hex FF you'd use &HFF not Hex(255)


[Edited by TheGoat on 14-12-2007 at 06:10 AM GMT]

14-12-2007 at 06:02 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Sending Hex on serial port
Next Topic (Run Embeded exe) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder