problem to receive data from vb6

General discussion on mikroC.
Post Reply
Author
Message
LIHEBAT
Posts: 3
Joined: 12 Dec 2010 13:14

problem to receive data from vb6

#1 Post by LIHEBAT » 12 Dec 2010 14:39

can anyone help me in this code? i have problem receive data from vb6. this my vb6 code and microC code.

vb6 :

Private Sub Form_Load()
' Fire Rx Event Every single Bytes
MSComm1.RThreshold = 1

' When Inputting Data, Input 1 Byte at a time
MSComm1.InputLen = 1

' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "9600,N,8,1"
' Disable DTR
MSComm1.DTREnable = False

' Open COM3
MSComm1.CommPort = 3 'im choosing to open port 3 on my pc, u can chage it
MSComm1.PortOpen = True
End Sub


Private Sub Command6_Click() 'push button
Dim sDATA As String

MSComm1.Output = "SOH" 'based on what number/alphabetic u program inside ur PIC.

End Sub


microC :
void main(void)
{
Usart_Init(9600);

TRISB = 0;
PORTB = 0;
while (1){

if(Usart_Data_Ready()) { // If data is received
int i;
i = Usart_Read(); // Read the received data
if(i == 0){
PORTB = 255;
Delay_ms(10000);
}
}

}
}

Lord Lucan
Posts: 60
Joined: 09 Dec 2010 14:41

Re: problem to receive data from vb6

#2 Post by Lord Lucan » 13 Dec 2010 12:35

When you send "SOH" from VB the software will transmit 0x53, 0x4F, 0x48 on the RS232 line. In your PIC software you are testing if 'i' is equal to zero (0x00) which will never be true.

LIHEBAT
Posts: 3
Joined: 12 Dec 2010 13:14

Re: problem to receive data from vb6

#3 Post by LIHEBAT » 14 Dec 2010 21:27

bumpz~

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: problem to receive data from vb6

#4 Post by Sobrietytest » 17 Dec 2010 08:03

Your question has been answered; your PIC software will not do anything unless you send 0x00 (&H0) from your VB6 program. As Lord Lucan said, RS232 doesn't transmit characters as you see them, it sends the ASCII hexadecimal equivalent and you can look at these codes on the ASCII table built into your compiler.

Maybe you could explain what you are trying to do and exactly what the problem is?

A VB tip: you can use the 'With' keyword to simplify your MSComm initialisation...

Code: Select all

///////////  VB6 CODE  ////////////////

With MSComm1
            .CommPort = 3
            .Handshaking = 0
            .RThreshold = 1
            .RTSEnable = True
            .Settings = "9600,n,8,1"
            .SThreshold = 1
            .PortOpen = True
            
         End With



LIHEBAT
Posts: 3
Joined: 12 Dec 2010 13:14

Re: problem to receive data from vb6

#5 Post by LIHEBAT » 18 Dec 2010 07:48

can u give some simple code? like when click button at vb6, then led will turn on using pic16f877a. code pic using usart and code vb6. can u help me?

Post Reply

Return to “mikroC General”