6 SDK Development Guide
1 SDK Overview
This chapter introduces the definition and composition of SDK to help users understand the SDK better.
1.1 SDK Introduction
The SDK of ED-AIC2000-120 series Camera is a set of Software Development Kit (SDK), which provides users with the interfaces required by the upper layer applications, and facilitates the secondary development of the Camera.
The SDK functions of ED-AIC2000-120 series Camera include the definition of Trigger/Tune button, the definition of DI in 12-Pin M12 interface, the control of laser switch, the control of status indicator, the control of alarm indicator, the control of 2-channel DO, and the control of light and light source.
The location of SDK in the camera system is shown in the figure below.
1.2 SDK Composition
The SDK of camera is composed of multiple header files and library files. The details file names and installation paths are as follows.
Function | Definition | Filename | Installation Path |
---|---|---|---|
IO control | header file | eda-io.h | /usr/include/eda/ |
library file | libeda_io.so | /usr/lib/ | |
Dynamic library files | libedaio.so | /usr/lib/python3/dist-packages/ | |
Camera Sensor Control | Open source library | picamear2 | picamera2 User Manual |
During the development process, users can complete the development of upper-layer applications based on actual needs and refer to the corresponding function description below.
2 Function Description
This chapter introduces how to write the code corresponding to each function to help users write the code required for upper-layer applications.
2.1 IO Control(C++)
This section describes the specific operations of indicator control, laser control, event listening, and output control.
2.1.1 Flow Diagram
2.1.2 Getting Instance and Initializing
Before operating IO, you need to obtain an IO instance and initialize the instance. The steps are as follows.
- Getting an IO instance.
eda::EdaIo *em = eda::EdaIo::getInstance();
- Initializing the instance.
em->setup();
2.1.3 Event Callback Function
IO control supports registering callback functions for events, including registering Input, registering Trigger button, and registering Tune button.
- DI 1 trigger event
em->registerInput(trigger_input);
The COMMON_IN pin in the 12-Pin M 12 interface is connected to ground signal, and the DI1 pin is connected to 5V signal for triggering.
- Registering Trigger button
em->registerTrigger(trigger_trigger);
- Registering Tune button
em->registerTune(trigger_tune);
Sample:
#include "eda/eda-io.h"
void trigger_input(int b){
printf("[Test] Tirgger input: %d\n", b);
}
int main(int argc, char *argv[]){
eda::EdaIo *em = eda::EdaIo::getInstance();
em->registerInput(trigger_input);
em->setup();
....
}
2.1.4 Controlling IO
The IO is used to control the laser on/off, status indicator on/off, alarm indicator on/off and 2 output signals enable/disable.
Preparation
Initialization of the instance has been completed.
Operating Instructions
- Laser On/Off
em->openLaser();
em->closeLaser();
- Status indicator On/Off
em->setScanStat(true);
em->setScanStat(false);
- Alarm indicator On/Off
em->openAlarm();
em->openAlarm();
- 2 outputs enable/disable
em->setDo1High(false);
em->setDo2High(false);
2.1.5 Controlling light
Both the camera side lights and area lights can be controled independently.
Preparation
Initialization of the instance has been completed.
Operating Instructions
Side light color
em->setRgbLight(1);
- 0: Closing side light
- 1: Setting the color to Red
- 2: Setting the color to Green
- 3: Setting the color to Blue
RGB color of side light
void setRgbLight_rgb(uint8_t r, uint8_t g, uint8_t b);
Area lights
- Enable (The default state)
em->enableLightSection(1);
The value range is 1~4, corresponding to different partitions.
- Disable
em->disableLightSection(1);
The value range is 1~4, corresponding to different partitions.
Enabling/disabling the area light does not turn on/off the light. The area light and the camera are linked. The area light will only turn on when the area light is enabled and the camera is turned on.
2.1.6 Code Examples
IO Control Class (C++)
typedef void (*IoTrigger)(int level);
class EdaIo{
public:
static EdaIo* getInstance();
static void close_io();
~EdaIo();
/**
* @brief Laser On
*
*/
void openLaser();
/**
* @brief Laser Off
*
*/
void closeLaser();
/**
* @brief set status indicator
*
* @param good
*/
void setScanStat(bool good);
/**
* @brief alarm indicator On
*
*/
void openAlarm();
/**
* @brief alarm indicator Off
*
*/
void closeAlarm();
/**
* @brief
*
* @param section 1~4
* @return int
*/
int enableLightSection(int section);
/**
* @brief
*
* @param section 1~4
* @return int
*/
int disableLightSection(int section);
/**
* @brief set output1 to [high/low]
*
* @param high
*/
void setDo1High(bool high);
/**
* @brief set output2 to [high/low]
*
* @param high
*/
void setDo2High(bool high);
// void setAimerColor(RGBColor color);
/**
* @brief register input trigger callback function
*
* @param callback
*/
void registerInput(IoTrigger callback);
/**
* @brief register button callback function
*
* @param callback
*/
void registerTrigger(IoTrigger callback);
/**
* @brief register Tune button callback function
*
* @param callback
*/
void registerTune(IoTrigger callback);
/**
* @brief set RGB light
*
* @param light 0: Close; 1: Red; 2: Green; 3: Blue,
* @return int
*/
void setRgbLight(uint8_t light);
/**
* @brief Set the RGB Light
*
* @param r red
* @param g green
* @param b blue
*/
void setRgbLight_rgb(uint8_t r, uint8_t g, uint8_t b);
/**
* @brief initializing IO settings
*
*/
void setup();
};
2.2 IO Control (Python)
This section introduces the operations of indicator control, laser control, event callback, and output control.
2.2.1 Flow Diagram
2.2.2 Import Module
Before operating IO, you need to import modules.
from libedaio import EdaIo,registerInput,registerTrigger,registerTune
2.2.3 Getting Instance and Initializing
After importing the library environment, you need to obtain an IO instance and initialize the instance. The steps are as follows.
- Getting an IO instance.
eda = EdaIo.singleton();
- Initializing the instance.
eda.setup();
2.2.4 Event Callback Function
IO control supports registering callback functions for events, including registering Input, registering Trigger button, and registering Tune button.
- DI 1 trigger event
registerInput(func_input);
The COMMON_IN pin in the 12-Pin M 12 interface is connected to ground signal, and the DI1 pin is connected to 5V signal for triggering.
- Registering Trigger button
registerTrigger(func_trigger);
- Registering Tune button
registerTune(func_tune);
Sample
#!/usr/bin/python3
from libedaio import EdaIo,registerInput
def func_input(v):
print("[Debug] Trigger: input!", v)
def main() -> int:
eda = EdaIo.singleton();
registerInput(func_input)
eda.setup()
…
if __name__ == "__main__":
main()
2.2.5 Controlling IO
Using IO to control the on/off of the laser, the on/off of the status indicator, the on/off of the alarm indicator and the enable/disable of the 2 outputs.
Preparation
Initialization of the instance has been completed.
Operating Instructions
- Laser On/Off
eda.openLaser();
eda.closeLaser();
- Status indicator On/Off
eda.setScanStat(true);
eda.setScanStat(false);
- Alarm indicator On/Off
eda.openAlarm();
eda.openAlarm();
- 2 outputs enable/disable
eda.setDo1High(false);
eda.setDo2High(false);
2.2.6 Controlling light
Both the camera side lights and area lights can be controlled independently.
Preparation
Initialization of the instance has been completed.
Operating Instructions
Side light color
eda.setRgbLight(1);
- 0: Closing side light
- 1: Setting the color to Red
- 2: Setting the color to Green
- 3: Setting the color to Blue
Area lights
- Enable (The default state)
eda.enableLightSection(1);
The value range is 1~4, corresponding to different partitions.
- Disable
eda.disableLightSection(1);
The value range is 1~4, corresponding to different partitions.
Enabling/disabling the area light does not turn on/off the light. The area light and the camera are linked. The area light will only turn on when the area light is enabled and the camera is turned on.
2.2.7 Code Examples
IO Control (Python 3)
from libedaio import EdaIo,registerInput,registerTrigger,registerTune
def func_trigger(v):
print("[Debug] Trigger: trigger button!", v)
...
eda = EdaIo.singleton(); # Get IO control instance
registerTrigger(func_trigger); # Register Trigger button callback
# registerInput(func_trigger); # Register Input callback
# registerTune(func_trigger); # Register Tune button callback
eda.setup(); # Initialization
...
eda.openLaser(); # Laser On
# eda.closeLaser(); # Laser Off
eda.setScanStat(True); # Set status indicator
eda.openAlarm(); # Alarm indicator on
# eda.closeAlarm(); # Alarm indicator off
eda.setDo1High(True); # Set output1
eda.setDo2High(False); # Set output2
eda.setRgbLight(1); # Set side light,0: Off; 1: Red; 2: Green; 3: Blue
2.3 Sensor Control Examples
Camera Sensor control software based on open source libraries picamera2
,official informationPicamera2 Manual,here are some simple instructions and examples。
2.3.2 Operating Steps
Before operating Camera, you need to import the IO module and then get the IO instance and initialise it (for details, see [2.2.2 Importing Module](#_2-2-2-Importing Module) and [2.2.3 Getting Instance and Initialising](#_2-2-3-Getting Instance and Initialising)), and then do the following.
- Importing modules
from picamera2 import Picamera2, Preview
- Get the Camera instance
picam2 = Picamera2()
- Create the preview configuration
preview_config = picam2.create_preview_configuration()
- Apply the preview configuration
picam2.configure(preview_config)
- Start the camera preview function, NULL means do not show the picture on the screen
picam2.start_preview(preview.NULL)
- Turn on the camera
picam2.start()
- Capture the picture
picam2.capture_file("test.jpg")
- Close the camera
picam2.close()
8. close the camera
3 Examples
This chapter introduces detailed code examples, including writing code, compiling code, and running code.
3.1 Code Example
The following is an example of how to implement the function ‘Turn on the camera and wait for 2s to capture a picture’, using Python lines to write the code.
The detailed code is as follows
from picamera2 import Picamera2, Preview # Import Picamera2 library and preview function.
import time # Import the time module for time-delay operations.
picam2 = Picamera2() # Create a Picamera2 object instance.
camera_config = picam2.create_preview_configuration() # Create the camera's preview configuration
picam2.configure(camera_config) # configure the camera
picam2.start_preview(Preview.NULL) # start the camera's preview function (NULL preview is selected here to indicate that there is no window to display)
picam2.start() # start the camera
time.sleep(2) # wait for 2 seconds to make sure the camera is stable
picam2.capture_file(‘test.jpg’) # capture the photo and save it to the current directory, the file name is ‘test.jpg’
picam2.close() # shut down the camera, freeing up resources
After writing is completed, save it as test123.py file.
TIP
The file name can be customized.
3.2 Compiling and Running Code
After the Python code is written, you need to log in to the camera device, compiling and running it on the Raspberry Pi OS.
Preparation:
- The connection of camera cables has been completed. For detailed operations, please refer to the Boot device
- The camera has been powered and connected to the network through the router.
- Obtained the camera IP address and successfully logged in to the camera system.
Steps:
Create a folder on the camera OS and upload the code files written in Chapter 3.1 Writing Code to the folder.
Execute the following command to view the files in the folder and ensure that the code file has been uploaded successfully.
ls
- Execute the following command to compile the written code.
sudo python test123.py
test123.py
: means the code file written in Chapter [3.1 Writing Code](#3.1-Writing Code).
TIP
After successful operation, you can see that the laser lights up and goes out after waiting for 2 seconds.