硬體上介面為485
軟體上有modbus協議
直接上**
#include
#include
#include
#include
#include
#include
#include
//開啟串列埠檔案
static
intopen_uart
(char
*dev)
return fd;
}//配置串列埠引數 波特率 資料位 校驗位 停止位
static
intset_opt
(int fd,
int nspeed,
int nbits,
char nevent,
int nstop)
bzero
(&newtio,
sizeof
( newtio ));
newtio.c_cflag |
= clocal | cread;
newtio.c_cflag &
=~csize;
switch
( nbits )
switch
( nevent )
switch
( nspeed )
if( nstop ==1)
else
if( nstop ==2)
newtio.c_cc[vtime]=0
; newtio.c_cc[vmin]=0
;tcflush
(fd,tciflush);if
((tcsetattr
(fd,tcsanow,
&newtio))!=
0)return0;
}static
int fd;
intth10s_init()
static
unsigned
short
modbus_crc16
(unsigned
char
*buf,
unsigned
short length)
}return crc <<
8| crc >>8;
}int
th10s_read
(float
*t,float
*h);
unsigned
int tmp =
0,crc;
memset
(buffer,0,
256)
;//接收陣列清零if(
read
(fd,buffer,
sizeof
(buffer)
)>8)
;//等待電腦串列埠除錯助手傳送資料
if(buffer[0]
==0x01
&& buffer[1]
==0x03
&& buffer[2]
==0x04
)return0;
}memset
(buffer,0,
256)
;//接收陣列清零
buffer[0]
=0x01
;buffer[1]
=0x03
;buffer[2]
=0x00
;buffer[3]
=0x00
; buffer[4]
=0x00
;buffer[5]
=0x02
;buffer[6]
=0x00
;buffer[7]
=0x00
; crc =
modbus_crc16
(buffer,6)
; buffer[6]
= crc >>8;
buffer[7]
= crc &
0xff
;write
(fd, buffer,8)
;//將收到的資料傳送回去
printf
("send %x %x %x %x %x %x %x %x %x\n"
,buffer[0]
,buffer[1]
,buffer[2]
,buffer[3]
,buffer[4]
,buffer[5]
,buffer[6]
,buffer[7]
,buffer[8]
);return-1
;}inttf_close
(void
)
嵌入式Linux 讀取bmp檔案頭資訊
檔案頭結構體 typedef struct bitmapfileheader 函式如下 返回值 錯誤時返回 1,解析正確返回0 int bmp analyze unsigned char path 讀取檔案頭資訊 read fd,fheader,sizeof fheader printf bfsiz...
嵌入式 linux 編譯
第二次換了編譯環境編譯時又提示 make 3 drivers video console vgacon.o 錯誤 1 在網上搜尋結果 根據資訊的大概意思是關於vga的支援問題,在這裡我直接把關於vga的配置選項去掉不選,即 在執行 make menuconfig 配置時 不選vga 驅動。devic...
linux嵌入式開發
我的環境 主機 ubuntu 64位 開發板 mini2440 6 makefile檔案修改 在 opt friendlyarm mini2440 linux 2.6.29下執行 sudo vi.makefile 搜尋arm linux得到乙個結果 cross compile?arm linux 然...