Sorry, Im writing my very first program.
Purebasic seems to be perfect for this task but my knowledge is very limited

The idea is to create a GUI to communicate with a device connected by a serial port.
I found severals examples on this forum from infratec which I thank very much, it really helps me....but i don't understand everything.
I need to receive string on the serial port like this one : $GPVTG,100,200,300,400 #LF
and display each field in a text box and it works pretty well but I'm not sure I did it right, or that I positioned the functions correctly.
Code: Select all
Procedure ComThread(*Parameter.ThreadParameterStructure)
Protected Byte.a, ReceivedBytes.i
Protected Text$
PostEvent(#ComThread_Started)
*Parameter\Com = OpenSerialPort(#PB_Any, *Parameter\Com$, 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
If *Parameter\Com
WriteSerialPortString(*Parameter\Com, "hello")
Repeat
If AvailableSerialPortInput(*Parameter\Com)
If ReadSerialPortData(*Parameter\Com, @Byte, 1) = 1
ReceivedBytes + 1
SetGadgetText(#Rx , Chr(Byte))
If Byte <> #LF
Text$ + Chr(Byte)
SetGadgetText(#RxString , Text$)
Else
SetGadgetText(#RxField1 , StringField(Text$ , 1 , ","))
SetGadgetText(#RxField2 , StringField(Text$ , 2 , ","))
EndIf
PostEvent(#ComThread_ByteReceived, 0, 0, 0, ReceivedBytes)
If Byte = #CR
PostEvent(#ComThread_LineReceived)
WaitSemaphore(*Parameter\Semaphore)
Else
*Parameter\Receive$ + Chr(Byte)
EndIf
EndIf
Else
Delay(10)
EndIf
Until *Parameter\Exit
CloseSerialPort(*Parameter\Com)
EndIf
PostEvent(#ComThread_Finished)
EndProcedure
I want the gadget text #RxString to display only the last received string.
How can I do that ? ( I am not sure to be clear )
Thank you for your help
