Cannot read answer from telnet communication - python

I'm currently working on a little script that I found on GitHub, made by RoGeorge : https://github.com/RoGeorge/DS1054Z_screen_capture.
This script should allows me to get a screenshot of my digital storage oscilloscope (DS1054z from RIGOL).
So I've putted this script on my Raspberry Pi to have use it, but once everything was correctly setup, the script seems to receive nothing from my scope. This is surprising because : I can ping the scope and I can communicate with him by the telnet command on the terminal.
So I've made a little script (that I will put just below) that permit me to see if the Telnet library for Python work or not.
Result : It do not work when we went to read, but it's send without problem.
import telnetlib
tn = telnetlib.Telnet('193.168.1.2','5555')
tn.set_debuglevel(100)
tn.write("*idn?")
tn.read_until('\n',1)
Output :
>> Telnet(193.168.1.2,5555): send '*idn?'
>> ''
Is my code correct ? Did anyone have an idea of what is happening ?
Thanks in advance !
PS : I've tested the script from GitHub and mine just above on my Windows 10 PC also. Don't work.

When you send a command you have to end it with a newline like this:
tn.write("*idn?\n")

Related

Can't seem to write VT220 commands through pyserial

So I have this script that connects to a linux machine while it's booting through serial to change bios settings. It's a messy bash script that connects through minicom. Thought I'd clean things up and remake the script with pyserial.
So far the basic VT100 commands work. Like '\x1B[A' for up arrow key, '\r' for enter, '\x1B' for escape. Good, that covers most the navigating and changing bios settings.
But the VT220 commands (which works in the bash script that uses minicom) don't work at all. Debug shows they get sent but they do nothing. Examples being '\x1B[3~' for delete or '\x1B[18~' for F7. I need these to actually enter the bios screen.
For the delete button I tried multiple variations:
b'\x1B[3~'
b'\x1B\x5B\x33\x7E'
'\[3~'
b'\[3~' (last two are using the actual ESC character that isn't showing up right here)
None of em work.I thought maybe I needed a different code for the python environment, so I tried firing up miniterm and sending the delete key manually with the debug filter. It works and miniterm debug says it sent '\x1B[3~', so I'm definitely using the right code.
For some extra information, I'm setting up the serial port with defaults and using the basic serial.write() function to send the command.
It doesn't really make sense to me that VT220 would directly be the issue since it should be entirely remote dependent. I have a feeling that the longer commands are maybe being sent as multiple steps, so the terminal is only receiving '\x1B[3'+'~' and not '\x1B[3~' but that's just a baseless hunch and I don't know how to verify that.
Any ideas?

How to implement a server for a python scripts testing system (with stdio)?

Could you advice how to implement server for scripts testing such as like on coursera.
There is input, where students attach their script.
And next steps are quite foggy for me as I see them:
server gets script
server checks extension of script
server runs bash script with testing data(std input), waits for result >> creates output file
output file is compared with solution
server sends response
Is it right? Are there any other solutions?
The answer is from the local stackoverflow. I think that is enough to start from here: https://github.com/DMOJ/judge.

BLE 4.2 RN4870 Command mode confih?guration

While working on one RN4870 modules, I came across this problem. How do you set the module into command mode when it boots? What is the command set to get it connected to another module automatically onces it boots.
I tried to make a script in Python to do this.
$$$
+
LB
C,0,82938DFF897 (C, public/random, address)
Both of them have been bonded and upon boot I have to connect through UART and go to command mode and try C2/C3 to connect one another. Is there a GPIO configuration to do the same? I'm kinda new to this module any help appreciated.
Your command should be ok
$$$ enter command mode
You need a delay to enter in command mode
LB ( I think you don't need the list of bonded device)
C,0,MAC ADDRESS is correct to connect to the remote bluetooth device.
I use then CI to start client operation
LC to read all the service and chracteristics
CHR Handle to read
CHW Handle to write
I hope is useful
Best Regards

How to redirect Python print commands to putty SSH console?

after many unsuccessful researches I've decided to ask my question here so maybe someone will provide me an answer or a lead for a problem I got.
I have a Python script that runs as a background process on an embedded device (the OS is a Linux distro). This script do important measurements and because of that, it can not be terminated or restarted.
I was wondering if it was possible to implement a chunk of code that will redirect the print() outputs to a Putty SSH console when we send it a command via a messaging protocol (MQTT).
So the situation will be like this:
Device receive a command, set a variable to 1
Print() outputs will now be visible on the current root session opened by Putty SSH client.
I don't know if it is possible but I'm opened to suggestions.
Thank you in advance for your answers, and sorry for my bad english.
As suggested by GhostCat, I've decided to go for a logging solution so anyone who can connect to the device by SSH can just "tail -F" the log file and see the debug messages.
I've removed all the print() statements in the code and replaced them by logging calls (which is, indeed, a more professional approach)
If someone had the same question as I, you can read this : http://www.blog.pythonlibrary.org/2014/02/11/python-how-to-create-rotating-logs/
or this : https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
to help you solve your issue.
Thanks again to GhostCat and Tripleee for their help.

Send file over serial port from Python

I'm trying to send a file (a .jpg image in this case) over a serial port.
Currently it works by calling an external script:
subprocess.Popen(['./sendFile.sh','myImage.jpg']).communicate()
where sendFile.sh is:
cp /home/pi/$1 /dev/ttyAMA0
This method works but is somehow unstable. Sometimes my Python program stops after the transferring the file.
I'm wondering if there's a way to do this in Python instead of calling a script for help? I searched about XMODEM, but it seems like both ends must have it installed. I'm sending the image to a GPRS chip, which doesn't allow me to modify any code on it. So installing something to the receiving end is impossible.
import serial
s = serial.Serial("/dev/ttyAMA0")
s.write(open("target.txt","rb").read())
You can use os.open to directly open a dev:
f = os.open('/dev/ttyAMA0', os.O_RDWR)
f.write(open("myImage.jpg").read))
f.close()

Categories

Resources