├── .gitignore ├── LICENSE └── main.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, Intelligent-distributed Cloud and Security Laboratory (ICNS Lab.) 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # This file is a part of EC_serial_communication 2 | # BSD 3-Clause License 3 | # 4 | # Copyright (c) 2019, Intelligent-distributed Cloud and Security Laboratory (ICNS Lab.) 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions are met: 9 | # 10 | # 1. Redistributions of source code must retain the above copyright notice, this 11 | # list of conditions and the following disclaimer. 12 | # 13 | # 2. Redistributions in binary form must reproduce the above copyright notice, 14 | # this list of conditions and the following disclaimer in the documentation 15 | # and/or other materials provided with the distribution. 16 | # 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 33 | # title : serial_Monitoring.py 34 | # description : Python, SA(Stand Alone) Data monitoring through serial communication 35 | # author : Jihoo Chun 36 | # date : 20190822 37 | # version : 0.3 38 | # notes : This EC_serial_communication is an implementation of edge cloud for communicating 39 | # self-driving cart and edge cloud. 40 | 41 | 42 | import serial 43 | import numpy as np 44 | import matplotlib.pyplot as plt 45 | # % matplotlib 46 | # notebook 47 | 48 | ser = serial.Serial('COM4', 9600, timeout=0) 49 | 50 | Lsonar = 0 51 | Rsonar = 0 52 | Lencoder = 0 53 | Rencoder = 0 54 | 55 | sensor = [] 56 | 57 | fig = plt.figure() # 그래프 창 생성, (9,9)형식으로 가로세로 9인치 설정가능 58 | ########sonar##### 나중에 메인문에 ax_sonar하나더해서 label붙여서 좌우 구분 59 | ax_sonar = fig.add_subplot(211) # ax라는 그림표하나 생성 추후 각 센서별로 여러개 만들예정, 11은 1행 1열에 위치 60 | ########Encoder##### 61 | # ax_Encoder=fig.add_subplot(212) 62 | 63 | # plt.ion() 64 | 65 | ####initialize### 66 | # ax.set_title('Sensor plot') 67 | ax_sonar.set_xlabel('PSD') 68 | ax_sonar.set_ylabel('distance_cm') 69 | ax_sonar.set_ylim([0, 200]) # 최대치 설정 70 | ax_sonar.legend() 71 | 72 | # #엔코더쓰려면 새로 좌표 정해서 쓰기 73 | # ax_Encoder.set_xlabel('Encoder') 74 | # ax_Encoder.set_ylabel('value') 75 | # ax_Encoder.legend() 76 | 77 | x = 0 78 | fig.show() 79 | 80 | 81 | def draw_all_plot(x): 82 | ax_sonar.plot(x, int(PSD), 'or', label='left') 83 | # ax_sonar.plot(x,int(Rsonar),'ob',label='right') 84 | 85 | 86 | # ax_Encoder.plot(x,int(Lencoder),'or',label='left') 87 | # ax_Encoder.plot(x,int(Rencoder),'ob',label='right') 88 | 89 | def switch1(x): 90 | global PSD # Lsonar 91 | global Rsonar 92 | global Lencoder 93 | global Rencoder 94 | 95 | if x == "LS": 96 | PSD = tmp 97 | elif x == 'RS': 98 | Rsonar = tmp 99 | elif x == 'LE': 100 | Lencoder = tmp 101 | elif x == 'RE': 102 | Rencoder = tmp 103 | 104 | 105 | def parsing_data(data): 106 | global tmp 107 | # global value 108 | 109 | data.pop() # tail 제거 110 | a = data[0] # head 첫번째값 111 | b = data[1] # head 두번째값 112 | c = a + b # 총 head 'LS' 이런식으로 결과값 나옴 113 | del data[0:2] # 센서값만 추출하기 위해 head 제거 114 | tmp = ''.join(data) ##최종 센서값 115 | switch1(c) # parsing 116 | 117 | 118 | # return tmp 119 | 120 | 121 | # print(Lsonar) 122 | 123 | while 1: 124 | for c in ser.read(): 125 | sensor.append(chr(c)) 126 | # plt.clf() #그래프초기화 127 | if c == 84: # T의 아스키 코드값, tail이 올때까지 데이터를 합친다 128 | parsing_data(sensor) 129 | del sensor[:] # line 초기화 130 | draw_all_plot(x) 131 | x += 1 132 | ax_sonar.figure.canvas.draw() 133 | # ax_Encoder.figure.canvas.draw() 134 | plt.pause(0.1) 135 | 136 | # 연습 137 | # counter += 1 138 | # del sensor[:] #line 초기화 139 | # ax.plot(x,counter,'or') #x축,y축값, 그래프종류 140 | # x+=1 141 | # ax.figure.canvas.draw() 142 | # plt.pause(0.1) 143 | --------------------------------------------------------------------------------