bckcookie
Newbie level 1
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
#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