Python Forum
Pyserial Issues with Python3.7 and Fluke Multimeter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyserial Issues with Python3.7 and Fluke Multimeter
#1
Hello All,
I am having issues running a very simple code to a Fluke 8846A Multimeter.

very curious as to what is wrong with such a simple code.

Any help would be much appreciated

import serial
import time

ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize = 8
ser.stopbits = 1
ser.xonxoff = 0
ser.rtscts = 0
ser.timeout = None
ser.port = "COM4"  
parity=serial.PARITY_NONE

ser.open()
print ("Connection to Fluke successful")
ser.write('SENS:VOLT:RANG 10 \r\n')
time.sleep(2)
print(ser.readline(10))
ser.close()
print ("Connection Severed")
Reply
#2
Thank you Larz60+, i will be sure to correctly post in the future. Here is the error i am seeing.
Error:
Traceback (most recent call last): File "C:\Users\JeffF\Desktop\Python 3.7\Fluke 8846A Mesurement.py", line 18, in <module> ser.write('SENS:VOLT:RANG 10 \r\n') File "C:\Users\JeffF\AppData\Local\Programs\Python\Python37\lib\site-packages\serial\serialwin32.py", line 308, in write data = to_bytes(data) File "C:\Users\JeffF\AppData\Local\Programs\Python\Python37\lib\site-packages\serial\serialutil.py", line 63, in to_bytes raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq)) TypeError: unicode strings are not supported, please encode to bytes: 'SENS:VOLT:RANG 10 \r\n'
Looking up this error it seems that i should be using the following:
ser.write('SENS:VOLT:RANG 10 \r\n'.encoder())
but using this function causes an endless loop after the time sleep command
Reply
#3
Did your try without \r? AFAIK, only Windows uses \r\n as EOL sequence

One more thing I have noticed - you don't actually initialize parity attribute - it is not part of ser object, just a standalone variable - though this is the default value. And initializing all attributes during object creations looks like a proper way
ser = serial.Serial("COM4", 9600)
It looks that you use default values for the rest of parameters anyway - see the docs
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#4
Ive tried both \r\n and \n both still providing the same error. My machine is capable of taking in any either <CR>, <LF> or the combination of <CR><LF>

Adding the code you recommended above and eliminating my default settings provides
Error:
Traceback (most recent call last): File "C:\Users\JeffF\Desktop\Python 3.7\Fluke 8846A Mesurement.py", line 13, in <module> ser.open() File "C:\Users\JeffF\AppData\Local\Programs\Python\Python37\lib\site-packages\serial\serialwin32.py", line 41, in open raise SerialException("Port is already open.") serial.serialutil.SerialException: Port is already open.
Even when i try to manually close the port before running the code, the same error comes up so i have reverted back to my original settings
Reply
#5
(Jul-06-2018, 09:18 PM)jfisher930 Wrote: Even when i try to manually close the port before running the code, the same error comes up so i have reverted back to my original settings
I did not state that your original settings are the issue - I just pointed out that they are mostly redundant (only the port and baudtrate have non-default values). I prefer to write as little as possible code - but that's my lazy ass Tongue

But, after some research, I found that 3.7 is not listed as a supported version, the latest supported version is 3.6. Going for the latest and the greatest Python version without checking compatibility may be a major problem (just had a person complaining in another forum about numpy misbehaving in 3.7 - turned out he has installed the version for 3.6)
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#6
Quote:But, after some research, I found that 3.7 is not listed as a supported version, the latest supported version is 3.6. Going for the latest and the greatest Python version without checking compatibility may be a major problem (just had a person complaining in another forum about numpy misbehaving in 3.7 - turned out he has installed the version for 3.6)

I'm using Python 3.7 with numpy, numba, scipy, flask, pyserial, zmq, aiohttp, websockets, nidaqmx, multiprocessing, threading on Windows 10 in production. The only problem I have with pyserial is a dying port, but this happened also with Python 3.6. The com port I'm using is an integrated Arduino on the board. It should work also with other COM ports.

If you're able to open the port again, then send bytes and not a str.
ser.write(b'SENS:VOLT:RANG 10 \r\n')
or
ser.write('SENS:VOLT:RANG 10 \r\n'.encode())
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
[quote='DeaD_EyE' pid='51872' dateline='1530950771']
Quote:If you're able to open the port again, then send bytes and not a str.
ser.write(b'SENS:VOLT:RANG 10 \r\n')
or
ser.write('SENS:VOLT:RANG 10 \r\n'.encode())

I have tried both of the suggested approaches and it just causes a loop to occur at the readline for whatever reason.

Updated Code:
import serial
import time
 
ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize = 8
ser.stopbits = 1
ser.xonxoff = 0
ser.rtscts = 0
ser.timeout = None
ser.port = "COM4"  
parity=serial.PARITY_NONE
 
ser.open()
print ("Connection to Fluke successful")
ser.write('MEAS:VOLT:RANG 10 \r\n'.encode())
time.sleep(2)
print ("Time Sleep successful")
print(ser.readline())
ser.close()
print ("Connection Severed")
Output:
Connection to Fluke successful Time Sleep successful
Reply
#8
[Good evening, i am beginner to use python language. I have interested to get more detail for connecting fluke 8846A and computer. Can you provide more tutorial about that to let me learn?
Reply
#9
If you buy me one, I'll make the tutorial for you :-)

The main pain point are Bytes vs Strings when using transports like network or serial.
I guess this was also problem with his loop. Maybe he tried to compare strings and bytes of equality.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#10
can i email to you for more information?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020