Home > Software engineering >  How do the MSComm control, instrumentation offline, please?
How do the MSComm control, instrumentation offline, please?

Time:09-23

I use MSComm control to read the real-time temperature of the temperature controller, read the normal now, but there is a problem, is the sample to detect instrument offline,

CodePudding user response:

Read data "no response", or send request information instrument, instrument with no response, is it not said "instrument offline"?

CodePudding user response:

Want to think so, but don't know how to achieve it? Is read MSComm1. Input? Can write code? thank you

CodePudding user response:

reference 1st floor Chen8013 response:
"no response" to read data, or send request information instrument, instrument response, is it not said "instrument offline"?


Want to think so, but don't know how to achieve it? Is read MSComm1. Input? Can write code? thank you

CodePudding user response:

Using the Timer controls the auxiliary judgment whether overtime no response,

CodePudding user response:

reference 4 floor zhao4zhong1 response:
using the Timer controls the auxiliary judgment whether overtime no response,


Can not give a reference code?

INByte=MSComm1. Input,,, I wanted to read MSComm1. Input, if is empty it is offline, but write wrong,

CodePudding user response:

There can be multiple solutions,

Assumes you are using the event-driven scheme, i.e., processing data reception in the OnComm event, then you can constantly reset Timer here,

If the Timer event occurs, that means the thermostat to send data over the scheduled events,

You can set the Timer timeout happened n times in a row to confirm the device is offline,

CodePudding user response:

refer to 6th floor of123 response:
can have a variety of solutions,

Assumes you are using the event-driven scheme, i.e., processing data reception in the OnComm event, then you can constantly reset Timer here,

If the Timer event occurs, that means the thermostat to send data over the scheduled events,

You can set the Timer timeout happened n times in a row to confirm the device is offline,

VB6 really great god appeared, I will step down,

CodePudding user response:

refer to 6th floor of123 response:
can have a variety of solutions,

Assumes you are using the event-driven scheme, i.e., processing data reception in the OnComm event, then you can constantly reset Timer here,

If the Timer event occurs, that means the thermostat to send data over the scheduled events,

You can set the Timer timeout happened n times in a row to confirm the device is offline,



 Private Sub Timer1_Timer () '300 ms regularly send command reads the real-time temperature 
Dim tbisend (7) As Byte
Dim CRC
Dim btLoCRC As Byte, btHiCRC As Byte
Dim Buf As String

If MSComm1. PortOpen=True Then
Tbisend (0)="& amp; H "+ Hex (Val (1)) address
'Tbisend (1)="& amp; H "+ Hex (Val) (3) 'function code 03 to read, 06 to write
Tbisend (2)="& amp; H "+ Hex (Val (16)) 'high starting address
Tbisend (3)="& amp; H "+ Hex (Val (1)) 'starting address low
Tbisend (4)="& amp; H "+ Hex (Val (0))
'register number highTbisend (5)="& amp; H "+ Hex (Val (1)) 'low register number
CRC=CRC16 (tbisend, 6, btLoCRC btHiCRC)
Tbisend (6)="& amp; H "+ (btLoCRC) 'CRC high
Tbisend (7)="& amp; H "+ (btHiCRC) 'CRC low

MSComm1. Send data Output=tbisend '

Timer2. Enabled=True 'open offline test
End the If

End Sub
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Private Sub MSComm1_OnComm ()
Dim INByte () As Byte
Dim Buf As String
Dim btLoCRC As Byte, btHiCRC As Byte
'Dim Data As an Integer

If MSComm1.Com mEvent=comEvReceive Then 'receives the data & lt; ComEvReceive: receiving events & gt;
INByte=MSComm1. Input
If INByte (1)=3 Then 'register
Data=https://bbs.csdn.net/topics/Hex (INByte (3)) + Hex (INByte (4)) 'read hexadecimal third, fourth byte, it combined with
Buf=CLng (" & amp; H "& amp; Data)/10 'reads the hexadecimal conversion for decimal, because real is 10 times greater than reading values, so divided by 10
Buf=Format (Buf, "# # # 0.0")
Label20. Caption=Buf + "℃
"Timer2. Enabled=False 'data reception, close the offline test
'End If
'MsgBox "CRC checksum error"
End the If

MSComm1. InBufferCount=0 'clear the cache, it must be before the last END IF
End the If

End Sub

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Private Sub Timer2_Timer () 'offline tip
Dim ind As Integer
Ind.=MSComm1 InBufferCount
If the ind & lt; 1 when the receive buffer is less than 1, Then 'prompt offline
Label20. Caption="TIME OUT"
End the If
End Sub



Can display to offline when do most, but is not accurate,

CodePudding user response:

refer to the eighth floor qq_34952996 response:
...

Private Sub Timer1_Timer () '300 ms regularly send command reads the real-time temperature
Dim tbisend (7) As Byte
Dim CRC
Dim btLoCRC As Byte, btHiCRC As Byte
Dim Buf As String

If MSComm1. PortOpen=True Then
tbisend (0)="& amp; H "+ Hex (Val (1)),
'addressTbisend (1)="& amp; H "+ Hex (Val) (3) 'function code 03 to read, 06 to write
Tbisend (2)="& amp; H "+ Hex (Val (16)) 'high starting address
.

Can write such code, visible levels have dishes to what extent...

CodePudding user response:

references 9 f Chen8013 response:
Quote: refer to the eighth floor qq_34952996 response:

.

Private Sub Timer1_Timer () '300 ms regularly send command reads the real-time temperature
Dim tbisend (7) As Byte
Dim CRC
Dim btLoCRC As Byte, btHiCRC As Byte
Dim Buf As String

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related