| ??? 07/10/09 12:48 Read: times |
#167009 - As I described... Responding to: ???'s previous message |
Here is an example. This code is a design that stays in the routine waiting for the response.
Function TComm_Read(Opcode As Integer, ByRef Response As Integer) As String
Dim Timeout As Integer
Dim InpVal As Integer
Dim InpByt() As Byte
'Set the DTR and RTS lines to select test box processor
MSComm.DTREnable = False
MSComm.RTSEnable = False
Sleep (5)
'Purge all existing port input
MSComm.InputLen = 1 'char at a time on input
MSComm.InputMode = comInputModeBinary 'read as binary data
MSComm.InBufferCount = 0 'Flush the input buffer
'Assemble and output the two character READ function
MSComm.Output = Chr$(27) + Chr$(Opcode)
'Poll for the single byte reply from the remote end
Timeout = 100 '100 msec total timeout
While Timeout > 0
Sleep (1)
If MSComm.InBufferCount >= 1 Then
InpByt = MSComm.Input
InpVal = InpByt(0)
TComm_Read = ""
Response = InpVal
Exit Function
End If
Timeout = Timeout - 1
Wend
TComm_Read = "Read Function Timeout"
End Function
Once you have the input byte from MSComm you can have it as a BYTE or an Integer or to make it be a part of being appended to a string: Dim InpStr As String ... InpStr = InpStr & Chr$(InpByt(0)) Michael Karas |
| Topic | Author | Date |
| serial port in vb | 01/01/70 00:00 | |
| In VB | 01/01/70 00:00 | |
| exmple pls | 01/01/70 00:00 | |
| Rule #1 in Serial - Always Test Tx 1st | 01/01/70 00:00 | |
| Use 2 PC's to test comm's | 01/01/70 00:00 | |
| As I described... | 01/01/70 00:00 | |
| thanks. i solve my problem | 01/01/70 00:00 | |
| Guidelines | 01/01/70 00:00 | |
In Theory | 01/01/70 00:00 |



