DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

VB2008: Send 00h to FFh in one byte using SerialPort

By: rekha singh | 01 Apr 2010 12:08 pm

Hi peoples.

 
The User of my application will enter Hexa values in text boxes (00h to FFh). I need to send these values through the serial port, but so that each text box with values 00h to FFh ONLY generate a transmitted byte, exactly the value placed in the text box.
 
Just found examples of this application in VB6, using the following command:
 
MSComm1.Output = (Chr(Val(txtText1. Text)))
 
In VB2008, you use the component "SerialPort" , and one of the methods for transmitting data to the output buffer is "Write". So I did it this way:
 
Dim As Integer ValHex
 
ValHex = Val("& H" & txtInput.Text)
txtDecimal.Text = ValHex
SerialPort1. Write(Chr( Val(txtDecimal. Text)))
 
So it works, BUT ... if the User enters into txtInput values greater than 7Fh, SerialPort always send the value 3Fh to the buffer!
 
I need the SerialPort component simply transmit a byte with values from 0 to 255 (00h to FFh)! That's it!
 
It seems that the problem is the type of encoding (Encoding UTF7, UTF8, etc..) UTF7 because the table only goes up to 7Fh! But I can not change it!
 
Can anyone give a hint?
 

Comments

No Comments Posted for this Article.

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move