Hi all,
I made some progress lastnight in reading data from the weather station, the code fragment below works! It's far from pretty(a mess really) but was only for test & now that the test works down to the real job at hand! The weather station once conneted will retrieve a total of 8 * 8 byte packets containing the weather station configuration & the last recorded data(current conditions). I know the sleep instruction looks bad to have to use it but it was the easiest way to cause a delay between the data request instructions. One thing I noticed is in the ControlTransfer instruction(Request Type) I had to pass a 0x21 to it to get it to work but while testing under USBTrace on the PC it recorded a value of 0x22 here! Not sure if this is a bug in the USB libraries in Android or B4A. A new version will be coming soon with the data displayed graphically. Any questions or comments on the code below will be most welcome!
Thanks guys for the suggestions/help in getting this working.
Tom.
Sub btnSend_Click
Dim sent As Int
Dim bc As ByteConverter
ListView1.Clear
For a = 0 To 7
RX_Data1(a) = 0
RX_Data2(a) = 0
RX_Data3(a) = 0
RX_Data4(a) = 0
RX_Data5(a) = 0
RX_Data6(a) = 0
RX_Data7(a) = 0
RX_Data8(a) = 0
Next
ListView1.AddSingleLine("Read Config")
TX_Data(0) = 0xA1
TX_Data(1) = 0
TX_Data(2) = 0
TX_Data(3) = 0x20
TX_Data(4) = 0xA1
TX_Data(5) = 0
TX_Data(6) = 0
TX_Data(7) = 0x20
sent = connection.ControlTransfer(0x21, 0x09, 0x0200, 0, TX_Data, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data1, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data2, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data3, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data4, 8, 100)
Sleep(25)
ListView1.AddSingleLine("Reading Weather Data!")
TX_Data(0) = 0xA1
TX_Data(1) = RX_Data4(7)
TX_Data(2) = RX_Data4(6)
TX_Data(3) = 0x20
TX_Data(4) = 0xA1
TX_Data(5) = RX_Data4(7)
TX_Data(6) = RX_Data4(6)
TX_Data(7) = 0x20
sent = connection.ControlTransfer(0x21, 0x09, 0x0200, 0, TX_Data, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data5, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data6, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data7, 8, 100)
Sleep(25)
sent = connection.BulkTransfer(inEndpoint, RX_Data8, 8, 100)
Sleep(25)
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data1))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data2))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data3))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data4))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data5))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data6))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data7))
ListView1.AddSingleLine(bc.HexFromBytes(RX_Data8)) ListView1.AddSingleLine("Weather Data Read Done!")
End Sub