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