-
Notifications
You must be signed in to change notification settings - Fork 6
CAN API
Ankur Yadav edited this page Aug 27, 2015
·
11 revisions
#CAN API
This page contains native API functions for accessing CAN of beaglebone black. Code of this API can be found in can.c. Sample JNI wrapper functions can be found here. Sample application for CAN can be found here
###CAN API functions description
- *int canOpenRaw(const char port) : This function takes port string as input and returns the file descriptor. If it fails then it returns -1.
Returns : If successful then CAN file descriptor after opening socket is returned and if it fails then -1 is returned.
Example :
String port = "vcan0";
int canFD = canOpenRaw(port); // This code opens vcan0 and returns a file descriptor to access it.
- unsigned char canReadBytes(const int fd, int length) : This functions takes file descriptor and length variable to store length of bytes read as input and returns the pointer to the array of data bytes read. If no data is read then NULL pointer is returned.
Returns : The pointer to the array of data bytes read. If no data is read then NULL pointer is returned.
Example :
byte[] receive;
receive = canReadBytes(canFD, length); // This code reads bytes from the opened devices and returns the pointer to the array of data bytes read.
- int canSendBytes(const int canFD, const int no_bytes, const uint8_t data[]) : This function takes can file descriptor, number of bytes and array of data to be transferred as input and writes given number of bytes of data from data buffer. It returns number of bytes successfully written to CAN device.
Returns : number of bytes successfully written to CAN device.
Example :
EditText et = (EditText)findViewById(R.id.editText1);
byte[] send = et.getText().toString().getBytes();
int ret = canSendBytes(canFD, length, send); // This code is used to send bytes to can device.
- void canClose(const int canFD) : This function is used to close CAN file descriptor.
Example :
canClose(canFD); //This code is used to close the file descriptor of can device.
###Screenshot of CAN android application