സീരിയൽ ലിങ്ക്#
ആമുഖം#
VEX ലിങ്ക് വഴി അസംസ്കൃത സീരിയൽ ഡാറ്റ അയച്ചും സ്വീകരിച്ചും രണ്ട് EXP ബ്രെയിനുകളെ ആശയവിനിമയം നടത്താൻ SerialLink അനുവദിക്കുന്നു. ലേബൽ ചെയ്ത സന്ദേശങ്ങൾക്ക് പകരം, SerialLink ഒരു ബഫർ (ഒരു സ്ട്രിംഗ് അല്ലെങ്കിൽ ഒരു ബൈറ്റിയർറേ) കൈമാറുന്നു. സെൻസർ ഡാറ്റ സ്ട്രീമിംഗ്, ഇഷ്ടാനുസൃത പാക്കറ്റ് ഫോർമാറ്റുകൾ അയയ്ക്കൽ, അല്ലെങ്കിൽ ബൈറ്റുകൾക്ക് മുകളിൽ നിങ്ങളുടെ സ്വന്തം പ്രോട്ടോക്കോൾ നിർമ്മിക്കൽ തുടങ്ങിയ വിപുലമായ റോബോട്ട്-ടു-റോബോട്ട് ആശയവിനിമയത്തിന് ഇത് ഉപയോഗപ്രദമാക്കുന്നു.
send ന്റെ ഓരോ ഉപയോഗവും ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിന്റെ റിസീവ് ബഫറിലേക്ക് ഡാറ്റ ചേർക്കുന്നു. ഡാറ്റ അത് എത്തുന്ന ക്രമത്തിലാണ് വായിക്കുന്നത് (ആദ്യം-ഇൻ, ആദ്യം-ഔട്ട്). മറ്റ് EXP ബ്രെയിൻ receive ഉപയോഗിക്കുന്നതിന് മുമ്പ് ഒന്നിലധികം ബഫറുകൾ അയച്ചാൽ, അവ ക്യൂവിൽ തന്നെ തുടരുകയും അവ അയച്ച ക്രമത്തിൽ ഓരോന്നായി തിരികെ നൽകുകയും ചെയ്യുന്നു. ഡാറ്റ ക്യൂവിൽ ആയിരിക്കാൻ സാധ്യതയുള്ളതിനാൽ, ഓരോ ലൂപ്പിലും വലിയ ബഫറുകൾ ആവർത്തിച്ച് അയയ്ക്കുന്നത് ബാക്ക്ലോഗ് സൃഷ്ടിച്ചേക്കാം; സമയ-നിർണ്ണായക ലിങ്കുകൾക്ക്, നിങ്ങൾക്ക് ആവശ്യമുള്ളത് മാത്രം അയയ്ക്കുക.
പ്രധാനം: രണ്ട് റോബോട്ടുകളും ഒരേ സമയം SerialLink ഉപയോഗിക്കുന്ന പ്രോജക്ടുകൾ പ്രവർത്തിപ്പിക്കുന്നുണ്ടാകണം, അല്ലെങ്കിൽ ഡാറ്റയൊന്നും അയയ്ക്കുകയോ സ്വീകരിക്കുകയോ ചെയ്യില്ല.
This page uses link as the example SerialLink name. Replace it with your own configured name as needed.
ലഭ്യമായ രീതികളുടെ ഒരു ലിസ്റ്റ് താഴെ കൊടുക്കുന്നു:
is_linked– ഈ ബ്രെയിൻ അതിന്റെ ജോടിയാക്കിയ ബ്രെയിനുമായി സജീവമായി ബന്ധിപ്പിച്ചിട്ടുണ്ടോ എന്ന് നൽകുന്നു.send– ജോടിയാക്കിയ തലച്ചോറിലേക്ക് ഒരു ഹ്രസ്വ സന്ദേശം (ഓപ്ഷണൽ ഇന്റ്/ഫ്ലോട്ട് ഡാറ്റയോടൊപ്പം) അയയ്ക്കുന്നു.receiveലഭിക്കുന്നു – അടുത്ത ഇൻകമിംഗ് സന്ദേശത്തിനായി കാത്തിരുന്ന് തിരികെ നൽകുന്നു.received– ഒരു പുതിയ സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
ഒരു ലിങ്ക് സൃഷ്ടിക്കുക#
രണ്ട് EXP ബ്രെയിനുകളിലും ഒരു സീരിയൽ ലിങ്ക് സൃഷ്ടിക്കുക, അങ്ങനെ അവയ്ക്കിടയിൽ ഒരു ആശയവിനിമയ ചാനൽ സ്ഥാപിക്കുക - V5 റോബോട്ട് റേഡിയോകൾ ഉപയോഗിച്ച് വയർലെസ് ആയി അല്ലെങ്കിൽ ഒരു വയർഡ് സ്മാർട്ട് കേബിൾ വഴി - അങ്ങനെ റോബോട്ടുകൾക്ക് പരസ്പരം റോ സീരിയൽ ഡാറ്റ അയയ്ക്കാൻ കഴിയും.
SerialLink(smartport, name, linktype, wired)
പാരാമീറ്റർ |
വിവരണം |
|---|---|
|
ഈ ലിങ്കിനായി ഉപയോഗിക്കുന്ന സ്മാർട്ട് പോർട്ട് - V5 റോബോട്ട് റേഡിയോ ബന്ധിപ്പിച്ചിരിക്കുന്ന പോർട്ട് (വയർലെസ്) അല്ലെങ്കിൽ സ്മാർട്ട് കേബിൾ പ്ലഗ് ചെയ്തിരിക്കുന്ന (വയർഡ്). |
|
ഈ ലിങ്ക് ഒരു സ്ട്രിംഗായി നൽകേണ്ട അദ്വിതീയ നാമം. |
|
ഈ ലിങ്ക് ജോഡിക്ക് ഈ ബ്രെയിൻ ഉപയോഗിക്കുന്ന റോൾ. ഓരോ ജോഡിയിലും ഒരു മാനേജർ ഉം ഒരു വർക്കർ ഉം ഉണ്ടായിരിക്കണം:
|
|
ഓപ്ഷണൽ. ഈ ലിങ്ക് വയർ ആണോ വയർലെസ് ആണോ എന്നത് പരിഗണിക്കാതെ തന്നെ:
|
റോബോട്ട് 1 നുള്ള കോഡ്
""" Create a wireless link in Port 1 name: VEXRoboticsLink123456789 linktype: Manager """ link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)റോബോട്ട് 2 നുള്ള കോഡ്
""" Create a wireless link in Port 1 name: VEXRoboticsLink123456789 linktype: Worker """ link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)
ലഭ്യമായ രീതികൾ#
നിങ്ങളുടെ സീരിയൽ ലിങ്ക് സജ്ജീകരിച്ച് ബ്രെയിനുകൾ ലിങ്ക് ചെയ്തുകഴിഞ്ഞാൽ, റോ സീരിയൽ ഡാറ്റ അയയ്ക്കാനും സ്വീകരിക്കാനും പ്രതികരിക്കാനും താഴെയുള്ള രീതികൾ നിങ്ങൾക്ക് ഉപയോഗിക്കാം.
is_linked#
is_linked രീതി, SerialLink-ലെ EXP ബ്രെയിനുകൾ പരസ്പരം ജോടിയാക്കുന്നുണ്ടോ എന്ന് നൽകുന്നു.
True– രണ്ട് EXP തലച്ചോറുകളും ഈ ലിങ്കിൽ ജോടിയാക്കപ്പെടുകയും ആശയവിനിമയം നടത്തുകയും ചെയ്യുന്നു.False– ഈ ലിങ്കിൽ രണ്ട് EXP ബ്രെയിനുകളും ജോടിയാക്കിയിട്ടില്ല.
കുറിപ്പ്: കൂടുതൽ കോഡ് പ്രവർത്തിപ്പിക്കുന്നതിന് മുമ്പ് ഒരു പ്രോജക്റ്റിന്റെ തുടക്കത്തിൽ EXP ബ്രെയിനുകൾ ലിങ്ക് ചെയ്തിട്ടുണ്ടെന്ന് ഉറപ്പാക്കുന്നത് എപ്പോഴും നല്ല രീതിയാണ്.
Usage:
link.is_linked()
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
ഈ രീതിക്ക് പാരാമീറ്ററുകൾ ഇല്ല. |
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a message to the other robot # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") link.send("HELLO")റോബോട്ട് 2 നുള്ള കോഡ്
# Display the message that Robot 1 sends # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() def received_message(bytearray, length): # Slice the bytearray to the valid data data = bytearray[:length] # Decode and strip the message before displaying it text = data.decode().strip() brain.screen.print("Got: ", text) # Call received_message whenever a message is received link.received(received_message)
send#
send മറ്റ് ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിലേക്ക് റോ സീരിയൽ ബൈറ്റുകൾ കൈമാറുന്നു.
receive ഉപയോഗിച്ച് ഡാറ്റ വായിക്കുമ്പോൾ, receive അതിന്റെ length പാരാമീറ്റർ വ്യക്തമാക്കിയ ബൈറ്റുകളുടെ എണ്ണം ശേഖരിച്ചുകഴിഞ്ഞാൽ മാത്രമേ തിരികെ ലഭിക്കൂ. അതിനാൽ, നിങ്ങളുടെ കോഡ് എല്ലായ്പ്പോഴും lengthഎന്ന നിശ്ചിത receive ഉപയോഗിച്ച് വിളിക്കുകയാണെങ്കിൽ, send ഉപയോഗിച്ച് അയയ്ക്കുന്ന ഓരോ സന്ദേശവും കൃത്യമായി അത്രയും ബൈറ്റുകളാണെന്ന് (പലപ്പോഴും പാഡിംഗ് വഴി) ഉറപ്പാക്കണം, അതിനാൽ റിസീവർ അധിക ബൈറ്റുകൾക്കായി കാത്തിരിക്കുന്നത് തടയില്ല.
കൃത്യമായ ഒരു ബൈറ്റ് എണ്ണത്തെ ആശ്രയിക്കാൻ നിങ്ങൾ ആഗ്രഹിക്കുന്നില്ലെങ്കിൽ, പകരം received ഉപയോഗിക്കുക; ഒരു പ്രത്യേക ദൈർഘ്യം ആവശ്യമില്ലാതെ ലഭ്യമായ ഏത് ബൈറ്റുകളും കൈകാര്യം ചെയ്യാൻ ഇത് നിങ്ങളെ അനുവദിക്കുന്നു.
Usage:
send(buffer)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ഡാറ്റ. ഇത് |
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a message to the other robot # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") link.send("HELLO")റോബോട്ട് 2 നുള്ള കോഡ്
# Display the message that Robot 1 sends # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() def received_message(bytearray, length): # Slice the bytearray to the valid data data = bytearray[:length] # Decode and strip the message before displaying it text = data.decode().strip() brain.screen.print("Got: ", text) # Call received_message whenever a message is received link.received(received_message)
receive#
receive returns serial data from the other linked EXP Brain in FIFO order (oldest unread data first).
receive കൃത്യമായ ബൈറ്റുകളുടെ എണ്ണത്തിനായി കാത്തിരിക്കുന്നതിനാൽ, receive ഉപയോഗിക്കുമ്പോൾ നിശ്ചിത ദൈർഘ്യമുള്ള സന്ദേശമയയ്ക്കലിന് പലപ്പോഴും പാഡിംഗ് ആവശ്യമാണ്, അങ്ങനെ ഓരോ സന്ദേശവും പ്രതീക്ഷിക്കുന്ന വലുപ്പത്തിൽ എത്തുന്നു. അയച്ചയാൾ send ബൈറ്റുകളിൽ താഴെ മാത്രമേ പ്രക്ഷേപണം ചെയ്യുന്നുള്ളൂവെങ്കിൽ, length ശേഷിക്കുന്ന ബൈറ്റുകൾക്കായി കാത്തിരിക്കുന്നത് തുടരുകയും ഒന്നും തിരികെ നൽകാതിരിക്കുകയും ചെയ്യും.
If the queue is empty and you provide a timeout, receive waits up to that many milliseconds for new data. If nothing arrives in that window, it returns None. Any data sent afterward remains queued to be read later.
Usage:
receive(length, timeout)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
ലഭിക്കേണ്ട ബൈറ്റുകളുടെ എണ്ണം. |
|
ഓപ്ഷണൽ. ക്യൂ ശൂന്യമാണെങ്കിൽ മാത്രം |
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a math problem for the other Brain to solve # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") """ Change whether to "add" or "subtract", then what numbers to use in the operation. """ packet = "add,7,2.5" # Pad with spaces until it's exactly 16 bytes while len(packet) < 16: packet = packet + " " link.send(packet)റോബോട്ട് 2 നുള്ള കോഡ്
# Solve the math problem that the other Brain sends # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() # Receive exactly 16 bytes buffer = link.receive(16) # Remove the added " " padding text = buffer.decode().strip() # Separate the operator and numbers parts = text.split(",") operator = parts[0] a = float(parts[1]) b = float(parts[2]) # Use what operator was sent if operator == "add": result = a + b elif operator == "subtract": result = a - b # If not "add" or "subtract", do nothing else: pass brain.screen.print("Result = ", result)
received#
received registers a function to be called whenever the EXP Brain receives serial data.
Usage:
link.received(callback)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
EXP ബ്രെയിൻ സീരിയൽ ഡാറ്റ സ്വീകരിക്കുമ്പോൾ നടപ്പിലാക്കുന്ന, മുമ്പ് നിർവചിക്കപ്പെട്ട ഒരു ഫംഗ്ഷൻ. |
received കോൾബാക്കുകൾ രണ്ട് ആർഗ്യുമെന്റുകൾ ഉപയോഗിച്ച് വിളിക്കുന്നു:
കോൾബാക്ക് ഒപ്പ്:
callback(buffer, length)
വാദം |
വിവരണം |
|---|---|
|
ലഭിച്ച സീരിയൽ ഡാറ്റ ഉൾക്കൊള്ളുന്ന ഒരു |
|
ഈ കോൾബാക്കിനായി |
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a message to the other robot # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") link.send("HELLO")റോബോട്ട് 2 നുള്ള കോഡ്
# Display the message that Robot 1 sends # Create the link link = SerialLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() def received_message(bytearray, length): # Slice the bytearray to the valid data data = bytearray[:length] # Decode and strip the message before displaying it text = data.decode().strip() brain.screen.print("Got: ", text) # Call received_message whenever a message is received link.received(received_message)