Can KFLOP read string/char sent from PC?

Moderators: TomKerekes, dynomotion

Post Reply
xuphoenix
Posts: 8
Joined: Sun Apr 19, 2020 3:32 am

Can KFLOP read string/char sent from PC?

Post by xuphoenix » Sun Apr 19, 2020 3:40 am

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.

User avatar
TomKerekes
Posts: 2540
Joined: Mon Dec 04, 2017 1:49 am

Re: Can KFLOP read string/char sent from PC?

Post by TomKerekes » Sun Apr 19, 2020 7:39 pm

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
Regards,

Tom Kerekes
Dynomotion, Inc.

xuphoenix
Posts: 8
Joined: Sun Apr 19, 2020 3:32 am

Re: Can KFLOP read string/char sent from PC?

Post by xuphoenix » Mon Apr 20, 2020 5:51 pm

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

User avatar
TomKerekes
Posts: 2540
Joined: Mon Dec 04, 2017 1:49 am

Re: Can KFLOP read string/char sent from PC?

Post by TomKerekes » Mon Apr 20, 2020 6:07 pm

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 
	}
}
Regards,

Tom Kerekes
Dynomotion, Inc.

xuphoenix
Posts: 8
Joined: Sun Apr 19, 2020 3:32 am

Re: Can KFLOP read string/char sent from PC?

Post by xuphoenix » Mon Apr 20, 2020 6:16 pm

Got it. Thank you so much!

Best,
Yang

Post Reply