Serial Port comunication witch arduino

Just starting out? Need help? Post your questions and find answers here.
ludoke
Enthusiast
Enthusiast
Posts: 155
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

Re: Serial Port comunication witch arduino

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Serial Port comunication witch arduino

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ludoke
Enthusiast
Enthusiast
Posts: 155
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

Re: Serial Port comunication witch arduino

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Serial Port comunication witch arduino

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply