Changes
From Dynomotion
/* Simplest C Program */
include "KMotionDef.h"<br/>main()<br/>{<br/> printf("Hello World!\n"); // send message to console<br/>}
===Basic Disk Read/Write===
KFLOP has no file system on its own, but when connected to a PC with a PC App running it can do basic Disk Read or Write Operation. Read capability was recently added in Version 4.33q. There isn't any PC Keyboard access (getchar()). See the KmotionDef.h file for supported functions:
// Note: standard C language printf <br />int printf(const char *format, ...); // Print formatted string to console<br />int sprintf(char *s, const char *format, ...); // Print formatted string to string<br /><br />typedef int FILE;<br />FILE *fopen(const char*, const char*); // Open a text file for writing on the PC (2nd param = "rt" or "wt") <br />int fprintf(FILE *f, const char * format, ...); // Print formatted string to the PC's Disk File<br />int fclose(FILE *f); // Close the disk file on the PC<br /><br />int Print(char *s); // Print a string to the console window<br />int PrintFloat(char *Format, double v); // Print a double using printf format, ex "%8.3f\n"<br />int PrintInt(char *Format, int v); // Print an integer using printf format, ex "result=%4d\n"<br /> <br />int sscanf(const char *_str, const char *_fmt, ...); //scan string and convert to values <br /><br />#define MAX_READ_DISK_LENGTH 1024 // max allowed length of disk file line length<br />extern volatile int read_disk_buffer_status; //status of read disk buffer 1=line available, 2=error, 3=eof <br />extern char read_disk_buffer[MAX_READ_DISK_LENGTH+1];<br />char *fgets(char *str, int n, FILE *file); //read string from PC disk file, str=buffer, n=buffer length, f=FILE pointer, returns NULL on error<br />int fscanf(FILE *f, const char *format, ...); //read sting from PC Disk file, convert values, returns number of items converted<br />int feof(FILE *f); // End of file status for disk reading
===Simple DiskReadWrite.c example===
include "KMotionDef.h"<br /><br />main()<br />{<br /> FILE *f;<br /> char s[256];<br /> double a=123.456,b=999.999,c=0.001;<br /> double x=0,y=0,z=0;<br /> int result;<br /> <br /> // write 3 comma separated values to a disk file<br /> f=fopen("c:\\Temp\\KFlopData.txt","wt");<br /> fprintf(s,"%f,%f,%f\n",a,b,c);<br /> fclose(f);<br /> <br /> // read them back in<br /> f=fopen("c:\\Temp\\KFlopData.txt","rt");<br /> if (!f)<br /> {<br /> printf("Unable to open file\n");<br /> return;<br /> }<br /> <br /> // read a line and convert 3 doubles<br /> result=fscanf(f,"%lf,%lf,%lf",&x,&y,&z);<br /> fclose(f);<br /> <br /> printf("# values converted = %d, x=%f, y=%f, z=%f\n",result,x,y,z);<br />}
==<br/>Wiring Diagrams==