Cannot read data from ELM327 device with PySerial - pyserial

I am trying to communicate with a ELM327 device using PySerial. However I am not able to read any data from the device. Here is the results of what I have tried in the terminal interpreter.
>>> import serial
>>> ELM327 = serial.Serial('/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0', 38400, timeout=5)
>>> ELM327.write(b'AT Z\r\n')
6
>>> ELM327.read()
b''
>>> ELM327.write(b'AT RV\r\n');
7
>>> ELM327.read()
b''
>>> ELM327.write(b'AT\r\n');
4
>>> ELM327.read()
b''
I have tried the same by changing the device to /dev/ttyUSB0 but get exactly the same results. I am running this as the super user as well. I also tried swapping out the \r\n with just \r and \n respectively. It is a ELM327 v1.5a device I'm trying to connect to. Any insight is much appreciated.

This looks like you are not using the correct bitrate. You are sending the correct commands (although I'd skip the spaces and the \n), but the device is obviously not correctly receiving them otherwise it would have ECHOed them to you.

Related

Wrongly formated numbers in CSV export from Grafana graphs

One of our customers has strange problem with CSV export from Grafana (3.1.1 - we still run this "ancient" version due to some other dependencies).
When they export numbers from graph showing rates as percentage, they get repeatedly strangely formatted results:
2018-09-11T00:00:00.000Z;44.773.054;39.500.635;37.322.795
2018-09-12T00:00:00.000Z;51.743.917;4.409.222;37.691.824
2018-09-13T00:00:00.000Z;1.421.662;4.341.522;3.631.485
Proper results should look like this:
2018-09-11T00:00:00.000Z;4.4773054;3.9500635;3.7322795
2018-09-12T00:00:00.000Z;5.1743917;4.409222;3.7691824
2018-09-13T00:00:00.000Z;1.421662;4.341522;3.631485
As you can see - digits are generally OK, but decimal point is gone and number is formatted as huge number with separators for thousands, millions etc.
Client uses Windows 7 Enterprise, Latest Chrome and OS is set to German lang. Our best guess is that it could be caused by some setting of LOCALs because German settings are different from UK/US settings. But we are unable to simulate it on any of our computers.
Maybe some of you already encountered something like this? I tried to google for it but did not find so far anything close enough to this. Thank you very much.
CSV is made in the browser + numeric values are formated by toLocaleString function, which uses browser local setting. You need to change browser local configuration.
x = 123456789
console.log('Original: ' + x)
console.log('en-EN: ' + x.toLocaleString('en-EN'))
console.log('de-DE: ' + x.toLocaleString('de-DE'))

Batch file doesn't read flags correctly

I've got a little batch file and it looks like this:
.\batchisp.exe –device at32uc3b1512 –hardware usb –operation erase f memory flash blankcheck loadbuffer G3Pro_USB.hex program verify start reset 0
The whole line is fine and works correctly if I run it straight in PowerShell. However, if I run the batch file, it runs this:
.\batchisp.exe ΓÇôdevice at32uc3b1512 ΓÇôhardware usb ΓÇôoperation erase f memory flash blankcheck loadbuffer G3Pro_USB.hex program verify start reset 0
Which does not work, because as you can see, the -'s have changed into ΓÇô's... Can anybody tell me why this is and how to fix it?
This is because the – marks are not - characters. They are actually endashes. These usually are caused by Word's automatic en/emdashing.
Powershell is smart enough to convert the endashes to dashes as "arguments", but cmd is not.
To fix this issue, replace – with -. A regex search/replace that catches all the alternative dash types that works in notepad++ is: [–—‒] to -.

Forcing Tesseract to give some answer

I am trying to recognize one line of handwritten digits. Currently I do some preprocessing with Python and OpenCV, split the image into connected components and feed these components to Tesseract with PSM=10 (page segmentation mode, 10 is "treat the image like a single character") and character whitelist restricted to "0123456789". I expect Tesseract to return garbage where my connected component segmentation fails and to return exactly one digit when my segmentation succeeds. Tesseract often returns nothing at all.
I have tried both pytesseract and python-tesseract as a Tesseract interface for Python. Pytesseract works by locating the executable tesseract.exe, running it with suitable parameters from the shell and collecting the answer. This is how I found out about my problem. After that, I tried python-tesseract, which implements a full-blown C API. Naturally, the result was the same.
Below is a sample of 5 images I fed into Tesseract separately (I've also uploaded the same images as separate files here):
I get 1,*,4,*,* on these images, * meaning that Tesseract returned only whitespace.
With other page segmentation modes, I get the following:
PSM_SINGLE_CHAR: 1*4**
PSM_SINGLE_BLOCK_VERT_TEXT: **43*
PSM_CIRCLE_WORD: 11***
PSM_SINGLE_LINE: 11491
PSM_AUTO: *****
PSM_SPARSE_TEXT: *****
PSM_SINGLE_WORD: 11499
PSM_AUTO_ONLY: *****
PSM_SINGLE_COLUMN: *****
PSM_SPARSE_TEXT_OS: *****
PSM_SINGLE_BLOCK: 11499
PSM_OSD_ONLY: *****
PSM_AUTO_OSD: *****
PSM_COUNT: 11499
Weirdly, when I run tesseract image.png image -l eng -psm 10 digits-only against these images, it returns *,*,4,9,*. (digits-only is tessedit_char_whitelist 0123456789)
How do I force Tesseract to give me some answer instead of nothing at all?

Send Ctrl+Z to serial port via command line

I am trying to send the following to the COM1 serial port via command line using ECHO or similar (I've also tried downloading a small program called serialsend, but I am stuck with how to send the equivalent of CTRL+Z. This is to send a SMS message via a Siemens TC35 GAM module. I am able to do it via Hyperterminal as a test and it works fine, but I cannot figure out how to send the CTRL+Z at the end to confirm the ned of the message.
This is what I have:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
Now, after Hello, which is the message I want to send, I have to send CTRL+Z. But cannot figure out how to do it, I have tried this:
AT
AT+CMGF=1
AT+CMSG="+xxxxxxxxxxx"
HELLO
\x1A
As I read somehwere that this would be the equivalent of doing it, but it hasnt worked.
Can anyone help me with this? I have found solutions, but they are not command line, which is what I need.
I have also tried using this format:
ECHO AT > COM1:
But as I don't know how to send CTRL+Z I don't know if it is working.
I wrote the free command line program SerialSend that you mentioned. Since this question was originally posted, I've added an extra feature that allows arbitrary byte values to be included (in hex format) in the text you're sending via the serial port. For example, to send Ctrl-Z (26 decimal, 0x1A hex), just use the following command:
SerialSend /hex "\x1a"
Port name/number, baudrate, etc can be configured with additional command line arguments. For example,
SerialSend /baudrate 9600 /devnum 2 /hex "\x1a"
For more details, see the SerialSend home page.
Hope that helps!
Ted
Use this:
port.Write(txt_msgbox.Text + char.ConvertFromUtf32(26));
It works :)
type this command Serial.println((char)26); in Arduino code ... one square box will appear on serial monitor. Copy that square and paste in Notepad++. It will be displayed as SUB with black background. wheneever you want to type cntrl+z, just copy this SUB and paste in serial monitor. It works.

pexpect parse router output

I've got a couple of pexpect lines to log onto a cisco router, and issue the show arp command. I then exit the router, having stored the data into the variable myARP (myARP=child.before)
When I then try and loop over the object (for lines in myARP: print(lines), the info is displayed 1 character per line
l
i
k
e
t
h
i
s
Apologies as this is probably a very basic question, but why can't I display as it is shown if I issue the command manually? Is it to do with the streaming nature of the telnet connection? How can this be resolved???
OK fixed - due to pexpects handling of line endings (/n/r) I think. Read Noahs usage docs for more info