Skip to main content

I am working with a project where iI need to read data from my device(i.e ADAM 4520)using serialserial to usbUSB converter. 
1st i, I tested with my PC using hyper terminal and with Raspberry Pi 3 using GtkTerm,it it is perfectly working. 
As both hyper terminal and gtkterm using asciiAscii and my device ADAM-4520 also understand asciiAscii,But But how to communicate through python code iI am not finding wayaway as iI am new to python and raspberry pi  ,please please guide me. Here

Here is my code:

import serial
import time
s=serial.Serial(port='/dev/ttyS0',
                baudrate=9600,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS,timeout=1)
st="#04"
st=''.join(str(ord(c)) for c in st)
x=st.encode('ascii')
while True:
   s.write(x)
   print(x)
   time.sleep(0.2)
   text=s.readline()
   temp=text.decode('ascii')
   #text=text.decode('utf-8')
      #text=text[5:-1]
   print(temp)
  

hereHere is my output:

354852
b''
354852
b''
354852
  

iI am receiving nothing. where aswhereas using gtkterm iI am getting a response.

 #04
>+261.27+310.83+049.09+206.77+126.81+049.79

#042
>+049.11

I am working with a project where i need to read data from my device(i.e ADAM 4520)using serial to usb converter. 1st i tested with my PC using hyper terminal and with Raspberry Pi 3 using GtkTerm,it is perfectly working. As both hyper terminal and gtkterm using ascii and my device ADAM-4520 also understand ascii,But how to communicate through python code i am not finding way as i am new to python and raspberry pi  ,please guide me. Here is my code

import serial
import time
s=serial.Serial(port='/dev/ttyS0',
                baudrate=9600,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS,timeout=1)
st="#04"
st=''.join(str(ord(c)) for c in st)
x=st.encode('ascii')
while True:
   s.write(x)
   print(x)
   time.sleep(0.2)
   text=s.readline()
   temp=text.decode('ascii')
   #text=text.decode('utf-8')
      #text=text[5:-1]
   print(temp)

here is my output

354852
b''
354852
b''
354852

i am receiving nothing. where as using gtkterm i am getting response.

 #04
>+261.27+310.83+049.09+206.77+126.81+049.79

#042
>+049.11

I am working with a project where I need to read data from my device(i.e ADAM 4520)using serial to USB converter. 
1st, I tested with my PC using hyper terminal and with Raspberry Pi 3 using GtkTerm, it is perfectly working. 
As both hyper terminal and gtkterm using Ascii and my device ADAM-4520 also understand Ascii, But how to communicate through python code I am not finding away as I am new to python and raspberry pi, please guide me.

Here is my code:

import serial
import time
s=serial.Serial(port='/dev/ttyS0',
                baudrate=9600,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS,timeout=1)
st="#04"
st=''.join(str(ord(c)) for c in st)
x=st.encode('ascii')
while True:
   s.write(x)
   print(x)
   time.sleep(0.2)
   text=s.readline()
   temp=text.decode('ascii')
   #text=text.decode('utf-8')
      #text=text[5:-1]
   print(temp)
  

Here is my output:

354852
b''
354852
b''
354852
  

I am receiving nothing. whereas using gtkterm I am getting a response.

 #04
>+261.27+310.83+049.09+206.77+126.81+049.79

#042
>+049.11
Made title more descriptive
Link
tlfong01
  • 4.8k
  • 3
  • 11
  • 24

how Rpi Python interfacing RS232 to send and receive ascii values using my Pi3?RS422/485 Converter Problem

Source Link
ram
  • 69
  • 1
  • 9

how to send and receive ascii values using my Pi3?

I am working with a project where i need to read data from my device(i.e ADAM 4520)using serial to usb converter. 1st i tested with my PC using hyper terminal and with Raspberry Pi 3 using GtkTerm,it is perfectly working. As both hyper terminal and gtkterm using ascii and my device ADAM-4520 also understand ascii,But how to communicate through python code i am not finding way as i am new to python and raspberry pi ,please guide me. Here is my code

import serial
import time
s=serial.Serial(port='/dev/ttyS0',
                baudrate=9600,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS,timeout=1)
st="#04"
st=''.join(str(ord(c)) for c in st)
x=st.encode('ascii')
while True:
   s.write(x)
   print(x)
   time.sleep(0.2)
   text=s.readline()
   temp=text.decode('ascii')
   #text=text.decode('utf-8')
      #text=text[5:-1]
   print(temp)

here is my output

354852
b''
354852
b''
354852

i am receiving nothing. where as using gtkterm i am getting response.

 #04
>+261.27+310.83+049.09+206.77+126.81+049.79

#042
>+049.11