
I have programmed a PIC micro controller to read several sensors around the house (temperature, humidity, voltage, current etc). The PIC than massages this date, does a little bit of magic and then spits out a 60 character string from its serial port every 60 seconds to an EM202 serial to Ethernet converter.
I can connect to the converter using putty or other telnet clients and "see" all the 60 character strings being sent once a minute. So at least that part is working.
Where the problem lies is in getting Purebasic to receive the data and save it to a file. The programme I have written captures part of the 60 character string, some times 3 or 4 characters usually around 30 and on very rare occasions all 60, there seems to be no pattern. There is no corrupt data, just missing data. The used is below (don't laugh too loud)
Code: Select all
If InitNetwork() = 0
MessageRequester("Error", "Unable to initialize network")
EndIf
ConnectionID = OpenNetworkConnection("192.168.1.100", 1001)
While 1=1
*Buffer = AllocateMemory(60)
result=ReceiveNetworkData(ConnectionID, *Buffer, 60) ;Result = # of bytes read
CloseNetworkConnection(ConnectionID)
Debug "Number of Characters"
Debug result
OpenFile(0, "D:\Test.txt") ; opens file to save data in
FileSeek(0, Lof(0)) ; Get end of file position
WriteData(0,*Buffer ,60) ; Append data
FreeMemory(*Buffer) ; Release memory
CloseFile(0) ; Close file
Delay(60000) ; wait 60 seconds
Wend
Do I have to keep opening and closing the network connection or can I keep it open and just listen for new data, if so clues as to ho to do tis would be welcome!!
Thanks
Wooly