THE ANNIN ROBOTICS FORUM HAS MOVED TO A NEW COMMUNITY. 👉
Serial comms python
 
Notifications
Clear all

Serial comms python

1 Posts
1 Users
0 Reactions
48 Views
Avatar of Yann Glauser
(@yann-glauser)
New Member Customer
Joined: 2 months ago
Posts: 2
Topic starter  

Hi there,

 

I have been trying to write my own code to control the robot and so far I have been trying to prove that I can get a good connection and send commands but I didn't quite manage that. I have tried multiple bits of codes and used some snippets from the AR4 source code as well as some of the last commands sent using the actual application to make sure the format of the command wasn't the problem.

 

Please see below the few snippets I have tried. Anyone has any pointers on what I could be doing wrong?

I'm on the right COM port as it is detected by my laptop and throws me an error if I run the code without something plugged in COM3. I have tried both 115200, 9600 as baud rate. Which one is the right one? The source code seemed to use both.

 

Sorry, not the most experienced on that front... 🙂

 

#import pyserial
import time
# ser = serial.Serial('com3', 9600)
# ser.write('MJX286.83Y0.13Z438.45Rz179.98Ry0.00Rx179.98Tr0Sp25Ac10Dc10Rm50WF')
#
# time.sleep(5);

import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
serialInst = serial.Serial()

portList = []

for onePort in ports:
    portList.append(str(onePort))
    print(str(onePort))

val = 3

serialInst.baudrate = 115200 # Checked on source code, it's 9600 -- 115200 is also used
serialInst.port = "COM" + str(val)
serialInst.open()
# variable = str('MJX286.83Y0.13Z438.45Rz179.98Ry0.00Rx179.98Tr0Sp25Ac10Dc10Rm50WF')
variable = 'LJV10Sp25Ac10Dc10Rm100WN'
test = variable.encode()

serialInst.write(variable.encode())
serialInst.flushInput()
time.sleep(.2)
serialInst.write(variable.encode())
serialInst.flushInput()
time.sleep(.2)
time.sleep(2);

# command = "TF"+"A"+'200'+"B"+'200'+"C"+'200'+"D"+'200'+"E"+'200'+"F"+'200'+"\n"
# # cmdSentEntryField.delete(0, 'end')
# # cmdSentEntryField.insert(0,command)
# serialInst.write(command.encode())
# serialInst.flushInput()
# time.sleep(.2)


   
Quote
Share:
Upload your Photo