Skip to content

Can

This device is driven by the HM series touch screen and can device communication. Before using this drive, please read the chapter and the technical specifications carefully.

How to establish a connection with can devices

1.Hardware connection

Connecting cable:

RS485

HM COM1/COM2 CAN
1 CANL self-definition CANL
4 CANH self-definition CANH
5 GND self-definition GND

2.Software setup

The can function is implemented by calling the script system function

int onCanxStart(PortID); Start can equipment
int onCanxstop (PortID); Off can equipment
int setBitrate (PortID); Set the can communication rate
int onCanxstop ( CanID, CanMask, PortID ); Can id filter
int reciveData ( data, Len, PortID ); Receive can data
int sendData ( data, Len, PortID, CanId, CanType ); Send can data

3.case

1, Set the port rate and start the can device

#include "MacroInit.h"
void Macro_main ( IN *p )
{

MarcoInit

//ToDo
int PortID, Result, Bitrate;
PortID = 0; //0:COM0 1:COM1
Bitrate = 5*1000; // Set the port rate 5k Settings range 5k 10k 20k to 1 meter
Result = 0;

Result = setBitrate ( Bitrate, PortID ); // The com0 sets the communication rate to 5, 000 normal return value 0, error returns non-0

Result = onCanxStart ( PortID ); // Normal return 0 error return to be 0
}

2, Receiving data

#include "MacroInit.h"
void Macro_main ( IN *p )
{

MarcoInit

//ToDo
int PortID, Result, Len;

unsigned data[128]; // Receive the data buffer

PortID = 0; //0:COM0 1:COM1
Len = 128; // Receive buffer length
Result = reciveData ( ( unsigned char * ) data, Len, PortID );;
}

3, Send data

#include "MacroInit.h"
void Macro_main ( IN *p )
{

MarcoInit

//ToDo
int PortID, Result, Len, CanType, CanId, i;
unsigned char data[128];
PortID = 0; //0:COM0 1:COM1
Result = 0;
Len = 127; // Transmission length
CanId = 0x22; //CAN ID
CanType = 0; // Frame type standard frame:0 Extended frame:0x80000000
for ( i = 0; i < 128; ++i )
{
data[i] = i;
}

Result = sendData ( ( unsigned char * ) data, Len, PortID, CanId, CanType );// Extended frame,COM0 Send data,length 127,CAN ID为0x22

}