How Can We Help?

Print

Sending and receiving ASCII characters via the HMI serial port

 

In some cases, we need to use the HMI for a direct communication to a specific device (electronic board, electronic device,…) This example shows how to send and receive ASCII characters through the serial port of the HMI. Download this example to test this feature.

See how it works in macros section of the HMI-Tool software.

The 2 macros in the HMI are as follows

For receive 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 send 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
}