Skip to content
Snippets Groups Projects
Commit 389e18eb authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

test py serial

parent 2a2b2ad2
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ var init = function() {
mod.address.value = '127.0.0.1'
mod.port.value = 1234
mod.device.value = '/dev/ttyUSB0'
mod.baud.value = 115200
mod.baud.value = 9600
mod.flow_dsrdtr.checked = true
mod.socket = null
socket_open()
......@@ -216,7 +216,8 @@ var interface = function(div){
}
else if (mod.label.nodeValue == 'send file') {
socket_send(JSON.stringify(mod.job))
mod.label.nodeValue = 'cancel'
//mod.label.nodeValue = 'cancel'
mod.label.nodeValue = 'sending ...'
}
else if (mod.label.nodeValue == 'cancel') {
mod.command = {}
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -14,7 +14,7 @@
#
# imports
#
import sys,serial,asyncio,websockets,json
import sys,serial,asyncio,websockets,json,time
#
# command line
#
......@@ -50,7 +50,6 @@ async def receive(websocket,path):
device = vars['device']
speed = int(vars['baud'])
flow = vars['flow']
print(f"open {device} at {speed} with {flow}")
try:
if (flow == "xonxoff"):
s = serial.Serial(
......@@ -66,25 +65,26 @@ async def receive(websocket,path):
device,baudrate=speed,timeout=0)
s.flushInput()
s.flushOutput()
await websocket.send(f"open {device} at {speed} with {flow}")
except serial.SerialException as err:
print(err)
await websocket.send(str(err))
elif (vars['type'] == 'close'):
await websocket.send(f"close {device}")
s.close()
elif (vars['type'] == 'command'):
#
# send command
#
print('send command')
data = vars['contents']
n = 0
for c in data:
print(c)
if (flow == "dsrdtr"):
while (s.getDSR() != True):
time.sleep(0.001)
elif (flow == "rtscts"):
while (s.getCTS() != True):
time.sleep(0.001)
s.write(c)
s.write(c.encode('ascii'))
s.flush()
n += 1
percent = (100.0*n)/len(data)
......@@ -93,22 +93,21 @@ async def receive(websocket,path):
#
# send file
#
print('send file')
data = vars['contents']
n = 0
for c in data:
print(c)
if (flow == "dsrdtr"):
while (s.getDSR() != True):
time.sleep(0.001)
elif (flow == "rtscts"):
while (s.getCTS() != True):
time.sleep(0.001)
s.write(c)
s.write(c.encode('ascii'))
s.flush()
n += 1
percent = (100.0*n)/len(data)
await websocket.send(str(percent))
await websocket.send(str(round(percent))+'%')
await websocket.send("done")
#
# start server
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment