一 概述
RS485通信協(xié)議是一種多點(diǎn)通信協(xié)議,它允許多個(gè)設(shè)備在同一總線上進(jìn)行通信,且每個(gè)設(shè)備都可以發(fā)送和接收數(shù)據(jù)。RS485通訊協(xié)議采用差分信號(hào)傳輸,具有高速、遠(yuǎn)距離、可靠性強(qiáng)等特點(diǎn),可實(shí)現(xiàn)長(zhǎng)距離的數(shù)據(jù)傳輸。
RS485信號(hào)利用兩線之間的電壓差來(lái)傳遞邏輯信號(hào),規(guī)定當(dāng)電壓差為+2V~+6V時(shí)為邏輯“1”,而電壓差為-2V~-6V時(shí)為邏輯“0”。這種傳輸方式對(duì)于外部干擾有良好的抵抗能力,可實(shí)現(xiàn)長(zhǎng)距離和高噪聲環(huán)境下的可靠傳輸。
RS485通信協(xié)議支持半雙工通信模式,在同一總線上可以連接多個(gè)驅(qū)動(dòng)器和接收器,方便建立設(shè)備網(wǎng)絡(luò)。此外,RS485通信協(xié)議的接口電平低,不易損壞芯片,電平與TTL電平兼容,方便與TTL電路連接。RS485通信協(xié)議是一種適用于工業(yè)控制系統(tǒng)和智能家居等領(lǐng)域的通信協(xié)議,具有高速、遠(yuǎn)距離、可靠性強(qiáng)等優(yōu)點(diǎn),能夠滿足大量數(shù)據(jù)傳輸?shù)男枨螅⑻岣邤?shù)據(jù)傳輸?shù)男屎蛯?shí)時(shí)性。
二 RS485通信的優(yōu)缺點(diǎn)
1 RS485通信協(xié)議優(yōu)點(diǎn):
抗干擾性強(qiáng):RS485采用平衡驅(qū)動(dòng)器和差分接收器的組合,具有抗共模干擾能力,能夠抵抗外部干擾,保證通信的穩(wěn)定性。
傳輸距離遠(yuǎn):RS485最大的通信距離約為1219米,最大傳輸速率為10Mbps,傳輸速率與傳輸距離成反比,可以在較長(zhǎng)的距離上進(jìn)行穩(wěn)定的數(shù)據(jù)傳輸。
通信速率高:RS485的數(shù)據(jù)最高傳輸速率為10Mbps,比傳統(tǒng)的串口通信協(xié)議快得多,可以滿足高速數(shù)據(jù)傳輸?shù)男枨蟆?/p>
支持多設(shè)備連接:RS485采用總線式拓?fù)浣Y(jié)構(gòu),允許多個(gè)設(shè)備共享同一通信線路,方便實(shí)現(xiàn)設(shè)備之間的互連互通。
2 RS485通信協(xié)議缺點(diǎn):
通信速率限制:雖然RS485支持高速數(shù)據(jù)傳輸,但隨著傳輸距離的增加,傳輸速率會(huì)受到限制。當(dāng)傳輸距離超過(guò)一定距離時(shí),需要使用中繼器來(lái)擴(kuò)展傳輸距離。
連接設(shè)備數(shù)量限制:由于RS485采用總線式拓?fù)浣Y(jié)構(gòu),連接的設(shè)備數(shù)量越多,線路越復(fù)雜,因此連接設(shè)備數(shù)量受到限制。
信號(hào)衰減問(wèn)題:在長(zhǎng)距離傳輸時(shí),由于信號(hào)衰減和噪聲干擾等原因,可能會(huì)出現(xiàn)數(shù)據(jù)傳輸錯(cuò)誤或丟失的情況。因此,對(duì)于長(zhǎng)距離傳輸,需要采取措施來(lái)保證數(shù)據(jù)的準(zhǔn)確性和完整性。
三 物理層接口
RS485通信協(xié)議的物理層接口包括差分信號(hào)傳輸、DB9或RJ45接口以及信號(hào)定義等。
差分信號(hào)傳輸是RS485通信協(xié)議的核心技術(shù),通過(guò)兩個(gè)信號(hào)線(A線和B線)來(lái)傳輸數(shù)據(jù)。A線傳輸數(shù)據(jù)的正信號(hào),B線傳輸數(shù)據(jù)的負(fù)信號(hào)。這種差分信號(hào)的優(yōu)點(diǎn)是可以抵消干擾信號(hào),提高通信的穩(wěn)定性。
在物理層接口中,RS485協(xié)議使用DB9或RJ45接口進(jìn)行連接。DB9接口包括A線、B線、地線和控制線等,而RJ45接口則采用水晶頭連接方式。
RS485通信協(xié)議的物理層還定義了電壓、時(shí)序、數(shù)據(jù)速率等參數(shù)。標(biāo)準(zhǔn)規(guī)定,邏輯1的電壓范圍為+2V~+6V,邏輯0的電壓范圍為-6V~-2V。在較長(zhǎng)的電纜長(zhǎng)度上,接收器接收到的電壓可能會(huì)降低到+/- 200 mV,但對(duì)于RS485仍然是完全可以接受的。RS485通信協(xié)議的物理層接口規(guī)定了通信協(xié)議的核心技術(shù)要求,包括差分信號(hào)傳輸、接口標(biāo)準(zhǔn)和信號(hào)定義等,以確保數(shù)據(jù)傳輸?shù)姆€(wěn)定性和可靠性。
四 RS485與Modbus的區(qū)別
物聯(lián)網(wǎng)的從業(yè)者,剛應(yīng)用RS485時(shí),經(jīng)常會(huì)接觸到另外一個(gè)協(xié)議:Modbus協(xié)議,它與RS485有什么關(guān)系和區(qū)別呢?
RS485與Modbus的區(qū)別主要體現(xiàn)在以下三個(gè)方面:
協(xié)議性質(zhì):RS485是一種物理層通信標(biāo)準(zhǔn),主要定義了電氣特性、信號(hào)傳輸方式和連接方式等,而Modbus是一種通信協(xié)議,定義了一種常用的通信格式和規(guī)則,用于在主設(shè)備和從設(shè)備之間進(jìn)行數(shù)據(jù)交換。
應(yīng)用范圍:RS485通常用作物理層協(xié)議,支持Modbus協(xié)議,而Modbus更常用于工業(yè)控制領(lǐng)域,是一種通用的通信語(yǔ)言,支持RS485、RS232等串口。
功能特性:RS485具有較長(zhǎng)的通信距離、較強(qiáng)的抗干擾能力,支持多點(diǎn)、雙向通信,而Modbus支持主從模式,可以實(shí)現(xiàn)多個(gè)設(shè)備之間的數(shù)據(jù)交換。
所以,RS485和Modbus在協(xié)議性質(zhì)、應(yīng)用范圍和功能特性方面存在明顯的區(qū)別。在工業(yè)控制和智能設(shè)備通信領(lǐng)域,二者常常被結(jié)合使用,以實(shí)現(xiàn)高效、穩(wěn)定的數(shù)據(jù)傳輸。
四 綜述
RS485通信協(xié)議在物聯(lián)網(wǎng)中具有重要的地位和價(jià)值。首先,RS485協(xié)議是一種可靠、高效的通信協(xié)議,適用于多個(gè)設(shè)備之間的長(zhǎng)距離通信,能夠滿足物聯(lián)網(wǎng)中大量設(shè)備之間數(shù)據(jù)傳輸?shù)男枨?。其次,RS485協(xié)議具有抗干擾能力強(qiáng)、傳輸距離遠(yuǎn)、支持多設(shè)備連接等優(yōu)點(diǎn),可以適應(yīng)復(fù)雜的物聯(lián)網(wǎng)環(huán)境,保證數(shù)據(jù)傳輸?shù)姆€(wěn)定性和可靠性。此外,RS485協(xié)議的傳輸層協(xié)議規(guī)定了數(shù)據(jù)傳輸?shù)母袷胶鸵?guī)則,包括數(shù)據(jù)幀的定義、傳輸順序、校驗(yàn)方式等,可以滿足物聯(lián)網(wǎng)中不同應(yīng)用場(chǎng)景的數(shù)據(jù)傳輸需求。
在物聯(lián)網(wǎng)中,RS485協(xié)議被廣泛應(yīng)用于各種領(lǐng)域,如工業(yè)控制、智能家居、城市管理、智能交通等。在這些領(lǐng)域中,RS485協(xié)議可以實(shí)現(xiàn)設(shè)備之間的快速、穩(wěn)定、可靠的數(shù)據(jù)傳輸,提高設(shè)備的智能化程度和用戶體驗(yàn)。例如,在智能家居中,RS485協(xié)議可以用于家庭內(nèi)部的各種設(shè)備之間的通信,包括智能電視、智能音響、智能照明、智能安防等,實(shí)現(xiàn)設(shè)備的互聯(lián)互通和集中控制。
AIoT星球君:RS485通信協(xié)議在物聯(lián)網(wǎng)中具有重要的地位和價(jià)值,它的優(yōu)點(diǎn)和特性使其成為工業(yè)控制系統(tǒng)和智能家居等領(lǐng)域的重要通信方式。通過(guò)使用RS485協(xié)議,可以實(shí)現(xiàn)設(shè)備的遠(yuǎn)程監(jiān)控和控制,提高設(shè)備的智能化程度和用戶體驗(yàn)。
五 組件的使用
1 Gitee鏈接地址
組件位于amaziot_bloom_os_sdklibrariesair_4g_swair_swam_485.c
Gitee源碼地址:https://gitee.com/ning./hongdou
Github源碼地址:https://github.com/ayumid/hongdou
2 應(yīng)用層組件功能介紹
提供485串口Modbus實(shí)例。實(shí)現(xiàn)輪詢,并將Modbus RTU 協(xié)議數(shù)據(jù),轉(zhuǎn)發(fā)到服務(wù)器。
該組件需要和文件組件組合使用,文件中記錄了485總線中哪些設(shè)備目前在線等信息。
3 代碼講解
dtu_485_task_init
初始化modbus任務(wù)
void dtu_485_task_init(void) { OSA_STATUS status = 0; /*creat message*/ status = OSAMsgQCreate(&dtu_485_msgq, "dtu_485_msgq", DTU_485_TASK_MSGQ_MSG_SIZE, DTU_MODBUS_TASK_MSGQ_QUEUE_SIZE, OS_FIFO); ASSERT(status == OS_SUCCESS); status = OSATaskCreate(&dtu_485_msgq_task_ref, dtu_485_task_stack, DTU_485_TASK_STACK_SIZE, 161, "modbus_task", dtu_modbus_task, NULL); ASSERT(status == OS_SUCCESS); }
dtu_alive_task
檢查設(shè)備在線情況任務(wù),輪詢檢查,檢查最后一次收到信息和當(dāng)前時(shí)間的時(shí)間差,判斷是否離線
static void dtu_alive_task(void *ptr) { OSA_STATUS status = 0; int i = 0; UINT32 timestamp = 0; // int id = 0; DTU_FILE_PARAM_T* dtu_file_ctx = NULL; dtu_file_ctx = dtu_get_file_ctx(); while(1) { // uprintf("%s[%d] timer msgrn", __FUNCTION__, __LINE__); //for循環(huán)查詢列表中哪些指令激活,按照激活指令參數(shù)配置 指令 for(i = 0; i < SW_DTU_NUM_MAX; i++) { //當(dāng)前列表第i指令被激活 if(DTU_MODBUS_ACTIVE == dtu_file_ctx-?>modbus.cmd[i].active) { //獲取當(dāng)前時(shí)間 timestamp = utils_utc8_2_timestamp(); if(timestamp - sw_dtu_alive[i].timercv > SW_DTU_TIMEOUT) { sw_dtu_alive[i].alive = 0; } uprintf("%s[%d] slave addr: %d id: %d cmd: 0x%02Xn", __FUNCTION__, __LINE__, dtu_file_ctx->modbus.cmd[i].slave_addr, st_dtu_md.id + 1, dtu_file_ctx->modbus.cmd[i].fn); } } sleep(1); } }
dtu_485_task
485主任務(wù),接收發(fā)送485串口數(shù)據(jù)
static void dtu_485_task(void *ptr) { OSA_STATUS status = 0; int ret = 0; int i = 0; // int id = 0; int send_len = 0; DTU_MSG_UART_DATA_PARAM_T uart_data = {0}; uint8_t ctx_send_buf[AGILE_MODBUS_MAX_ADU_LENGTH]; uint8_t ctx_read_buf[1]; // uint8_t send[100] = {0}; // uint8_t recv[100] = {0}; // uint8_t* temp = NULL; DTU_FILE_PARAM_T* dtu_file_ctx = NULL; dtu_file_ctx = dtu_get_file_ctx(); agile_modbus_rtu_t ctx_dtu = {0}; agile_modbus_t *ctx = &ctx_dtu._ctx; agile_modbus_rtu_init(&ctx_dtu, ctx_send_buf, sizeof(ctx_send_buf), ctx_read_buf, sizeof(ctx_read_buf)); dtu_modbus_interval_timer_init(); st_dtu_md.state = DTU_MODBUS_POOLLING_STATE; if(DTU_MODBUS_TYPE_ENABLE == dtu_file_ctx->modbus.config.type) { dtu_modbus_interval_timer_start(); } //#define AGILE_MODBUS_FC_READ_COILS 0x01 //#define AGILE_MODBUS_FC_READ_DISCRETE_INPUTS 0x02 //#define AGILE_MODBUS_FC_READ_HOLDING_REGISTERS 0x03 //#define AGILE_MODBUS_FC_READ_INPUT_REGISTERS 0x04 //#define AGILE_MODBUS_FC_WRITE_SINGLE_COIL 0x05 //#define AGILE_MODBUS_FC_WRITE_SINGLE_REGISTER 0x06 //#define AGILE_MODBUS_FC_READ_EXCEPTION_STATUS 0x07 //#define AGILE_MODBUS_FC_WRITE_MULTIPLE_COILS 0x0F //#define AGILE_MODBUS_FC_WRITE_MULTIPLE_REGISTERS 0x10 //#define AGILE_MODBUS_FC_REPORT_SLAVE_ID 0x11 //#define AGILE_MODBUS_FC_MASK_WRITE_REGISTER 0x16 //#define AGILE_MODBUS_FC_WRITE_AND_READ_REGISTERS 0x17 while(1) { //阻塞1s等待從機(jī)回復(fù)的數(shù)據(jù) status = OSAMsgQRecv(dtu_modbus_msgq, (void *)&uart_data, DTU_MODBUS_TASK_MSGQ_MSG_SIZE, OSA_SUSPEND); if(status == OS_SUCCESS) { if(DTU_MODBUS_TIMER_INTERVAL_MSG == uart_data.id) { // uprintf("%s[%d] timer msgrn", __FUNCTION__, __LINE__); if(DTU_MODBUS_POOLLING_STATE == st_dtu_md.state) { //for循環(huán)查詢列表中哪些指令激活,按照激活指令參數(shù)配置 指令 for(i = st_dtu_md.id; i < DTU_MODBUS_CMD_NUM; i++) { //當(dāng)前列表第i指令被激活 if(DTU_MODBUS_ACTIVE == dtu_file_ctx-?>modbus.cmd[i].active) { //設(shè)置從機(jī)地址 agile_modbus_set_slave(ctx, dtu_file_ctx->modbus.cmd[i].slave_addr); uprintf("%s[%d] slave addr: %d id: %d cmd: 0x%02Xn", __FUNCTION__, __LINE__, dtu_file_ctx->modbus.cmd[i].slave_addr, st_dtu_md.id + 1, dtu_file_ctx->modbus.cmd[i].fn); } else { // uprintf("%s[%d] none cmd continue i:%d id: %dn", __FUNCTION__, __LINE__, i + 1, st_dtu_md.id); st_dtu_md.id = i + 1; continue; } //根據(jù)指令01 來(lái)組包 if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_READ_COILS) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_read_bits(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } //根據(jù)指令02 來(lái)組包 else if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_READ_DISCRETE_INPUTS) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_read_input_bits(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } //根據(jù)指令03 來(lái)組包 else if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_READ_HOLDING_REGISTERS) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_read_registers(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } //根據(jù)指令04 來(lái)組包 else if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_READ_INPUT_REGISTERS) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_read_input_registers(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } //根據(jù)指令05 來(lái)組包 else if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_WRITE_SINGLE_COIL) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_write_bit(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } //根據(jù)指令06 來(lái)組包 else if(dtu_file_ctx->modbus.cmd[i].fn == AGILE_MODBUS_FC_WRITE_SINGLE_REGISTER) { //組包數(shù)據(jù) send_len = agile_modbus_serialize_write_register(ctx, dtu_file_ctx->modbus.cmd[i].reg_addr, dtu_file_ctx->modbus.cmd[i].reg_n_d); } // uprintf("%s[%d] find cmdrn", __FUNCTION__, __LINE__); //當(dāng)前激活id,跳出這次循環(huán) break; } st_dtu_md.id++; // uprintf("%s[%d] sendbuf len: %d mdid: %drn", __FUNCTION__, __LINE__, send_len, st_dtu_md.id); if(st_dtu_md.id > DTU_MODBUS_CMD_NUM) { st_dtu_md.id = 0; st_dtu_md.state = DTU_MODBUS_POOLLING_WN_STATE; uprintf("%s[%d] poolling end", __FUNCTION__, __LINE__); //停止modbus驅(qū)動(dòng)定時(shí)器 // dtu_modbus_interval_timer_stop(); //輪訓(xùn)完畢后,重新開始之前等待時(shí)間 // dtu_sleep(dtu_file_ctx->modbus.config.delay); //開始modbus驅(qū)動(dòng)定時(shí)器 // dtu_modbus_interval_timer_start(); } else { // uprintf("%s[%d] send md hexrn", __FUNCTION__, __LINE__); // int j = 0; // for(j = 0; j < send_len; j++) // { // uprintf("reg data[%d]: %Xrn", j, ctx-?>send_buf[j]); // } //發(fā)送數(shù)據(jù)到串口 UART_SEND_DATA(ctx->send_buf, send_len); } } else if(DTU_MODBUS_POOLLING_WN_STATE == st_dtu_md.state) { //for循環(huán)查詢列表中哪些指令激活,按照激活指令參數(shù)配置 指令 for(i = st_dtu_md.id; i < DTU_MODBUS_CMD_WN_NUM; i++) { //當(dāng)前列表第i指令被激活 if(DTU_MODBUS_ACTIVE == dtu_file_ctx-?>modbus.cmd_wn[i].active) { //設(shè)置從機(jī)地址 agile_modbus_set_slave(ctx, dtu_file_ctx->modbus.cmd_wn[i].slave_addr); uprintf("%s[%d] slave addr: %d id: %d cmd: 0x%02X", __FUNCTION__, __LINE__, dtu_file_ctx->modbus.cmd_wn[i].slave_addr, st_dtu_md.id + 1, dtu_file_ctx->modbus.cmd_wn[i].fn); } else { // uprintf("%s[%d] none cmd continue i:%d id: %dn", __FUNCTION__, __LINE__, i + 1, st_dtu_md.id); st_dtu_md.id = i + 1; continue; } //根據(jù)指令0F 來(lái)組包 // if(dtu_file_ctx->modbus.cmd_wn[i].fn == AGILE_MODBUS_FC_WRITE_MULTIPLE_COILS) // { // uprintf("cmd 0x10 regnum: %drn", dtu_file_ctx->modbus.cmd_wn[i].reg_n_d); //組包數(shù)據(jù) // send_len = agile_modbus_serialize_write_registers(ctx, dtu_file_ctx->modbus.cmd_wn[i].reg_addr, dtu_file_ctx->modbus.cmd_wn[i].reg_n, (UINT16*)&dtu_file_ctx->modbus.cmd_wn[i].reg_data); // int j = 0; // for(j = 0; j < dtu_file_ctx-?>modbus.cmd_wn[i].reg_n_d; j++) // { // uprintf("reg data[%d]: %Xrn", j, dtu_file_ctx->modbus.cmd_wn[i].reg_data[j]); // } // } //根據(jù)指令10 來(lái)組包 if(dtu_file_ctx->modbus.cmd_wn[i].fn == AGILE_MODBUS_FC_WRITE_MULTIPLE_REGISTERS) { // uprintf("cmd 0x10 regnum: %drn", dtu_file_ctx->modbus.cmd_wn[i].reg_n_d); //組包數(shù)據(jù) send_len = agile_modbus_serialize_write_registers(ctx, dtu_file_ctx->modbus.cmd_wn[i].reg_addr, dtu_file_ctx->modbus.cmd_wn[i].reg_n, (UINT16*)&dtu_file_ctx->modbus.cmd_wn[i].reg_data); // int j = 0; // for(j = 0; j < dtu_file_ctx-?>modbus.cmd_wn[i].reg_n_d; j++) // { // uprintf("reg data[%d]: %Xrn", j, dtu_file_ctx->modbus.cmd_wn[i].reg_data[j]); // } } // uprintf("%s[%d] find cmdrn", __FUNCTION__, __LINE__); //當(dāng)前激活id,跳出這次循環(huán) break; } st_dtu_md.id++; // uprintf("%s[%d] sendbuf len: %d mdid: %drn", __FUNCTION__, __LINE__, send_len, st_dtu_md.id); if(st_dtu_md.id > DTU_MODBUS_CMD_WN_NUM) { st_dtu_md.id = 0; st_dtu_md.state = DTU_MODBUS_POOLLING_STATE; uprintf("%s[%d] wn poolling end", __FUNCTION__, __LINE__); //停止modbus驅(qū)動(dòng)定時(shí)器 dtu_modbus_interval_timer_stop(); //輪訓(xùn)完畢后,重新開始之前等待時(shí)間 dtu_sleep(dtu_file_ctx->modbus.config.delay); //開始modbus驅(qū)動(dòng)定時(shí)器 dtu_modbus_interval_timer_start(); } else { // uprintf("%s[%d] send md hexrn", __FUNCTION__, __LINE__); // int j = 0; // for(j = 0; j < send_len; j++) // { // uprintf("reg data[%d]: %Xrn", j, ctx-?>send_buf[j]); // } //發(fā)送數(shù)據(jù)到串口 UART_SEND_DATA(ctx->send_buf, send_len); } } } else if(DTU_MODBUS_DATA_MSG == uart_data.id && NULL != uart_data.UArgs) { // uprintf("%s[%d] modbus res", __FUNCTION__, __LINE__); // // UINT8* p = uart_data.UArgs; // for (i = 0; i < uart_data.len; i++) // { // uprintf("0x%02X" , p[i]); // } //如果是modbus數(shù)據(jù),判斷目前是modbus rtu上報(bào)模式,modbus tcp上報(bào)模式,還是json上報(bào)格式 if(DTU_MODBUS_RESPONSE_JSON_TYPE == dtu_file_ctx-?>modbus.config.res_type) { uprintf("modbus json res"); dtu_modbus_json_modbus_res(uart_data.UArgs, uart_data.len); } // else if(DTU_MODBUS_RESPONSE_TCP_TYPE == dtu_file_ctx->modbus.config.res_type) // { // //判斷是否是modbus一幀數(shù)據(jù) // ret = dtu_modbus_protocol_check(uart_data.UArgs, uart_data.len); // if(DTU_MODBUS_PROTOCOL_SUCCESS == ret) // { // uprintf("modbus tcp res"); // } // } else { uprintf("modbus rtu res"); //modbus rtu幀,直接發(fā) #ifdef DTU_BASED_ON_TCP dtu_socket_write(uart_data.UArgs, uart_data.len); #endif /* ifdef DTU_BASED_ON_TCP.2023-10-31 12:01:18 by: zhaoning */ #ifdef DTU_BASED_ON_MQTT dtu_mqtt_send(uart_data.UArgs, uart_data.len); #endif /* ifdef DTU_BASED_ON_MQTT.2023-10-31 12:01:28 by: zhaoning */ } //釋放數(shù)據(jù)內(nèi)存 free(uart_data.UArgs); //置空 uart_data.UArgs = NULL; } } } }
dtu_485_interval_timer_init
初始化指令間隔定時(shí)器,Modbus輪詢過(guò)程中每個(gè)指令之間的間隔時(shí)間
static void dtu_485_interval_timer_init(void) { OSA_STATUS status = 0; //初始化指令間隔定時(shí)器 status = OSATimerCreate(&st_dtu_md.md_timer_ref); ASSERT(status == OS_SUCCESS); }
dtu_485_interval_timer_start
開始指令間隔定時(shí)器
void dtu_485_interval_timer_start(void) { DTU_FILE_PARAM_T* dtu_file_ctx = NULL; dtu_file_ctx = dtu_get_file_ctx(); OSATimerStart(st_dtu_md.md_timer_ref, dtu_file_ctx->modbus.config.interval * 200, dtu_file_ctx->modbus.config.interval * 200 , dtu_modbus_interval_timer_callback, 0); }
4 Demo實(shí)戰(zhàn)
4.1 創(chuàng)建一個(gè)Demo
復(fù)制20.9_di_xtu示例工程,到同一個(gè)文件夾下,修改文件名為20.12_485_air_sw,如圖:
4.2 修改makefile
增加文件組件所在目錄頭文件路徑,和源文件路徑,以及一些宏定義,如圖:
-D是makefile中定義宏定義必要的前綴,可以搜索相關(guān)makefile學(xué)習(xí)文章學(xué)習(xí)相關(guān)知識(shí)。
DTU_BASED_ON_TCP 表示當(dāng)前是TCP模式,當(dāng)前組件使用需要am.h中包含一些對(duì)應(yīng)。
DTU_TYPE_5X6 表示使用SOM板貼片5x6卡,可以使用其它卡,修改為對(duì)應(yīng)宏定義就可以。
DTU_UART_115200_BAUD 表示使用115200波特率
DTU_TYPE_JSON_INCLUDE 表示把JSON功能包含進(jìn)來(lái)
4.3 增加頭文件
使用代碼編輯器,將新建的工程文件加入代碼編輯器中,打開main.c,修改main.c,加入am.h頭文件,如圖:
4.4 修改代碼
示例使用的是板載5x6卡,用戶的硬件可能是使用外置卡,或者是三合一全網(wǎng)通卡,因?yàn)橛布先N卡使用的模組SIM卡接口不一樣(外置卡SIM1,5x6卡和三合一卡SIM2),所以,需要通過(guò)一個(gè)全局變量來(lái)制定SIM卡硬件接口。
extern外部變量SDK_INIT_SIM_SELECT_VALUE,這里判斷了是否使用外置卡,這個(gè)宏定義在Makefile里面定義。
在Phase1Inits_enter中,宏定義判斷是否要包含對(duì)SDK_INIT_SIM_SELECT_VALUE變量的修改。
在Phase2Inits_exit 調(diào)用文件組件提供的對(duì)外API,如圖:
4.5 編譯
在SDK根目錄打開命令行,輸入命令.build.bat -l .amaziot_bloom_os_sdksamplelibraries20.14_modbus_xtu
PS F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08 λ .build.bat -l .amaziot_bloom_os_sdksamplelibraries20.14_485_air_sw 子目錄或文件 outbin 已經(jīng)存在。 子目錄或文件 buildcJSON 已經(jīng)存在。 子目錄或文件 buildobj 已經(jīng)存在。 gnumake: Entering directory `F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.14_modbus_xtu' armcc.exe -c --cpu Cortex-R4 --no_unaligned_access -g -O2 --apcs /inter --diag_suppress 2084,1,2,177,188,223,550,1296,2795,6319,9931,9933 --diag_error=warning --gnu --thumb --loose_implicit_cast -DDATA_COLLECTOR_IMPL -DISPT_OVER_SSP -DDIAG_SSP_DOUBLE_BUFFER_USE_DYNAMIC_ALLOCATION -DENV_XSCALE -DL1_DCXO_ENABLED -DLTE_HIGH_MOBILITY_OPTIMIZATION -DRUN_XIP_MODE -DCRANE_Z2 -DCA_LONG_IPC_MSG -DNEZHA3 -DNEZHA3_1826 -DUPGRADE_PLMS -DUPGRADE_PLMS_SR -DLTE_GSMMULTIBCCH -DGPLC_LTE_RSSI_SCAN -DL1V_NEW_RSSI -DUPGRADE_PLMS_3G -DUPGRADE_PLMS_L1 -DUPGRADE_FG_PLMS -DFG_PLMS_URR -DUPGRADE_L1A_FG_PLMS -DUPGRADE_PLMS_STAGE_2 -DUPGRADE_MBCCH -DMULTI_BCCH_READY_IND -DURR_MRAT_ICS_SEARCH -DUPGRADE_ICS -DMRAT_NAS -DUPGRADE_PLMS_SEARCH_API -DICS_MBCCH -DICS_MBCCH_2G_RSSI -DDIAG_NEWPP -DPHS_SW_DEMO -DPHS_SW_DEMO_TTC -DPHS_SW_DEMO_TTC_PM -DFULL_SYSTEM -D_DDR_INIT_ -D_TAVOR_HARBELL_ -DUPGRADE_ARBEL_PLATFORM -D_TAVOR_B0_SILICON_ -DTDL1C_SPY_ENABLE -DDLM_TAVOR -DTAVOR -DFLAVOR_DUALCORE -DDEBUG_D2_MOR_REG_RESEREVED_ENABLE -D_DIAG_USE_COMMSTACK_ -D_TAVOR_DIAG_ -DPM_DEBUG_MODE_ENABLED -DPM_D2FULL_MODE -DPM_EXT_DBG_INT_ARR -DFEATURE_WB_AMR_PS -DMACRO_FOR_LWG -DHL_LWG -DOPTIMIZE_FOR_2G_BCCH -DPLAT_TEST -D_FDI_USE_OSA_ -DPLAT_USE_THREADX -DLWIP_IPNETBUF_SUPPORT -DCRANE_MCU_DONGLE -DAT_OVER_UART -DPHS_SW_DEMO_TTC_PM -DUPGRADE_LTE_ONLY -DEXT_AT_MODEM_SUPPORT -DLTEONLY_THIN_SINGLE_SIM -DLFS_FILE_SYS -DLFS_FILE_SYS_V2 -DPSM_ENABLE -DNO_PAHO_MQTT -DNO_XML -DNO_LWM2M -DREMOVE_MBEDTLS -DNO_AT_NET -DCRANE_SD_NOT_SUPPORT -DNTP -DYMODEM_EEH_DUMP -DENABLE_DM_LTEONLY -DLTEONLY_THIN -DNO_EXTEND_MY_Q_AT -DNOT_SUPPORT_HTTPS -DNOT_SUPPORT_PM813 -DCRANEL_4MRAM -DREMOVE_PB -DUART_NEW_VERSION -DREMOVE_MEP -DREMOVE_SMS -DREMOVE_ENVSIM -DAPN_INCODE -DLTEONLY_THIN_SINGLE_SIM_2MFLASH -DASR160X_OPENCPU_FEATURE -DENABLE_UART3_FEATRUE -DENABLE_UART4_FEATRUE -DYUGE_MBEDTLS_3_2_1 -DENABLE_MAC_TX_DATA_LOGGING -DDISABLE_NVRAM_ACCESS -DINTEL_UPGRADE_EE_HANDLER_SUPPORT -DLTE_W_PS -DL1_DUAL_MODE -DUPGRADE_HERMON_DUAL -DINTEL_UPGRADE_DUAL_RAT -DINTEL_UPGRADE_GPRS_CIPHER_FLUSH -DUPGRADE_ENHANCED_QUAD_BAND -DINTEL_2CHIP_PLAT -DI_2CHIP_PLAT -DUPGRDE_TAVOR_COMMUNICATION -DRUN_WIRELESS_MODEM -DFLAVOR_DDR12MB_GB1MB5 -DFEATURE_SHMEM -DACIPC_ENABLE_NEW_CALLBACK_MECHANISM -DRELIABLE_DATA -DMAP_NSS -DTV_FNAME=""SW_PLATFORM=PMD2NONE PHS_SW_DEMO PHS_SW_DEMO_PM SRCNUCLEUS FULL_SYSTEM NOACRTC PDFLT PLAT_TEST PV2 DIAGOSHMEM NVM WITHL1V"" -DTV_FDESC=""SW_DESCRIPTION="" -DENABLE_ACIPC -D_DATAOMSL_ENABLED_ -DUSB_CABLE_DETECTION_VIA_PMIC -DMIPS_TEST -DMIPS_TEST_RAM -DFLAVOR_DIET_RAM -DNVM_INCLUDE -DMSL_INCLUDE -DMSL_POOL_MEM -DNO_AUDIO -DOSA_QUEUE_NAMES -D_DIAG_DISABLE_USB_ -DOSA_NUCLEUS -DOSA_USED -DPM_D2NONE_MODE -DCRANE_SOC_TEMPERATURE_SENSOR -DL1_SW_UPDATE_FOR_DIGRF -DPHS_L1_SW_UPDATE_R7 -DUPGRADE_LTE -DFRBD_CALIB_NVM -DFRBD_AGC_CALIB -DFRBD_FDT_CALIB -DHSPA_MPR -DCAPT_PARAMS_OPTIMIZE -DL1_WB_R99_ONLY -DL1V_WB_R99_ONLY -DINTERGRATED_RF_SUPPORT -DL1_RX_DIV_SUPPORT -DENABLE_OOS_HANDLING -DTAVOR_D2_WB_L1_SUPPORT -DL1_DDR_HIGH_FREQ -DUPGRADE_DIGRF3G_SUPPORT -DW_PS_PLUS_G_PAGING -D"NO_APLP=0" -DINTEL_UPGRADE_UNIFIED_VOICE_TASK -DINTEL_UPGRADE_R99 -DAPLP_SPY_ENABLE -D__TARGET_FEATURE_DOUBLEWORD -DWHOLE_UMTS_STACK -DUSE_TTPCOM_CSR_BLUETOOTH_AUDIO_GAIN_CONTROL -DL1_UPGRADE_R5 -DUPGRADE_EDGE -DUPGRADE_R4_FS1 -DINTEL_UPGRADE_GSM_CRL_IF -DUPGRADE_EGPRS_M -DINTEL_UPGRADE_EGPRS_M -DINTEL_UPGRADE_RF_PARAMS_IN_CF_TDS -DINTEL_UPGRADE_2SAMPLES_PER_SYMBOL -D"GPRS_MULTISLOT_CLASS=12" -D"EGPRS_MULTISLOT_CLASS=12" -DMARVELL_UPGRADE_BSIC_REDESIGN -DMSL_INCLUDE -DINTEL_HERMON_SAC -DCRANE_CUST_BUILD -DL1_SW_UPDATE_FOR_DIGRF -DFLAVOR_COM -DSILICON_PV2 -DSILICON_SEAGULL -DSILICON_TTC_CORE_SEAGULL -DPCAC_INCLUDE -Otime -DBUILD_DATE=""11 22 2023"" -DBUILD_TIME=""11:19:00"" -Iatcmdsinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonyyugeinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalUARTinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalcoreinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalPMUinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalGPIOinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xosposixinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xdiagdiag_logicsrc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xcswSysCfginc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xcswplatforminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xenvwin32inc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xcswBSPinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xcswplatformdev_platbuild -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xososainc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xosthreadxinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xosnu_xscaleinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacpsminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcachttpclientsrc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xdiagdiag_logicinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptimerinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopintcinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xcswPMinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoppminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilTickManagerinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopBSPinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonyatcmdsrvinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonyatparserinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonysdkinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcachttpclientinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacciinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcinclude -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcincludearch -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcincludeipv4 -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcincludeipv6 -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcincludelwip -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcaclwipv4v6srcincludenetif -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopmmi_matinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xtavorArbelinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xtavorenvinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonymodeminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacdusterinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacfotainc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalI2Cinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalACIPCinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilfatsysflash -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilFDIsrcINCLUDE -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalMMUinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilFDIsrcFDI_ADD -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilFDIsrcFM_INC -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilfatsysfshdr -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutillittlefsinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacttsinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacdialinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilcsw_memoryinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoputilitiesinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopcommpminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilnvminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilEEhandlerinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilEEhandlersrc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopRTCinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhoptelephonyci_clientinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalBT_deviceinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalUARTinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopmrdinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopdmainc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilsoftutilinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhalSPIinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacwebsocketinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacatnet_srvinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xsoftutilfotacomminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xaud_swAudioinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xaud_swACM_COMMinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xaud_swaudio_stubsrc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhopaaminc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xaud_swAudioHALinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xhaldbgshellinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08includeasr160xpcacopencpuinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08amaziot_bloom_os_sdkutils -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08CSDK_CODEcJSONinc -IF:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.14_modbus_xtuaminc -IF:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.14_modbus_xtuatcmdsinc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/librariesamxtu -DDTU_BASED_ON_TCP -DDTU_TYPE_5X6 -DDTU_UART_115200_BAUD -DDTU_TYPE_MODBUS_INCLUDE -DDTU_TYPE_JSON_INCLUDE -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/libraries/third_party/agile_modbus-1.1.3inc -IF:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/libraries/third_party/agile_modbus-1.1.3util -o buildobj/ext_at_cmds.o F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.14_modbus_xtu/atcmds/src/ext_at_cmds.c armlink.exe buildobj/main.o buildobj/ext_at_cmds.o buildobj/ext_at_controller.o buildobj/am_file.o buildobj/am_at.o buildobj/am_trans.o buildobj/am_socket.o buildobj/am_hb.o buildobj/am_net.o buildobj/am_json.o buildobj/am_modbus.o buildobj/utils_string.o buildobj/agile_modbus_slave_util.o buildobj/agile_modbus.o buildobj/agile_modbus_rtu.o buildobj/agile_modbus_tcp.o buildCSDK_CODE.lib -o F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08outbinArbel_PMD2NONE_40M.axf --via F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08prebuilt_1606lArbel_PMD2NONE_targ_objliblist.txt --elf --scatter F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08prebuilt_1606lCrane_DS_4M_Ram_2M_Flash_XIP_CIPSRAM_Common_SingleSIM.sct --predefine="-DLTEONLY_THIN_SINGLE_SIM" --map --symbols --info sizes,totals --list F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08outbinArbel_PMD2NONE_40M.map --keep init.o(Header) --keep init.o(Vectors) --diag_suppress 6312,6314,6319,6329 --feedback F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08outfeedbackLinkOptLteonlyThin_SingleSim_NoSMS.txt F:3.asr-bcat.1-asr16061.softwareBLOOM_OS_1606_OPENCPU_1191_A08toolsbuildimage_1606l.bat SDK_PROD_TYPE : [DM] SDK_CUST_SKU : [THIN_SINGLE_SIM_NO_SMS] SDK_PS_MODE : [LTEONLY] SDK_CHIP_VER : [Z2A0] SDK_OS_TYPE : [TX] Platform Convertion Tools v4.01 with PS option extension Convertion done! |INPUT |outbincp_1606L.bin |MARK |NAME |EXEADDR .LOADADDR.LENGTH .CPZLADDR|COMPRESS STASTIC | |--------|--------|--------.--------.--------.--------|------------------------------| |This Is LteOnly 4M| |RW_CPZ_1|DDR_RW_ |7e11c000.8006b8a4.0000d290.8006c000|0000d290->00003000 |This Is LteOnly 4M| |RW_CPZ_2|PS_NCAH |7e388000.80078b34.00001300.8006f000|00001300->00001000 |This Is LteOnly 4M| |RW_CPZ_3|ITCM |7e3dac00.80079e34.0000f51c.80070000|0000f51c->0000a000 |This Is LteOnly 4M| |RW_CPZ_4|CODE_PS |7e1ad000.80089350.0002fcdc.8007a000|0002fcdc->0001e000 |This Is LteOnly 4M| |RW_CPZ_5|CODEPSB |7e1df000.800b902c.000339bc.80098000|000339bc->0001b000 |This Is LteOnly 4M| |RW_CPZ_6|CODEPSC |7e216000.800ec9e8.000323ec.800b3000|000323ec->0001b000 |This Is LteOnly 4M| |RW_CPZ_7|CODEPSD |7e24c000.8011edd4.00028d88.800ce000|00028d88->0001a000 |This Is LteOnly 4M| |RW_CPZ_8|CODEPSE |7e27a000.80147b5c.0002e310.800e8000|0002e310->0001a000 |This Is LteOnly 4M| |RW_CPZ_9|CODEPSF |7e2ac000.80175e6c.0001c948.80102000|0001c948->00011000 |This Is LteOnly 4M| |RW_CPZ_A|CODE_PL |7e2cd000.801927b4.0002f914.80113000|0002f914->0001e000 |This Is LteOnly 4M| |RW_CPZ_B|CODEPLB |7e2fd000.801c20c8.00038d38.80131000|00038d38->00021000 |This Is LteOnly 4M| |RW_CPZ_C|CODEPLC |7e337000.801fae00.000268d4.80152000|000268d4->00012000 |--------|--------|--------.--------.--------.--------|------------------------------| | | 0x0020a6d4 -> 0x0014d000| | | 2.041(MB) -> 1.301(MB)| |------------------------------------------------------------------------------------| cp_1606L.axf cp_1606L.bin cp_1606L.map gnumake: Leaving directory `F:/3.asr-b/cat.1-asr1606/1.software/BLOOM_OS_1606_OPENCPU_1191_A08/amaziot_bloom_os_sdk/sample/libraries/20.14_modbus_xtu' "copy NEZHAC_CP_CNR_MIFI_TX.bin to ./ " 已復(fù)制 1 個(gè)文件。
4.6 生成固件
參考入門中開發(fā)工具,生成工具。
4.7 查看現(xiàn)象
固件下載到模組后,配置服務(wù)器地址,配置Modubs指令,之后用Modbus客戶端來(lái)模擬查看
[11-22 11:46:54:993] [11-22 11:46:54:993]OK [11-22 11:46:56:212] [11-22 11:46:56:212]AT+TRANSIP="TCP","101.200.35.208",8866 [11-22 11:46:56:212] [11-22 11:46:56:212]OK [11-22 11:46:58:042] [11-22 11:46:58:042]CONNECT OK [11-22 11:46:59:123] [11-22 11:46:59:123]AT+MBADD=1,1,1,1,0,10 [11-22 11:46:59:123] [11-22 11:46:59:123]OK [11-22 11:46:59:515] [11-22 11:46:59:515]AT+MBADD=2,1,1,2,0,10 [11-22 11:46:59:515] [11-22 11:46:59:515]OK [11-22 11:47:00:287] [11-22 11:47:00:287]AT+MBADD=3,1,1,3,0,10 [11-22 11:47:00:287] [11-22 11:47:00:287]OK [11-22 11:47:00:709] [11-22 11:47:00:709]AT+MBADD=20,1,1,4,0,10 [11-22 11:47:00:709] [11-22 11:47:00:709]OK [11-22 11:47:01:172] [11-22 11:47:01:172]AT+MBADD=49,1,1,5,0,10 [11-22 11:47:01:172] [11-22 11:47:01:172]OK [11-22 11:47:01:669] [11-22 11:47:01:669]AT+MBADD=50,1,1,6,0,6666 [11-22 11:47:01:669] [11-22 11:47:01:669]OK [11-22 11:47:02:336] [11-22 11:47:02:336]AT+MBADDWN=1,1,1,16,0,5,"16B352A9F615D7D3FE198" [11-22 11:47:02:336] [11-22 11:47:02:336]OK [11-22 11:47:02:937] [11-22 11:47:02:937]AT+MBCFG=1,1,3,6 [11-22 11:47:02:937] [11-22 11:47:02:937]OK
5 總結(jié)
根據(jù)實(shí)驗(yàn)現(xiàn)象,用戶需要實(shí)現(xiàn)自己的AT指令,只需要參考組件中的例子,按照自己需求修改,
本文章源自奇跡物聯(lián)開源的物聯(lián)網(wǎng)應(yīng)用知識(shí)庫(kù)Cellular IoT Wiki,更多技術(shù)干貨歡迎關(guān)注收藏Wiki:Cellular IoT Wiki 知識(shí)庫(kù)(https://rckrv97mzx.feishu.cn/wiki/wikcnBvAC9WOkEYG5CLqGwm6PHf)
歡迎同學(xué)們走進(jìn)AmazIOT知識(shí)庫(kù)的世界!
這里是為物聯(lián)網(wǎng)人構(gòu)建的技術(shù)應(yīng)用百科,以便幫助你更快更簡(jiǎn)單的開發(fā)物聯(lián)網(wǎng)產(chǎn)品。
Cellular IoT Wiki初心:
在我們長(zhǎng)期投身于蜂窩物聯(lián)網(wǎng) ODM/OEM 解決方案的實(shí)踐過(guò)程中,一直被物聯(lián)網(wǎng)技術(shù)碎片化與產(chǎn)業(yè)資源碎片化的問(wèn)題所困擾。從產(chǎn)品定義、芯片選型,到軟硬件研發(fā)和測(cè)試,物聯(lián)網(wǎng)技術(shù)的碎片化以及產(chǎn)業(yè)資源的碎片化,始終對(duì)團(tuán)隊(duì)的產(chǎn)品開發(fā)交付質(zhì)量和效率形成制約。為了減少因物聯(lián)網(wǎng)碎片化而帶來(lái)的重復(fù)開發(fā)工作,我們著手對(duì)物聯(lián)網(wǎng)開發(fā)中高頻應(yīng)用的技術(shù)知識(shí)進(jìn)行沉淀管理,并基于 Bloom OS 搭建了不同平臺(tái)的 RTOS 應(yīng)用生態(tài)。后來(lái)我們發(fā)現(xiàn),很多物聯(lián)網(wǎng)產(chǎn)品開發(fā)團(tuán)隊(duì)都面臨著相似的困擾,于是,我們決定向全體物聯(lián)網(wǎng)行業(yè)開發(fā)者開放奇跡物聯(lián)內(nèi)部沉淀的應(yīng)用技術(shù)知識(shí)庫(kù) Wiki,期望能為更多物聯(lián)網(wǎng)產(chǎn)品開發(fā)者減輕一些重復(fù)造輪子的負(fù)擔(dān)。
Cellular IoT Wiki沉淀的技術(shù)內(nèi)容方向如下:
奇跡物聯(lián)的業(yè)務(wù)服務(wù)范圍:基于自研的NB-IoT、Cat1、Cat4等物聯(lián)網(wǎng)模組,為客戶物聯(lián)網(wǎng)ODM/OEM解決方案服務(wù)。我們的研發(fā)技術(shù)中心在石家莊,PCBA生產(chǎn)基地分布在深圳、石家莊、北京三個(gè)工廠,滿足不同區(qū)域&不同量產(chǎn)規(guī)模&不同產(chǎn)品開發(fā)階段的生產(chǎn)制造任務(wù)。跟傳統(tǒng)PCBA工廠最大的區(qū)別是我們只服務(wù)物聯(lián)網(wǎng)行業(yè)客戶。
連接我們,和10000+物聯(lián)網(wǎng)開發(fā)者一起 降低技術(shù)和成本門檻
讓蜂窩物聯(lián)網(wǎng)應(yīng)用更簡(jiǎn)單~~
哈哈你終于滑到最重要的模塊了,
千萬(wàn)不!要!劃!走!忍住沖動(dòng)!~
歡迎加入飛書“開源技術(shù)交流群”,隨時(shí)找到我們哦~
點(diǎn)擊鏈接如何加入奇跡物聯(lián)技術(shù)話題群(https://rckrv97mzx.feishu.cn/docx/Xskpd1cFQo7hu9x5EuicbsjTnTf)可以獲取加入技術(shù)話題群攻略
Hey 物聯(lián)網(wǎng)從業(yè)者,
你是否有了解過(guò)奇跡物聯(lián)的官方公眾號(hào)“eSIM物聯(lián)工場(chǎng)”呢?
這里是奇跡物聯(lián)的物聯(lián)網(wǎng)應(yīng)用技術(shù)開源wiki主陣地,歡迎關(guān)注公眾號(hào),不迷路~
及時(shí)獲得最新物聯(lián)網(wǎng)應(yīng)用技術(shù)沉淀發(fā)布
注:本文部分內(nèi)容來(lái)源于網(wǎng)絡(luò),如有侵權(quán),請(qǐng)及時(shí)聯(lián)系我們。
-
物聯(lián)網(wǎng)
+關(guān)注
關(guān)注
2912文章
44877瀏覽量
375668 -
MODBUS
+關(guān)注
關(guān)注
28文章
1819瀏覽量
77203 -
通訊協(xié)議
+關(guān)注
關(guān)注
10文章
279瀏覽量
20394
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論