Page 1 of 1
Can KFLOP read string/char sent from PC?
Posted: Sun Apr 19, 2020 3:40 am
by xuphoenix
Hi, KMotion gives a lot of predefined script commands in the library. However, I need to self-define new commands (strings) from PC to KFLOP. Does KFLOP have any function to read the strings sent from USB? Thanks.
Re: Can KFLOP read string/char sent from PC?
Posted: Sun Apr 19, 2020 7:39 pm
by TomKerekes
Hi xuphoenix,
The normal method for the PC to send User commands to KFLOP is to use the existing script commands to write a command codes (or strings) to KFLOP's memory. Your KFLOP User program can then detect the command, perform the operation, then clear the command to inform the PC the command has been completed.
See the Script commands:
SetPersistDec and
GetPersitDec. From KFLOP the persist Variables can be accessed as
persist.UserData[X]
Larger blocks of data can use the 8MByte Gather Buffer see
GetGatherDec and
SetGatherDec. From KFLOP the gather buffer can be accessed as
gather_buffer[X]
HTH
Re: Can KFLOP read string/char sent from PC?
Posted: Mon Apr 20, 2020 5:51 pm
by xuphoenix
Thank you for your prompt response, Tom.
That script command can solve my problem. Is there any C program function that can detect the data update/change in the Persist Array? So that the KFLOP knows that a new command comes and needs to be executed. Thanks.
Best regards,
Yang
Re: Can KFLOP read string/char sent from PC?
Posted: Mon Apr 20, 2020 6:07 pm
by TomKerekes
Hi Yang,
Here is an example:
Code: Select all
#include "KMotionDef.h"
#define VAR 10
void main()
{
for (;;) // forever loop
{
while (persist.UserData[VAR] <= 0) ; // wait for a non-zero command
// do the command
persist.UserData[VAR] = 0; // inform the PC command was completed or -1 for fail
}
}
Re: Can KFLOP read string/char sent from PC?
Posted: Mon Apr 20, 2020 6:16 pm
by xuphoenix
Got it. Thank you so much!
Best,
Yang