Trying to send commands to the hardware: Laser on and off. But Python is failing and the hardware never getting the command.
Command list:
ss.py:
import serial
ser = serial.Serial('/dev/tty.usbserial', serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
print(ser.name)
# if i add ' then also error
ser.write(\xA0h\xC1h\x01\x00h\xSt.\xAFh)
ser.close()
On execute error occure:
File "ss.py", line 5
ser.write(\xA0h\xC1h\x01\x00h\xSt.\xAFh)
^
SyntaxError: unexpected character after line continuation character
or
Error:
$ python ss.py
Traceback (most recent call last):
File "ss.py", line 3, in <module>
ser = serial.Serial('/dev/tty.usbserial', serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
File "/Library/Python/2.7/site-packages/serial/serialutil.py", line 220, in __init__
self.bytesize = bytesize
File "/Library/Python/2.7/site-packages/serial/serialutil.py", line 306, in bytesize
raise ValueError("Not a valid byte size: {!r}".format(bytesize))
ValueError: Not a valid byte size: 'N'
I suspect that you need to send the commands one at a time, rather than as a single string.
for command in [b'0xA0h', b'0xC1h', b'0x01', b'0x00h', b'0xSt', b'0xAFh']:
ser.write(command)
Notice that I have also altered the beginning of each subcommand to indicate that it is a hex value.
========EDIT========
Looking at the command list in your question, I wonder if you have used the "Switch on" command to make sure the system is on?
I also see that it is possible to send a string to query the device. Have you tried that?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.