Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing RS232 buffer with MSComm

Status
Not open for further replies.

wingbar

New Member
Hi guys,
I face some problem on using MSComm ....
I want to send a byte of data to the RS232 buffer and the data
received is the Hex of the sent data. After trying for few times,
I get weird Hex numbers....
Is it my program problem or the hardware ??
the following is my program.....
Private Sub end_Click()
MSComm1.PortOpen = False
End
End Sub

Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub

Private Sub receive_Click()
Dim InByte() As Byte
Dim buf$, i%
InByte = MSComm1.Input
For i = LBound(InByte) To UBound(InByte)
buf = buf + Hex(InByte(i))
Next i
txt2.Text = buf
End Sub

Private Sub send_Click()
Dim a As Integer
Dim OutByte(1 To 1) As Byte
'For a = 1 To 100
OutByte(1) = &H1F
MSComm1.Output = OutByte
'Next a
End Sub
 
Try this code:
Code:
Private Sub end_Click() 
MSComm1.PortOpen = False 
End 
End Sub 

Private Sub Form_Load() 
MSComm1.PortOpen = True 
End Sub 

Private Sub receive_Click() 
Dim InByte As String
Dim i As Integer, buf as string
InByte = MSComm1.Input 
For i = 1 To Len(InByte) 
buf = buf & Hex(asc(mid(InByte,i,1)))
Next i
txt2.Text = buf 
End Sub 

Private Sub send_Click() 
Dim a As Integer 
Dim OutByte As string * 1
OutByte = Chr(&H1F)
MSComm1.Output = OutByte 
'Next a 
End Sub

Check your baud rates properly.
 
thanks ...
I am able to send and receive back my data through RS232 buffer but after i connect all my components, the only response i received back is FFhex when I send a byte of data from the range of 70hex to 79hex.
From the info i got, it said that to send data to the write buffer, I need to send 0X to 5X hex, where X represents the data I want to send while 0 to 5 represent each write buffer. And if I want to read back the data, I need to send 70,71 and 72 hex.
My question is, is it true that I need to send some specific codes to be able to read and write from the buffers ? If so, why ?
 
I am not sure I follow what you are saying.

To receive data on the serial port all you really need to do is use:

Code:
Private Sub MSComm1_OnComm()
 Dim InByte() As String
 Dim buf$, i% 
 InByte = MSComm1.Input 
 For i = LBound(InByte) To UBound(InByte) 
   buf = buf + Hex(InByte(i)) 
 Next i 
 txt2.Text = buf 
End Sub
Instead of having a button receive, when you click on it. Also all data you get is a string data...... You are sending and receiving ASCII characters. How you interpret them is upto you. You can make them the ASCII value by using the ASC(string) function, then if you like you can change that number to HEX if that is how you want to display it.

What are you trying to communicate with... or what is sending this 5X data?

Ivancho
 
wingbar said:
thanks ...
I am able to send and receive back my data through RS232 buffer but after i connect all my components, the only response i received back is FFhex when I send a byte of data from the range of 70hex to 79hex.
From the info i got, it said that to send data to the write buffer, I need to send 0X to 5X hex, where X represents the data I want to send while 0 to 5 represent each write buffer. And if I want to read back the data, I need to send 70,71 and 72 hex.
My question is, is it true that I need to send some specific codes to be able to read and write from the buffers ? If so, why ?
Are you working with some specific device?
 
Hi,
sorry for not writing my question clearly...
Actually I'm doing a chip tester project. my hardware is connected like this :
RS232 buffer <----> UART <----> Decoder <----> Buffer <----> Socket
-The decoder includes input address and data decoder, Buffer includes Write and Read buffer and the socket I use is the ZIF socket.
From the info I got, I need to send some hex numbers to write my data in the appropriate write buffer while to read the tested result from the read buffer, I need to send 70 to 71Hex.
So, I'm wondering if it is because of the IC of the buffers?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top