ПЗ (1190607), страница 7
Текст из файла (страница 7)
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
string filename = openFileDialog1.FileName;
string fileText = System.IO.File.ReadAllText(filename);
HexPath.Text = openFileDialog1.FileName;
}
}
private void DownloadFile_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(HexPath.Text)) {
byte[] bytes = new byte[1024];
int recivedMsg;
IPHostEntry ipHost = Dns.Resolve(raspberryIP);
IPEndPoint endPt = new IPEndPoint(ipHost.AddressList[0], 11000);
Socket Sender = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Sender.Connect(endPt);
byte[] msgToSend = Encoding.UTF8.GetBytes("Файл");
Sender.Send(msgToSend);
recivedMsg = Sender.Receive(bytes);
if (Encoding.UTF8.GetString(bytes, 0, recivedMsg) == "Ready")
{
string filePath = HexPath.Text;
Sender.SendFile(filePath);
}
Sender.Shutdown(SocketShutdown.Send);
recivedMsg = Sender.Receive(bytes);
if (Encoding.UTF8.GetString(bytes, 0, recivedMsg) != "Complite")
{
StatusBar.Text = "Выполнено";
Sender.Shutdown(SocketShutdown.Both);
Sender.Close();
}
}
}
private void CameraOnOff_Click(object sender, EventArgs e)
{
if(cameraStatus == false)
{
m_mjpeg.ParseStream(new Uri("http://192.168.0.43:8080/?action=stream"));
cameraStatus = true;
}
else if (cameraStatus == true)
{
m_mjpeg.StopStream();
cameraStatus = false;
VideoBox.Image = null;
}
}
private void mjpeg_FrameReady(object sender, FrameReadyEventArgs e)
{
VideoBox.Image = e.Bitmap;
}
}
}
ПРИЛОЖЕНИЕ Б
(обязательное)
Листинг Raspberry Pi программы
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import serial
import socket
import subprocess
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
def Lamp():
GPIO.output(25, 1)
time.sleep(0.05)
GPIO.output(25, 0)
time.sleep(0.1)
GPIO.output(25, 1)
time.sleep(0.05)
GPIO.output(25, 0)
return
ser = serial.Serial('/dev/ttyACM0', 9600)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('', 11000))
sock.listen(1)
print('server online')
while True:
conn, addr = sock.accept()
print("Connection open")
data = conn.recv(10240)
Lamp()
print('client send: ' + str(data))
if str(data) == 'Файл':
conn.send('Ready')
f = open('arduino.ino.ino','wb')
l = conn.recv(1024)
while(l):
print "Receiving"
f.write(l)
l = conn.recv(1024)
f.close()
print "File received"
subprocess.call("sudo make",shell = True)
if subprocess.call("sudo make upload",shell = True) == 0:
conn.send('Complited')
print "Arduino reprogrammed"
if str(data) == 'Температурный датчик':
ser.write("1")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'IR датчик приближения линии':
ser.write("2")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Датчик Холла':
ser.write("3")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Сонар':
ser.write("4")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Датчик вибрации':
ser.write("5")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Датчик освещения':
ser.write("6")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Датчик наклона':
ser.write("7")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if str(data) == 'Датчик влажности':
ser.write("8")
receivedData = ser.readline()
print receivedData,
conn.send(receivedData)
if( data[0:4] == "Move"):
if (data[5:6] == "b"):
temp = data[4:5]
else:
temp = data[4:6]
if( data[12:13] == "1" or data[11:12] == "1"):
temp = 100 + int(temp)
ser.write(int(temp))
if (data[12:13] == "2" or data[11:12] == "2"):
temp = 200 + int(temp)
ser.write(int(temp))
if (data[12:13] == "3" or data[11:12] == "3"):
temp = 300 + int(temp)
ser.write(int(temp))
if (data[12:13] == "4" or data[11:12] == "4"):
temp = 400 + int(temp)
ser.write(int(temp))
if (data[0:4] == "Turn"):
if (data[5:6] == "b"):
temp = data[4:5]
else:
temp = data[4:6]
print("Turn")
if (data[12:13] == "1" or data[11:12] == "1"):
temp = 500 + int(temp)
print(temp)
ser.write(int(temp))
if (data[12:13] == "2" or data[11:12] == "2"):
temp = 600 + int(temp)
print(temp)
ser.write(int(temp))
if (data[12:13] == "3" or data[11:12] == "3"):
temp = 700 + int(temp)
print(temp)
ser.write(int(temp))
conn.close()
print("Connection closed")
ПРИЛОЖЕНИЕ В
(обязательное)
Листинг Arduino программы
#include <dht.h>
#include <Servo.h>
#define DHT11_PIN 24
Servo ser1;
Servo ser2;
Servo ser3;
Servo ser4;
Servo ser5;
int echoPin = 23;
int trigPin = 22;
int vibrSensPin = 25;
int irPin = 29;
int svet = 26;
int magA = A1;
int magD = 27;
int naklon = 28;
dht DHT;
int chk;
int vibrSensorStatus;
int tcrt;
int temp;
float temp2;
String dataRecived;
void setup(){
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(vibrSensPin, INPUT);
pinMode(svet,INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
digitalWrite(LED_BUILTIN, LOW);
if(Serial.available() > 0){
dataRecived = Serial.readString();
switch (dataRecived.toInt()){
case 1:
chk = DHT.read11(DHT11_PIN);
if ( chk == DHTLIB_OK){
Serial.print("Temperature: ");
Serial.print(DHT.temperature, 1);
Serial.print("C\n");
}else{
Serial.print("An error occurred\n");
}
break;
case 2:
Serial.print("Signal:");
Serial.print(digitalRead(irPin));
Serial.print("\n");
break;
case 3:
Serial.print("Analog data:");
Serial.print(analogRead(magA));
Serial.print(" Digital data:");
Serial.print(digitalRead(magD));
Serial.print("\n");
break;
case 4:
int duration, cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
cm = duration / 58;
Serial.print("Distance to nearby obj: ");
Serial.print(cm);
Serial.print("cm\n");
delay(1000);
break;
case 5:
for(int i = 0; i < 5; i++)
{
vibrSensorStatus = digitalRead(vibrSensPin);
if(vibrSensorStatus == LOW) Serial.print("LOW->");
else Serial.print("HIGH->");
delay(50);
}
Serial.print("\n");
break;
case 6:
Serial.print("Digital data: ");
Serial.print(digitalRead(naklon));
Serial.print("\n");
break;
case 7:
Serial.print("Digital data: ");
Serial.print(digitalRead(svet));
Serial.print("\n");
break;
case 8:
chk = DHT.read11(DHT11_PIN);
if ( chk == DHTLIB_OK){
Serial.print("Humidity: ");
Serial.print(DHT.humidity, 1);
Serial.print("%\n");
}else{
Serial.print("An error occurred");
}
break;
default:
Serial.println(dataRecived);
break;
}
if(dataRecived.toInt() > 100 && dataRecived.toInt() < 200){
ser1.attach(30);
ser2.attach(31);
temp = dataRecived.toInt() - 100;
temp2 = temp/19;
temp2 = temp2 * 1.8 * 1000;
ser1.write(0);
delay(500);
ser1.write(0);
ser2.write(0);
delay(temp2);
ser1.write(90);
ser2.write(90);
}
if(dataRecived.toInt() > 200 && dataRecived.toInt() < 300){
temp = dataRecived.toInt() - 200;
ser1.attach(30);
ser2.attach(31);
temp = dataRecived.toInt() - 200;
temp2 = temp/19;
temp2 = temp2 * 1.8 * 1000;
ser1.write(0);
ser2.write(0);
delay(temp2);
ser1.write(90);
ser2.write(90);
}
if(dataRecived.toInt() > 300 && dataRecived.toInt() < 400){
temp = dataRecived.toInt() - 300;
ser1.attach(30);
ser2.attach(31);
temp = dataRecived.toInt() - 300;
temp2 = temp/19;
temp2 = temp2 * 1.8 * 1000;
ser2.write(0);
delay(500);
ser1.write(0);
ser2.write(0);
delay(temp2);
ser1.write(90);
ser2.write(90);
}
if(dataRecived.toInt() > 400 && dataRecived.toInt() < 500){
temp = dataRecived.toInt() - 400;
ser1.attach(30);
ser2.attach(31);
temp = dataRecived.toInt() - 400;
temp2 = temp/19;
temp2 = temp2 * 1.8 * 1000;
ser1.write(180);
ser2.write(180);
delay(temp2);
ser1.write(90);
ser2.write(90);
}
if(dataRecived.toInt() > 500 && dataRecived.toInt() < 600){
temp = dataRecived.toInt() - 500;
ser3.attach(32);
ser3.write(temp);
delay(400);
ser3.detach();
}
if(dataRecived.toInt() > 600 && dataRecived.toInt() < 700){
temp = dataRecived.toInt() - 600;
ser4.attach(33);
ser4.write(temp);
delay(400);
ser4.detach();
}
if(dataRecived.toInt() > 700 && dataRecived.toInt() < 800){
temp = dataRecived.toInt() - 700;
ser5.attach(34);
ser5.write(temp);
delay(400);
ser5.detach();
}
}
}
67















