# -*- coding:utf-8 -*-
import serial
from socket import *
import time
host = '' # 监听 所有的ip
port = 13142 # 服务器端口
bufsize = 1024
addr = (host, port)
def serialmode():
ser = serial.Serial("com6", 115200)
sdata = ser.readline().decode("GB2312")
while True:
a, b, c = sdata.split(",")
print(a, b, c)
def UDPmode():
udpServer = socket(AF_INET, SOCK_DGRAM)
udpServer.bind(addr) # 开始监听
print("Waiting for connection....")
while True:
data, xxx = udpServer.recvfrom(bufsize)
data = data.decode(encoding='ascii')
print(data, end=" ")
print("nowtime:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
if __name__ == '__main__':
serialmode() #串口
UDPmode() #UDP监听