Menene API

menene API

da Bayanin kalmomin API za ku ga su fiye da sau ɗaya da sau biyu lokacin da kuka karanta labarai game da software. Amma ba kowa ya san menene API ba. Abin da ya sa muke bayyana shi a cikin wannan labarin. Abu na farko da za a fara fada shine, su ne takaitattun kalmomin Programming Interface, ma’ana, a yaren Spanish, wato Programming Interface. Kuma sau da yawa yana haifar da rikice-rikice har ma tsakanin waɗanda suka san wasu shirye-shirye.

Misali, Arduino yana da API na shirye-shiryen kansa, yana ba da ayyuka da yawa waɗanda zaku iya amfani dasu a cikin Arduino IDE ko wasu mahalli don tsara microcontroller don ba ku damar ƙirƙirar ayyukanku. Amma ... za ku iya gaya mani bambanci tsakanin laburaren shirye-shirye da API? Shin akwai bambance-bambance tsakanin tsarin da API? Shin API ɗaya ne da ABI? Akwai shakku da yawa wadanda watakila ci gaba da haifar da rudani kuma za mu bayyana su a yanzu.

Ban sani ba ko kun san hakan ƙananan harsuna, kamar mai tarawa ko ASM, ya dogara ne kai tsaye kan tsarin kayan aikin kayan, yayin da manyan-manyan keɓaɓɓu daga kayan aikin don sauƙaƙe aikin mai shirin, amma sun dogara da tsarin aiki (syscalls) ko kan wasu APIs, da dai sauransu. Don haka duk wannan bai zama kamar Sinanci ba, bari mu ga abin da ya shafi ...

Menene API?

Una API kayan aiki ne wanda ake samarda masu haɓakawa dashi don haka suna da jerin ayyukansu, ƙananan hanyoyin da hanyoyin ko hanyoyin don OOP waɗanda za a iya amfani da su ta hanyar ɗakunan karatu na yanzu. Daga cikin abin da API ke bayarwa daga ayyuka don ƙirƙirar aikace-aikace masu sauƙi, ayyuka masu alaƙa da AI, tare da tsara zane-zane, gudanar da albarkatun kayan masarufi, da sauransu.

Misali, na tabbata kun saba da APIs kamar irin wanda Linux ke bayarwa ta hanyar glibc library, ko zane-zane kamar su OpenGL da Vulkan, ko kuma wasu kamar OpenCL don ƙididdiga iri-iri, OpenXR don kama-da-wane da haɓaka gaskiya, da dai sauransu. Sauran tsarin aiki da software suma sun hada da APIs nasu don sauran masu shirye-shiryen zasu iya ƙirƙirar addons, plugins ko kayayyaki don wannan tsarin, da dai sauransu.

Misali tare da Arduino

Idan kana da lamba Arduino kuma kuna yawan amfani da Arduino IDE, ko kowane yanayi na ci gaba don Arduino, zaku san cewa lokacin da kuka ƙirƙiri lambar kuna amfani da zaɓuɓɓuka da yawa don umurtar mai kula da ku don aiwatar da jerin ayyuka. Misali, pinMode () aiki ne na yau da kullun don daidaita sahun Arduino, dama?

Lokacin da kake rubutu pinMode (9, INTUTI)Misali, kana nuna cewa pin 9 na kwamitin Arduino yakamata yayi aiki azaman shigar dashi, ma'ana, microcontroller zai jira bayanan su shiga ta wannan fil din don karanta shi da aiwatar da wani aiki. Amma kun taɓa yin mamakin yadda zai iya fahimtar wannan umurnin?

Da kyau, Arduino yana da Ci gaban API wanda aka samar mana. Za a iya ƙara ɗakunan karatu na ɓangare na uku zuwa wannan API ɗin kamar yadda muka gani a misalai da yawa akan wannan rukunin yanar gizon. Kamar SparkFun's don wasu na'urori masu auna firikwensin, da sauransu. Tare da wannan duka, ana iya shigar da ayyukan a cikin Arduino IDE kuma zai fassara lambar da kyau don ɗora ta a cikin ƙwaƙwalwar ajiyar mai sarrafawa don ta iya sarrafa ta.

Idan baku da wannan API ɗin ba, ba za ku iya ƙirƙirar waɗannan shirye-shiryen don Arduino ta hanya mai sauƙi ba, tunda ya kamata mu yi ƙoƙari mu sanya su cikin lambar taro don ATMega328P microcontroller, wato, a ASM don gine-ginen AVR. Kuma wannan zai fi rikitarwa, tunda dole ne kai tsaye kayi amfani da umarnin da wannan ISA ke samu. Idan haka ne, ba kawai zai zama dole ku san takaddar wannan ISA ba, har ma da sauran fannoni kamar yawan rajista, da dai sauransu. Wato, ya kamata ku sami ƙarancin sani na kayan aikin da kuke aiki.

de misali, lambar ASM Abin da yakamata ku samar don LED don yin haske a cikin madauki zai kasance:

<br data-mce-bogus="1">

.ORG 0x0000
; the next instruction has to be written to
; address 0x0000
rjmp START
; the reset vector: jump to "main"
START:
ldi r16, low(RAMEND) ; set up the stack
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16
ldi r16, 0xFF
; load register 16 with 0xFF (all bits 1)
out DDRB, r16
; write the value in r16 (0xFF) to Data
; Direction Register B
LOOP:
sbi PortB, 5
; switch off the LED
rcall delay_05
cbi PortB, 5
; wait for half a second
; switch it on
rcall delay_05 ; wait for half a secon
rjmp LOOP ; jump to loop
DELAY_05:
; the subroutine:
ldi r16, 31
; load r16 with 31
OUTER_LOOP:
; outer loop label
ldi r24, low(1021) ; load registers r24:r25 with 1021, our new
; init value
ldi r25, high(1021) ; the loop label
DELAY_LOOP:
; "add immediate to word": r24:r25 are
; incremented
adiw r24, 1
; if no overflow ("branch if not equal"), go
; back to "delay_loop"
brne DELAY_LOOP
dec r16
; decrement r16
brne OUTER_LOOP
ret
; and loop if outer loop not finished
; return from subroutine

Duk da yake godiya ga API kayan aikin duka, rubuce-rubuce a babban matakin waɗannan lambobin masu zuwa masu zuwa (sun fi gajarta kuma sun fi fahimta):

<br data-mce-bogus="1">

int ledPin = 13; 		// LED que se encuentra en el pin 13
   void setup(){ 
   pinMode(ledPin, OUTPUT);	// El p1n 13 será una salida digital 
} 
void loop(){ 
   digitalWrite(ledPin, HIGH);	// Enciende el LED
   delay(1000); 				// Pausa de 1 segundo 
   digitalWrite(ledPin, LOW); 	// Apaga el LED 
   delay(1000);				// Pausa de 1 segundo 

Bambanci tare da ABI

API vs Linux ABI

ABI wani ƙaramin sanannen lokaci ne, shine Matsayin Binary na Aikace-aikace, ko a cikin Yarjejeniyar Binary na Turanci. A wannan yanayin, yana da ma'amala tsakanin matakan shirin, gabaɗaya tsakanin ɗakin karatu ko tsarin aiki da harshe na injina don ginin da kuke: SPARC, AMD64, ARM, PPC, RISC-V, da sauransu.

Godiya ga ABI, hanyar kiran ayyuka an ƙaddara, tsarin binary wanda zai iya fahimtar injin da kake tattarawa ko tsarin kira, yadda ake sarrafa keɓaɓɓu, yadda ake wuce bayanai, da sauransu.

Bambanci tare da Tsarin aiki

Un tsari ko tsari shine mafi yawan kayan aiki a hannunka don taimakawa bunkasa aikin da aka bayar. Abubuwan shahararrun mutane galibi suna saita wasu ƙa'idodin lamba, suna samar da abubuwa masu amfani, da dai sauransu. Misali, JUnit tsari ne na Java, ko Symfony / Cake don PHP, da sauransu.

Bambanci tare da SDK da NDK

SDK Kayan aikin haɓaka Software ne, wato, kayan aikin inganta software. Ya wuce abin da yake tsarin ko API. Misali na iya zama Android Studio ko iOS xCode, da sauransu. Misali, na farko, baya ga Android API kanta, shima ya hada da IDE ko hadadden yanayin bunkasuwar shirye-shirye da harhadawa, dakunan karatu, kayan aiki, da sauransu

A gefe guda, NDK (Kit ɗin Developmentasar Developmentan Nasar) kari ne. Misali, Android NDK na bawa masu haɓaka damar sake amfani da lambar C / C ++ ta hanyar gabatar da shi zuwa aikace-aikace ta hanyar JNI (Java Native Interface) ...

Bambanci tare da laburare

Glibc zane Wikipedia

A ƙarshe, ɗakin karatu shine tarin lambar tushe mai sake amfani hakan yana saukaka rayuwar masu shirye-shirye. Misali, a cikin C laburare stdio.h akwai aikin printf don buga rubutu akan allon. Don wannan ya yiwu, ana buƙatar lambar tushe wanda ke sa tsarin aiki yayi wannan aikin. Amma tunda abu ne mai maimaituwa wanda ake amfani dashi akai-akai, kawai ta hanyar kiran wannan ɗakin karatun zaka iya amfani da bugawa ba tare da rubuta duk lambar daga karce ba. A wasu kalmomin, a wasu kalmomin, ana iya ganin su azaman tubalan precast.

Laburare da API suna iya rikicewa cikin sauƙi, a zahiri, an rufe dakunan karatu a cikin API. Misali glibc...

Ina fatan cewa bayan wannan kuna da ra'ayi kara bayyana game da menene API, ABI, tsarin, SDK da laburare, ban da iya bambance tsakanin su daga yanzu.


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Kasance na farko don yin sharhi

Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.