Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:08:21+00:00 2026-06-10T22:08:21+00:00

I’m a newbie in python and recently I made a similar question about how

  • 0

I’m a newbie in python and recently I made a similar question about how to convert a decimal value to an integer with low byte first and then high byte is here and is solved but now I have a problem because I want python to take a decimal value from a raw_input convert it to an integer with low byte first and then high byte and insert it into a 16-bit integer to send it to the serial port to a servo controller (devantech sd84). I’ve contained the raw_input into a value and then the struc.pack in other value then I put the second value into the 16-bit integer but before this can occurs python returns this error:

    Traceback (most recent call last):
    File "C:/Users/Pablo/Desktop/kdfkldkfgv", line 28, in <module>
    POS_SERVO = struct.pack('<h', 'posicion')
    error: cannot convert argument to integer

Here is the complete code:

    # -*- coding: utf-8 -*-
  import serial
  import time
  import struct
  # Para cambiar de Sistema Operativo cambiar puerto 
  #en la siguiente línea: Win COM# linux /dev/ttyS# /dev/ttyUSB#
  # #=un número asignado por tu sistema.
  port='COM3'
  sync='\xAA\xA0\x55'
  SET_SERVO='\x01'
  GET_SERVO='\x02'
  SET_SPEED='\x03'
  SET_MODE='\x04'
  GET_MODE='\x05'
  SET_AD_CNT='\x06' #Controla el número de canales analógicos.
  GET_AD_CNT='\x07' #Devuelve el número de canales analógicos actuales.
  GET_INPUT='\X08' # Devuelve el estado de una entrada.
  GET_ADC='\X09' #Devuelve el valor de un canal analógico.
  GET_VERSION='\x0A' #Devuelve la versión del procesador seleccionado.
  GET_BULK='\x15' #Usado para test en fábriica.
  TEST='\X16' #Usado para test en fábrica.
  ser = serial.Serial(port, baudrate=115200, bytesize=8, parity='N', stopbits=2,timeout=1)

  if ser.isOpen():
print "Estado del puerto: Correcto."
print "Procedo a enviar modo del canal 1 y posiciones del mismo."
posicion = raw_input('Inserta un numero entre 400 y 2200:')
POS_SERVO = struct.pack('<h', 'posicion')
ser.write(sync+SET_MODE+'\x01\x01\x19')
ser.write(sync+SET_SERVO+'\x01\x02'+POS_SERVO)
time.sleep(1.6) 
ser.close
print "Todo el proceso completado correctamente."

   else:
print "El puertito está cerrado"

   print "Hasta Luego :D"

For the interest of people who have the same controler I’ll explain that 16-bit integer first three bytes are sync (\xAA\xA0\x55) then the type of command SET_SERVO (position) (\x01) then the channel 1-84 for 1 is (\x01) then a byte count in this case 2 (\x02) and the servo position low byte and then the high byte (POS_SERVO) (for example for 1500 \xDC\x05)

I don’t know how to solve it, because it’s not an argument in fact it is a value and I don’t know how to tell that to python.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:08:22+00:00Added an answer on June 10, 2026 at 10:08 pm

    You’re passing a string literal; you should be passing a value instead, indicated by using the bare name. But you’ll need to convert it to an integer before it can be handled.

    POS_SERVO = struct.pack('<h', int(posicion))
    

    You should consider validating the input though, to make sure that it’s the corect type and within the desired range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.