Page 4 of 4

Re: Serial Port comunication witch arduino

Posted: Tue Dec 17, 2019 10:35 am
by ludoke
mk-soft,
many thanks for your patience.
Your code works good as it is.
If I replace #CRLF$ by CRLF$ it does not work.

\DataBit = 8
\StopBit = 1
\Handshake = #PB_SerialPort_NoHandshake
\BufferSize = 2048
\EndOfText = #CRLF$ <--------with only CRLF$ it do not work !
\StatusCB = @StatusCB()
\ReceiveCB = @ReceiveCB()
\ThreadID = CreateThread(@thComport(), ComData)

I think only 2 procedures are important for me

Procedure ReceiveCB(Text.s)
PostEvent(#My_Event_NewData,#window_main, 0, 0, AllocateString(Text))
EndProcedure

Procedure zend()
ComData\SendText = GetGadgetText(#str_input)
ComData\SendSignal = 1
EndProcedure

I am confused with the enumerations, sometimes you just use a number, I replace the number with a #name, this seems clearer to me.
I also always use an abbreviation for the type of gadget such as #but_, # window_, # str_ etc so that I know what kind of gadget it is.I don't have much experience.

Re: Serial Port comunication witch arduino

Posted: Tue Dec 17, 2019 6:32 pm
by mk-soft
If I replace #CRLF$ by CRLF$ it does not work.
Logical

CRLF$ is a variable of type String.
#CRLF$ is a ready string constant.

EnableExplicit at the beginning of the program should help.
I am confused with the enumerations, sometimes you just use a number, I replace the number with a #name, this seems clearer to me.
I also always use an abbreviation for the type of gadget such as #but_, # window_, # str_ etc so that I know what kind of gadget it is.I don't have much experience.
With mini examples it can happen that one takes on the fast instead of constant names (enumeration) directly the numbers.

Normally I always use constant names, too.

Re: Serial Port comunication witch arduino

Posted: Thu Dec 19, 2019 10:34 am
by ludoke
MK-SOFT,
I am a bit confused about ' Global Comdata .uditComdata ' because it is declared later in the code and not after the structure udtComdata declaration .
The procedure thComport(*Comdata.udtComdata) refers to Comdata, and has not yet been declared.
If I understand correctly, it is not necessary to declare global variables at the top of the code.

Your code is of a very high level for me, it is not that easy for a beginner. But it works.

Re: Serial Port comunication witch arduino

Posted: Thu Dec 19, 2019 8:07 pm
by mk-soft
Please read the basics of variables and structures in the PB help.

As well as what are pointers

Basics are important, and you should take the time to learn them.

---

P.S.
The procedure thComport(*Comdata.udtComdata) expects a pointer to the data with a structure of type udtComdata

So you can use the thread procedure more than once, for example to manage two comports.

But you have to create memory for the data. There are several ways. One of them is the one with Global VariablenName.TypeAsStructure.

Global ComData1.udtComdata
Global ComData2.udtComdata