Nghiên cứu và xây dựng hệ thống giám sát môi trường tại các trung tâm tích hợp dữ liệu

101 668 0
Nghiên cứu và xây dựng hệ thống giám sát môi trường tại các trung tâm tích hợp dữ liệu

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ĐẠI HỌC THÁI NGUYÊN TRƢỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG ––––––––––––––––––––––––– PHẠM NGỌC PHƢƠNG NGHIÊN CỨU VÀ XÂY DỰNG HỆ THỐNG GIÁM SÁT MÔI TRƢỜNG TẠI CÁC TRUNG TÂM TÍCH HỢP DỮ LIỆU Chuyên ngành: Khoa học máy tính Mã số: 60 48 01 LUẬN VĂN THẠC SĨ KHOA HỌC MÁY TÍNH Ngƣời hƣớng dẫn khoa học: PGS TS Nguyễn Văn Tam THÁI NGUYÊN - 2013 Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ LỜI CAM ĐOAN Tôi xin cam đoan luận văn tơi thực hồn thành sở tìm kiếm, thu thập, nghiên cứu, tổng hợp phần lý thuyết phương pháp kĩ thuật trình bày văn nước giới Mọi tài liệu tham khảo nêu phần cuối luận văn Luận văn hồn tồn khơng chép nguyên từ nguồn tài liệu khác Nếu có sai sót, tơi xin chịu trách nhiệm./ HỌC VIÊN Phạm Ngọc Phƣơng Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ i MỤC LỤC MỞ ĐẦU i NỘI DUNG Chƣơng 1: TỔNG QUAN VỀ GIÁM SÁT MƠI TRƢỜNG TRONG CÁC TRUNG TÂM TÍCH HỢP DỮ LIỆU 1.1.Giới thiệu môi trƣờng vận hành Trung tâm tích hợp liệu 1.1.1 Mơi trường vận hành Trung tâm tích hợp liệu 1.1.2 Khảo sát trung tâm tích hợp liệu tỉnh Quảng Ninh Đại học Thái Nguyên 1.1.2.1 Khảo sát Trung tâm tích hợp liệu tỉnh Quảng Ninh 1.1.2.2 Khảo sát Trung tâm tích hợp liệu Đại học Thái Nguyên .6 1.2 Nghiên cứu lý thuyết hệ thống đo lƣờng, giám sát 1.2.1 Định nghĩa đo lường hệ thống thông tin đo lường 1.2.1.1 Định nghĩa đo lường 1.2.1.2 Định nghĩa hệ thống thông tin đo lường .8 1.2.2 Phân loại hệ thống thông tin đo lường 10 1.2.2.1 Phân loại dựa tín hiệu vào .10 1.2.2.2 Phân loại dựa tín hiệu 11 Người ta phân loại hệ thống thông tin đo lường theo tín hiệu thành loại hệ thống gồm : 11 1.2.3 Tổ chức làm việc hệ thống thông tin đo lường 12 1.3 Xây dựng toán giám sát mơi trường Trung tâm tích hợp liệu với thông số chọn lọc 13 1.3.1 Giám sát môi trường trung tâm tích hợp liệu 13 1.3.2 Xây dựng tốn giám sát mơi trường Trung tâm tích hợp liệu với thơng số chọn lọc 13 1.3.2.1 Giám sát nhiệt độ .14 1.3.2.2 Giám sát độ ẩm 17 1.3.2.3 Giám sát báo cháy .19 1.3.2.4 Giám sát điện lưới .22 Chƣơng 2: NGHIÊN CỨU VÀ XÂY DỰNG HỆ THỐNG GIÁM SÁT TRONG CÁC TRUNG TÂM TÍCH HỢP DỮ LIỆU VỚI CÁC THÔNG SỐ CHỌN LỌC 24 Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ ii 2.1 Xây dựng sơ đồ khối hệ thống giám sát 24 2.1.1 Xây dựng khối vi điều khiển trung tâm 26 2.1.1.1 Cấu trúc nhân AVR 28 2.1.1.2 Cấu trúc nhớ .29 2.1.2 Xây dựng khối thu nhận tín hiệu từ cảm biến nhiệt, độ ẩm điện lưới 29 2.1.2.1 Khối giám sát nhiệt độ 29 2.1.2.2 Khối giám sát độ ẩm 32 2.1.2.5 Khối giám sát nguồn điện 34 2.1.3 Xây dựng khối giao tiếp máy tính 35 2.1.4 Xây dựng khối cảnh báo qua GSM 39 2.15 Xây dựng khối cấp nguồn 42 2.2 Xây dựng chƣơng trình điều khiển cho hệ thống giám sát 44 2.2.1 Thuật toán đo lường, giám sát hệ thống xử lý trung tâm 44 2.2.2 Thuật tốn truyền thơng khối vi điều khiển trung tâm máy chủ quản lý 45 2.2.3 Thuật toán giám sát nhiệt độ 46 2.2.4 Thuật toán giám sát độ ẩm 47 2.2.5 Thuật toán đọc giá trị báo cháy lỗi cấp nguồn 48 2.2.6 Thuật tốn giám sát máy tính 49 2.2.7 Thuật toán cảnh báo từ xa qua modem GSM 50 2.2.8 Mã nguồn điều khiển 50 CHƢƠNG 3: CÀI ĐẶT THỬ NGHIỆM HỆ THỐNG GIÁM SÁT MƠI TRƢỜNG TẠI TRUNG TÂM TÍCH HỢP DỮ LIỆU 51 3.1 Cài đặt thử nghiệm hệ thống Trung tâm tích hợp liệu 51 3.2 Các kịch thử nghiệm kết giám sát 54 3.3 Đánh giá kết 57 KẾT LUẬN VÀ KIẾN NGHỊ 58 TÀI LIỆU THAM KHẢO 59 DANH MỤC CƠNG TRÌNH CÔNG BỐ CỦA TÁC GIẢ 60 PHỤ LỤC 61 Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ iii BẢNG CÁC THUẬT NGỮ TIẾNG VIỆT VÀ TỪ VIẾT TẮT Định nghĩa/Từ viết tắt STT Giải thích CNTT Cơng nghệ thơng tin CSDL Cơ sở liệu ĐHTN Đại học Thái Nguyên HTĐ Hệ thống thông tin đo lường TTTHDL Trung tâm tích hợp liệu BẢNG CÁC THUẬT NGỮ TIẾNG ANH VÀ TỪ VIẾT TẮT Thuật ngữ viết tắt Tiếng Anh Tiếng Việt ADC Analog to Digital Converter Bộ chuyển đổi tương tự sang số ALU Arithmetic and Logic Unit Đơn vị số học logic ASCII American Standard Code for Information Interchange Chuẩn mã trao đổi thông tin Hoa Kì ATS Automatic Transfer Switches Hệ thống tự động chuyển đổi nguồn điện CPU Central processing unit Khối điều khiển trung tâm CMOS Complementary Metal-OxideSemiconductor Chuẩn logic CMOS dựa vi mạch tích hợp DC Data Center Trung tâm tích hợp liệu DAC Digital to Analog Converter Bộ chuyển đổi số sang tương tự EEPROM Electrically Erasable Programmable Read-Only Memory Chíp nhớ khả trình khơng bị xóa điện HVAC Heating, Ventilation and Air Conditioning Nhiệt, thơng gió điều hịa khơng khí HTTP HyperText Transfer Protocol Giao thức chuyển tải siêu văn ISP Internet Service Provider Nhà cung cấp địch vụ Internet Internet Internet Hệ thống thơng tin tồn cầu LAN Local Area Network Mạng cục LCD Liquid Crystal Display Màn tinh thể lỏng LAN Local Area Network Mạng cục PWM Pulse Width Modulation Bộ điều chế độ rộng xung ROM Read-Only Memory Bộ nhớ đọc Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ iv Thuật ngữ viết tắt Tiếng Anh Tiếng Việt RAM Random Access Memory Bộ nhớ truy xuất ngẫu nhiên SRAM Static Random Access Memory RAM tĩnh TTL Transistor - Transistor Logic Bộ logic xây dựng từ transistor UART Universal Asinchonus Receiver Transmitter Thiết bị thu / phát không đồng UPS Uninterruptible Power Supplier Hệ thống nguồn cung cấp liên tục C (MCU) Microcontroller Unit Bộ vi điều khiển P MicroProcessor Bộ vi xử lý Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ v DANH MỤC CÁC BẢNG BIỂU Bảng biểu Trang Bảng 3.1 Nội dung Tham số cài đặt giám sát thử nghiệm Bảng A.1 Yêu cầu phân cấp điện 60 Bảng A.2 Các yêu cầu Hệ thống học 66 Số hóa trung tâm học liệu 51 http://www.lrc-tnu.edu.vn/ vi DANH MỤC CÁC HÌNH VẼ Hình vẽ Hình A Nội dung Trang Một mơi trường trung tâm tích hợp liệu với nhiều tham số phải giám sát Hình 1.1 Bản vẽ kiến trúc mạng xương sống TTTHDL tỉnh Quảng Ninh Hình 1.2 Bản vẽ mặt bố trí thiết bị tài TTTHDL tỉnh Quảng Ninh Hình 1.3 Hình 1.4 Hình 1.5 Hình 1.6 Bản vẽ kiến trúc mạng xương sống TTTHDL Đại học Thái Nguyên Bản vẽ mặt bố trí thiết bị tài TTTHDL Đại học Thái Nguyên Sơ đồ cấu trúc hệ thống thông tin đo lường Hệ thống đo sử dụng vi xử lý trao đổi vi xử lý giao diện 11 Hình 1.7 Xây dựng sơ đồ hệ thống giám sát mơi trường 13 Hình 1.8 Thiết kế dạng cho hệ thống giám sát nhiệt độ 16 Hình 1.9 Thiết kế dạng cho hệ thống giám sát nhiệt độ 17 Hình 1.10 Thiết kế sơ đồ khối cho hệ thống giám sát độ ẩm 18 Hình 1.11 Hình 1.12 Thiết kế hệ thống giám sát báo cháy cho TTTHDL khơng có tủ báo cháy Thiết kế hệ thống giám sát báo cháy cho TTTHDL có tủ báo cháy 21 21 Hình 1.13 Nguyên lý giám sát điện lưới 22 Hình 2.1 Sơ đồ khối hệ thống giám sát 25 Hình 2.2 Mạch nguyên lý khối vi điều khiển trung tâm 26 Hình 2.3 Cấu trúc vi điều khiển AVR ATmega16 27 Hình 2.4 Sơ đồ cấu trúc CPU AVR ATmega16 28 Hình 2.5 Sơ đồ nhớ tổng quát AVR ATmega16 29 Hình 2.6 Sơ đồ khối cấu tạo cảm biến nhiệt DS18B20 30 Hình 2.7 Sơ đồ kết nối dây dọc liệu nhiệt độ từ cảm biến DS18B20 Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 31 vii Hình 2.8 Hình 2.9 Sơ đồ kết nối LM35 đọc liệu cảm biến nhiệt độ qua ADC Sơ đồ kết nối dây dọc liệu nhiệt độ từ cảm biến DHT11 32 33 Hình 2.10 Mạch nguyên lý khối giám sát báo cháy 34 Hình 2.11 Mạch nguyên lý khối giám sát nguồn điện 35 Hình 2.12 Tín hiệu tương đương UART RS232 36 Hình 2.13 Truyền bit theo phương pháp song song nối tiếp 37 Hình 2.14 Bản vẽ kết nối máy chủ vi điều khiển qua giao tiếp RS232 39 Hình 2.15 Thiết kế khối cảnh báo sử dụng modem GSM 39 Hình 2.16 Sơ đồ khối bên GSM modem 40 Hình 2.17 Mạch nguyên lý khối cảnh báo qua GSM 41 Hình 2.18 Mạch nguyên lý nguồn tuyến tính 43 Hình 2.19 Lưu đồ thuật toán xử lý vi khối xử lý trung tâm 44 Hình 2.20 Lưu đồ thuật tốn truyền thơng 45 Hình 2.21 Lưu đồ thuật tốn giám sát nhiệt độ 46 Hình 2.22 Lưu đồ thuật tốn giám sát độ ẩm 47 Hình 2.23 Lưu đồ thuật tốn giám sát báo cháy lỗi cấp nguồn 48 Hình 2.24 Lưu đồ thuật tốn giám sát máy tính 49 Hình 2.25 Lưu đồ thuật tốn cảnh báo từ xa qua modem GSM 50 Hình 3.1 Mơ hình kết nối hệ thống thử nghiệm giám sát môi trường TTTHDL ĐHTN 52 Hình 3.2 Thử nghiệm lắp đặt mạch xử lý trung tâm 53 Hình 3.3 Thử nghiệm cài đặt phần mềm giám sát máy chủ 53 Hình 3.4 Các giao diện thiết lập thông số cảnh báo giám sát 54 Hình 3.5 Giao diện theo dõi lịch sử giám sát 54 Hình 3.4 Kết thử nghiệm giám sát nhiệt độ 55 Hình 3.7 Kết thử nghiệm giám sát độ ẩm 56 Hình 3.8 Kết thử nghiệm giám sát báo cháy 56 Hình 3.9 Kết thử nghiệm giám sát nguồn điện 57 Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ MỞ ĐẦU Khi nhắc đến tảng hệ thống thông tin khơng nhắc đến Trung tâm tích hợp liệu (Data Center), trái tim toàn hệ thống Việc xây dựng Trung tâm tích hợp liệu (viết tắt TTTHDL) xu tất yếu nhu cầu bắt buộc, thiếu doanh nghiệp hay tổ chức Việc xây dựng TTTHDL tiêu chuẩn đảm bảo mục tiêu tối ưu cho hoạt động, đảm bảo tính sẵn sàng, tính thuận tiện vận hành phát triển hệ thống sau Thực tế thiết kế chuẩn hạ tầng kỹ thuật, TTTHDL gồm thành phần chính: Hạ tầng mạng: máy chủ, hệ thống lưu trữ, thiết bị mạng… Hạ tầng vật lý quan trọng: hệ thống làm mát HVAC, hệ thống phòng cháy chữa cháy, hệ thống nguồn cấp UPS, hệ thống an ninh vật lý v.v Hình A: Một mơi trường trung tâm tích hợp liệu với nhiều tham số phải giám sát Như vậy, môi trường vận hành TTTHDL tồn hệ thống riêng biệt điều khiển tham số khác (điện áp, nhiệt độ, độ ẩm, nguồn điện, v.v.) với chung mục đích trì TTTHDL hoạt động an toàn, hiệu ổn định Tuy nhiên, thực tế hệ thống thường hoạt động độc lập giám sát xử lý cố tập trung dẫn đến tình trạng Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 78 UCSRC=0x86; UBRRH=0x00; UBRRL=0x19; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // ADC initialization // ADC Clock frequency: 187.500 kHz // ADC Voltage Reference: Int., cap on AREF // ADC Auto Trigger Source: Free Running // Only the most significant bits of // the AD conversion result are used ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x85;//bo chia tan so f/32 // SPI initialization // SPI disabled SPCR=0x00; // TWI initialization // TWI disabled TWCR=0x00; init_ds18b20(); //Init Ds18B20 // Alphanumeric LCD initialization // Connections specified in the // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu: // RS - PORTB Bit // RD - PORTB Bit // EN - PORTB Bit // D4 - PORTB Bit // D5 - PORTB Bit // D6 - PORTB Bit // D7 - PORTB Bit // Characters/line: 16 PORTC=0x00; y=7; lcd_init(16); lcd_gotoxy(0,0); //Di den cot1 dong lcd_putsf("ADC: RH: "); //Hien thi sau ky tu "" lcd_gotoxy(6,0); //Di den cot1 dong lcd_putchar(0b11011111); // ki tu lcd_putsf("C"); lcd_gotoxy(15,0); //Di den cot1 dong lcd_putsf("%"); lcd_gotoxy(0,1); //Di den cot1 dong lcd_putsf("DS18B: "); //Hien thi sau ky tu "" lcd_putsf("C"); lcd_gotoxy(0,2); //Di den cot1 dong lcd_putsf("PW: -Fire "); //Hien thi sau ky tu "" delay_ms(2000); lcd_gotoxy(0,3); //Di den cot1 dong lcd_putsf("RX:"); Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 79 alert=0; normal=1; while (1) { Read_Alert();//ktra canh bao nhietdovadoam();//Doc nhiet va dam read_ds18b20();//Doc nhiet DS18B20 read_temp(4);//Doc nhiet ADC lcd_putnum(temp,4,0);//Hien thi LCD tai vi tri 4x0 if(alert==1){lcd_gotoxy(8,3); lcd_putsf("Alert!");} else if(alert==0) {lcd_gotoxy(8,3); lcd_putsf("Normal");} Truyennhan(); delay_ms(50); // Place your code here } } Phụ lục C: Mã nguồn phần mềm giám sát viết cho máy chủ quản lý unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, jpeg, ComCtrls, CPort, Mask, DB, ADODB; type TForm1 = class(TForm) Button1: TButton; Button3: TButton; Label5: TLabel; Label6: TLabel; Panel1: TPanel; Timer1: TTimer; TabControl1: TTabControl; Label1: TLabel; Label3: TLabel; Label4: TLabel; Shape1: TShape; Shape2: TShape; Shape3: TShape; Shape4: TShape; Image4: TImage; Image5: TImage; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 80 Image6: TImage; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Shape5: TShape; Shape6: TShape; Image3: TImage; Timer2: TTimer; Label7: TLabel; Label8: TLabel; Label9: TLabel; Shape7: TShape; Shape8: TShape; Image7: TImage; Shape9: TShape; Shape10: TShape; StaticText6: TStaticText; StaticText7: TStaticText; Shape11: TShape; StaticText8: TStaticText; Shape12: TShape; Image8: TImage; Edit5: TEdit; ComPort1: TComPort; ComPort2: TComPort; StaticText10: TStaticText; Button6: TButton; Panel2: TPanel; Timer3: TTimer; Button8: TButton; Image9: TImage; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; Label2: TLabel; Label10: TLabel; Edit6: TEdit; Label11: TLabel; Label12: TLabel; Label13: TLabel; Shape13: TShape; Shape14: TShape; Shape15: TShape; Shape16: TShape; Label14: TLabel; Label15: TLabel; Label16: TLabel; Label17: TLabel; Shape18: TShape; Shape17: TShape; Image10: TImage; Button5: TButton; Timer4: TTimer; Shape19: TShape; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 81 Shape20: TShape; ADOConnection1: TADOConnection; ADOTable1: TADOTable; DataSource1: TDataSource; Shape21: TShape; Shape22: TShape; Shape23: TShape; Label21: TLabel; Label22: TLabel; Label23: TLabel; Label24: TLabel; Label25: TLabel; Edit7: TEdit; Panel3: TPanel; Memo1: TMemo; Image2: TImage; Label19: TLabel; Image1: TImage; Memo2: TMemo; Button2: TButton; Timer5: TTimer; Memo3: TMemo; Memo4: TMemo; DataSource2: TDataSource; ADOConnection2: TADOConnection; ADOTable2: TADOTable; ADOQuery1: TADOQuery; Button4: TButton; procedure Creat(Sender: TObject); procedure Time(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Timer3Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure TabControl1Change(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure Timer4Timer(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Timer5Timer(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button7Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Count: Integer; fire1,fire2,fire3,fire4,pw1,pw2,ups1,ups2,tempx: Integer; temp1,temp2,temp3,humi,temp9:Integer; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 82 temp5,temp6,temp7,temp10:String; temp_x1,temp_y1,temp_x2,temp_y2,startGSM,retry: Integer; jj,ii,kk,qq,alert,normal,nortifi:integer; temp8 : Array[1 12] of Integer; // temp10 : Array[1 5] of String; implementation uses Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8,Unit9; {$R *.dfm} procedure TForm1.Creat(Sender: TObject); var i:integer; begin timer1.Enabled:=false; timer2.Enabled:=false; timer3.Enabled:=false; timer4.Enabled:=false; timer5.Enabled:=false; tempx:=1; startGSM:=0; retry:=0; //Khoi tao cac bien trang thai alert:=0; normal:=1; nortifi:=0; temp1:=20; temp2:=21; temp3:=22; humi:=43; fire1:=1;fire2:=1;fire3:=1;fire4:=1; pw1:=1; pw1:=1;ups1:=1; ups2:=1; // khoi tao bien de ve thi jj:=16; ii:=16; kk:=16; qq:=16; temp_x1:=16; temp_y1:=image1.Height-15; temp_x2:=16; temp_y2:=image1.Height-15; Image1.Canvas.Pen.Width:=1; Image1.Canvas.Pen.Color:=clBlack; Image1.Canvas.brush.Color:=clBlack; image1.canvas.Rectangle(0,0,image1.Width,image1.Height); //Ve duong ngang Image1.Canvas.Pen.Color:=clGray; Image1.Canvas.brush.Color:=clGray; for i:=1 to 10 begin Image1.Canvas.moveTo(15,image1.Height-25*I-15); Image1.Canvas.lineTo(Image1.width-0, image1.Height-25*i-15); end; //Bieu dien thang nhiet Image1.Canvas.Pen.Color:=clRed; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 83 Image1.Canvas.brush.Color:=clBlack; Image1.Canvas.Font.Color:=clRed; for i:=1 to 10 begin image1.Canvas.TextOut(0,image1.Height-25*i-20, InttoStr(10*i)); end; //Bieu dien thang thoi gian Image1.Canvas.Pen.Color:=clBlue; Image1.Canvas.brush.Color:=clBlack; Image1.Canvas.Font.Color:=clWhite; ; for i:=2 to 25 begin image1.Canvas.TextOut(25*i-20,image1.Height-15, InttoStr(10*i-10)); end; //Ve duong doc Image1.Canvas.Pen.Color:=clGray; Image1.Canvas.brush.Color:=clGray; for i:=2 to 25 begin Image1.Canvas.moveTo(25*i-10, 10); Image1.Canvas.lineTo(25*i-10, Image1.height-15); end; //Ve cot x va y cua thi Image1.Canvas.Pen.Color:=clRed; Image1.Canvas.brush.Color:=clRed; image1.canvas.MoveTo(15,0); image1.canvas.LineTo(15,image1.Height-15); image1.canvas.MoveTo(15,image1.Height-15); image1.canvas.LineTo(image1.width,image1.height-15); // bat dau ve thi Image1.Canvas.Pen.Width:=2; Datasource1.DataSet.Active:=true; ADOTable1.Active:=true; Datasource2.DataSet.Active:=true; ADOTable2.Active:=true; { Comport1.Port:=ADOTable1.FieldByName('com_gsm_port').Value; Comport1.BaudRate:=br9600; Comport1.DataBits := dbEight; Comport1.Parity.Bits:=prNone; Comport1.StopBits:=sbOneStopBit; Comport1.FlowControl.FlowControl:=fcNone; Comport2.Port:=ADOTable1.FieldByName('com_dcems_port').Value; Comport2.BaudRate:=br9600; Comport2.DataBits := dbEight; Comport2.Parity.Bits:=prNone; Comport2.StopBits:=sbOneStopBit; Comport2.FlowControl.FlowControl:=fcNone; } Comport2.ShowSetupDialog; Comport2.Open; Form1.WindowState:=wsMaximized; Shape9.Brush.color:=clgray; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 84 Shape10.Brush.color:=clgray; Timer1.enabled:=true; Timer2.enabled:=true; Timer3.enabled:=true; Timer4.enabled:=true; Timer5.enabled:=true; end; procedure TForm1.Time(Sender: TObject); var pp:integer; begin Panel1.Caption:=FormatDateTime('hh:nn:ss',Now); // Hien thi gio Panel2.caption:= FormatDateTime('dd/mm/yyyy',Now); //Hien thi ADOTable1.TableName:='config'; Timer3.Interval:= ADOTable1.FieldByName('interval').Value; Timer4.Interval:= ADOTable1.FieldByName('interval').Value; if (((ADOTable1.FieldByName('pw1_en').Value='1')and (pw1=0)) or ((ADOTable1.FieldByName('pw2_en').Value='1') and (pw2=0)) or ((ADOTable1.FieldByName('ups1_en').Value='1') and (ups1=0)) or ((ADOTable1.FieldByName('ups2_en').Value='1') and (ups2=0)) or ((ADOTable1.FieldByName('fire1_en').Value='1') and (fire1=0)) or ((ADOTable1.FieldByName('fire2_en').Value='1') and (fire2=0))or ((ADOTable1.FieldByName('fire3_en').Value='1') and (fire3=0)) or ((ADOTable1.FieldByName('fire4_en').Value='1') and (fire4=0))or ((temp1 ADOTable1.FieldByName('temp_alert_b').Value) and (ADOTable1.FieldByName('temp1_en').Value='1'))or ((temp2 ADOTable1.FieldByName('temp_alert_b').Value) and (ADOTable1.FieldByName('temp2_en').Value='1'))or ((temp3 ADOTable1.FieldByName('temp_alert_b').Value) and (ADOTable1.FieldByName('temp3_en').Value='1'))or ((humi ADOTable1.FieldByName('humi_alert_b').Value) and (ADOTable1.FieldByName('humi_en').Value='1'))) then begin alert:=1; //thiet lap gia tri canh bao normal:=0; ADOTable1.Edit;//Luu vao CSDL ADOTable1.TableName:='config'; ADOTable1.FieldByName('alert').AsVariant:='1'; ADOTable1.FieldByName('normal').AsVariant:='0'; ADOTable1.UpdateStatus; ADOTable1.Post; Shape21.Brush.color:=clGray; Shape23.Brush.color:=clRed; end; if (((temp1>ADOTable1.FieldByName('temp_norti1_a').Value) and (ADOTable1.FieldByName('temp1_en').Value='1')) or Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 85 ((temp1< ADOTable1.FieldByName('temp_norti1_b').Value) and (ADOTable1.FieldByName('temp1_en').Value='1'))or ((temp1>ADOTable1.FieldByName('temp_norti2_a').Value) and (ADOTable1.FieldByName('temp1_en').Value='1')) or ((temp1< ADOTable1.FieldByName('temp_norti2_b').Value) and (ADOTable1.FieldByName('temp1_en').Value='1'))or ((humi>ADOTable1.FieldByName('humi_norti1_a').Value) and (ADOTable1.FieldByName('humi_en').Value='1')) or ((humi< ADOTable1.FieldByName('humi_norti1_b').Value) and (ADOTable1.FieldByName('humi_en').Value='1'))or ((humi>ADOTable1.FieldByName('humi_norti2_a').Value) and (ADOTable1.FieldByName('humi_en').Value='1')) or ((humi< ADOTable1.FieldByName('humi_norti2_b').Value) and (ADOTable1.FieldByName('humi_en').Value='1'))) then begin nortifi:=1; //thiet lap gia tri canh bao normal:=0; ADOTable1.Edit;//Luu vao CSDL ADOTable1.TableName:='config'; ADOTable1.FieldByName('nortification').AsVariant:='1'; ADOTable1.FieldByName('normal').AsVariant:='0'; ; ADOTable1.UpdateStatus; ADOTable1.Post; Shape22.Brush.color:=clYellow; Shape21.Brush.color:=clGray; //Tin hieu canh bao end; end; procedure TForm1.Button4Click(Sender: TObject); var num1:String; begin Comport1.Port:= ADOTable1.FieldByName('com_gsm_port').Value; ComPort1.Open; if comport1.connected true then Comport1.ClearBuffer(True, True); //Test so if ((ADOTable1.FieldByName('gsm_enable').Value='1') and (ADOTable1.FieldByName('sdt1_enable').Value='1')) then begin num1:=ADOTable1.FieldByName('sdt1').Value; ComPort1.WriteStr('AT+CMGF=1'+ #13#10); Sleep(100); ComPort1.WriteStr('AT+CMGS="'); ComPort1.WriteStr(num1); ComPort1.WriteStr('"'+#13#10); Sleep(100); ComPort1.WriteStr('Test SMS from DCEMS successfull!' + #26+ #13#10); Sleep(1000); end; end; procedure TForm1.Button5Click(Sender: TObject); var num1:String; begin Comport1.Port:= ADOTable1.FieldByName('com_gsm_port').Value; Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 86 ComPort1.Open; if comport1.connected true then Comport1.ClearBuffer(True, True); //Test so if ((ADOTable1.FieldByName('gsm_enable').Value='1') and (ADOTable1.FieldByName('sdt1_enable').Value='1') and (startGSM=1)) then begin num1:=ADOTable1.FieldByName('sdt1').Value; { ComPort1.WriteStr('AT+CMGF=1'+ #13#10); Sleep(100); ComPort1.WriteStr('AT+CMGS="'); ComPort1.WriteStr(num1); ComPort1.WriteStr('"'+#13#10); Sleep(100); ComPort1.WriteStr('Test SMS from DCEMS successfull!' + #26+ #13#10); Sleep(1000); } //Goi dien ComPort1.WriteStr('ATD'); ComPort1.WriteStr(num1); ComPort1.WriteStr(';'); ComPort1.WriteStr(#13#10); Sleep(100); end; end; procedure TForm1.Button6Click(Sender: TObject); begin Application.CreateForm(TForm9, Form9); Form9.Show; end; procedure TForm1.Timer3Timer(Sender: TObject); begin //Doc so dien thoai canh bao man hinh Edit5.Text:=ADOTable1.FieldByName('sdt1').Value; Edit6.Text:=ADOTable1.FieldByName('sdt2').Value; Edit7.Text:=ADOTable1.FieldByName('sdt3').Value; //Doc trang thai Power if (ADOTable1.FieldByName('pw1_en').Value='1') then shape5.Brush.color:=clLime else shape5.Brush.color:=clgray; if (ADOTable1.FieldByName('pw2_en').Value='1') then shape19.Brush.color:=clLime else shape19.Brush.color:=clgray; if (ADOTable1.FieldByName('ups1_en').Value='1') then shape6.Brush.color:=clLime else shape6.Brush.color:=clgray; if (ADOTable1.FieldByName('ups2_en').Value='1') then shape20.Brush.color:=clLime else shape20.Brush.color:=clgray; //Doc trang thai Bao chay if (ADOTable1.FieldByName('fire1_en').Value='1') then Shape13.Brush.color:=clLime else Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 87 Shape13.Brush.color:=clgray; if (ADOTable1.FieldByName('fire2_en').Value='1') then shape14.Brush.color:=clLime else shape14.Brush.color:=clgray; if (ADOTable1.FieldByName('fire3_en').Value='1') then shape15.Brush.color:=clLime else shape15.Brush.color:=clgray; if (ADOTable1.FieldByName('fire4_en').Value='1') then shape16.Brush.color:=clLime else shape16.Brush.color:=clgray; //3 Trang thai canh bao if (ADOTable1.FieldByName('normal').Value='1') then Shape21.Brush.color:=clLime else shape21.Brush.color:=clgray; if (ADOTable1.FieldByName('nortification').Value='1') then Shape22.Brush.color:=clYellow else shape22.Brush.color:=clgray; if (ADOTable1.FieldByName('alert').Value='1') then begin Shape23.Brush.color:=clRed; if ((ADOTable1.FieldByName('gsm_enable').Value='1')and (ADOTable1.FieldByName('call_enable').Value='1')) then begin if (Button5.Enabled=true)then Button5.Click; Button5.Enabled:=false; end; if ((ADOTable1.FieldByName('gsm_enable').Value='1')and (ADOTable1.FieldByName('sms_enable').Value='1')) then begin if (Button4.Enabled=true)then Button4.Click; Button4.Enabled:=false; end; end else shape23.Brush.color:=clgray; end; procedure TForm1.Button1Click(Sender: TObject); begin Application.CreateForm(TForm7, Form7); Form7.Show; end; procedure TForm1.TabControl1Change(Sender: TObject); begin if TabControl1.TabIndex = then begin Form1.Show; Form1.TabControl1.TabIndex := 0; end; if TabControl1.TabIndex = then begin Application.CreateForm(TForm2, Form2); Form2.Show; Form1.TabControl1.TabIndex := 1; end; if TabControl1.TabIndex = then Số hóa trung tâm học liệu http://www.lrc-tnu.edu.vn/ 88 begin Application.CreateForm(TForm3, Form3); Form3.Show; Form1.TabControl1.TabIndex := 2; end; if TabControl1.TabIndex = then begin Application.CreateForm(TForm8, Form8); //delay(1000); Form8.Show; Form1.TabControl1.TabIndex := 3; end; if TabControl1.TabIndex = then begin Application.CreateForm(TForm6, Form6); Form6.Show; Form1.TabControl1.TabIndex := 4; end; end; procedure TForm1.Button8Click(Sender: TObject); begin Application.CreateForm(TForm5, Form5); Form5.Show; Form5.WindowState:= wsMaximized; end; procedure TForm1.Timer2Timer(Sender: TObject); var tt: Integer; begin if(Comport2.Connected=true) then begin if(ADOTable1.FieldByName('temp1_en').Value='1')then begin Comport2.WriteStr('T'); if (Comport2.TriggersOnRxChar) then begin for tt:=1 to 12 begin Comport2.WriteStr('T'); Comport2.Read(temp8[tt],1); end; end; end; Memo1.Text:= inttostr(temp8[1]); Panel3.Caption:=inttostr(temp8[1])+ ' oC'; Memo2.Text:= inttostr(temp8[2]); Memo3.Text:= inttostr(temp8[3]); Memo4.Text:= inttostr(temp8[4]); //Nhiet va am if(ADOTable1.FieldByName('temp1_en').Value='1')then if (ABS(temp8[1]-temp1)

Ngày đăng: 18/11/2014, 22:34

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan