Home > Software engineering >  Novice consult
Novice consult

Time:09-22

I want to read XMT808 -s meter data, communications protocol RS485 serial port, send data using the acsi code, data frame format: A/address/symbol/display data; Send data one-time send outside the field data frame way, data head is: "A", then to address, symbols and data real-time display values, such as the instrument shows 2.000, instrument address set to 1, the instrument to send data frames for "A1 + 2.000". Set the address reply delivery mode, send address 1 PC to the instrument, must be in A natural code 1 to send, can't to 1 ASCI code sent to,

I have attached some hardware, COM3, 4800 baud rate, address 1,

What in a serial port debug serial port to send data, instrument to reply?

CodePudding user response:

With the example of the code, debugging,

CodePudding user response:

 Private Sub Command1_Click () 
MSComm1. The Output=CRH (& amp; H1)
End Sub

Private Sub Command2_Click ()
Unload Me
End Sub

Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. PortOpen=True
End Sub

Private Sub Text1_Change ()
'how to get in a text box meter value sent?
End Sub

CodePudding user response:

I create a button, click on the send a 1, instrument send numerical how get?
 Private Sub Command1_Click () 
MSComm1. The Output=CRH (& amp; Send a natural code 1 H1) ', this hair right?
End Sub

Private Sub Command2_Click ()
Unload Me
End Sub

Private Sub Form_Load ()
MPort=3
MSComm1.ComMSComm1. Settings="4800, n, 8, 1", "
MSComm1. PortOpen=True
End Sub

Private Sub Text1_Change ()
'how to get in a text box meter value sent?
End Sub

CodePudding user response:

What is called "natural code"?
 OnComm event example 
Next example shows how to deal with the communication errors and events, can be in the relevant Case statement after insert code to handle specific error or event,

Private Sub MSComm_OnComm ()
Select Case mEvent MSComm1.Com
'to Handle each event or error by placing
'the code below each case statement

Error
'Case comEventBreak 'received Break,
Case comEventCDTO 'CD (RLSD) timeout,
Case comEventCTSTO 'CTS Timeout,
Case comEventDSRTO 'DSR Timeout,
Case comEventFrame 'Framing Error
Case comEventOverrun 'data loss,
Case comEventRxOver 'receive buffer overflow,
Case comEventRxParity Parity error,
'Case comEventTxFull 'transmission buffer is full,
Case comEventDCB 'access to DCB] the accidental error

"
Case comEvCD 'CD line state changes,
Case comEvCTS 'CTS line state changes,
Case comEvDSR 'DSR line state changes,
Case comEvRing 'Ring Indicator changes,
Case comEvReceive 'received RThreshold # of
Chars.
Case comEvSend 'transmission buffer is Sthreshold letters'
'
Case comEvEof 'found in the input data stream EOF character
'
End the Select
End Sub

The Input attribute sample
This example shows you how to read data from the receive buffer,

Private Sub Command1_Click ()
Dim InString as String
'read all the available data,
MSComm1. InputLen=0

'inspection data,
If MSComm1. InBufferCount Then
'the Read data.
InString=MSComm1. Input
End the If
End Sub

MSComm control example
The following simple example demonstrates the basic serial communication using modems:

Private Sub Form_Load ()
'save the input substring of buffer
Dim Instring As String
'use COM1,
MPort=1
MSComm1.Com'9600 baud, parity, 8 bits of data, a stop bit,
MSComm1. Settings="9600, N, 8, 1", "
'when the input occupied,
'tell control to read the entire buffer,
MSComm1. InputLen=0
'opening ports,
MSComm1. PortOpen=True
'that command attention to modem,
MSComm1. The Output="ATV1Q0" & amp; CRH $(13) 'ensure
'a modem with "OK" response,
'wait for the data back to the serial port,
Do
DoEvents
Buffer $=Buffer $& amp; MSComm1. Input
Loop Until InStr (Buffer $, "OK" & amp; VbCRLF)
'read the "OK" response to the serial port,

'close the serial port,
MSComm1. PortOpen=False
End Sub

Note MSComm controls a polling or event-driven method can be used from the port to get the data, this simple example USES the polling method, examples of the event-driven method please refer to the OnComm event help,
  • Related