Zum Inhalt

Can

Mit diesem Treiber kommunizieren die Touchscreens der HM-Serie mit CAN-Geräten. Lesen Sie vor der Verwendung dieses Treibers dieses Kapitel und die technischen Unterlagen sorgfältig.

Verbindung mit CAN-Geräten herstellen

1.Hardwareanschluss

Verbindungskabel:

RS485

HM COM1/COM2 CAN
1 CANL benutzerdefiniert CANL
4 CANH benutzerdefiniert CANH
5 GND benutzerdefiniert GND

2.Softwareeinstellungen

Die CAN-Funktion wird über Systemfunktionen in Skripten aufgerufen

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.Beispiel

1, Baudrate einstellen und CAN-Gerät starten

#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, Daten empfangen

#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, Daten senden

#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

}