Kan ikke finde MSComm1.object
Koden skulle sætte op så det er muligt at læse gemmen RS-232 via I2C protokolden. Jeg får fejl ved kommandoen MSComm1.object.Nogle der kan hjælpe.
Private Function temperature(ByVal address As Short) As Double
Dim temperature_int As Integer
Dim temperature_frac As Integer
'For I2C bus communication, addresses are shifted one place to left,
'as the least significant bit is used for the R/W flag.
'In binary, shifting to left is equivalent to multiplying by two
address = address * 2
On Error GoTo errors
'UPGRADE_ISSUE: VBControlExtender property MSComm1.object was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
open_iic_bus(MSComm1.object)
'an extra stop doesn't hurt...and ensures we start from a clean bus condition
IIC_stop()
'read sequence, as per DS1621 datasheet
IIC_start() 'Bus Master initiates a START condition.
IIC_tx_byte(address) 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte(&HAC) 'Bus Master sends Access Config command protocol.DS1621 generates acknowledge bit.
IIC_tx_byte(&H1) 'Bus Master sets up DS1621 for output polarity active low, one-shot conversion.
'DS1621 generates acknowledge bit.
IIC_start() 'Bus Master generates a repeated START condition.
IIC_tx_byte(address) 'Bus Master sends DS1621 address; R/ W= 0.DS1621 generates acknowledge bit.
IIC_tx_byte(&HEE) 'Bus Master sends Start Convert T command protocol.DS1621 generates acknowledge bit.
IIC_stop() 'Bus Master initiates STOP condition.
IIC_start() 'Bus Master initiates a START condition.
IIC_tx_byte(address) 'Bus Master sends DS1621 address; R/ W= 0 (DS1621 generates acknowledge bit).
IIC_tx_byte(&HAA) 'Bus Master sends Read Temperature command protocol.DS1621 generates acknowledge bit.
IIC_start() 'Bus Master generates a repeated START condition.
IIC_tx_byte(address + 1) 'Bus Master sends DS1621 address; R/ W= 1 = READING (DS1621 generates acknowledge bit).
temperature_int = IIC_rx_byte(1) 'Bus Master receives first byte of data and generates acknowledge.
temperature_frac = IIC_rx_byte(0) 'Bus Master receives second byte of data from DS162 and does not generate acknowledge to signal end of reception.
IIC_stop() 'Bus Master initiates STOP condition.
'some bynary math to convert to a data format Visual Basic can understand
temperature = (temperature_int * 256 + temperature_frac) / 128 * 5 / 10
If temperature_int >= 128 Then
temperature = temperature - 256
End If
Exit Function
errors:
temperature = ERROR_TEMPERATURE_NOT_READ
End Function
