1.Hardware connection
This device driver is used to communicate with SK series touch screen and CAN device. Before using this driver, please read this chapter and related technical instructions carefully.
How to establish a connection with a CAN device
1.Hardware connection
connecting cables:
|
SK series touch screen COM1/COM2 |
CAN |
||
|---|---|---|---|
|
1 |
CANL |
Pin customization |
CANL |
|
4 |
CANH |
Pin customization |
CANH |
|
5 |
GND |
Pin customization |
GND |
2.Software settings
The function of CANBus is realized by calling the script system function
onCanxStart(PortID): start the CAN device
onCanxstop(PortID): close the CAN device
setBitrate (Bitrate , PortID): set the CAN communication rate
onCanxstop( CanID, CanMask, PortID ): set CAN ID filtering
reciveData ( data, Len, PortID, &CanId ): Receive CAN data
sendData ( data, Len, PortID, CanId, CanType ): send CAN data
For details, please refer to "CAN Communication Function"
3.Case
Initialization function, it is recommended to use the initialization function to power on and initialize once
#include "MacroInit.h"
void Macro_main(IN *p)
{
MarcoInit
//ToDo
int com = 1; // 0:COM2 1:COM1
int baudRate = 10*1000; // baud rate
int id = 0; // Set filter ID
int mask = 0; // Set filter mask
onCanxstop(com); // Close CAN
setBitrate(baudRate, com); // Set the baud rate
onCanxStart(com); // Open CAN
// addFillter(id, mask, com); // Set filtering, enable filtering, CAN filtering rule references the last CAN filtering calculation method
}
Read data function, it is recommended to use the global macro loop to execute
#include "MacroInit.h"
void Macro_main(IN *p)
{
MarcoInit
//ToDo
int com = 1; // 0:COM2 1:COM1
char buf[8] = {0}; // Receive data cache
int len = 0; // Receive data length
int canId = 0; // Receive data ID
int i = 0;
len = reciveData(buf, 8, com, &canId); // Receive CAN data
if(0 < len)
{
*((unsigned int *)(&LocalWord[50030])) = canId; // Display receiving CAN ID to LW50030 32-bit integer type
LocalWord[50032] = len; // Display receiving data length to LW50032 16-bit integer type
for(i=0; i< 8; ++i) // Display 8 addresses starting from LW50040
{
LocalWord[50040+i] = buf[i] & 0xff;
}
}
}
Write data function, trigger execution as needed
#include "MacroInit.h"
void Macro_main(IN *p)
{
MarcoInit
//ToDo
int com = 1; // 0:COM2 1:COM1
char buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; // Set the send data is 1 2 3 4 5 6 7 8
int canId = 0x02; // Set the send data ID
int mondel = 0x0; // Standard frame:0 Extension frame:0x80000000 Remote frame:0x40000000 Remote extension frame:0xC0000000
int i = 0;
sendData(buf, 8, mondel, canId, com); // send data
}