Print

Historical data collector of ASCII Data from Serial Port

 

The following example illustrates the application of the Historical Data Collector with a macro to record ASCII strings from the serial port.

The data is automatically recorded when the local bit LB1 is set. LB1 is set in the macro n°0 when data arrives on COM

You can:

      • Clear all historical data
      • backup data on USB disk (Formatted FAT32) plugged on the HMI
      • Screenshot the HMI screen on USB disk
      • See data comes from the port COM
      • Send Data via the COM port

Download this simple example (HMI project) : Historical data collector of ASCII Data from Serial Port

After push button [>USB], you will find the .csv file on the USB disk

The 2 macros in the HMI is as follows

For send data

#include "MacroInit.h"
#include
void Macro_main(IN *p)
{
MarcoInit
//ToDo
unsigned char ch[512];
int length = 0;
int PortID = 0; //com1:0 com2:1
if(LocalBit[0]) //Stop receiving data when modifying ASCII, and then receive it after completion
return;
memset(ch , 0 , 512);
length = GETCHARS(PortID,ch); //Receiving data
if(length > 2) //The receiving condition of the data is set, the first byte is not shown end the last byte
{
LocalBit[1] = 1; //Bit set for information (datalog, call screen, ..)
memset(&LocalWord[100] , 0 , 256);
memcpy((unsigned char *)(&LocalWord[100]) , &ch[0] , length-0);
CLEARBUFFER(PortID); //emptying
}
}

For receive data

#include "MacroInit.h"
#include
// SEND BUTTON
void Macro_main(IN *p)
{
MarcoInit
//ToDo
unsigned char ch[512];
unsigned char * data = (unsigned char *)(&LocalWord[0]);
int PortID = 0; //com1:0 com2:1
memset(ch , 0 , 512);
ch[0] = ':';
memcpy(&ch[1] , data , strlen(data));
ch[strlen(data)+1] = '!';
PUTCHARS(PortID,ch,strlen(data)+2);
LocalBit[0] = 0; //Receiving data
}