Problem in VB6.0 via RS232 from 8051 MCU to PC

Status
Not open for further replies.

bckcookie

Newbie level 1
Joined
May 7, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,301
Sensor signal via RS232 from 8051 MCU to PC! But it doesnt work to appear on VB6.0. It's ok for MCU hardware & RS232 port. I think the com port setting codes have something wrong in VB.


#include<REGX52.H>
#include<STDIO.H>

main()

{
TMOD = 0X20;
TH1 = 230;
TL1 = 230;
TR1 = 1;

SCON = 0X52; //0X70;

while(1)
{

RI = 0;
TI = 0;
SBUF = P1 | 0Xf0;
while(TI==0);


if(SBUF==0xfe)
P2=0x3e;

else if(SBUF==0xfd)
P2=0x3d;


else if(SBUF==0xfb)
P2= 0xfb;

else if(SBUF==0xf7)
P2= 0xf7;
}

}


Please advise me what's problem in VB6.0 the following code:

Private Sub Form_Load()
On Error Resume Next
LOAD1.FillColor = RGB(0, 255, 0)
LOAD2.FillColor = RGB(0, 255, 0)
LOAD3.FillColor = RGB(0, 255, 0)
LOAD4.FillColor = RGB(0, 255, 0)
MSComm1(0).PortOpen = False
MSComm1(0).CommPort = 1
MSComm1(0).PortOpen = True
If MSComm1(0).PortOpen = True Then
MSComm1(0).PortOpen = False
MSComm1(0).CommPort = 1
MSComm1(0).Settings = "1200,n,8,1"
MSComm1(0).PortOpen = True
tex1.Text = "COM1"
Else
MSComm1(0).PortOpen = False
MSComm1(0).CommPort = 2
MSComm1(0).PortOpen = True
If MSComm1(0).PortOpen = True Then
MSComm1(0).PortOpen = False
MSComm1(0).CommPort = 2
MSComm1(0).Settings = "1200,n,8,1"
MSComm1(0).PortOpen = True
tex1.Text = "COM2"
Else
MSComm1(0).PortOpen = False
tex1.Text = "FAILED"
End If
End If
End Sub

Private Sub MSComm1_OnComm1()
Dim InByte As Byte


Select Case MSComm1(0).CommEvent
Case comEvReceive

If MSComm1(0).InBufferCount > 0 Then
InByte = MSComm1(0).Input

If InByte = &HFD Then
End If

End Select

End If
End Sub


Private Sub START_Click()

MSComm1(0).Input = "11111110"
delayms 100
If InByte = "0" Then
LOAD1.FillColor = RGB(0, 255, 0)
ElseIf InByte = "1" Then
LOAD1.FillColor = RGB(255, 0, 0)
Text0(0).Text = Text0(0).Text + "GasSensor-" + Format(Now, "DD.MMM.YYYY.HH:MM:SS") + vbNewLine
End If


MSComm1(0).Input = "11111101"
delayms 100
If InByte = "0" Then
LOAD2.FillColor = RGB(0, 255, 0)
ElseIf InByte = "1" Then
LOAD2.FillColor = RGB(255, 0, 0)
Text0(0).Text = Text0(0).Text + "FireSensor-" + Format(Now, "DD.MMM.YYYY.HH:MM:SS") + vbNewLine
End If
 

I haven't read through your code thoroughly, but here's one thing I've noticed.

bckcookie said:
MSComm1(0).Input = "11111101"
MSDN said:
Input Property. Returns and removes a stream of data from the receive buffer. This property is not available at design time and is read-only at run time. https://msdn.microsoft.com/en-us/library/aa259416.aspx
Assigning a value to the Input property of MSComm should cause a run-time error. This property is read-only. If you want MSComm to transmit, use Output property.

Added after 2 minutes:

P.S. I've noticed that this is your first post. In the future, use the
Code:
 tags, which will format the code in a more readable way.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…